browser_storage_basic_usercontextid_1.js (4766B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 // A test to check that the storage inspector is working correctly without 6 // userContextId. 7 8 "use strict"; 9 10 const testCases = [ 11 [ 12 ["cookies", "http://test1.example.org"], 13 [ 14 getCookieId("c1", "test1.example.org", "/browser"), 15 getCookieId("cs2", ".example.org", "/"), 16 getCookieId("c3", "test1.example.org", "/"), 17 getCookieId("c4", ".example.org", "/"), 18 getCookieId("uc1", ".example.org", "/"), 19 getCookieId("uc2", ".example.org", "/"), 20 ], 21 ], 22 [ 23 ["cookies", "https://sectest1.example.org"], 24 [ 25 getCookieId("uc1", ".example.org", "/"), 26 getCookieId("uc2", ".example.org", "/"), 27 getCookieId("cs2", ".example.org", "/"), 28 getCookieId("c4", ".example.org", "/"), 29 getCookieId( 30 "sc1", 31 "sectest1.example.org", 32 "/browser/devtools/client/storage/test" 33 ), 34 getCookieId( 35 "sc2", 36 "sectest1.example.org", 37 "/browser/devtools/client/storage/test" 38 ), 39 ], 40 ], 41 [ 42 ["localStorage", "http://test1.example.org"], 43 ["key", "ls1", "ls2"], 44 ], 45 [["localStorage", "http://sectest1.example.org"], ["iframe-u-ls1"]], 46 [["localStorage", "https://sectest1.example.org"], ["iframe-s-ls1"]], 47 [ 48 ["sessionStorage", "http://test1.example.org"], 49 ["key", "ss1"], 50 ], 51 [ 52 ["sessionStorage", "http://sectest1.example.org"], 53 ["iframe-u-ss1", "iframe-u-ss2"], 54 ], 55 [["sessionStorage", "https://sectest1.example.org"], ["iframe-s-ss1"]], 56 [ 57 ["indexedDB", "http://test1.example.org"], 58 ["idb1 (default)", "idb2 (default)"], 59 ], 60 [ 61 ["indexedDB", "http://test1.example.org", "idb1 (default)"], 62 ["obj1", "obj2"], 63 ], 64 [["indexedDB", "http://test1.example.org", "idb2 (default)"], ["obj3"]], 65 [ 66 ["indexedDB", "http://test1.example.org", "idb1 (default)", "obj1"], 67 [1, 2, 3], 68 ], 69 [["indexedDB", "http://test1.example.org", "idb1 (default)", "obj2"], [1]], 70 [["indexedDB", "http://test1.example.org", "idb2 (default)", "obj3"], []], 71 [["indexedDB", "http://sectest1.example.org"], []], 72 [ 73 ["indexedDB", "https://sectest1.example.org"], 74 ["idb-s1 (default)", "idb-s2 (default)"], 75 ], 76 [ 77 ["indexedDB", "https://sectest1.example.org", "idb-s1 (default)"], 78 ["obj-s1"], 79 ], 80 [ 81 ["indexedDB", "https://sectest1.example.org", "idb-s2 (default)"], 82 ["obj-s2"], 83 ], 84 [ 85 ["indexedDB", "https://sectest1.example.org", "idb-s1 (default)", "obj-s1"], 86 [6, 7], 87 ], 88 [ 89 ["indexedDB", "https://sectest1.example.org", "idb-s2 (default)", "obj-s2"], 90 [16], 91 ], 92 [ 93 ["Cache", "http://test1.example.org", "plop"], 94 [ 95 MAIN_DOMAIN + "404_cached_file.js", 96 MAIN_DOMAIN + "browser_storage_basic.js", 97 ], 98 ], 99 ]; 100 101 /** 102 * Test that the desired number of tree items are present 103 */ 104 function testTree(tests) { 105 const doc = gPanelWindow.document; 106 for (const [item] of tests) { 107 ok( 108 doc.querySelector("[data-id='" + JSON.stringify(item) + "']"), 109 `Tree item ${item.toSource()} should be present in the storage tree` 110 ); 111 } 112 } 113 114 /** 115 * Test that correct table entries are shown for each of the tree item 116 */ 117 async function testTables(tests) { 118 const doc = gPanelWindow.document; 119 // Expand all nodes so that the synthesized click event actually works 120 gUI.tree.expandAll(); 121 122 // First tree item is already selected so no clicking and waiting for update 123 for (const id of tests[0][1]) { 124 ok( 125 doc.querySelector(".table-widget-cell[data-id='" + id + "']"), 126 "Table item " + id + " should be present" 127 ); 128 } 129 130 // Click rest of the tree items and wait for the table to be updated 131 for (const [treeItem, items] of tests.slice(1)) { 132 await selectTreeItem(treeItem); 133 134 // Check whether correct number of items are present in the table 135 is( 136 doc.querySelectorAll( 137 ".table-widget-column:first-of-type .table-widget-cell" 138 ).length, 139 items.length, 140 "Number of items in table is correct" 141 ); 142 143 // Check if all the desired items are present in the table 144 for (const id of items) { 145 ok( 146 doc.querySelector(".table-widget-cell[data-id='" + id + "']"), 147 "Table item " + id + " should be present" 148 ); 149 } 150 } 151 } 152 153 add_task(async function () { 154 // storage-listings.html explicitly mixes secure and insecure frames. 155 // We should not enforce https for tests using this page. 156 await pushPref("dom.security.https_first", false); 157 158 await openTabAndSetupStorage(MAIN_DOMAIN + "storage-listings.html"); 159 160 testTree(testCases); 161 await testTables(testCases); 162 });