| OLD | NEW |
| (Empty) | |
| 1 <!DOCTYPE HTML> |
| 2 <html> |
| 3 <title>WebStorage Test: StorageEvent - only if something changes</title> |
| 4 <script src="/resources/testharness.js"></script> |
| 5 <script src="/resources/testharnessreport.js"></script> |
| 6 <body> |
| 7 <script> |
| 8 const iframe = document.createElement('iframe'); |
| 9 |
| 10 function tests(storageName) { |
| 11 test(t => assert_true(storageName in window), storageName + ' exists'); |
| 12 |
| 13 const storage = window[storageName]; |
| 14 const iframeStorage = iframe.contentWindow[storageName]; |
| 15 |
| 16 add_completion_callback(() => { |
| 17 storage.clear(); |
| 18 }); |
| 19 |
| 20 promise_test(t => { |
| 21 const w = new EventWatcher(t, iframe.contentWindow, 'storage'); |
| 22 |
| 23 // Random key to make sure we don't conflict with any cruft leftover from |
| 24 // earlier runs. Any synchronization would be really hard with localStorage |
| 25 // limited guarantees. |
| 26 const testKey = Math.random().toString(36).slice(2); |
| 27 |
| 28 storage.setItem(testKey, 'foo'); |
| 29 storage.setItem(testKey, 'foo'); |
| 30 storage.setItem(testKey, 'bar'); |
| 31 return w.wait_for('storage') |
| 32 .then(e => { |
| 33 assert_equals(e.storageArea, iframeStorage); |
| 34 assert_equals(e.key, testKey); |
| 35 assert_equals(e.newValue, 'foo'); |
| 36 return w.wait_for('storage'); |
| 37 }) |
| 38 .then(e => { |
| 39 assert_equals(e.storageArea, iframeStorage); |
| 40 assert_equals(e.key, testKey); |
| 41 assert_equals(e.oldValue, 'foo'); |
| 42 assert_equals(e.newValue, 'bar'); |
| 43 }); |
| 44 }, 'Setting to same value does not trigger event for ' + storageName); |
| 45 |
| 46 promise_test(t => { |
| 47 const w = new EventWatcher(t, iframe.contentWindow, 'storage'); |
| 48 |
| 49 // Random key to make sure we don't conflict with any cruft leftover from |
| 50 // earlier runs. Any synchronization would be really hard with localStorage |
| 51 // limited guarantees. |
| 52 const testKey1 = Math.random().toString(36).slice(2); |
| 53 const testKey2 = Math.random().toString(36).slice(2); |
| 54 |
| 55 storage.removeItem(testKey1); |
| 56 storage.setItem(testKey2, 'foo'); |
| 57 return w.wait_for('storage') |
| 58 .then(e => { |
| 59 assert_equals(e.storageArea, iframeStorage); |
| 60 assert_equals(e.key, testKey2); |
| 61 assert_equals(e.newValue, 'foo'); |
| 62 }); |
| 63 }, 'Deleting non-existent key does not trigger event for ' + storageName); |
| 64 |
| 65 |
| 66 promise_test(t => { |
| 67 const w = new EventWatcher(t, iframe.contentWindow, 'storage'); |
| 68 |
| 69 // Random key to make sure we don't conflict with any cruft leftover from |
| 70 // earlier runs. Any synchronization would be really hard with localStorage |
| 71 // limited guarantees. |
| 72 const testKey = Math.random().toString(36).slice(2); |
| 73 |
| 74 storage.setItem(testKey, 'foo'); |
| 75 storage.clear(); |
| 76 storage.clear(); |
| 77 storage.setItem(testKey, 'bar'); |
| 78 return w.wait_for('storage') |
| 79 .then(e => { |
| 80 assert_equals(e.storageArea, iframeStorage); |
| 81 assert_equals(e.key, testKey); |
| 82 assert_equals(e.newValue, 'foo'); |
| 83 return w.wait_for('storage'); |
| 84 }) |
| 85 .then(e => { |
| 86 assert_equals(e.storageArea, iframeStorage); |
| 87 assert_equals(e.key, null); |
| 88 assert_equals(e.oldValue, null); |
| 89 assert_equals(e.newValue, null); |
| 90 return w.wait_for('storage'); |
| 91 }) |
| 92 .then(e => { |
| 93 assert_equals(e.storageArea, iframeStorage); |
| 94 assert_equals(e.key, testKey); |
| 95 assert_equals(e.oldValue, null); |
| 96 assert_equals(e.newValue, 'bar'); |
| 97 }); |
| 98 }, 'Clearing empty storage does not trigger event for ' + storageName); |
| 99 |
| 100 } |
| 101 |
| 102 iframe.onload = () => { |
| 103 tests('sessionStorage'); |
| 104 tests('localStorage'); |
| 105 }; |
| 106 iframe.src = 'about:blank'; |
| 107 document.body.appendChild(iframe); |
| 108 </script> |
| 109 </body> |
| 110 </html> |
| 111 |
| OLD | NEW |