Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <head> |
michael@0 | 4 | <meta charset="utf-8"> |
michael@0 | 5 | <title>Test for DataStore - add([array]) remove([array])</title> |
michael@0 | 6 | </head> |
michael@0 | 7 | <body> |
michael@0 | 8 | <div id="container"></div> |
michael@0 | 9 | <script type="application/javascript;version=1.7"> |
michael@0 | 10 | |
michael@0 | 11 | var gStore; |
michael@0 | 12 | |
michael@0 | 13 | function is(a, b, msg) { |
michael@0 | 14 | alert((a === b ? 'OK' : 'KO') + ' ' + msg) |
michael@0 | 15 | } |
michael@0 | 16 | |
michael@0 | 17 | function ok(a, msg) { |
michael@0 | 18 | alert((a ? 'OK' : 'KO')+ ' ' + msg) |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | function cbError() { |
michael@0 | 22 | alert('KO error'); |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | function finish() { |
michael@0 | 26 | alert('DONE'); |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | function testGetDataStores() { |
michael@0 | 30 | navigator.getDataStores('foo').then(function(stores) { |
michael@0 | 31 | is(stores.length, 1, "getDataStores('foo') returns 1 element"); |
michael@0 | 32 | is(stores[0].name, 'foo', 'The dataStore.name is foo'); |
michael@0 | 33 | is(stores[0].readOnly, false, 'The dataStore foo is not in readonly'); |
michael@0 | 34 | |
michael@0 | 35 | var store = stores[0]; |
michael@0 | 36 | ok("get" in store, "store.get exists"); |
michael@0 | 37 | ok("put" in store, "store.put exists"); |
michael@0 | 38 | ok("add" in store, "store.add exists"); |
michael@0 | 39 | ok("remove" in store, "store.remove exists"); |
michael@0 | 40 | ok("clear" in store, "store.clear exists"); |
michael@0 | 41 | |
michael@0 | 42 | gStore = stores[0]; |
michael@0 | 43 | |
michael@0 | 44 | runTest(); |
michael@0 | 45 | }, cbError); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | var itemNumber = 60; |
michael@0 | 49 | |
michael@0 | 50 | function testStoreAdd() { |
michael@0 | 51 | var objects = []; |
michael@0 | 52 | for (var i = 0; i < itemNumber; ++i) { |
michael@0 | 53 | objects.push(i); |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | function testStoreAddInternal() { |
michael@0 | 57 | if (!objects.length) { |
michael@0 | 58 | ok(true, "We inserted " + itemNumber + " items"); |
michael@0 | 59 | runTest(); |
michael@0 | 60 | return; |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | var obj = objects.shift(); |
michael@0 | 64 | gStore.add(obj).then(function() { |
michael@0 | 65 | ok(true, "We inserted a new item!"); |
michael@0 | 66 | testStoreAddInternal(); |
michael@0 | 67 | }, cbError); |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | testStoreAddInternal(); |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | function testStoreGet() { |
michael@0 | 74 | var objects = []; |
michael@0 | 75 | for (var i = 1; i <= itemNumber; ++i) { |
michael@0 | 76 | objects.push(i); |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | gStore.get.apply(gStore, objects).then(function(data) { |
michael@0 | 80 | is(data.length, objects.length, "Get - Data matches"); |
michael@0 | 81 | for (var i = 0; i < data.length; ++i) { |
michael@0 | 82 | is(data[i], objects[i] - 1, "Get - Data matches: " + i + " " + data[i] + " == " + objects[i]); |
michael@0 | 83 | } |
michael@0 | 84 | runTest(); |
michael@0 | 85 | }, cbError); |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | var tests = [ |
michael@0 | 89 | // Test for GetDataStore |
michael@0 | 90 | testGetDataStores, |
michael@0 | 91 | |
michael@0 | 92 | // Add many items |
michael@0 | 93 | function() { testStoreAdd() }, |
michael@0 | 94 | function() { testStoreGet() }, |
michael@0 | 95 | ]; |
michael@0 | 96 | |
michael@0 | 97 | function runTest() { |
michael@0 | 98 | if (!tests.length) { |
michael@0 | 99 | finish(); |
michael@0 | 100 | return; |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | var test = tests.shift(); |
michael@0 | 104 | test(); |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | runTest(); |
michael@0 | 108 | </script> |
michael@0 | 109 | </body> |
michael@0 | 110 | </html> |