| 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.IEUserDataTest'); |
| 16 |
goog.setTestOnly('goog.storage.mechanism.IEUserDataTest'); |
| 17 |
|
| 18 |
goog.require('goog.storage.mechanism.IEUserData'); |
| 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 |
|
| 28 |
function setUp() { |
| 29 |
var ieUserData = new goog.storage.mechanism.IEUserData('test'); |
| 30 |
if (ieUserData.isAvailable()) { |
| 31 |
mechanism = ieUserData; |
| 32 |
// There should be at least 32 KiB. |
| 33 |
minimumQuota = 32 * 1024; |
| 34 |
mechanism_shared = new goog.storage.mechanism.IEUserData('test'); |
| 35 |
mechanism_separate = new goog.storage.mechanism.IEUserData('test2'); |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
function tearDown() { |
| 40 |
if (!!mechanism) { |
| 41 |
mechanism.clear(); |
| 42 |
mechanism = null; |
| 43 |
} |
| 44 |
if (!!mechanism_shared) { |
| 45 |
mechanism_shared.clear(); |
| 46 |
mechanism_shared = null; |
| 47 |
} |
| 48 |
if (!!mechanism_separate) { |
| 49 |
mechanism_separate.clear(); |
| 50 |
mechanism_separate = null; |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
function testAvailability() { |
| 55 |
if (goog.userAgent.IE && !goog.userAgent.isDocumentModeOrHigher(9)) { |
| 56 |
assertNotNull(mechanism); |
| 57 |
assertTrue(mechanism.isAvailable()); |
| 58 |
assertNotNull(mechanism_shared); |
| 59 |
assertTrue(mechanism_shared.isAvailable()); |
| 60 |
assertNotNull(mechanism_separate); |
| 61 |
assertTrue(mechanism_separate.isAvailable()); |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
function testEncoding() { |
| 66 |
function assertEncodingPair(cleartext, encoded) { |
| 67 |
assertEquals( |
| 68 |
encoded, goog.storage.mechanism.IEUserData.encodeKey_(cleartext)); |
| 69 |
assertEquals( |
| 70 |
cleartext, goog.storage.mechanism.IEUserData.decodeKey_(encoded)); |
| 71 |
} |
| 72 |
assertEncodingPair('simple', '_simple'); |
| 73 |
assertEncodingPair( |
| 74 |
'aa.bb%cc!\0$\u4e00.', '_aa.2Ebb.25cc.21.00.24.E4.B8.80.2E'); |
| 75 |
} |