Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | <html xmlns="http://www.w3.org/1999/xhtml"> |
michael@0 | 2 | <head> |
michael@0 | 3 | <title>bug 600307</title> |
michael@0 | 4 | |
michael@0 | 5 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 6 | <script type="text/javascript" src="localStorageCommon.js"></script> |
michael@0 | 7 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 8 | |
michael@0 | 9 | <script type="text/javascript"> |
michael@0 | 10 | |
michael@0 | 11 | /* |
michael@0 | 12 | This is strictly implementation specific test for dom storage code from bug 600307. |
michael@0 | 13 | It exercises code for asynchronous data flushing with regard to cache life time and its preload. |
michael@0 | 14 | |
michael@0 | 15 | "flush + reload" means to tell the database to store all pending data then wipe the cached content and reload it from the db |
michael@0 | 16 | |
michael@0 | 17 | "reload" only means to simulate situation when there is a pending flush for an origin but a new cache is about to preload |
michael@0 | 18 | which is a corner case happening rarely ; this helps check the next preload operation will load correct data from the database anyway |
michael@0 | 19 | |
michael@0 | 20 | Case 1: set | flush + reload | remove | set | remove | flush + reload | get ?= null |
michael@0 | 21 | checks coalescing optimization for single key changes does work correctly for repeated removals of a key |
michael@0 | 22 | |
michael@0 | 23 | Case 2: set | set | clear | flush + reload | count ?= 0 |
michael@0 | 24 | checks whether clear operation superseeds setting keys, the database must be empty for the origin |
michael@0 | 25 | |
michael@0 | 26 | Case 3: set | set | clear | reload | count ?= 0 |
michael@0 | 27 | check the corner case when a data clear flush is pending but a new cache is about to preload |
michael@0 | 28 | */ |
michael@0 | 29 | |
michael@0 | 30 | function startTest() |
michael@0 | 31 | { |
michael@0 | 32 | // Have an untouched land |
michael@0 | 33 | localStorage.clear(); |
michael@0 | 34 | |
michael@0 | 35 | // Initial flush |
michael@0 | 36 | localStorageFlush(function() { |
michael@0 | 37 | is(localStorage.length, 0, "localStorage empty at the test start"); |
michael@0 | 38 | |
michael@0 | 39 | // Basic test 1 (set a key, check presence after reload): |
michael@0 | 40 | localStorage.setItem("item", "value"); |
michael@0 | 41 | localStorageFlushAndReload(function() { |
michael@0 | 42 | is(localStorage.getItem("item"), "value", "Basic persistance works"); |
michael@0 | 43 | is(localStorage.length, 1, "1 item in localStorage"); |
michael@0 | 44 | |
michael@0 | 45 | // Basic test 2 (set a key twice, check presence of the last value): |
michael@0 | 46 | localStorage.setItem("item", "value2"); |
michael@0 | 47 | localStorage.setItem("item", "value3"); |
michael@0 | 48 | localStorageFlushAndReload(function() { |
michael@0 | 49 | is(localStorage.getItem("item"), "value3", "Basic persistance 2 works"); |
michael@0 | 50 | |
michael@0 | 51 | // Basic test 3 (remove a key, check it has been deleted): |
michael@0 | 52 | localStorage.removeItem("item"); |
michael@0 | 53 | localStorageFlushAndReload(function() { |
michael@0 | 54 | is(localStorage.getItem("item"), null, "Basic delete works"); |
michael@0 | 55 | |
michael@0 | 56 | // Basic test 4 (set and remove a key, check it is not present): |
michael@0 | 57 | localStorage.setItem("item", "value4"); |
michael@0 | 58 | localStorage.removeItem("item"); |
michael@0 | 59 | localStorageFlushAndReload(function() { |
michael@0 | 60 | is(localStorage.getItem("item"), null, "Basic delete 2 works"); |
michael@0 | 61 | |
michael@0 | 62 | |
michael@0 | 63 | // Case 1: |
michael@0 | 64 | localStorage.setItem("item", "value"); |
michael@0 | 65 | localStorageFlushAndReload(function() { |
michael@0 | 66 | localStorage.removeItem("item"); |
michael@0 | 67 | localStorage.setItem("item", "value2"); |
michael@0 | 68 | localStorage.removeItem("item"); |
michael@0 | 69 | localStorageFlushAndReload(function() { |
michael@0 | 70 | is(localStorage.getItem("item"), null, "Item deleted in case 1"); |
michael@0 | 71 | |
michael@0 | 72 | // Case 2: |
michael@0 | 73 | localStorage.setItem("item", "value"); |
michael@0 | 74 | localStorage.setItem("item2", "value2"); |
michael@0 | 75 | localStorage.clear(); |
michael@0 | 76 | localStorageFlushAndReload(function() { |
michael@0 | 77 | is(localStorage.length, 0, "localStorage clean in case 2"); |
michael@0 | 78 | |
michael@0 | 79 | // Case 3: |
michael@0 | 80 | localStorageFlush(function() { |
michael@0 | 81 | localStorage.setItem("item", "value"); |
michael@0 | 82 | localStorage.setItem("item2", "value2"); |
michael@0 | 83 | localStorage.clear(); |
michael@0 | 84 | localStorageReload(); |
michael@0 | 85 | is(localStorage.length, 0, "localStorage clean in case 4"); |
michael@0 | 86 | |
michael@0 | 87 | if (SpecialPowers.Cc["@mozilla.org/xre/app-info;1"].getService( |
michael@0 | 88 | SpecialPowers.Ci.nsIXULRuntime).processType != SpecialPowers.Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT) { |
michael@0 | 89 | // Following tests cannot be run in a child/plugin process type |
michael@0 | 90 | SimpleTest.finish(); |
michael@0 | 91 | return; |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | // Cookies clean 1 |
michael@0 | 95 | localStorageFlush(function() { |
michael@0 | 96 | localStorage.setItem("item", "value"); |
michael@0 | 97 | localStorageClearAll(); |
michael@0 | 98 | is(localStorage.length, 0, "localStorage clean after cookies deletion"); |
michael@0 | 99 | localStorage.setItem("item2", "value2"); |
michael@0 | 100 | is(localStorage.getItem("item"), null, "Unexpected key 1, cookies delete"); |
michael@0 | 101 | is(localStorage.getItem("item2"), "value2", "Expected key 2, cookies delete"); |
michael@0 | 102 | localStorageFlushAndReload(function() { |
michael@0 | 103 | is(localStorage.getItem("item"), null, "Unexpected key 1, cookies delete"); |
michael@0 | 104 | is(localStorage.getItem("item2"), "value2", "Expected key 2, cookies delete"); |
michael@0 | 105 | |
michael@0 | 106 | // Cookies clean 2 |
michael@0 | 107 | localStorage.clear(); |
michael@0 | 108 | localStorageFlush(function() { |
michael@0 | 109 | localStorage.setItem("item", "value"); |
michael@0 | 110 | localStorageClearAll(); |
michael@0 | 111 | is(localStorage.length, 0, "localStorage clean after cookies deletion 2"); |
michael@0 | 112 | localStorageFlushAndReload(function() { |
michael@0 | 113 | is(localStorage.length, 0, "localStorage clean after cookies deletion 2"); |
michael@0 | 114 | |
michael@0 | 115 | |
michael@0 | 116 | // Domain clean 1 |
michael@0 | 117 | localStorageFlush(function() { |
michael@0 | 118 | localStorage.setItem("item", "value"); |
michael@0 | 119 | localStorageClearDomain("test"); |
michael@0 | 120 | is(localStorage.length, 0, "localStorage clean after domain deletion"); |
michael@0 | 121 | localStorage.setItem("item2", "value2"); |
michael@0 | 122 | is(localStorage.getItem("item"), null, "Unexpected key 1, domain delete"); |
michael@0 | 123 | is(localStorage.getItem("item2"), "value2", "Expected key 2, domain delete"); |
michael@0 | 124 | localStorageFlushAndReload(function() { |
michael@0 | 125 | is(localStorage.getItem("item"), null, "Unexpected key 1, domain delete"); |
michael@0 | 126 | is(localStorage.getItem("item2"), "value2", "Expected key 2, domain delete"); |
michael@0 | 127 | |
michael@0 | 128 | // Domain clean 2 |
michael@0 | 129 | localStorage.clear(); |
michael@0 | 130 | localStorageFlush(function() { |
michael@0 | 131 | localStorage.setItem("item", "value"); |
michael@0 | 132 | localStorageClearDomain("test"); |
michael@0 | 133 | is(localStorage.length, 0, "localStorage clean after domain deletion 2"); |
michael@0 | 134 | localStorageFlushAndReload(function() { |
michael@0 | 135 | is(localStorage.length, 0, "localStorage clean after domain deletion 2"); |
michael@0 | 136 | |
michael@0 | 137 | SimpleTest.finish(); |
michael@0 | 138 | |
michael@0 | 139 | }); |
michael@0 | 140 | }); |
michael@0 | 141 | }); |
michael@0 | 142 | }); |
michael@0 | 143 | }); |
michael@0 | 144 | }); |
michael@0 | 145 | }); |
michael@0 | 146 | }); |
michael@0 | 147 | }); |
michael@0 | 148 | }); |
michael@0 | 149 | }); |
michael@0 | 150 | }); |
michael@0 | 151 | }); |
michael@0 | 152 | }); |
michael@0 | 153 | }); |
michael@0 | 154 | }); |
michael@0 | 155 | }); |
michael@0 | 156 | } |
michael@0 | 157 | |
michael@0 | 158 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 159 | |
michael@0 | 160 | </script> |
michael@0 | 161 | |
michael@0 | 162 | </head> |
michael@0 | 163 | |
michael@0 | 164 | <body onload="startTest();"> |
michael@0 | 165 | </body> |
michael@0 | 166 | </html> |