head_bookmarks.js (2624B)
1 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 // Import common head. 7 /* import-globals-from ../../../../../toolkit/components/places/tests/head_common.js */ 8 var commonFile = do_get_file( 9 "../../../../../toolkit/components/places/tests/head_common.js", 10 false 11 ); 12 if (commonFile) { 13 let uri = Services.io.newFileURI(commonFile); 14 Services.scriptloader.loadSubScript(uri.spec, this); 15 } 16 17 // Put any other stuff relative to this test folder below. 18 19 ChromeUtils.defineESModuleGetters(this, { 20 PlacesUIUtils: "moz-src:///browser/components/places/PlacesUIUtils.sys.mjs", 21 }); 22 23 // Needed by some test that relies on having an app registered. 24 const { updateAppInfo } = ChromeUtils.importESModule( 25 "resource://testing-common/AppInfo.sys.mjs" 26 ); 27 updateAppInfo({ 28 name: "PlacesTest", 29 ID: "{230de50e-4cd1-11dc-8314-0800200c9a66}", 30 version: "1", 31 platformVersion: "", 32 }); 33 34 // Default bookmarks constant. 35 const DEFAULT_BOOKMARKS_ON_MENU = 1; 36 37 var createCorruptDB = async function () { 38 let dbPath = PathUtils.join(PathUtils.profileDir, "places.sqlite"); 39 await IOUtils.remove(dbPath); 40 41 // Create a corrupt database. 42 let src = PathUtils.join(do_get_cwd().path, "corruptDB.sqlite"); 43 await IOUtils.copy(src, dbPath); 44 45 // Check there's a DB now. 46 Assert.ok(await IOUtils.exists(dbPath), "should have a DB now"); 47 }; 48 49 const SINGLE_TRY_TIMEOUT = 100; 50 const NUMBER_OF_TRIES = 30; 51 52 /** 53 * Similar to waitForConditionPromise, but poll for an asynchronous value 54 * every SINGLE_TRY_TIMEOUT ms, for no more than tryCount times. 55 * 56 * @param {Function} promiseFn 57 * A function to generate a promise, which resolves to the expected 58 * asynchronous value. 59 * @param {msg} timeoutMsg 60 * The reason to reject the returned promise with. 61 * @param {number} [tryCount] 62 * Maximum times to try before rejecting the returned promise with 63 * timeoutMsg, defaults to NUMBER_OF_TRIES. 64 * @returns {Promise} to the asynchronous value being polled. 65 * @throws if the asynchronous value is not available after tryCount attempts. 66 */ 67 var waitForResolvedPromise = async function ( 68 promiseFn, 69 timeoutMsg, 70 tryCount = NUMBER_OF_TRIES 71 ) { 72 let tries = 0; 73 do { 74 try { 75 let value = await promiseFn(); 76 return value; 77 } catch (ex) {} 78 await new Promise(resolve => do_timeout(SINGLE_TRY_TIMEOUT, resolve)); 79 } while (++tries <= tryCount); 80 throw new Error(timeoutMsg); 81 };