Bug 1931425 - Limit how often moz-label's #setStyles runs r=reusable-components-revie...
[gecko.git] / netwerk / test / unit / test_cookies_upgrade_10.js
blob66680fc34a4d4a06fc7aed2116afe95f7dfe168f
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 file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 "use strict";
7 function getDBVersion(dbfile) {
8 let dbConnection = Services.storage.openDatabase(dbfile);
9 let version = dbConnection.schemaVersion;
10 dbConnection.close();
12 return version;
15 function indexExists(dbfile, indexname) {
16 let dbConnection = Services.storage.openDatabase(dbfile);
17 let result = dbConnection.indexExists(indexname);
18 dbConnection.close();
20 return result;
23 add_task(async function () {
24 try {
25 let testfile = do_get_file("data/cookies_v10.sqlite");
26 let profileDir = do_get_profile();
28 // Cleanup from any previous tests or failures.
29 let destFile = profileDir.clone();
30 destFile.append("cookies.sqlite");
31 if (destFile.exists()) {
32 destFile.remove(false);
35 testfile.copyTo(profileDir, "cookies.sqlite");
36 Assert.equal(10, getDBVersion(destFile));
38 Assert.ok(destFile.exists());
40 // Check that the index exists
41 Assert.ok(indexExists(destFile, "moz_basedomain"));
43 // Do something that will cause the cookie service access and upgrade the
44 // database.
45 Services.cookies.cookies;
47 // Pretend that we're about to shut down, to tell the cookie manager
48 // to clean up its connection with its database.
49 Services.startup.advanceShutdownPhase(
50 Services.startup.SHUTDOWN_PHASE_APPSHUTDOWN
53 // check for upgraded schema.
54 Assert.ok(getDBVersion(destFile) >= 13);
56 // Check that the index was deleted
57 Assert.ok(!indexExists(destFile, "moz_basedomain"));
58 } catch (e) {
59 throw new Error(`FAILED: ${e}`);
61 });