Bug 729940 - Part 0: Fix {local,session}Storage tests which rely on hashtable iteration order. r=honzab
authorJustin Lebar <justin.lebar@gmail.com>
Fri, 02 Mar 2012 18:43:50 -0500
changeset 88183 c228a0a6f2ceb822edc5700c9a73b89d9159a3cf
parent 88182 2b4aed5ee94e035a7cee32c308ca9b8590a426bb
child 88184 065dc9204d09edfd1d9f90a29a665dfcc6846297
push id6725
push userryanvm@gmail.com
push dateFri, 02 Mar 2012 23:44:09 +0000
treeherdermozilla-inbound@c228a0a6f2ce [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershonzab
bugs729940
milestone13.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 729940 - Part 0: Fix {local,session}Storage tests which rely on hashtable iteration order. r=honzab
dom/tests/mochitest/localstorage/test_localStorageBase.html
dom/tests/mochitest/localstorage/test_localStorageBasePrivateBrowsing.html
dom/tests/mochitest/localstorage/test_localStorageBaseSessionOnly.html
dom/tests/mochitest/sessionstorage/test_sessionStorageBase.html
--- a/dom/tests/mochitest/localstorage/test_localStorageBase.html
+++ b/dom/tests/mochitest/localstorage/test_localStorageBase.html
@@ -89,36 +89,39 @@ function startTest()
   localStorage.setItem("key1", "value1");
   is(localStorage.length, 1, "The storage has one key-value pair");
   is(localStorage.key(0), "key1");
   is(localStorage.getItem("key1"), "value1");
 
   // add a second key
   localStorage.setItem("key2", "value2");
   is(localStorage.length, 2, "The storage has two key-value pairs");
-  is(localStorage.key(1), "key1"); // This test might not be accurate because order is not preserved
-  is(localStorage.key(0), "key2");
   is(localStorage.getItem("key1"), "value1");
   is(localStorage.getItem("key2"), "value2");
+  var firstKey = localStorage.key(0);
+  var secondKey = localStorage.key(1);
+  ok((firstKey == 'key1' && secondKey == 'key2') ||
+     (firstKey == 'key2' && secondKey == 'key1'),
+     'Both keys should be present.');
 
   // change the second key
   localStorage.setItem("key2", "value2-2");
   is(localStorage.length, 2, "The storage has two key-value pairs");
-  is(localStorage.key(1), "key1"); // After key value changes the order must be preserved
-  is(localStorage.key(0), "key2");
+  is(localStorage.key(0), firstKey); // After key value changes the order must be preserved
+  is(localStorage.key(1), secondKey);
   checkException(function() {localStorage.key(-1);}, INDEX_SIZE_ERR);
   checkException(function() {localStorage.key(2);}, INDEX_SIZE_ERR);
   is(localStorage.getItem("key1"), "value1");
   is(localStorage.getItem("key2"), "value2-2");
 
   // change the first key
   localStorage.setItem("key1", "value1-2");
   is(localStorage.length, 2, "The storage has two key-value pairs");
-  is(localStorage.key(1), "key1"); // After key value changes the order must be preserved
-  is(localStorage.key(0), "key2");
+  is(localStorage.key(0), firstKey); // After key value changes the order must be preserved
+  is(localStorage.key(1), secondKey);
   checkException(function() {localStorage.key(-1);}, INDEX_SIZE_ERR);
   checkException(function() {localStorage.key(2);}, INDEX_SIZE_ERR);
   is(localStorage.getItem("key1"), "value1-2");
   is(localStorage.getItem("key2"), "value2-2");
 
   // remove the second key
   localStorage.removeItem("key2");
   is(localStorage.length, 1, "The storage has one key-value pair");
--- a/dom/tests/mochitest/localstorage/test_localStorageBasePrivateBrowsing.html
+++ b/dom/tests/mochitest/localstorage/test_localStorageBasePrivateBrowsing.html
@@ -108,36 +108,39 @@ function doTest()
   localStorage.setItem("key1", "value1");
   is(localStorage.length, 1, "The storage has one key-value pair");
   is(localStorage.key(0), "key1");
   is(localStorage.getItem("key1"), "value1");
 
   // add a second key
   localStorage.setItem("key2", "value2");
   is(localStorage.length, 2, "The storage has two key-value pairs");
-  is(localStorage.key(1), "key1"); // This test might not be accurate because order is not preserved
-  is(localStorage.key(0), "key2");
   is(localStorage.getItem("key1"), "value1");
   is(localStorage.getItem("key2"), "value2");
+  var firstKey = localStorage.key(0);
+  var secondKey = localStorage.key(1);
+  ok((firstKey == 'key1' && secondKey == 'key2') ||
+     (firstKey == 'key2' && secondKey == 'key1'),
+     'Both keys should be present.');
 
   // change the second key
   localStorage.setItem("key2", "value2-2");
   is(localStorage.length, 2, "The storage has two key-value pairs");
-  is(localStorage.key(1), "key1"); // After key value changes the order must be preserved
-  is(localStorage.key(0), "key2");
+  is(localStorage.key(0), firstKey); // After key value changes the order must be preserved
+  is(localStorage.key(1), secondKey);
   checkException(function() {localStorage.key(-1);}, INDEX_SIZE_ERR);
   checkException(function() {localStorage.key(2);}, INDEX_SIZE_ERR);
   is(localStorage.getItem("key1"), "value1");
   is(localStorage.getItem("key2"), "value2-2");
 
   // change the first key
   localStorage.setItem("key1", "value1-2");
   is(localStorage.length, 2, "The storage has two key-value pairs");
-  is(localStorage.key(1), "key1"); // After key value changes the order must be preserved
-  is(localStorage.key(0), "key2");
+  is(localStorage.key(0), firstKey); // After key value changes the order must be preserved
+  is(localStorage.key(1), secondKey);
   checkException(function() {localStorage.key(-1);}, INDEX_SIZE_ERR);
   checkException(function() {localStorage.key(2);}, INDEX_SIZE_ERR);
   is(localStorage.getItem("key1"), "value1-2");
   is(localStorage.getItem("key2"), "value2-2");
 
   // remove the second key
   localStorage.removeItem("key2");
   is(localStorage.length, 1, "The storage has one key-value pair");
--- a/dom/tests/mochitest/localstorage/test_localStorageBaseSessionOnly.html
+++ b/dom/tests/mochitest/localstorage/test_localStorageBaseSessionOnly.html
@@ -99,36 +99,39 @@ function startTest()
   localStorage.setItem("key1", "value1");
   is(localStorage.length, 1, "The storage has one key-value pair");
   is(localStorage.key(0), "key1");
   is(localStorage.getItem("key1"), "value1");
 
   // add a second key
   localStorage.setItem("key2", "value2");
   is(localStorage.length, 2, "The storage has two key-value pairs");
-  is(localStorage.key(1), "key1"); // This test might not be accurate because order is not preserved
-  is(localStorage.key(0), "key2");
   is(localStorage.getItem("key1"), "value1");
   is(localStorage.getItem("key2"), "value2");
+  var firstKey = localStorage.key(0);
+  var secondKey = localStorage.key(1);
+  ok((firstKey == 'key1' && secondKey == 'key2') ||
+     (firstKey == 'key2' && secondKey == 'key1'),
+     'Both keys should be present.');
 
   // change the second key
   localStorage.setItem("key2", "value2-2");
   is(localStorage.length, 2, "The storage has two key-value pairs");
-  is(localStorage.key(1), "key1"); // After key value changes the order must be preserved
-  is(localStorage.key(0), "key2");
+  is(localStorage.key(0), firstKey); // After key value changes the order must be preserved
+  is(localStorage.key(1), secondKey);
   checkException(function() {localStorage.key(-1);}, INDEX_SIZE_ERR);
   checkException(function() {localStorage.key(2);}, INDEX_SIZE_ERR);
   is(localStorage.getItem("key1"), "value1");
   is(localStorage.getItem("key2"), "value2-2");
 
   // change the first key
   localStorage.setItem("key1", "value1-2");
   is(localStorage.length, 2, "The storage has two key-value pairs");
-  is(localStorage.key(1), "key1"); // After key value changes the order must be preserved
-  is(localStorage.key(0), "key2");
+  is(localStorage.key(0), firstKey); // After key value changes the order must be preserved
+  is(localStorage.key(1), secondKey);
   checkException(function() {localStorage.key(-1);}, INDEX_SIZE_ERR);
   checkException(function() {localStorage.key(2);}, INDEX_SIZE_ERR);
   is(localStorage.getItem("key1"), "value1-2");
   is(localStorage.getItem("key2"), "value2-2");
 
   // remove the second key
   localStorage.removeItem("key2");
   is(localStorage.length, 1, "The storage has one key-value pair");
--- a/dom/tests/mochitest/sessionstorage/test_sessionStorageBase.html
+++ b/dom/tests/mochitest/sessionstorage/test_sessionStorageBase.html
@@ -91,36 +91,39 @@ function startTest()
   sessionStorage.setItem("key1", "value1");
   is(sessionStorage.length, 1, "The storage has one key-value pair");
   is(sessionStorage.key(0), "key1");
   is(sessionStorage.getItem("key1"), "value1");
 
   // add a second key
   sessionStorage.setItem("key2", "value2");
   is(sessionStorage.length, 2, "The storage has two key-value pairs");
-  is(sessionStorage.key(1), "key1"); // This test might not be accurate because order is not preserved
-  is(sessionStorage.key(0), "key2");
   is(sessionStorage.getItem("key1"), "value1");
   is(sessionStorage.getItem("key2"), "value2");
+  var firstKey = sessionStorage.key(0);
+  var secondKey = sessionStorage.key(1);
+  ok((firstKey == 'key1' && secondKey == 'key2') ||
+     (firstKey == 'key2' && secondKey == 'key1'),
+     'Both keys should be present.');
 
   // change the second key
   sessionStorage.setItem("key2", "value2-2");
   is(sessionStorage.length, 2, "The storage has two key-value pairs");
-  is(sessionStorage.key(1), "key1"); // After key value changes the order must be preserved
-  is(sessionStorage.key(0), "key2");
+  is(sessionStorage.key(0), firstKey); // After key value changes the order must be preserved
+  is(sessionStorage.key(1), secondKey);
   checkException(function() {sessionStorage.key(-1);}, INDEX_SIZE_ERR);
   checkException(function() {sessionStorage.key(2);}, INDEX_SIZE_ERR);
   is(sessionStorage.getItem("key1"), "value1");
   is(sessionStorage.getItem("key2"), "value2-2");
 
   // change the first key
   sessionStorage.setItem("key1", "value1-2");
   is(sessionStorage.length, 2, "The storage has two key-value pairs");
-  is(sessionStorage.key(1), "key1"); // After key value changes the order must be preserved
-  is(sessionStorage.key(0), "key2");
+  is(sessionStorage.key(0), firstKey); // After key value changes the order must be preserved
+  is(sessionStorage.key(1), secondKey);
   checkException(function() {sessionStorage.key(-1);}, INDEX_SIZE_ERR);
   checkException(function() {sessionStorage.key(2);}, INDEX_SIZE_ERR);
   is(sessionStorage.getItem("key1"), "value1-2");
   is(sessionStorage.getItem("key2"), "value2-2");
 
   // remove the second key
   sessionStorage.removeItem("key2");
   is(sessionStorage.length, 1, "The storage has one key-value pair");