Bug 1407778 - Added status Error property on Sqlite.openConnection. r=mak
This commit is contained in:
@@ -945,7 +945,9 @@ function openConnection(options) {
|
||||
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");
|
||||
|
||||
1
toolkit/modules/tests/xpcshell/corrupt.sqlite
Normal file
1
toolkit/modules/tests/xpcshell/corrupt.sqlite
Normal file
@@ -0,0 +1 @@
|
||||
CORRUPTED_SQLITE_FILE_CONTENTS
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
var {classes: Cc, interfaces: Ci, utils: Cu} = Components;
|
||||
var {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
|
||||
|
||||
do_get_profile();
|
||||
|
||||
@@ -91,6 +91,24 @@ add_task(async function test_open_normal() {
|
||||
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");
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ support-files =
|
||||
propertyLists/bug710259_propertyListBinary.plist
|
||||
propertyLists/bug710259_propertyListXML.plist
|
||||
chromeappsstore.sqlite
|
||||
corrupt.sqlite
|
||||
zips/zen.zip
|
||||
|
||||
[test_BinarySearch.js]
|
||||
|
||||
Reference in New Issue
Block a user