Bug 1347728 - Fix JSON dump of blocklists r=kjozwiak,mgoodwin

MozReview-Commit-ID: rwX5Nn9d6b

--HG--
extra : rebase_source : 5df03011e57211e6cf2d67f1bda3f71d188c7f91
This commit is contained in:
Mathieu Leplatre 2017-03-22 15:46:55 +01:00
parent 8b9281c90a
commit 04cf765d30
2 changed files with 16 additions and 9 deletions

View File

@ -102,8 +102,13 @@ class BlocklistClient {
});
}
get identifier() {
return `${this.bucketName}/${this.collectionName}`;
}
get filename() {
return `${this.bucketName}/${this.collectionName}.json`;
const identifier = OS.Path.join(...this.identifier.split("/"));
return `${identifier}.json`;
}
/**

View File

@ -1,7 +1,5 @@
const { Constructor: CC } = Components;
const KEY_PROFILEDIR = "ProfD";
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://testing-common/httpd.js");
Cu.import("resource://gre/modules/Timer.jsm");
@ -58,9 +56,10 @@ function* clear_state() {
yield sqliteHandle.close();
}
// Remove profile data.
const path = OS.Path.join(OS.Constants.Path.profileDir, client.filename);
yield OS.File.remove(path, { ignoreAbsent: true });
// Remove JSON dumps folders in profile dir.
const dumpFile = OS.Path.join(OS.Constants.Path.profileDir, client.filename);
const folder = OS.Path.dirname(dumpFile);
yield OS.File.removeDir(folder, { ignoreAbsent: true });
}
}
@ -132,7 +131,8 @@ add_task(clear_state);
add_task(function* test_list_is_written_to_file_in_profile() {
for (let {client, testData} of gBlocklistClients) {
const profFile = FileUtils.getFile(KEY_PROFILEDIR, client.filename.split("/"));
const filePath = OS.Path.join(OS.Constants.Path.profileDir, client.filename);
const profFile = new FileUtils.File(filePath);
strictEqual(profFile.exists(), false);
yield client.maybeSync(2000, Date.now(), {loadDump: false});
@ -157,7 +157,8 @@ add_task(clear_state);
add_task(function* test_update_json_file_when_addons_has_changes() {
for (let {client, testData} of gBlocklistClients) {
yield client.maybeSync(2000, Date.now() - 1000, {loadDump: false});
const profFile = FileUtils.getFile(KEY_PROFILEDIR, client.filename.split("/"));
const filePath = OS.Path.join(OS.Constants.Path.profileDir, client.filename);
const profFile = new FileUtils.File(filePath);
const fileLastModified = profFile.lastModifiedTime = profFile.lastModifiedTime - 1000;
const serverTime = Date.now();
@ -192,7 +193,8 @@ add_task(clear_state);
add_task(function* test_do_nothing_when_blocklist_is_up_to_date() {
for (let {client} of gBlocklistClients) {
yield client.maybeSync(2000, Date.now() - 1000, {loadDump: false});
const profFile = FileUtils.getFile(KEY_PROFILEDIR, client.filename.split("/"));
const filePath = OS.Path.join(OS.Constants.Path.profileDir, client.filename);
const profFile = new FileUtils.File(filePath);
const fileLastModified = profFile.lastModifiedTime = profFile.lastModifiedTime - 1000;
const serverTime = Date.now();