dom/tests/mochitest/localstorage/test_localStorageKeyOrder.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/tests/mochitest/localstorage/test_localStorageKeyOrder.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,73 @@
     1.4 +<html xmlns="http://www.w3.org/1999/xhtml">
     1.5 +<head>
     1.6 +<title>localStorage key order test</title>
     1.7 +
     1.8 +<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     1.9 +<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.10 +
    1.11 +<!--
    1.12 +  Check we preserve order of keys in localStorage when
    1.13 +  keys are just modified. When a new key is added or
    1.14 +  a key is removed order is again unspecified.
    1.15 +-->
    1.16 +
    1.17 +<script type="text/javascript">
    1.18 +
    1.19 +function startTest()
    1.20 +{
    1.21 +  try
    1.22 +  {
    1.23 +    var keyNames = new Array;
    1.24 +    localStorage.a = "1";
    1.25 +    localStorage.b = "2";
    1.26 +    localStorage.c = "3";
    1.27 +    localStorage.d = "4";
    1.28 +    localStorage.e = "5";
    1.29 +
    1.30 +    is(localStorage.a, "1", "a = 1");
    1.31 +    is(localStorage.b, "2", "b = 2");
    1.32 +    is(localStorage.c, "3", "c = 3");
    1.33 +    is(localStorage.d, "4", "d = 4");
    1.34 +    is(localStorage.e, "5", "e = 5");
    1.35 +    is(localStorage.length, 5, "length = 5");
    1.36 +
    1.37 +    for (var i = 0; i < localStorage.length; ++i)
    1.38 +      keyNames[i] = localStorage.key(i);
    1.39 +
    1.40 +    localStorage.a = "10";
    1.41 +    localStorage.b = "20";
    1.42 +    localStorage.c = "30";
    1.43 +    localStorage.d = "40";
    1.44 +    localStorage.e = "50";
    1.45 +
    1.46 +    is(localStorage.a, "10", "a = 10");
    1.47 +    is(localStorage.b, "20", "b = 20");
    1.48 +    is(localStorage.c, "30", "c = 30");
    1.49 +    is(localStorage.d, "40", "d = 40");
    1.50 +    is(localStorage.e, "50", "e = 50");
    1.51 +    is(localStorage.length, 5, "length = 5");
    1.52 +
    1.53 +    for (var i = 0; i < localStorage.length; ++i)
    1.54 +      is(keyNames[i], localStorage.key(i), "key "+keyNames[i]+" on same index");
    1.55 +
    1.56 +    keyNamesStringify = "[\"" + keyNames.join("\",\"") + "\"]";
    1.57 +    frame.location = "http://mochi.test:8888/tests/dom/tests/mochitest/localstorage/frameOrder.html?" +
    1.58 +      keyNamesStringify;
    1.59 +  }
    1.60 +  catch (ex)
    1.61 +  {
    1.62 +    localStorage.clear();
    1.63 +    throw ex;
    1.64 +  }
    1.65 +}
    1.66 +
    1.67 +SimpleTest.waitForExplicitFinish();
    1.68 +
    1.69 +</script>
    1.70 +
    1.71 +</head>
    1.72 +
    1.73 +<body onload="startTest();">
    1.74 +  <iframe src="" name="frame"></frame>
    1.75 +</body>
    1.76 +</html>

mercurial