зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1186034 - Part 2: Tests for new permission manager migration pathways. r=ehsan
--HG-- rename : extensions/cookie/test/unit/test_permmanager_migrate_4-5.js => extensions/cookie/test/unit/test_permmanager_migrate_4-7.js
This commit is contained in:
Родитель
cab40a9f9c
Коммит
017f9a9077
|
@ -121,7 +121,7 @@ function run_test() {
|
|||
|
||||
// The schema should be upgraded to 6, and a 'modificationTime' column should
|
||||
// exist with all records having a value of 0.
|
||||
do_check_eq(connection.schemaVersion, 6);
|
||||
do_check_eq(connection.schemaVersion, 7);
|
||||
|
||||
let select = connection.createStatement("SELECT modificationTime FROM moz_perms")
|
||||
let numMigrated = 0;
|
||||
|
|
|
@ -47,7 +47,9 @@ add_task(function test() {
|
|||
let id = 0;
|
||||
|
||||
function insertHost(host, type, permission, expireType, expireTime, modificationTime, appId, isInBrowserElement) {
|
||||
stmtInsert.bindByName("id", id++);
|
||||
let thisId = id++;
|
||||
|
||||
stmtInsert.bindByName("id", thisId);
|
||||
stmtInsert.bindByName("host", host);
|
||||
stmtInsert.bindByName("type", type);
|
||||
stmtInsert.bindByName("permission", permission);
|
||||
|
@ -57,30 +59,39 @@ add_task(function test() {
|
|||
stmtInsert.bindByName("appId", appId);
|
||||
stmtInsert.bindByName("isInBrowserElement", isInBrowserElement);
|
||||
|
||||
try {
|
||||
stmtInsert.executeStep();
|
||||
stmtInsert.reset();
|
||||
} catch (e) {
|
||||
stmtInsert.reset();
|
||||
throw e;
|
||||
}
|
||||
stmtInsert.execute();
|
||||
|
||||
return {
|
||||
id: thisId,
|
||||
host: host,
|
||||
type: type,
|
||||
permission: permission,
|
||||
expireType: expireType,
|
||||
expireTime: expireTime,
|
||||
modificationTime: modificationTime,
|
||||
appId: appId,
|
||||
isInBrowserElement: isInBrowserElement
|
||||
};
|
||||
}
|
||||
|
||||
// Add some rows to the database
|
||||
insertHost("foo.com", "A", 1, 0, 0, 0, 0, false);
|
||||
insertHost("foo.com", "A", 1, 0, 0, 0, 1000, false);
|
||||
insertHost("foo.com", "A", 1, 0, 0, 0, 2000, true);
|
||||
insertHost("sub.foo.com", "B", 1, 0, 0, 0, 0, false);
|
||||
insertHost("subber.sub.foo.com", "B", 1, 0, 0, 0, 0, false);
|
||||
insertHost("bar.ca", "B", 1, 0, 0, 0, 0, false);
|
||||
insertHost("bar.ca", "B", 1, 0, 0, 0, 1000, false);
|
||||
insertHost("bar.ca", "A", 1, 0, 0, 0, 1000, true);
|
||||
insertHost("file:///some/path/to/file.html", "A", 1, 0, 0, 0, 0, false);
|
||||
insertHost("file:///another/file.html", "A", 1, 0, 0, 0, 0, false);
|
||||
insertHost("moz-nullprincipal:{8695105a-adbe-4e4e-8083-851faa5ca2d7}", "A", 1, 0, 0, 0, 0, false);
|
||||
insertHost("moz-nullprincipal:{12ahjksd-akjs-asd3-8393-asdu2189asdu}", "B", 1, 0, 0, 0, 0, false);
|
||||
insertHost("<file>", "A", 1, 0, 0, 0, 0, false);
|
||||
insertHost("<file>", "B", 1, 0, 0, 0, 0, false);
|
||||
let created = [
|
||||
insertHost("foo.com", "A", 1, 0, 0, 0, 0, false),
|
||||
insertHost("foo.com", "C", 1, 0, 0, 0, 0, false),
|
||||
insertHost("foo.com", "A", 1, 0, 0, 0, 1000, false),
|
||||
insertHost("foo.com", "A", 1, 0, 0, 0, 2000, true),
|
||||
insertHost("sub.foo.com", "B", 1, 0, 0, 0, 0, false),
|
||||
insertHost("subber.sub.foo.com", "B", 1, 0, 0, 0, 0, false),
|
||||
insertHost("bar.ca", "B", 1, 0, 0, 0, 0, false),
|
||||
insertHost("bar.ca", "B", 1, 0, 0, 0, 1000, false),
|
||||
insertHost("bar.ca", "A", 1, 0, 0, 0, 1000, true),
|
||||
insertHost("file:///some/path/to/file.html", "A", 1, 0, 0, 0, 0, false),
|
||||
insertHost("file:///another/file.html", "A", 1, 0, 0, 0, 0, false),
|
||||
insertHost("moz-nullprincipal:{8695105a-adbe-4e4e-8083-851faa5ca2d7}", "A", 1, 0, 0, 0, 0, false),
|
||||
insertHost("moz-nullprincipal:{12ahjksd-akjs-asd3-8393-asdu2189asdu}", "B", 1, 0, 0, 0, 0, false),
|
||||
insertHost("<file>", "A", 1, 0, 0, 0, 0, false),
|
||||
insertHost("<file>", "B", 1, 0, 0, 0, 0, false),
|
||||
];
|
||||
|
||||
// CLose the db connection
|
||||
stmtInsert.finalize();
|
||||
|
@ -91,22 +102,23 @@ add_task(function test() {
|
|||
let expected = [
|
||||
// The http:// entries under foo.com won't be inserted, as there are history entries for foo.com,
|
||||
// and http://foo.com or a subdomain are never visited.
|
||||
// However, permissions for subdomains of foo.com will be present for both http:// and https://,
|
||||
// as they do not apply to any entry in the history
|
||||
// ["http://foo.com", "A", 1, 0, 0],
|
||||
// ["http://foo.com^appId=1000", "A", 1, 0, 0],
|
||||
// ["http://foo.com^appId=2000&inBrowser=1", "A", 1, 0, 0],
|
||||
|
||||
["http://sub.foo.com", "B", 1, 0, 0],
|
||||
["http://subber.sub.foo.com", "B", 1, 0, 0],
|
||||
//
|
||||
// Because we search for port/scheme combinations under eTLD+1, we should not have http:// entries
|
||||
// for subdomains of foo.com either
|
||||
// ["http://sub.foo.com", "B", 1, 0, 0],
|
||||
// ["http://subber.sub.foo.com", "B", 1, 0, 0],
|
||||
|
||||
["https://foo.com", "A", 1, 0, 0],
|
||||
["https://foo.com", "C", 1, 0, 0],
|
||||
["https://foo.com^appId=1000", "A", 1, 0, 0],
|
||||
["https://foo.com^appId=2000&inBrowser=1", "A", 1, 0, 0],
|
||||
["https://sub.foo.com", "B", 1, 0, 0],
|
||||
["https://subber.sub.foo.com", "B", 1, 0, 0],
|
||||
|
||||
// bar.ca will have both http:// and https:// for all entries, because the foo did the bar a favour
|
||||
// bar.ca will have both http:// and https:// for all entries, because there are no associated history entries
|
||||
["http://bar.ca", "B", 1, 0, 0],
|
||||
["https://bar.ca", "B", 1, 0, 0],
|
||||
["http://bar.ca^appId=1000", "B", 1, 0, 0],
|
||||
|
@ -119,8 +131,14 @@ add_task(function test() {
|
|||
// Because we put ftp://some.subdomain.of.foo.com:8000/some/subdirectory in the history, we should
|
||||
// also have these entries
|
||||
["ftp://foo.com:8000", "A", 1, 0, 0],
|
||||
["ftp://foo.com:8000", "C", 1, 0, 0],
|
||||
["ftp://foo.com:8000^appId=1000", "A", 1, 0, 0],
|
||||
["ftp://foo.com:8000^appId=2000&inBrowser=1", "A", 1, 0, 0],
|
||||
|
||||
// In addition, because we search for port/scheme combinations under eTLD+1, we should have the
|
||||
// following entries
|
||||
["ftp://sub.foo.com:8000", "B", 1, 0, 0],
|
||||
["ftp://subber.sub.foo.com:8000", "B", 1, 0, 0],
|
||||
];
|
||||
|
||||
let found = expected.map((it) => 0);
|
||||
|
@ -159,4 +177,40 @@ add_task(function test() {
|
|||
found.forEach((count, i) => {
|
||||
do_check_true(count == 1, "Expected count = 1, got count = " + count + " for permission " + expected[i]);
|
||||
});
|
||||
|
||||
// Check to make sure that all of the tables which we care about are present
|
||||
{
|
||||
let db = Services.storage.openDatabase(GetPermissionsFile(profile));
|
||||
do_check_true(db.tableExists("moz_perms"));
|
||||
do_check_true(db.tableExists("moz_hosts"));
|
||||
do_check_true(db.tableExists("moz_hosts_is_backup"));
|
||||
do_check_false(db.tableExists("moz_perms_v6"));
|
||||
|
||||
let mozHostsStmt = db.createStatement("SELECT " +
|
||||
"host, type, permission, expireType, expireTime, " +
|
||||
"modificationTime, appId, isInBrowserElement " +
|
||||
"FROM moz_hosts WHERE id = :id");
|
||||
|
||||
// Check that the moz_hosts table still contains the correct values.
|
||||
created.forEach((it) => {
|
||||
mozHostsStmt.reset();
|
||||
mozHostsStmt.bindByName("id", it.id);
|
||||
mozHostsStmt.executeStep();
|
||||
do_check_eq(mozHostsStmt.getUTF8String(0), it.host);
|
||||
do_check_eq(mozHostsStmt.getUTF8String(1), it.type);
|
||||
do_check_eq(mozHostsStmt.getInt64(2), it.permission);
|
||||
do_check_eq(mozHostsStmt.getInt64(3), it.expireType);
|
||||
do_check_eq(mozHostsStmt.getInt64(4), it.expireTime);
|
||||
do_check_eq(mozHostsStmt.getInt64(5), it.modificationTime);
|
||||
do_check_eq(mozHostsStmt.getInt64(6), it.appId);
|
||||
do_check_eq(mozHostsStmt.getInt64(7), it.isInBrowserElement);
|
||||
});
|
||||
|
||||
// Check that there are the right number of values
|
||||
let mozHostsCount = db.createStatement("SELECT count(*) FROM moz_hosts");
|
||||
mozHostsCount.executeStep();
|
||||
do_check_eq(mozHostsCount.getInt64(0), created.length);
|
||||
|
||||
db.close();
|
||||
}
|
||||
});
|
|
@ -1,175 +0,0 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
let PERMISSIONS_FILE_NAME = "permissions.sqlite";
|
||||
|
||||
function GetPermissionsFile(profile)
|
||||
{
|
||||
let file = profile.clone();
|
||||
file.append(PERMISSIONS_FILE_NAME);
|
||||
return file;
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
add_task(function test() {
|
||||
/* Create and set up the permissions database */
|
||||
let profile = do_get_profile();
|
||||
let perms = [];
|
||||
|
||||
let db = Services.storage.openDatabase(GetPermissionsFile(profile));
|
||||
db.schemaVersion = 5;
|
||||
|
||||
db.executeSimpleSQL(
|
||||
"CREATE TABLE moz_hosts (" +
|
||||
" id INTEGER PRIMARY KEY" +
|
||||
",origin TEXT" +
|
||||
",type TEXT" +
|
||||
",permission INTEGER" +
|
||||
",expireType INTEGER" +
|
||||
",expireTime INTEGER" +
|
||||
",modificationTime INTEGER" +
|
||||
")");
|
||||
|
||||
db.executeSimpleSQL(
|
||||
"CREATE TABLE moz_hosts_v4 (" +
|
||||
" id INTEGER PRIMARY KEY" +
|
||||
",host TEXT" +
|
||||
",type TEXT" +
|
||||
",permission INTEGER" +
|
||||
",expireType INTEGER" +
|
||||
",expireTime INTEGER" +
|
||||
",modificationTime INTEGER" +
|
||||
",appId INTEGER" +
|
||||
",isInBrowserElement INTEGER" +
|
||||
")");
|
||||
|
||||
let stmtInsert = db.createStatement(
|
||||
"INSERT INTO moz_hosts (" +
|
||||
"id, origin, type, permission, expireType, expireTime, modificationTime" +
|
||||
") VALUES (" +
|
||||
":id, :origin, :type, :permission, :expireType, :expireTime, :modificationTime" +
|
||||
")");
|
||||
|
||||
let stmt4Insert = db.createStatement(
|
||||
"INSERT INTO moz_hosts_v4 (" +
|
||||
"id, host, type, permission, expireType, expireTime, modificationTime, appId, isInBrowserElement" +
|
||||
") VALUES (" +
|
||||
":id, :host, :type, :permission, :expireType, :expireTime, :modificationTime, :appId, :isInBrowserElement" +
|
||||
")");
|
||||
|
||||
let id = 0;
|
||||
|
||||
// Insert an origin into the database, and return its principal, type, and permission values
|
||||
function insertV5(origin, type, permission, expireType, expireTime, modificationTime) {
|
||||
let thisId = id++;
|
||||
|
||||
stmtInsert.bindByName("id", thisId);
|
||||
stmtInsert.bindByName("origin", origin);
|
||||
stmtInsert.bindByName("type", type);
|
||||
stmtInsert.bindByName("permission", permission);
|
||||
stmtInsert.bindByName("expireType", expireType);
|
||||
stmtInsert.bindByName("expireTime", expireTime);
|
||||
stmtInsert.bindByName("modificationTime", modificationTime);
|
||||
|
||||
stmtInsert.execute();
|
||||
|
||||
return function(stmtLookup, stmt4Lookup) {
|
||||
stmtLookup.bindByName("id", thisId);
|
||||
|
||||
do_check_true(stmtLookup.executeStep());
|
||||
do_check_eq(stmtLookup.getUTF8String(0), origin);
|
||||
do_check_eq(stmtLookup.getUTF8String(1), type);
|
||||
do_check_eq(stmtLookup.getInt64(2), permission);
|
||||
do_check_eq(stmtLookup.getInt64(3), expireType);
|
||||
do_check_eq(stmtLookup.getInt64(4), expireTime);
|
||||
do_check_eq(stmtLookup.getInt64(5), modificationTime);
|
||||
do_check_false(stmtLookup.executeStep());
|
||||
stmtLookup.reset();
|
||||
};
|
||||
}
|
||||
|
||||
function insertV4(host, type, permission, expireType, expireTime, modificationTime, appId, isInBrowserElement) {
|
||||
let thisId = id++;
|
||||
|
||||
stmt4Insert.bindByName("id", thisId);
|
||||
stmt4Insert.bindByName("host", host);
|
||||
stmt4Insert.bindByName("type", type);
|
||||
stmt4Insert.bindByName("permission", permission);
|
||||
stmt4Insert.bindByName("expireType", expireType);
|
||||
stmt4Insert.bindByName("expireTime", expireTime);
|
||||
stmt4Insert.bindByName("modificationTime", modificationTime);
|
||||
stmt4Insert.bindByName("appId", appId);
|
||||
stmt4Insert.bindByName("isInBrowserElement", isInBrowserElement);
|
||||
|
||||
stmt4Insert.execute();
|
||||
|
||||
return function(stmtLookup, stmt4Lookup) {
|
||||
stmt4Lookup.bindByName("id", thisId);
|
||||
|
||||
do_check_true(stmt4Lookup.executeStep());
|
||||
do_check_eq(stmt4Lookup.getUTF8String(0), host);
|
||||
do_check_eq(stmt4Lookup.getUTF8String(1), type);
|
||||
do_check_eq(stmt4Lookup.getInt64(2), permission);
|
||||
do_check_eq(stmt4Lookup.getInt64(3), expireType);
|
||||
do_check_eq(stmt4Lookup.getInt64(4), expireTime);
|
||||
do_check_eq(stmt4Lookup.getInt64(5), modificationTime);
|
||||
do_check_eq(stmt4Lookup.getInt64(6), appId);
|
||||
do_check_eq(!!stmt4Lookup.getInt64(7), isInBrowserElement);
|
||||
do_check_false(stmt4Lookup.executeStep());
|
||||
stmt4Lookup.reset();
|
||||
};
|
||||
}
|
||||
|
||||
// Add some rows to the database
|
||||
perms = [
|
||||
insertV5("http://foo.com", "A", 1, 0, 0, 0),
|
||||
insertV5("https://foo.com", "A", 1, 0, 0, 0),
|
||||
insertV5("https://foo.com^appId=1000", "A", 1, 0, 0, 0),
|
||||
insertV5("http://foo.com^appId=2000&inBrowser=1", "A", 1, 0, 0, 0),
|
||||
insertV5("https://sub.foo.com", "B", 1, 0, 0, 0),
|
||||
insertV5("http://subber.sub.foo.com", "B", 1, 0, 0, 0),
|
||||
insertV5("http://bar.ca", "B", 1, 0, 0, 0),
|
||||
insertV5("https://bar.ca", "B", 1, 0, 0, 0),
|
||||
insertV5("ftp://bar.ca", "A", 2, 0, 0, 0),
|
||||
insertV5("http://bar.ca^appId=1000", "B", 1, 0, 0, 0),
|
||||
insertV5("http://bar.ca^appId=1000&inBrowser=1", "A", 1, 0, 0, 0),
|
||||
insertV5("file:///some/path/to/file.html", "A", 1, 0, 0, 0),
|
||||
insertV5("file:///another/file.html", "A", 1, 0, 0, 0),
|
||||
insertV5("about:home", "A", 1, 0, 0, 0),
|
||||
|
||||
|
||||
insertV4("https://foo.com", "A", 1, 0, 0, 0, 1000, false),
|
||||
insertV4("http://foo.com", "A", 1, 0, 0, 0, 2000, true),
|
||||
insertV4("https://sub.foo.com", "B", 1, 0, 0, 0, 0, false),
|
||||
insertV4("http://subber.sub.foo.com", "B", 1, 0, 0, 0, 0, false),
|
||||
insertV4("http://bar.ca", "B", 1, 0, 0, 0, 0, false),
|
||||
insertV4("https://bar.ca", "B", 1, 0, 0, 0, 0, false),
|
||||
];
|
||||
|
||||
// Force the permission manager to initialize
|
||||
let enumerator = Services.perms.enumerator;
|
||||
do_check_true(enumerator.hasMoreElements());
|
||||
|
||||
stmtInsert.finalize();
|
||||
stmt4Insert.finalize();
|
||||
db.close();
|
||||
|
||||
db = Services.storage.openDatabase(GetPermissionsFile(profile));
|
||||
do_check_eq(db.schemaVersion, 6);
|
||||
|
||||
let stmtLookup = db.createStatement(
|
||||
"SELECT origin, type, permission, expireType, expireTime, modificationTime FROM moz_perms WHERE id = :id;");
|
||||
let stmt4Lookup = db.createStatement(
|
||||
"SELECT host, type, permission, expireType, expireTime, modificationTime, appId, isInBrowserElement FROM moz_hosts WHERE id = :id;");
|
||||
|
||||
// Call each of the validation callbacks
|
||||
perms.forEach((cb) => cb(stmtLookup, stmt4Lookup));
|
||||
|
||||
// Close the db connection
|
||||
stmtLookup.finalize();
|
||||
stmt4Lookup.finalize();
|
||||
db.close();
|
||||
});
|
|
@ -0,0 +1,293 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "PlacesTestUtils",
|
||||
"resource://testing-common/PlacesTestUtils.jsm");
|
||||
|
||||
let PERMISSIONS_FILE_NAME = "permissions.sqlite";
|
||||
|
||||
function GetPermissionsFile(profile)
|
||||
{
|
||||
let file = profile.clone();
|
||||
file.append(PERMISSIONS_FILE_NAME);
|
||||
return file;
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
add_task(function test() {
|
||||
/* Create and set up the permissions database */
|
||||
let profile = do_get_profile();
|
||||
|
||||
let db = Services.storage.openDatabase(GetPermissionsFile(profile));
|
||||
db.schemaVersion = 5;
|
||||
|
||||
/*
|
||||
* V5 table
|
||||
*/
|
||||
db.executeSimpleSQL(
|
||||
"CREATE TABLE moz_hosts (" +
|
||||
" id INTEGER PRIMARY KEY" +
|
||||
",origin TEXT" +
|
||||
",type TEXT" +
|
||||
",permission INTEGER" +
|
||||
",expireType INTEGER" +
|
||||
",expireTime INTEGER" +
|
||||
",modificationTime INTEGER" +
|
||||
")");
|
||||
|
||||
let stmt5Insert = db.createStatement(
|
||||
"INSERT INTO moz_hosts (" +
|
||||
"id, origin, type, permission, expireType, expireTime, modificationTime" +
|
||||
") VALUES (" +
|
||||
":id, :origin, :type, :permission, :expireType, :expireTime, :modificationTime" +
|
||||
")");
|
||||
|
||||
/*
|
||||
* V4 table
|
||||
*/
|
||||
db.executeSimpleSQL(
|
||||
"CREATE TABLE moz_hosts_v4 (" +
|
||||
" id INTEGER PRIMARY KEY" +
|
||||
",host TEXT" +
|
||||
",type TEXT" +
|
||||
",permission INTEGER" +
|
||||
",expireType INTEGER" +
|
||||
",expireTime INTEGER" +
|
||||
",modificationTime INTEGER" +
|
||||
",appId INTEGER" +
|
||||
",isInBrowserElement INTEGER" +
|
||||
")");
|
||||
|
||||
let stmtInsert = db.createStatement(
|
||||
"INSERT INTO moz_hosts_v4 (" +
|
||||
"id, host, type, permission, expireType, expireTime, modificationTime, appId, isInBrowserElement" +
|
||||
") VALUES (" +
|
||||
":id, :host, :type, :permission, :expireType, :expireTime, :modificationTime, :appId, :isInBrowserElement" +
|
||||
")");
|
||||
|
||||
let id = 0;
|
||||
|
||||
function insertOrigin(origin, type, permission, expireType, expireTime, modificationTime) {
|
||||
let thisId = id++;
|
||||
|
||||
stmt5Insert.bindByName("id", thisId);
|
||||
stmt5Insert.bindByName("origin", origin);
|
||||
stmt5Insert.bindByName("type", type);
|
||||
stmt5Insert.bindByName("permission", permission);
|
||||
stmt5Insert.bindByName("expireType", expireType);
|
||||
stmt5Insert.bindByName("expireTime", expireTime);
|
||||
stmt5Insert.bindByName("modificationTime", modificationTime);
|
||||
|
||||
stmt5Insert.execute();
|
||||
|
||||
return {
|
||||
id: thisId,
|
||||
origin: origin,
|
||||
type: type,
|
||||
permission: permission,
|
||||
expireType: expireType,
|
||||
expireTime: expireTime,
|
||||
modificationTime: modificationTime
|
||||
};
|
||||
}
|
||||
|
||||
function insertHost(host, type, permission, expireType, expireTime, modificationTime, appId, isInBrowserElement) {
|
||||
let thisId = id++;
|
||||
|
||||
stmtInsert.bindByName("id", thisId);
|
||||
stmtInsert.bindByName("host", host);
|
||||
stmtInsert.bindByName("type", type);
|
||||
stmtInsert.bindByName("permission", permission);
|
||||
stmtInsert.bindByName("expireType", expireType);
|
||||
stmtInsert.bindByName("expireTime", expireTime);
|
||||
stmtInsert.bindByName("modificationTime", modificationTime);
|
||||
stmtInsert.bindByName("appId", appId);
|
||||
stmtInsert.bindByName("isInBrowserElement", isInBrowserElement);
|
||||
|
||||
stmtInsert.execute();
|
||||
|
||||
return {
|
||||
id: thisId,
|
||||
host: host,
|
||||
type: type,
|
||||
permission: permission,
|
||||
expireType: expireType,
|
||||
expireTime: expireTime,
|
||||
modificationTime: modificationTime,
|
||||
appId: appId,
|
||||
isInBrowserElement: isInBrowserElement
|
||||
};
|
||||
}
|
||||
|
||||
let created5 = [
|
||||
insertOrigin("https://foo.com", "A", 2, 0, 0, 0),
|
||||
insertOrigin("http://foo.com", "A", 2, 0, 0, 0),
|
||||
insertOrigin("http://foo.com^appId=1000&inBrowser=1", "A", 2, 0, 0, 0),
|
||||
];
|
||||
|
||||
// Add some rows to the database
|
||||
let created = [
|
||||
insertHost("foo.com", "A", 1, 0, 0, 0, 0, false),
|
||||
insertHost("foo.com", "C", 1, 0, 0, 0, 0, false),
|
||||
insertHost("foo.com", "A", 1, 0, 0, 0, 1000, false),
|
||||
insertHost("foo.com", "A", 1, 0, 0, 0, 2000, true),
|
||||
insertHost("sub.foo.com", "B", 1, 0, 0, 0, 0, false),
|
||||
insertHost("subber.sub.foo.com", "B", 1, 0, 0, 0, 0, false),
|
||||
insertHost("bar.ca", "B", 1, 0, 0, 0, 0, false),
|
||||
insertHost("bar.ca", "B", 1, 0, 0, 0, 1000, false),
|
||||
insertHost("bar.ca", "A", 1, 0, 0, 0, 1000, true),
|
||||
insertHost("file:///some/path/to/file.html", "A", 1, 0, 0, 0, 0, false),
|
||||
insertHost("file:///another/file.html", "A", 1, 0, 0, 0, 0, false),
|
||||
insertHost("moz-nullprincipal:{8695105a-adbe-4e4e-8083-851faa5ca2d7}", "A", 1, 0, 0, 0, 0, false),
|
||||
insertHost("moz-nullprincipal:{12ahjksd-akjs-asd3-8393-asdu2189asdu}", "B", 1, 0, 0, 0, 0, false),
|
||||
insertHost("<file>", "A", 1, 0, 0, 0, 0, false),
|
||||
insertHost("<file>", "B", 1, 0, 0, 0, 0, false),
|
||||
];
|
||||
|
||||
// CLose the db connection
|
||||
stmtInsert.finalize();
|
||||
db.close();
|
||||
stmtInsert = null;
|
||||
db = null;
|
||||
|
||||
let expected = [
|
||||
// The http:// entries under foo.com won't be inserted, as there are history entries for foo.com,
|
||||
// and http://foo.com or a subdomain are never visited.
|
||||
// ["http://foo.com", "A", 1, 0, 0],
|
||||
// ["http://foo.com^appId=1000", "A", 1, 0, 0],
|
||||
// ["http://foo.com^appId=2000&inBrowser=1", "A", 1, 0, 0],
|
||||
//
|
||||
// Because we search for port/scheme combinations under eTLD+1, we should not have http:// entries
|
||||
// for subdomains of foo.com either
|
||||
// ["http://sub.foo.com", "B", 1, 0, 0],
|
||||
// ["http://subber.sub.foo.com", "B", 1, 0, 0],
|
||||
|
||||
["https://foo.com", "A", 1, 0, 0],
|
||||
["https://foo.com", "C", 1, 0, 0],
|
||||
["https://foo.com^appId=1000", "A", 1, 0, 0],
|
||||
["https://foo.com^appId=2000&inBrowser=1", "A", 1, 0, 0],
|
||||
["https://sub.foo.com", "B", 1, 0, 0],
|
||||
["https://subber.sub.foo.com", "B", 1, 0, 0],
|
||||
|
||||
// bar.ca will have both http:// and https:// for all entries, because there are no associated history entries
|
||||
["http://bar.ca", "B", 1, 0, 0],
|
||||
["https://bar.ca", "B", 1, 0, 0],
|
||||
["http://bar.ca^appId=1000", "B", 1, 0, 0],
|
||||
["https://bar.ca^appId=1000", "B", 1, 0, 0],
|
||||
["http://bar.ca^appId=1000&inBrowser=1", "A", 1, 0, 0],
|
||||
["https://bar.ca^appId=1000&inBrowser=1", "A", 1, 0, 0],
|
||||
["file:///some/path/to/file.html", "A", 1, 0, 0],
|
||||
["file:///another/file.html", "A", 1, 0, 0],
|
||||
|
||||
// Because we put ftp://some.subdomain.of.foo.com:8000/some/subdirectory in the history, we should
|
||||
// also have these entries
|
||||
["ftp://foo.com:8000", "A", 1, 0, 0],
|
||||
["ftp://foo.com:8000", "C", 1, 0, 0],
|
||||
["ftp://foo.com:8000^appId=1000", "A", 1, 0, 0],
|
||||
["ftp://foo.com:8000^appId=2000&inBrowser=1", "A", 1, 0, 0],
|
||||
|
||||
// In addition, because we search for port/scheme combinations under eTLD+1, we should have the
|
||||
// following entries
|
||||
["ftp://sub.foo.com:8000", "B", 1, 0, 0],
|
||||
["ftp://subber.sub.foo.com:8000", "B", 1, 0, 0],
|
||||
];
|
||||
|
||||
let found = expected.map((it) => 0);
|
||||
|
||||
// Add some places to the places database
|
||||
yield PlacesTestUtils.addVisits(Services.io.newURI("https://foo.com/some/other/subdirectory", null, null));
|
||||
yield PlacesTestUtils.addVisits(Services.io.newURI("ftp://some.subdomain.of.foo.com:8000/some/subdirectory", null, null));
|
||||
|
||||
// Force initialization of the nsPermissionManager
|
||||
let enumerator = Services.perms.enumerator;
|
||||
while (enumerator.hasMoreElements()) {
|
||||
let permission = enumerator.getNext().QueryInterface(Ci.nsIPermission);
|
||||
let isExpected = false;
|
||||
|
||||
expected.forEach((it, i) => {
|
||||
if (permission.principal.origin == it[0] &&
|
||||
permission.type == it[1] &&
|
||||
permission.capability == it[2] &&
|
||||
permission.expireType == it[3] &&
|
||||
permission.expireTime == it[4]) {
|
||||
isExpected = true;
|
||||
found[i]++;
|
||||
}
|
||||
});
|
||||
|
||||
do_check_true(isExpected,
|
||||
"Permission " + (isExpected ? "should" : "shouldn't") +
|
||||
" be in permission database: " +
|
||||
permission.principal.origin + ", " +
|
||||
permission.type + ", " +
|
||||
permission.capability + ", " +
|
||||
permission.expireType + ", " +
|
||||
permission.expireTime);
|
||||
}
|
||||
|
||||
found.forEach((count, i) => {
|
||||
do_check_true(count == 1, "Expected count = 1, got count = " + count + " for permission " + expected[i]);
|
||||
});
|
||||
|
||||
// Check to make sure that all of the tables which we care about are present
|
||||
{
|
||||
let db = Services.storage.openDatabase(GetPermissionsFile(profile));
|
||||
do_check_true(db.tableExists("moz_perms"));
|
||||
do_check_true(db.tableExists("moz_hosts"));
|
||||
do_check_true(db.tableExists("moz_hosts_is_backup"));
|
||||
do_check_true(db.tableExists("moz_perms_v6"));
|
||||
|
||||
let mozHostsStmt = db.createStatement("SELECT " +
|
||||
"host, type, permission, expireType, expireTime, " +
|
||||
"modificationTime, appId, isInBrowserElement " +
|
||||
"FROM moz_hosts WHERE id = :id");
|
||||
|
||||
// Check that the moz_hosts table still contains the correct values.
|
||||
created.forEach((it) => {
|
||||
mozHostsStmt.reset();
|
||||
mozHostsStmt.bindByName("id", it.id);
|
||||
mozHostsStmt.executeStep();
|
||||
do_check_eq(mozHostsStmt.getUTF8String(0), it.host);
|
||||
do_check_eq(mozHostsStmt.getUTF8String(1), it.type);
|
||||
do_check_eq(mozHostsStmt.getInt64(2), it.permission);
|
||||
do_check_eq(mozHostsStmt.getInt64(3), it.expireType);
|
||||
do_check_eq(mozHostsStmt.getInt64(4), it.expireTime);
|
||||
do_check_eq(mozHostsStmt.getInt64(5), it.modificationTime);
|
||||
do_check_eq(mozHostsStmt.getInt64(6), it.appId);
|
||||
do_check_eq(mozHostsStmt.getInt64(7), it.isInBrowserElement);
|
||||
});
|
||||
|
||||
// Check that there are the right number of values
|
||||
let mozHostsCount = db.createStatement("SELECT count(*) FROM moz_hosts");
|
||||
mozHostsCount.executeStep();
|
||||
do_check_eq(mozHostsCount.getInt64(0), created.length);
|
||||
|
||||
// Check that the moz_perms_v6 table contains the backup of the entry we created
|
||||
let mozPermsV6Stmt = db.createStatement("SELECT " +
|
||||
"origin, type, permission, expireType, expireTime, modificationTime " +
|
||||
"FROM moz_perms_v6 WHERE id = :id");
|
||||
|
||||
// Check that the moz_hosts table still contains the correct values.
|
||||
created5.forEach((it) => {
|
||||
mozPermsV6Stmt.reset();
|
||||
mozPermsV6Stmt.bindByName("id", it.id);
|
||||
mozPermsV6Stmt.executeStep();
|
||||
do_check_eq(mozPermsV6Stmt.getUTF8String(0), it.origin);
|
||||
do_check_eq(mozPermsV6Stmt.getUTF8String(1), it.type);
|
||||
do_check_eq(mozPermsV6Stmt.getInt64(2), it.permission);
|
||||
do_check_eq(mozPermsV6Stmt.getInt64(3), it.expireType);
|
||||
do_check_eq(mozPermsV6Stmt.getInt64(4), it.expireTime);
|
||||
do_check_eq(mozPermsV6Stmt.getInt64(5), it.modificationTime);
|
||||
});
|
||||
|
||||
// Check that there are the right number of values
|
||||
let mozPermsV6Count = db.createStatement("SELECT count(*) FROM moz_perms_v6");
|
||||
mozPermsV6Count.executeStep();
|
||||
do_check_eq(mozPermsV6Count.getInt64(0), created5.length);
|
||||
|
||||
db.close();
|
||||
}
|
||||
});
|
|
@ -0,0 +1,162 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "PlacesTestUtils",
|
||||
"resource://testing-common/PlacesTestUtils.jsm");
|
||||
|
||||
let PERMISSIONS_FILE_NAME = "permissions.sqlite";
|
||||
|
||||
function GetPermissionsFile(profile)
|
||||
{
|
||||
let file = profile.clone();
|
||||
file.append(PERMISSIONS_FILE_NAME);
|
||||
return file;
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
add_task(function test() {
|
||||
/* Create and set up the permissions database */
|
||||
let profile = do_get_profile();
|
||||
|
||||
let db = Services.storage.openDatabase(GetPermissionsFile(profile));
|
||||
db.schemaVersion = 5;
|
||||
|
||||
/*
|
||||
* V5 table
|
||||
*/
|
||||
db.executeSimpleSQL(
|
||||
"CREATE TABLE moz_hosts (" +
|
||||
" id INTEGER PRIMARY KEY" +
|
||||
",origin TEXT" +
|
||||
",type TEXT" +
|
||||
",permission INTEGER" +
|
||||
",expireType INTEGER" +
|
||||
",expireTime INTEGER" +
|
||||
",modificationTime INTEGER" +
|
||||
")");
|
||||
|
||||
let stmt5Insert = db.createStatement(
|
||||
"INSERT INTO moz_hosts (" +
|
||||
"id, origin, type, permission, expireType, expireTime, modificationTime" +
|
||||
") VALUES (" +
|
||||
":id, :origin, :type, :permission, :expireType, :expireTime, :modificationTime" +
|
||||
")");
|
||||
|
||||
let id = 0;
|
||||
|
||||
function insertOrigin(origin, type, permission, expireType, expireTime, modificationTime) {
|
||||
let thisId = id++;
|
||||
|
||||
stmt5Insert.bindByName("id", thisId);
|
||||
stmt5Insert.bindByName("origin", origin);
|
||||
stmt5Insert.bindByName("type", type);
|
||||
stmt5Insert.bindByName("permission", permission);
|
||||
stmt5Insert.bindByName("expireType", expireType);
|
||||
stmt5Insert.bindByName("expireTime", expireTime);
|
||||
stmt5Insert.bindByName("modificationTime", modificationTime);
|
||||
|
||||
stmt5Insert.execute();
|
||||
|
||||
return {
|
||||
id: thisId,
|
||||
host: origin,
|
||||
type: type,
|
||||
permission: permission,
|
||||
expireType: expireType,
|
||||
expireTime: expireTime,
|
||||
modificationTime: modificationTime
|
||||
};
|
||||
}
|
||||
|
||||
let created5 = [
|
||||
insertOrigin("https://foo.com", "A", 2, 0, 0, 0),
|
||||
insertOrigin("http://foo.com", "A", 2, 0, 0, 0),
|
||||
insertOrigin("http://foo.com^appId=1000&inBrowser=1", "A", 2, 0, 0, 0),
|
||||
];
|
||||
|
||||
let created4 = []; // Didn't create any v4 entries, so the DB should be empty
|
||||
|
||||
// CLose the db connection
|
||||
stmt5Insert.finalize();
|
||||
db.close();
|
||||
stmt5Insert = null;
|
||||
db = null;
|
||||
|
||||
let expected = [
|
||||
["https://foo.com", "A", 2, 0, 0, 0],
|
||||
["http://foo.com", "A", 2, 0, 0, 0],
|
||||
["http://foo.com^appId=1000&inBrowser=1", "A", 2, 0, 0, 0]
|
||||
];
|
||||
|
||||
let found = expected.map((it) => 0);
|
||||
|
||||
// Force initialization of the nsPermissionManager
|
||||
let enumerator = Services.perms.enumerator;
|
||||
while (enumerator.hasMoreElements()) {
|
||||
let permission = enumerator.getNext().QueryInterface(Ci.nsIPermission);
|
||||
let isExpected = false;
|
||||
|
||||
expected.forEach((it, i) => {
|
||||
if (permission.principal.origin == it[0] &&
|
||||
permission.type == it[1] &&
|
||||
permission.capability == it[2] &&
|
||||
permission.expireType == it[3] &&
|
||||
permission.expireTime == it[4]) {
|
||||
isExpected = true;
|
||||
found[i]++;
|
||||
}
|
||||
});
|
||||
|
||||
do_check_true(isExpected,
|
||||
"Permission " + (isExpected ? "should" : "shouldn't") +
|
||||
" be in permission database: " +
|
||||
permission.principal.origin + ", " +
|
||||
permission.type + ", " +
|
||||
permission.capability + ", " +
|
||||
permission.expireType + ", " +
|
||||
permission.expireTime);
|
||||
}
|
||||
|
||||
found.forEach((count, i) => {
|
||||
do_check_true(count == 1, "Expected count = 1, got count = " + count + " for permission " + expected[i]);
|
||||
});
|
||||
|
||||
// Check to make sure that all of the tables which we care about are present
|
||||
{
|
||||
let db = Services.storage.openDatabase(GetPermissionsFile(profile));
|
||||
do_check_true(db.tableExists("moz_perms"));
|
||||
do_check_true(db.tableExists("moz_hosts"));
|
||||
do_check_false(db.tableExists("moz_hosts_is_backup"));
|
||||
do_check_false(db.tableExists("moz_perms_v6"));
|
||||
|
||||
let mozHostsStmt = db.createStatement("SELECT " +
|
||||
"host, type, permission, expireType, expireTime, " +
|
||||
"modificationTime, appId, isInBrowserElement " +
|
||||
"FROM moz_hosts WHERE id = :id");
|
||||
|
||||
// Check that the moz_hosts table still contains the correct values.
|
||||
created4.forEach((it) => {
|
||||
mozHostsStmt.reset();
|
||||
mozHostsStmt.bindByName("id", it.id);
|
||||
mozHostsStmt.executeStep();
|
||||
do_check_eq(mozHostsStmt.getUTF8String(0), it.host);
|
||||
do_check_eq(mozHostsStmt.getUTF8String(1), it.type);
|
||||
do_check_eq(mozHostsStmt.getInt64(2), it.permission);
|
||||
do_check_eq(mozHostsStmt.getInt64(3), it.expireType);
|
||||
do_check_eq(mozHostsStmt.getInt64(4), it.expireTime);
|
||||
do_check_eq(mozHostsStmt.getInt64(5), it.modificationTime);
|
||||
do_check_eq(mozHostsStmt.getInt64(6), it.appId);
|
||||
do_check_eq(mozHostsStmt.getInt64(7), it.isInBrowserElement);
|
||||
});
|
||||
|
||||
// Check that there are the right number of values
|
||||
let mozHostsCount = db.createStatement("SELECT count(*) FROM moz_hosts");
|
||||
mozHostsCount.executeStep();
|
||||
do_check_eq(mozHostsCount.getInt64(0), created4.length);
|
||||
|
||||
db.close();
|
||||
}
|
||||
});
|
|
@ -0,0 +1,293 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "PlacesTestUtils",
|
||||
"resource://testing-common/PlacesTestUtils.jsm");
|
||||
|
||||
let PERMISSIONS_FILE_NAME = "permissions.sqlite";
|
||||
|
||||
function GetPermissionsFile(profile)
|
||||
{
|
||||
let file = profile.clone();
|
||||
file.append(PERMISSIONS_FILE_NAME);
|
||||
return file;
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
add_task(function test() {
|
||||
/* Create and set up the permissions database */
|
||||
let profile = do_get_profile();
|
||||
|
||||
let db = Services.storage.openDatabase(GetPermissionsFile(profile));
|
||||
db.schemaVersion = 6;
|
||||
|
||||
/*
|
||||
* V5 table
|
||||
*/
|
||||
db.executeSimpleSQL(
|
||||
"CREATE TABLE moz_perms (" +
|
||||
" id INTEGER PRIMARY KEY" +
|
||||
",origin TEXT" +
|
||||
",type TEXT" +
|
||||
",permission INTEGER" +
|
||||
",expireType INTEGER" +
|
||||
",expireTime INTEGER" +
|
||||
",modificationTime INTEGER" +
|
||||
")");
|
||||
|
||||
let stmt6Insert = db.createStatement(
|
||||
"INSERT INTO moz_perms (" +
|
||||
"id, origin, type, permission, expireType, expireTime, modificationTime" +
|
||||
") VALUES (" +
|
||||
":id, :origin, :type, :permission, :expireType, :expireTime, :modificationTime" +
|
||||
")");
|
||||
|
||||
/*
|
||||
* V4 table
|
||||
*/
|
||||
db.executeSimpleSQL(
|
||||
"CREATE TABLE moz_hosts (" +
|
||||
" id INTEGER PRIMARY KEY" +
|
||||
",host TEXT" +
|
||||
",type TEXT" +
|
||||
",permission INTEGER" +
|
||||
",expireType INTEGER" +
|
||||
",expireTime INTEGER" +
|
||||
",modificationTime INTEGER" +
|
||||
",appId INTEGER" +
|
||||
",isInBrowserElement INTEGER" +
|
||||
")");
|
||||
|
||||
let stmtInsert = db.createStatement(
|
||||
"INSERT INTO moz_hosts (" +
|
||||
"id, host, type, permission, expireType, expireTime, modificationTime, appId, isInBrowserElement" +
|
||||
") VALUES (" +
|
||||
":id, :host, :type, :permission, :expireType, :expireTime, :modificationTime, :appId, :isInBrowserElement" +
|
||||
")");
|
||||
|
||||
let id = 0;
|
||||
|
||||
function insertOrigin(origin, type, permission, expireType, expireTime, modificationTime) {
|
||||
let thisId = id++;
|
||||
|
||||
stmt6Insert.bindByName("id", thisId);
|
||||
stmt6Insert.bindByName("origin", origin);
|
||||
stmt6Insert.bindByName("type", type);
|
||||
stmt6Insert.bindByName("permission", permission);
|
||||
stmt6Insert.bindByName("expireType", expireType);
|
||||
stmt6Insert.bindByName("expireTime", expireTime);
|
||||
stmt6Insert.bindByName("modificationTime", modificationTime);
|
||||
|
||||
stmt6Insert.execute();
|
||||
|
||||
return {
|
||||
id: thisId,
|
||||
origin: origin,
|
||||
type: type,
|
||||
permission: permission,
|
||||
expireType: expireType,
|
||||
expireTime: expireTime,
|
||||
modificationTime: modificationTime
|
||||
};
|
||||
}
|
||||
|
||||
function insertHost(host, type, permission, expireType, expireTime, modificationTime, appId, isInBrowserElement) {
|
||||
let thisId = id++;
|
||||
|
||||
stmtInsert.bindByName("id", thisId);
|
||||
stmtInsert.bindByName("host", host);
|
||||
stmtInsert.bindByName("type", type);
|
||||
stmtInsert.bindByName("permission", permission);
|
||||
stmtInsert.bindByName("expireType", expireType);
|
||||
stmtInsert.bindByName("expireTime", expireTime);
|
||||
stmtInsert.bindByName("modificationTime", modificationTime);
|
||||
stmtInsert.bindByName("appId", appId);
|
||||
stmtInsert.bindByName("isInBrowserElement", isInBrowserElement);
|
||||
|
||||
stmtInsert.execute();
|
||||
|
||||
return {
|
||||
id: thisId,
|
||||
host: host,
|
||||
type: type,
|
||||
permission: permission,
|
||||
expireType: expireType,
|
||||
expireTime: expireTime,
|
||||
modificationTime: modificationTime,
|
||||
appId: appId,
|
||||
isInBrowserElement: isInBrowserElement
|
||||
};
|
||||
}
|
||||
|
||||
let created6 = [
|
||||
insertOrigin("https://foo.com", "A", 2, 0, 0, 0),
|
||||
insertOrigin("http://foo.com", "A", 2, 0, 0, 0),
|
||||
insertOrigin("http://foo.com^appId=1000&inBrowser=1", "A", 2, 0, 0, 0),
|
||||
];
|
||||
|
||||
// Add some rows to the database
|
||||
let created = [
|
||||
insertHost("foo.com", "A", 1, 0, 0, 0, 0, false),
|
||||
insertHost("foo.com", "C", 1, 0, 0, 0, 0, false),
|
||||
insertHost("foo.com", "A", 1, 0, 0, 0, 1000, false),
|
||||
insertHost("foo.com", "A", 1, 0, 0, 0, 2000, true),
|
||||
insertHost("sub.foo.com", "B", 1, 0, 0, 0, 0, false),
|
||||
insertHost("subber.sub.foo.com", "B", 1, 0, 0, 0, 0, false),
|
||||
insertHost("bar.ca", "B", 1, 0, 0, 0, 0, false),
|
||||
insertHost("bar.ca", "B", 1, 0, 0, 0, 1000, false),
|
||||
insertHost("bar.ca", "A", 1, 0, 0, 0, 1000, true),
|
||||
insertHost("file:///some/path/to/file.html", "A", 1, 0, 0, 0, 0, false),
|
||||
insertHost("file:///another/file.html", "A", 1, 0, 0, 0, 0, false),
|
||||
insertHost("moz-nullprincipal:{8695105a-adbe-4e4e-8083-851faa5ca2d7}", "A", 1, 0, 0, 0, 0, false),
|
||||
insertHost("moz-nullprincipal:{12ahjksd-akjs-asd3-8393-asdu2189asdu}", "B", 1, 0, 0, 0, 0, false),
|
||||
insertHost("<file>", "A", 1, 0, 0, 0, 0, false),
|
||||
insertHost("<file>", "B", 1, 0, 0, 0, 0, false),
|
||||
];
|
||||
|
||||
// CLose the db connection
|
||||
stmtInsert.finalize();
|
||||
db.close();
|
||||
stmtInsert = null;
|
||||
db = null;
|
||||
|
||||
let expected = [
|
||||
// The http:// entries under foo.com won't be inserted, as there are history entries for foo.com,
|
||||
// and http://foo.com or a subdomain are never visited.
|
||||
// ["http://foo.com", "A", 1, 0, 0],
|
||||
// ["http://foo.com^appId=1000", "A", 1, 0, 0],
|
||||
// ["http://foo.com^appId=2000&inBrowser=1", "A", 1, 0, 0],
|
||||
//
|
||||
// Because we search for port/scheme combinations under eTLD+1, we should not have http:// entries
|
||||
// for subdomains of foo.com either
|
||||
// ["http://sub.foo.com", "B", 1, 0, 0],
|
||||
// ["http://subber.sub.foo.com", "B", 1, 0, 0],
|
||||
|
||||
["https://foo.com", "A", 1, 0, 0],
|
||||
["https://foo.com", "C", 1, 0, 0],
|
||||
["https://foo.com^appId=1000", "A", 1, 0, 0],
|
||||
["https://foo.com^appId=2000&inBrowser=1", "A", 1, 0, 0],
|
||||
["https://sub.foo.com", "B", 1, 0, 0],
|
||||
["https://subber.sub.foo.com", "B", 1, 0, 0],
|
||||
|
||||
// bar.ca will have both http:// and https:// for all entries, because there are no associated history entries
|
||||
["http://bar.ca", "B", 1, 0, 0],
|
||||
["https://bar.ca", "B", 1, 0, 0],
|
||||
["http://bar.ca^appId=1000", "B", 1, 0, 0],
|
||||
["https://bar.ca^appId=1000", "B", 1, 0, 0],
|
||||
["http://bar.ca^appId=1000&inBrowser=1", "A", 1, 0, 0],
|
||||
["https://bar.ca^appId=1000&inBrowser=1", "A", 1, 0, 0],
|
||||
["file:///some/path/to/file.html", "A", 1, 0, 0],
|
||||
["file:///another/file.html", "A", 1, 0, 0],
|
||||
|
||||
// Because we put ftp://some.subdomain.of.foo.com:8000/some/subdirectory in the history, we should
|
||||
// also have these entries
|
||||
["ftp://foo.com:8000", "A", 1, 0, 0],
|
||||
["ftp://foo.com:8000", "C", 1, 0, 0],
|
||||
["ftp://foo.com:8000^appId=1000", "A", 1, 0, 0],
|
||||
["ftp://foo.com:8000^appId=2000&inBrowser=1", "A", 1, 0, 0],
|
||||
|
||||
// In addition, because we search for port/scheme combinations under eTLD+1, we should have the
|
||||
// following entries
|
||||
["ftp://sub.foo.com:8000", "B", 1, 0, 0],
|
||||
["ftp://subber.sub.foo.com:8000", "B", 1, 0, 0],
|
||||
];
|
||||
|
||||
let found = expected.map((it) => 0);
|
||||
|
||||
// Add some places to the places database
|
||||
yield PlacesTestUtils.addVisits(Services.io.newURI("https://foo.com/some/other/subdirectory", null, null));
|
||||
yield PlacesTestUtils.addVisits(Services.io.newURI("ftp://some.subdomain.of.foo.com:8000/some/subdirectory", null, null));
|
||||
|
||||
// Force initialization of the nsPermissionManager
|
||||
let enumerator = Services.perms.enumerator;
|
||||
while (enumerator.hasMoreElements()) {
|
||||
let permission = enumerator.getNext().QueryInterface(Ci.nsIPermission);
|
||||
let isExpected = false;
|
||||
|
||||
expected.forEach((it, i) => {
|
||||
if (permission.principal.origin == it[0] &&
|
||||
permission.type == it[1] &&
|
||||
permission.capability == it[2] &&
|
||||
permission.expireType == it[3] &&
|
||||
permission.expireTime == it[4]) {
|
||||
isExpected = true;
|
||||
found[i]++;
|
||||
}
|
||||
});
|
||||
|
||||
do_check_true(isExpected,
|
||||
"Permission " + (isExpected ? "should" : "shouldn't") +
|
||||
" be in permission database: " +
|
||||
permission.principal.origin + ", " +
|
||||
permission.type + ", " +
|
||||
permission.capability + ", " +
|
||||
permission.expireType + ", " +
|
||||
permission.expireTime);
|
||||
}
|
||||
|
||||
found.forEach((count, i) => {
|
||||
do_check_true(count == 1, "Expected count = 1, got count = " + count + " for permission " + expected[i]);
|
||||
});
|
||||
|
||||
// Check to make sure that all of the tables which we care about are present
|
||||
{
|
||||
let db = Services.storage.openDatabase(GetPermissionsFile(profile));
|
||||
do_check_true(db.tableExists("moz_perms"));
|
||||
do_check_true(db.tableExists("moz_hosts"));
|
||||
do_check_true(db.tableExists("moz_hosts_is_backup"));
|
||||
do_check_true(db.tableExists("moz_perms_v6"));
|
||||
|
||||
let mozHostsStmt = db.createStatement("SELECT " +
|
||||
"host, type, permission, expireType, expireTime, " +
|
||||
"modificationTime, appId, isInBrowserElement " +
|
||||
"FROM moz_hosts WHERE id = :id");
|
||||
|
||||
// Check that the moz_hosts table still contains the correct values.
|
||||
created.forEach((it) => {
|
||||
mozHostsStmt.reset();
|
||||
mozHostsStmt.bindByName("id", it.id);
|
||||
mozHostsStmt.executeStep();
|
||||
do_check_eq(mozHostsStmt.getUTF8String(0), it.host);
|
||||
do_check_eq(mozHostsStmt.getUTF8String(1), it.type);
|
||||
do_check_eq(mozHostsStmt.getInt64(2), it.permission);
|
||||
do_check_eq(mozHostsStmt.getInt64(3), it.expireType);
|
||||
do_check_eq(mozHostsStmt.getInt64(4), it.expireTime);
|
||||
do_check_eq(mozHostsStmt.getInt64(5), it.modificationTime);
|
||||
do_check_eq(mozHostsStmt.getInt64(6), it.appId);
|
||||
do_check_eq(mozHostsStmt.getInt64(7), it.isInBrowserElement);
|
||||
});
|
||||
|
||||
// Check that there are the right number of values
|
||||
let mozHostsCount = db.createStatement("SELECT count(*) FROM moz_hosts");
|
||||
mozHostsCount.executeStep();
|
||||
do_check_eq(mozHostsCount.getInt64(0), created.length);
|
||||
|
||||
// Check that the moz_perms_v6 table contains the backup of the entry we created
|
||||
let mozPermsV6Stmt = db.createStatement("SELECT " +
|
||||
"origin, type, permission, expireType, expireTime, modificationTime " +
|
||||
"FROM moz_perms_v6 WHERE id = :id");
|
||||
|
||||
// Check that the moz_hosts table still contains the correct values.
|
||||
created6.forEach((it) => {
|
||||
mozPermsV6Stmt.reset();
|
||||
mozPermsV6Stmt.bindByName("id", it.id);
|
||||
mozPermsV6Stmt.executeStep();
|
||||
do_check_eq(mozPermsV6Stmt.getUTF8String(0), it.origin);
|
||||
do_check_eq(mozPermsV6Stmt.getUTF8String(1), it.type);
|
||||
do_check_eq(mozPermsV6Stmt.getInt64(2), it.permission);
|
||||
do_check_eq(mozPermsV6Stmt.getInt64(3), it.expireType);
|
||||
do_check_eq(mozPermsV6Stmt.getInt64(4), it.expireTime);
|
||||
do_check_eq(mozPermsV6Stmt.getInt64(5), it.modificationTime);
|
||||
});
|
||||
|
||||
// Check that there are the right number of values
|
||||
let mozPermsV6Count = db.createStatement("SELECT count(*) FROM moz_perms_v6");
|
||||
mozPermsV6Count.executeStep();
|
||||
do_check_eq(mozPermsV6Count.getInt64(0), created6.length);
|
||||
|
||||
db.close();
|
||||
}
|
||||
});
|
|
@ -0,0 +1,162 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "PlacesTestUtils",
|
||||
"resource://testing-common/PlacesTestUtils.jsm");
|
||||
|
||||
let PERMISSIONS_FILE_NAME = "permissions.sqlite";
|
||||
|
||||
function GetPermissionsFile(profile)
|
||||
{
|
||||
let file = profile.clone();
|
||||
file.append(PERMISSIONS_FILE_NAME);
|
||||
return file;
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
add_task(function test() {
|
||||
/* Create and set up the permissions database */
|
||||
let profile = do_get_profile();
|
||||
|
||||
let db = Services.storage.openDatabase(GetPermissionsFile(profile));
|
||||
db.schemaVersion = 6;
|
||||
|
||||
/*
|
||||
* V5 table
|
||||
*/
|
||||
db.executeSimpleSQL(
|
||||
"CREATE TABLE moz_perms (" +
|
||||
" id INTEGER PRIMARY KEY" +
|
||||
",origin TEXT" +
|
||||
",type TEXT" +
|
||||
",permission INTEGER" +
|
||||
",expireType INTEGER" +
|
||||
",expireTime INTEGER" +
|
||||
",modificationTime INTEGER" +
|
||||
")");
|
||||
|
||||
let stmt6Insert = db.createStatement(
|
||||
"INSERT INTO moz_perms (" +
|
||||
"id, origin, type, permission, expireType, expireTime, modificationTime" +
|
||||
") VALUES (" +
|
||||
":id, :origin, :type, :permission, :expireType, :expireTime, :modificationTime" +
|
||||
")");
|
||||
|
||||
let id = 0;
|
||||
|
||||
function insertOrigin(origin, type, permission, expireType, expireTime, modificationTime) {
|
||||
let thisId = id++;
|
||||
|
||||
stmt6Insert.bindByName("id", thisId);
|
||||
stmt6Insert.bindByName("origin", origin);
|
||||
stmt6Insert.bindByName("type", type);
|
||||
stmt6Insert.bindByName("permission", permission);
|
||||
stmt6Insert.bindByName("expireType", expireType);
|
||||
stmt6Insert.bindByName("expireTime", expireTime);
|
||||
stmt6Insert.bindByName("modificationTime", modificationTime);
|
||||
|
||||
stmt6Insert.execute();
|
||||
|
||||
return {
|
||||
id: thisId,
|
||||
host: origin,
|
||||
type: type,
|
||||
permission: permission,
|
||||
expireType: expireType,
|
||||
expireTime: expireTime,
|
||||
modificationTime: modificationTime
|
||||
};
|
||||
}
|
||||
|
||||
let created6 = [
|
||||
insertOrigin("https://foo.com", "A", 2, 0, 0, 0),
|
||||
insertOrigin("http://foo.com", "A", 2, 0, 0, 0),
|
||||
insertOrigin("http://foo.com^appId=1000&inBrowser=1", "A", 2, 0, 0, 0),
|
||||
];
|
||||
|
||||
let created4 = []; // Didn't create any v4 entries, so the DB should be empty
|
||||
|
||||
// CLose the db connection
|
||||
stmt6Insert.finalize();
|
||||
db.close();
|
||||
stmt6Insert = null;
|
||||
db = null;
|
||||
|
||||
let expected = [
|
||||
["https://foo.com", "A", 2, 0, 0, 0],
|
||||
["http://foo.com", "A", 2, 0, 0, 0],
|
||||
["http://foo.com^appId=1000&inBrowser=1", "A", 2, 0, 0, 0]
|
||||
];
|
||||
|
||||
let found = expected.map((it) => 0);
|
||||
|
||||
// Force initialization of the nsPermissionManager
|
||||
let enumerator = Services.perms.enumerator;
|
||||
while (enumerator.hasMoreElements()) {
|
||||
let permission = enumerator.getNext().QueryInterface(Ci.nsIPermission);
|
||||
let isExpected = false;
|
||||
|
||||
expected.forEach((it, i) => {
|
||||
if (permission.principal.origin == it[0] &&
|
||||
permission.type == it[1] &&
|
||||
permission.capability == it[2] &&
|
||||
permission.expireType == it[3] &&
|
||||
permission.expireTime == it[4]) {
|
||||
isExpected = true;
|
||||
found[i]++;
|
||||
}
|
||||
});
|
||||
|
||||
do_check_true(isExpected,
|
||||
"Permission " + (isExpected ? "should" : "shouldn't") +
|
||||
" be in permission database: " +
|
||||
permission.principal.origin + ", " +
|
||||
permission.type + ", " +
|
||||
permission.capability + ", " +
|
||||
permission.expireType + ", " +
|
||||
permission.expireTime);
|
||||
}
|
||||
|
||||
found.forEach((count, i) => {
|
||||
do_check_true(count == 1, "Expected count = 1, got count = " + count + " for permission " + expected[i]);
|
||||
});
|
||||
|
||||
// Check to make sure that all of the tables which we care about are present
|
||||
{
|
||||
let db = Services.storage.openDatabase(GetPermissionsFile(profile));
|
||||
do_check_true(db.tableExists("moz_perms"));
|
||||
do_check_true(db.tableExists("moz_hosts"));
|
||||
do_check_false(db.tableExists("moz_hosts_is_backup"));
|
||||
do_check_false(db.tableExists("moz_perms_v6"));
|
||||
|
||||
let mozHostsStmt = db.createStatement("SELECT " +
|
||||
"host, type, permission, expireType, expireTime, " +
|
||||
"modificationTime, appId, isInBrowserElement " +
|
||||
"FROM moz_hosts WHERE id = :id");
|
||||
|
||||
// Check that the moz_hosts table still contains the correct values.
|
||||
created4.forEach((it) => {
|
||||
mozHostsStmt.reset();
|
||||
mozHostsStmt.bindByName("id", it.id);
|
||||
mozHostsStmt.executeStep();
|
||||
do_check_eq(mozHostsStmt.getUTF8String(0), it.host);
|
||||
do_check_eq(mozHostsStmt.getUTF8String(1), it.type);
|
||||
do_check_eq(mozHostsStmt.getInt64(2), it.permission);
|
||||
do_check_eq(mozHostsStmt.getInt64(3), it.expireType);
|
||||
do_check_eq(mozHostsStmt.getInt64(4), it.expireTime);
|
||||
do_check_eq(mozHostsStmt.getInt64(5), it.modificationTime);
|
||||
do_check_eq(mozHostsStmt.getInt64(6), it.appId);
|
||||
do_check_eq(mozHostsStmt.getInt64(7), it.isInBrowserElement);
|
||||
});
|
||||
|
||||
// Check that there are the right number of values
|
||||
let mozHostsCount = db.createStatement("SELECT count(*) FROM moz_hosts");
|
||||
mozHostsCount.executeStep();
|
||||
do_check_eq(mozHostsCount.getInt64(0), created4.length);
|
||||
|
||||
db.close();
|
||||
}
|
||||
});
|
|
@ -36,5 +36,8 @@ skip-if = debug == true
|
|||
[test_permmanager_removepermission.js]
|
||||
[test_permmanager_matchesuri.js]
|
||||
[test_permmanager_matches.js]
|
||||
[test_permmanager_migrate_4-5.js]
|
||||
[test_permmanager_migrate_5-6.js]
|
||||
[test_permmanager_migrate_4-7.js]
|
||||
[test_permmanager_migrate_5-7a.js]
|
||||
[test_permmanager_migrate_5-7b.js]
|
||||
[test_permmanager_migrate_6-7a.js]
|
||||
[test_permmanager_migrate_6-7b.js]
|
||||
|
|
Загрузка…
Ссылка в новой задаче