browser_storage_localstorage_navigation.js (2152B)
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 "use strict"; 6 7 add_task(async function () { 8 const URL1 = buildURLWithContent( 9 "example.com", 10 `<h1>example.com</h1>` + 11 `<script>localStorage.setItem("lorem", "ipsum");</script>` 12 ); 13 const URL2 = buildURLWithContent( 14 "example.net", 15 `<h1>example.net</h1>` + 16 `<script>localStorage.setItem("foo", "bar");</script>` 17 ); 18 19 // open tab 20 await openTabAndSetupStorage(URL1); 21 const doc = gPanelWindow.document; 22 23 // Check first domain 24 // check that both host appear in the storage tree 25 checkTree(doc, ["localStorage", "https://example.com"]); 26 // check the table for values 27 await selectTreeItem(["localStorage", "https://example.com"]); 28 checkStorageData("lorem", "ipsum"); 29 30 // clear up local storage data before navigating 31 info("Cleaning up localStorage…"); 32 await SpecialPowers.spawn(gBrowser.selectedBrowser, [], async function () { 33 const win = content.wrappedJSObject; 34 await win.localStorage.clear(); 35 }); 36 37 // Check second domain 38 await navigateTo(URL2); 39 // wait for storage tree refresh, and check host 40 info("Waiting for storage tree to refresh and show correct host…"); 41 await waitUntil(() => isInTree(doc, ["localStorage", "https://example.net"])); 42 ok( 43 !isInTree(doc, ["localStorage", "https://example.com"]), 44 "example.com item is not in the tree anymore" 45 ); 46 47 // reload the current tab and check data 48 await reloadBrowser(); 49 // wait for storage tree refresh, and check host 50 info("Waiting for storage tree to refresh and show correct host…"); 51 await waitUntil(() => isInTree(doc, ["localStorage", "https://example.net"])); 52 53 // check the table for values 54 await selectTreeItem(["localStorage", "https://example.net"]); 55 checkStorageData("foo", "bar"); 56 57 info("Check that the localStorage node still has the expected label"); 58 is( 59 getTreeNodeLabel(doc, ["localStorage"]), 60 "Local Storage", 61 "localStorage item is properly displayed" 62 ); 63 });