| 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 |
|
| 15 |
goog.provide('goog.storage.mechanism.HTML5LocalStorageTest'); |
| 16 |
goog.setTestOnly('goog.storage.mechanism.HTML5LocalStorageTest'); |
| 17 |
|
| 18 |
goog.require('goog.storage.mechanism.HTML5LocalStorage'); |
| 19 |
/** @suppress {extraRequire} */ |
| 20 |
goog.require('goog.storage.mechanism.mechanismSeparationTester'); |
| 21 |
/** @suppress {extraRequire} */ |
| 22 |
goog.require('goog.storage.mechanism.mechanismSharingTester'); |
| 23 |
/** @suppress {extraRequire} */ |
| 24 |
goog.require('goog.storage.mechanism.mechanismTestDefinition'); |
| 25 |
goog.require('goog.testing.jsunit'); |
| 26 |
goog.require('goog.userAgent'); |
| 27 |
goog.require('goog.userAgent.product'); |
| 28 |
|
| 29 |
function shouldRunTests() { |
| 30 |
// Disabled in Safari because Apple SafariDriver runs tests in Private |
| 31 |
// Browsing mode, and Safari does not permit writing to localStorage in |
| 32 |
// Private Browsing windows. |
| 33 |
return !goog.userAgent.product.SAFARI; |
| 34 |
} |
| 35 |
|
| 36 |
function setUp() { |
| 37 |
var localStorage = new goog.storage.mechanism.HTML5LocalStorage(); |
| 38 |
if (localStorage.isAvailable()) { |
| 39 |
mechanism = localStorage; |
| 40 |
// There should be at least 2 MiB. |
| 41 |
minimumQuota = 2 * 1024 * 1024; |
| 42 |
mechanism_shared = new goog.storage.mechanism.HTML5LocalStorage(); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
function tearDown() { |
| 47 |
if (!!mechanism) { |
| 48 |
mechanism.clear(); |
| 49 |
mechanism = null; |
| 50 |
} |
| 51 |
if (!!mechanism_shared) { |
| 52 |
mechanism_shared.clear(); |
| 53 |
mechanism_shared = null; |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
function testAvailability() { |
| 58 |
if (goog.userAgent.WEBKIT && goog.userAgent.isVersionOrHigher('532.5') || |
| 59 |
goog.userAgent.GECKO && goog.userAgent.isVersionOrHigher('1.9.1') || |
| 60 |
goog.userAgent.IE && goog.userAgent.isVersionOrHigher('8')) { |
| 61 |
assertNotNull(mechanism); |
| 62 |
assertTrue(mechanism.isAvailable()); |
| 63 |
assertNotNull(mechanism_shared); |
| 64 |
assertTrue(mechanism_shared.isAvailable()); |
| 65 |
} |
| 66 |
} |