html5sessionstorage_test.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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.HTML5SessionStorageTest');
  15. goog.setTestOnly('goog.storage.mechanism.HTML5SessionStorageTest');
  16. goog.require('goog.storage.mechanism.HTML5SessionStorage');
  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 sessionStorage = new goog.storage.mechanism.HTML5SessionStorage();
  27. if (sessionStorage.isAvailable()) {
  28. mechanism = sessionStorage;
  29. // There should be at least 2 MiB.
  30. minimumQuota = 2 * 1024 * 1024;
  31. mechanism_shared = new goog.storage.mechanism.HTML5SessionStorage();
  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. window.location.protocol != 'file:' ||
  48. goog.userAgent.IE && goog.userAgent.isVersionOrHigher('8')) {
  49. assertNotNull(mechanism);
  50. assertTrue(mechanism.isAvailable());
  51. assertNotNull(mechanism_shared);
  52. assertTrue(mechanism_shared.isAvailable());
  53. }
  54. }