browser_storage_file_url.js (1998B)
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 various storage types work when using file:// URLs. 6 7 "use strict"; 8 9 add_task(async function () { 10 const TESTPAGE = "storage-file-url.html"; 11 12 // We need to load TESTPAGE using a file:// path so we need to get that from 13 // the current test path. 14 const testPath = getResolvedURI(gTestPath); 15 const dir = getChromeDir(testPath); 16 17 // Then append TESTPAGE to the test path. 18 dir.append(TESTPAGE); 19 20 // Then generate a FileURI to ensure the path is valid. 21 const uriString = Services.io.newFileURI(dir).spec; 22 23 // Now we have a valid file:// URL pointing to TESTPAGE. 24 await openTabAndSetupStorage(uriString); 25 26 // uriString points to the test inside objdir e.g. 27 // `/path/to/fx/objDir/_tests/testing/mochitest/browser/devtools/client/ 28 // storage/test/storage-file-url.html`. 29 // 30 // When opened in the browser this may resolve to a different path e.g. 31 // `path/to/fx/repo/devtools/client/storage/test/storage-file-url.html`. 32 // 33 // The easiest way to get the actual path is to request it from the content 34 // process. 35 const browser = gBrowser.selectedBrowser; 36 const actualPath = await SpecialPowers.spawn(browser, [], () => { 37 return content.document.location.href; 38 }); 39 40 const cookiePath = actualPath 41 .substr(0, actualPath.lastIndexOf("/")) 42 .replace(/file:\/\//g, ""); 43 await checkState([ 44 [ 45 ["cookies", actualPath], 46 [ 47 getCookieId("test1", "", cookiePath), 48 getCookieId("test2", "", cookiePath), 49 ], 50 ], 51 [ 52 ["indexedDB", actualPath, "MyDatabase (default)", "MyObjectStore"], 53 [12345, 54321, 67890, 98765], 54 ], 55 [ 56 ["localStorage", actualPath], 57 ["test3", "test4"], 58 ], 59 [ 60 ["sessionStorage", actualPath], 61 ["test5", "test6"], 62 ], 63 ]); 64 });