ieuserdata_test.js 2.5 KB

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