browser_aboutdebugging_addons_debug_storage.js (2795B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 "use strict"; 4 5 /* import-globals-from helper-addons.js */ 6 Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-addons.js", this); 7 8 add_task(async () => { 9 const EXTENSION_NAME = "temporary-web-extension"; 10 const EXTENSION_ID = "test-devtools@mozilla.org"; 11 12 await enableExtensionDebugging(); 13 14 const { document, tab, window } = await openAboutDebugging(); 15 await selectThisFirefoxPage(document, window.AboutDebugging.store); 16 17 const { extension } = await installTemporaryExtensionFromXPI( 18 { 19 background() { 20 const open = indexedDB.open("TestDatabase", 1); 21 22 open.onupgradeneeded = function () { 23 const db = open.result; 24 db.createObjectStore("TestStore", { keyPath: "id" }); 25 }; 26 27 open.onsuccess = function () { 28 const db = open.result; 29 const tx = db.transaction("TestStore", "readwrite"); 30 const store = tx.objectStore("TestStore"); 31 32 store.put({ id: 1, name: "John", age: 12 }); 33 store.put({ id: 2, name: "Bob", age: 24 }); 34 tx.oncomplete = () => db.close(); 35 }; 36 }, 37 id: EXTENSION_ID, 38 name: EXTENSION_NAME, 39 }, 40 document 41 ); 42 43 const { devtoolsWindow } = await openAboutDevtoolsToolbox( 44 document, 45 tab, 46 window, 47 EXTENSION_NAME 48 ); 49 50 info("Select the storage panel"); 51 const toolbox = getToolbox(devtoolsWindow); 52 await toolbox.selectTool("storage"); 53 const storage = toolbox.getCurrentPanel(); 54 55 info("Check the content of the storage panel treeview"); 56 const ids = [ 57 "indexedDB", 58 `moz-extension://${extension.uuid}`, 59 "TestDatabase (default)", 60 "TestStore", 61 ]; 62 ok( 63 !!storage.panelWindow.document.querySelector( 64 `[data-id='${JSON.stringify(ids)}']` 65 ), 66 "The indexedDB database for the extension is visible" 67 ); 68 69 info("Select the indexedDB database for the extension"); 70 const updated = storage.UI.once("store-objects-updated"); 71 storage.UI.tree.selectedItem = ids; 72 await updated; 73 74 info("Wait until table populated"); 75 await waitUntil(() => storage.UI.table.items.size === 2); 76 const items = storage.UI.table.items; 77 78 info("Check the content of the storage panel table"); 79 is(items.size, 2); 80 const user1 = JSON.parse(items.get(1).value); 81 const user2 = JSON.parse(items.get(2).value); 82 is(user1.name, "John", "user 1 has the expected name"); 83 is(user1.age, 12, "user 1 has the expected age"); 84 is(user2.name, "Bob", "user 2 has the expected name"); 85 is(user2.age, 24, "user 2 has the expected age"); 86 87 await closeWebExtAboutDevtoolsToolbox(devtoolsWindow, window); 88 await removeTemporaryExtension(EXTENSION_NAME, document); 89 await removeTab(tab); 90 });