browser_storage_keys.js (4149B)
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 // Test to verify that the keys shown in sidebar are correct 6 7 // Format of the test cases: { 8 // action: Either "selectTreeItem" to select a tree item or 9 // "assertTableItem" to select a table item, 10 // ids: ID array for tree item to select if `action` is "selectTreeItem", 11 // id: ID of the table item if `action` is "assertTableItem", 12 // keyValuePairs: Array of key value pair objects which will be asserted 13 // to exist in the storage sidebar (optional) 14 // } 15 16 "use strict"; 17 18 const LONG_WORD = "a".repeat(1000); 19 20 add_task(async function () { 21 await openTabAndSetupStorage( 22 MAIN_DOMAIN_SECURED + "storage-complex-keys.html" 23 ); 24 25 gUI.tree.expandAll(); 26 27 await testLocalStorage(); 28 await testSessionStorage(); 29 await testIndexedDB(); 30 }); 31 32 async function testLocalStorage() { 33 const tests = [ 34 { 35 action: "selectTreeItem", 36 ids: ["localStorage", "https://test1.example.org"], 37 }, 38 { 39 action: "assertTableItem", 40 id: "", 41 value: "1", 42 }, 43 { 44 action: "assertTableItem", 45 id: "键", 46 value: "2", 47 }, 48 ]; 49 50 await makeTests(tests); 51 } 52 53 async function testSessionStorage() { 54 const tests = [ 55 { 56 action: "selectTreeItem", 57 ids: ["sessionStorage", "https://test1.example.org"], 58 }, 59 { 60 action: "assertTableItem", 61 id: "Key with spaces", 62 value: "3", 63 }, 64 { 65 action: "assertTableItem", 66 id: "Key#with~special$characters", 67 value: "4", 68 }, 69 { 70 action: "assertTableItem", 71 id: LONG_WORD, 72 value: "5", 73 }, 74 ]; 75 76 await makeTests(tests); 77 } 78 79 async function testIndexedDB() { 80 const tests = [ 81 { 82 action: "selectTreeItem", 83 ids: ["indexedDB", "https://test1.example.org", "idb (default)", "obj"], 84 }, 85 { 86 action: "assertTableItem", 87 id: "", 88 value: JSON.stringify({ id: "", name: "foo" }), 89 keyValuePairs: [ 90 { name: ".id", value: "" }, 91 { name: ".name", value: "foo" }, 92 ], 93 }, 94 { 95 action: "assertTableItem", 96 id: "键", 97 value: JSON.stringify({ id: "键", name: "foo2" }), 98 keyValuePairs: [ 99 { name: "键.id", value: "键" }, 100 { name: "键.name", value: "foo2" }, 101 ], 102 }, 103 { 104 action: "assertTableItem", 105 id: "Key with spaces", 106 value: JSON.stringify({ id: "Key with spaces", name: "foo3" }), 107 keyValuePairs: [ 108 { name: "Key with spaces.id", value: "Key with spaces" }, 109 { name: "Key with spaces.name", value: "foo3" }, 110 ], 111 }, 112 { 113 action: "assertTableItem", 114 id: "Key#with~special$characters", 115 value: JSON.stringify({ 116 id: "Key#with~special$characters", 117 name: "foo4", 118 }), 119 keyValuePairs: [ 120 { 121 name: "Key#with~special$characters.id", 122 value: "Key#with~special$characters", 123 }, 124 { name: "Key#with~special$characters.name", value: "foo4" }, 125 ], 126 }, 127 { 128 action: "assertTableItem", 129 id: LONG_WORD, 130 value: JSON.stringify({ id: LONG_WORD, name: "foo5" }), 131 keyValuePairs: [ 132 { name: `${LONG_WORD}.id`, value: LONG_WORD }, 133 { name: `${LONG_WORD}.name`, value: "foo5" }, 134 ], 135 }, 136 ]; 137 138 await makeTests(tests); 139 } 140 141 async function makeTests(tests) { 142 for (const item of tests) { 143 info(`Selecting item ${JSON.stringify(item)}`); 144 145 switch (item.action) { 146 case "selectTreeItem": 147 await selectTreeItem(item.ids); 148 break; 149 150 case "assertTableItem": 151 await selectTableItem(item.id); 152 // Check the ID and value in the data section 153 await findVariableViewProperties([ 154 { name: item.id, value: item.value }, 155 ]); 156 // If there are key value pairs defined, check those in the 157 // parsed value section 158 if (item.keyValuePairs) { 159 await findVariableViewProperties(item.keyValuePairs, true); 160 } 161 break; 162 } 163 } 164 }