html5localstorage_test.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2011 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. goog.provide('goog.storage.mechanism.HTML5LocalStorageTest');
  15. goog.setTestOnly('goog.storage.mechanism.HTML5LocalStorageTest');
  16. goog.require('goog.storage.mechanism.HTML5LocalStorage');
  17. /** @suppress {extraRequire} */
  18. goog.require('goog.storage.mechanism.mechanismSeparationTester');
  19. /** @suppress {extraRequire} */
  20. goog.require('goog.storage.mechanism.mechanismSharingTester');
  21. /** @suppress {extraRequire} */
  22. goog.require('goog.storage.mechanism.mechanismTestDefinition');
  23. goog.require('goog.testing.jsunit');
  24. goog.require('goog.userAgent');
  25. function setUp() {
  26. var localStorage = new goog.storage.mechanism.HTML5LocalStorage();
  27. if (localStorage.isAvailable()) {
  28. mechanism = localStorage;
  29. // There should be at least 2 MiB.
  30. minimumQuota = 2 * 1024 * 1024;
  31. mechanism_shared = new goog.storage.mechanism.HTML5LocalStorage();
  32. }
  33. }
  34. function tearDown() {
  35. if (!!mechanism) {
  36. mechanism.clear();
  37. mechanism = null;
  38. }
  39. if (!!mechanism_shared) {
  40. mechanism_shared.clear();
  41. mechanism_shared = null;
  42. }
  43. }
  44. function testAvailability() {
  45. if (goog.userAgent.WEBKIT && goog.userAgent.isVersionOrHigher('532.5') ||
  46. goog.userAgent.GECKO && goog.userAgent.isVersionOrHigher('1.9.1') ||
  47. goog.userAgent.IE && goog.userAgent.isVersionOrHigher('8')) {
  48. assertNotNull(mechanism);
  49. assertTrue(mechanism.isAvailable());
  50. assertNotNull(mechanism_shared);
  51. assertTrue(mechanism_shared.isAvailable());
  52. }
  53. }