-
Notifications
You must be signed in to change notification settings - Fork 54
/
test_current_from_v48.js
146 lines (123 loc) · 4.92 KB
/
test_current_from_v48.js
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const gCreatedParentGuid = "m47___FOLDER";
const gTestItems = [{
// Folder shortcuts to built-in folders.
guid: "m47_____ROOT",
url: "place:folder=PLACES_ROOT",
targetParentGuid: "rootGuid",
}, {
guid: "m47_____MENU",
url: "place:folder=BOOKMARKS_MENU",
targetParentGuid: "menuGuid",
}, {
guid: "m47_____TAGS",
url: "place:folder=TAGS",
targetParentGuid: "tagsGuid",
}, {
guid: "m47____OTHER",
url: "place:folder=UNFILED_BOOKMARKS",
targetParentGuid: "unfiledGuid",
}, {
guid: "m47__TOOLBAR",
url: "place:folder=TOOLBAR",
targetParentGuid: "toolbarGuid",
}, {
guid: "m47___MOBILE",
url: "place:folder=MOBILE_BOOKMARKS",
targetParentGuid: "mobileGuid",
}, {
// Folder shortcut to using id.
guid: "m47_______ID",
url: "place:folder=%id%",
expectedUrl: "place:parent=%guid%",
}, {
// Folder shortcut to multiple folders.
guid: "m47____MULTI",
url: "place:folder=TOOLBAR&folder=%id%&sort=1",
expectedUrl: "place:parent=%toolbarGuid%&parent=%guid%&sort=1",
}, {
// Folder shortcut to non-existent folder.
guid: "m47______NON",
url: "place:folder=454554545",
expectedUrl: "place:invalidOldParentId=454554545&excludeItems=1",
}];
add_task(async function setup() {
await setupPlacesDatabase("places_v43.sqlite");
// Setup database contents to be migrated.
let path = OS.Path.join(OS.Constants.Path.profileDir, DB_FILENAME);
let db = await Sqlite.openConnection({ path });
let rows = await db.execute(`SELECT id FROM moz_bookmarks
WHERE guid = :guid`,
{ guid: PlacesUtils.bookmarks.unfiledGuid });
let unfiledId = rows[0].getResultByName("id");
// Insert a test folder.
await db.execute(`INSERT INTO moz_bookmarks (guid, title, parent)
VALUES (:guid, "Folder", :parent)`,
{ guid: gCreatedParentGuid, parent: unfiledId });
rows = await db.execute(`SELECT id FROM moz_bookmarks
WHERE guid = :guid`,
{ guid: gCreatedParentGuid });
let createdFolderId = rows[0].getResultByName("id");
for (let item of gTestItems) {
item.url = item.url.replace("%id%", createdFolderId);
// We can reuse the same guid, it doesn't matter for this test.
await db.execute(`INSERT INTO moz_places (url, guid, url_hash)
VALUES (:url, :guid, :hash)
`, { url: item.url, guid: item.guid, hash: PlacesUtils.history.hashURL(item.url) });
await db.execute(`INSERT INTO moz_bookmarks (id, fk, guid, title, parent)
VALUES (:id, (SELECT id FROM moz_places WHERE guid = :guid),
:guid, :title,
(SELECT id FROM moz_bookmarks WHERE guid = :parentGuid))
`, {
id: item.folder,
guid: item.guid,
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
title: item.guid,
});
}
await db.close();
});
add_task(async function database_is_valid() {
// Accessing the database for the first time triggers migration.
Assert.equal(PlacesUtils.history.databaseStatus,
PlacesUtils.history.DATABASE_STATUS_UPGRADED);
let db = await PlacesUtils.promiseDBConnection();
Assert.equal((await db.getSchemaVersion()), CURRENT_SCHEMA_VERSION);
});
add_task(async function test_correct_folder_queries() {
for (let item of gTestItems) {
let bm = await PlacesUtils.bookmarks.fetch(item.guid);
if (item.targetParentGuid) {
Assert.equal(bm.url, `place:parent=${PlacesUtils.bookmarks[item.targetParentGuid]}`,
`Should have updated the URL for ${item.guid}`);
} else {
let expected = item.expectedUrl
.replace("%guid%", gCreatedParentGuid)
.replace("%toolbarGuid%", PlacesUtils.bookmarks.toolbarGuid);
Assert.equal(bm.url, expected, `Should have updated the URL for ${item.guid}`);
}
}
});
add_task(async function test_hashes_valid() {
let db = await PlacesUtils.promiseDBConnection();
// Ensure all the hashes in moz_places are valid.
let rows = await db.execute(`SELECT url, url_hash FROM moz_places`);
for (let row of rows) {
let url = row.getResultByName("url");
let url_hash = row.getResultByName("url_hash");
Assert.equal(url_hash, PlacesUtils.history.hashURL(url),
`url hash should be correct for ${url}`);
}
});
add_task(async function test_sync_counters_updated() {
let db = await PlacesUtils.promiseDBConnection();
for (let test of gTestItems) {
let rows = await db.execute(`SELECT syncChangeCounter FROM moz_bookmarks
WHERE guid = :guid`, {guid: test.guid});
Assert.equal(rows.length, 1, `Should only be one record for ${test.guid}`);
Assert.equal(rows[0].getResultByName("syncChangeCounter"), 2,
`Should have bumped the syncChangeCounter for ${test.guid}`);
}
});