1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
let rootDir = do_get_file("chromefiles/", true);
const SOURCE_PROFILE_DIR = "Library/Application Support/Google/Chrome/Default/";
const PROFILE = {
id: "Default",
name: "Person 1",
};
add_setup(async function setup_fake_paths() {
let pathId;
if (AppConstants.platform == "macosx") {
pathId = "ULibDir";
} else if (AppConstants.platform == "win") {
pathId = "LocalAppData";
} else {
pathId = "Home";
}
registerFakePath(pathId, rootDir);
let file = do_get_file(`${SOURCE_PROFILE_DIR}HistoryCorrupt`);
file.copyTo(file.parent, "History");
registerCleanupFunction(() => {
let historyFile = do_get_file(`${SOURCE_PROFILE_DIR}History`, true);
try {
historyFile.remove(false);
} catch (ex) {
// It is ok if this doesn't exist.
if (ex.result != Cr.NS_ERROR_FILE_NOT_FOUND) {
throw ex;
}
}
});
let subDirs =
AppConstants.platform == "linux" ? ["google-chrome"] : ["Google", "Chrome"];
if (AppConstants.platform == "macosx") {
subDirs.unshift("Application Support");
} else if (AppConstants.platform == "win") {
subDirs.push("User Data");
} else {
subDirs.unshift(".config");
}
let target = rootDir.clone();
// Pretend this is the default profile
subDirs.push("Default");
while (subDirs.length) {
target.append(subDirs.shift());
}
await IOUtils.makeDirectory(target.path, {
createAncestor: true,
ignoreExisting: true,
});
target.append("Bookmarks");
await IOUtils.remove(target.path, { ignoreAbsent: true });
let bookmarksData = createChromeBookmarkStructure();
await IOUtils.writeJSON(target.path, bookmarksData);
});
add_task(async function test_corrupt_history() {
let migrator = await MigrationUtils.getMigrator("chrome");
Assert.ok(await migrator.isSourceAvailable());
let data = await migrator.getMigrateData(PROFILE);
Assert.ok(
data & MigrationUtils.resourceTypes.BOOKMARKS,
"Bookmarks resource available."
);
Assert.ok(
!(data & MigrationUtils.resourceTypes.HISTORY),
"Corrupt history resource unavailable."
);
});
|