test_cookies_upgrade_10.js (1760B)
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/. */ 4 5 "use strict"; 6 7 function getDBVersion(dbfile) { 8 let dbConnection = Services.storage.openDatabase(dbfile); 9 let version = dbConnection.schemaVersion; 10 dbConnection.close(); 11 12 return version; 13 } 14 15 function indexExists(dbfile, indexname) { 16 let dbConnection = Services.storage.openDatabase(dbfile); 17 let result = dbConnection.indexExists(indexname); 18 dbConnection.close(); 19 20 return result; 21 } 22 23 add_task(async function () { 24 try { 25 let testfile = do_get_file("data/cookies_v10.sqlite"); 26 let profileDir = do_get_profile(); 27 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); 33 } 34 35 testfile.copyTo(profileDir, "cookies.sqlite"); 36 Assert.equal(10, getDBVersion(destFile)); 37 38 Assert.ok(destFile.exists()); 39 40 // Check that the index exists 41 Assert.ok(indexExists(destFile, "moz_basedomain")); 42 43 // Do something that will cause the cookie service access and upgrade the 44 // database. 45 Services.cookies.cookies; 46 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 51 ); 52 53 // check for upgraded schema. 54 Assert.greaterOrEqual(getDBVersion(destFile), 13); 55 56 // Check that the index was deleted 57 Assert.ok(!indexExists(destFile, "moz_basedomain")); 58 } catch (e) { 59 throw new Error(`FAILED: ${e}`); 60 } 61 });