author | Zack Noyes, William Loughton <zacknoyes2@gmail.com> |
Tue, 23 Jan 2018 23:11:54 -0800 | |
changeset 400694 | 8f3552d6162728fffd709a25d8600acb06a69427 |
parent 400693 | a29e9dbb8c42f927889b8f755e8c5e137920cdb1 |
child 400695 | b19b1b50594e7e9d075e9dcb27bc88fe25850c95 |
push id | 33313 |
push user | ncsoregi@mozilla.com |
push date | Thu, 25 Jan 2018 10:14:49 +0000 |
treeherder | mozilla-central@040afea6562f [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | mak |
bugs | 1407778 |
milestone | 60.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
--- a/toolkit/modules/Sqlite.jsm +++ b/toolkit/modules/Sqlite.jsm @@ -940,17 +940,19 @@ function openConnection(options) { dbOptions.setProperty("readOnly", true); } dbOptions = dbOptions.enumerator.hasMoreElements() ? dbOptions : null; Services.storage.openAsyncDatabase(file, dbOptions, (status, connection) => { if (!connection) { log.warn(`Could not open connection to ${path}: ${status}`); - reject(new Error(`Could not open connection to ${path}: ${status}`)); + let error = new Error(`Could not open connection to ${path}: ${status}`); + error.status = status; + reject(error); return; } log.info("Connection opened"); try { resolve( new OpenedConnection(connection.QueryInterface(Ci.mozIStorageAsyncConnection), identifier, openedOptions)); } catch (ex) {
new file mode 100644 --- /dev/null +++ b/toolkit/modules/tests/xpcshell/corrupt.sqlite @@ -0,0 +1,1 @@ +CORRUPTED_SQLITE_FILE_CONTENTS
--- a/toolkit/modules/tests/xpcshell/test_sqlite.js +++ b/toolkit/modules/tests/xpcshell/test_sqlite.js @@ -1,11 +1,11 @@ "use strict"; -var {classes: Cc, interfaces: Ci, utils: Cu} = Components; +var {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; do_get_profile(); Cu.import("resource://gre/modules/Promise.jsm"); Cu.import("resource://gre/modules/PromiseUtils.jsm"); Cu.import("resource://gre/modules/osfile.jsm"); Cu.import("resource://gre/modules/FileUtils.jsm"); Cu.import("resource://gre/modules/Services.jsm"); @@ -86,16 +86,34 @@ add_task(async function test_setup() { initTestLogging("Trace"); }); add_task(async function test_open_normal() { let c = await Sqlite.openConnection({path: "test_open_normal.sqlite"}); await c.close(); }); +add_task(async function test_open_normal_error() { + let currentDir = await OS.File.getCurrentDirectory(); + + let src = OS.Path.join(currentDir, "corrupt.sqlite"); + Assert.ok((await OS.File.exists(src)), "Database file found"); + + // Ensure that our database doesn't already exist. + let path = OS.Path.join(OS.Constants.Path.profileDir, "corrupt.sqlite"); + Assert.ok(!(await OS.File.exists(path)), "Database file should not exist yet"); + + await OS.File.copy(src, path); + + let openPromise = Sqlite.openConnection({path}); + await Assert.rejects(openPromise, reason => { + return reason.status == Cr.NS_ERROR_FILE_CORRUPTED; + }, "Check error status"); +}); + add_task(async function test_open_unshared() { let path = OS.Path.join(OS.Constants.Path.profileDir, "test_open_unshared.sqlite"); let c = await Sqlite.openConnection({path, sharedMemoryCache: false}); await c.close(); }); add_task(async function test_get_dummy_database() {
--- a/toolkit/modules/tests/xpcshell/xpcshell.ini +++ b/toolkit/modules/tests/xpcshell/xpcshell.ini @@ -1,14 +1,15 @@ [DEFAULT] head = head.js support-files = propertyLists/bug710259_propertyListBinary.plist propertyLists/bug710259_propertyListXML.plist chromeappsstore.sqlite + corrupt.sqlite zips/zen.zip [test_BinarySearch.js] skip-if = toolkit == 'android' [test_CanonicalJSON.js] [test_client_id.js] skip-if = toolkit == 'android' [test_Color.js]