1
Cu.import("resource://services-sync/util.js");
2
Cu.import("resource://services-sync/engines.js");
3
Cu.import("resource://services-sync/engines/history.js");
4
Cu.import("resource://services-sync/engines/bookmarks.js");
6
const kDBName = "places.sqlite";
7
const storageSvc = Cc["@mozilla.org/storage/service;1"]
8
.getService(Ci.mozIStorageService);
10
const fxuri = Utils.makeURI("http://getfirefox.com/");
11
const tburi = Utils.makeURI("http://getthunderbird.com/");
13
function setPlacesDatabase(aFileName) {
14
removePlacesDatabase();
15
_("Copying over places.sqlite.");
16
let file = do_get_file(aFileName);
17
file.copyTo(gProfD, kDBName);
20
function removePlacesDatabase() {
21
_("Removing places.sqlite.");
22
let file = gProfD.clone();
27
// Windows is awesome. NOT.
31
Svc.Obs.add("places-shutdown", function () {
32
do_timeout(0, removePlacesDatabase);
36
// Verify initial database state. Function borrowed from places tests.
37
function test_initial_state() {
38
// Mostly sanity checks our starting DB to make sure it's setup as we expect
40
let dbFile = gProfD.clone();
41
dbFile.append(kDBName);
42
let db = storageSvc.openUnsharedDatabase(dbFile);
44
let stmt = db.createStatement("PRAGMA journal_mode");
45
do_check_true(stmt.executeStep());
46
// WAL journal mode should have been unset this database when it was migrated
48
do_check_neq(stmt.getString(0).toLowerCase(), "wal");
51
do_check_true(db.indexExists("moz_bookmarks_guid_uniqueindex"));
52
do_check_true(db.indexExists("moz_places_guid_uniqueindex"));
54
// There should be a non-zero amount of bookmarks without a guid.
55
stmt = db.createStatement(
57
+ "FROM moz_bookmarks "
58
+ "WHERE guid IS NULL "
60
do_check_true(stmt.executeStep());
61
do_check_neq(stmt.getInt32(0), 0);
64
// There should be a non-zero amount of places without a guid.
65
stmt = db.createStatement(
68
+ "WHERE guid IS NULL "
70
do_check_true(stmt.executeStep());
71
do_check_neq(stmt.getInt32(0), 0);
74
// Check our schema version to make sure it is actually at 10.
75
do_check_eq(db.schemaVersion, 10);
80
function test_history_guids() {
81
let engine = new HistoryEngine();
82
let store = engine._store;
84
Svc.History.addPageWithDetails(fxuri, "Get Firefox!", Date.now() * 1000);
85
Svc.History.addPageWithDetails(tburi, "Get Thunderbird!", Date.now() * 1000);
87
// Hack: flush the places db by adding a random bookmark.
88
let uri = Utils.makeURI("http://mozilla.com/");
89
let fxid = Svc.Bookmark.insertBookmark(
90
Svc.Bookmark.toolbarFolder, uri, Svc.Bookmark.DEFAULT_INDEX, "Mozilla");
92
let fxguid = store.GUIDForUri(fxuri, true);
93
let tbguid = store.GUIDForUri(tburi, true);
94
dump("fxguid: " + fxguid + "\n");
95
dump("tbguid: " + tbguid + "\n");
97
_("History: Verify GUIDs are added to the guid column.");
98
let stmt = Svc.History.DBConnection.createAsyncStatement(
99
"SELECT id FROM moz_places WHERE guid = :guid");
101
stmt.params.guid = fxguid;
102
let result = Utils.queryAsync(stmt, ["id"]);
103
do_check_eq(result.length, 1);
105
stmt.params.guid = tbguid;
106
result = Utils.queryAsync(stmt, ["id"]);
107
do_check_eq(result.length, 1);
109
_("History: Verify GUIDs weren't added to annotations.");
110
stmt = Svc.History.DBConnection.createAsyncStatement(
111
"SELECT a.content AS guid FROM moz_annos a WHERE guid = :guid");
113
stmt.params.guid = fxguid;
114
result = Utils.queryAsync(stmt, ["guid"]);
115
do_check_eq(result.length, 0);
117
stmt.params.guid = tbguid;
118
result = Utils.queryAsync(stmt, ["guid"]);
119
do_check_eq(result.length, 0);
122
function test_bookmark_guids() {
123
let engine = new BookmarksEngine();
124
let store = engine._store;
126
let fxid = Svc.Bookmark.insertBookmark(
127
Svc.Bookmark.toolbarFolder, fxuri, Svc.Bookmark.DEFAULT_INDEX,
129
let tbid = Svc.Bookmark.insertBookmark(
130
Svc.Bookmark.toolbarFolder, tburi, Svc.Bookmark.DEFAULT_INDEX,
133
let fxguid = store.GUIDForId(fxid);
134
let tbguid = store.GUIDForId(tbid);
136
_("Bookmarks: Verify GUIDs are added to the guid column.");
137
let stmt = Svc.History.DBConnection.createAsyncStatement(
138
"SELECT id FROM moz_bookmarks WHERE guid = :guid");
140
stmt.params.guid = fxguid;
141
let result = Utils.queryAsync(stmt, ["id"]);
142
do_check_eq(result.length, 1);
143
do_check_eq(result[0].id, fxid);
145
stmt.params.guid = tbguid;
146
result = Utils.queryAsync(stmt, ["id"]);
147
do_check_eq(result.length, 1);
148
do_check_eq(result[0].id, tbid);
150
_("Bookmarks: Verify GUIDs weren't added to annotations.");
151
stmt = Svc.History.DBConnection.createAsyncStatement(
152
"SELECT a.content AS guid FROM moz_items_annos a WHERE guid = :guid");
154
stmt.params.guid = fxguid;
155
result = Utils.queryAsync(stmt, ["guid"]);
156
do_check_eq(result.length, 0);
158
stmt.params.guid = tbguid;
159
result = Utils.queryAsync(stmt, ["guid"]);
160
do_check_eq(result.length, 0);
163
function run_test() {
164
setPlacesDatabase("places_v10_from_v11.sqlite");
166
_("Verify initial setup: v11 database is available");
167
test_initial_state();
168
test_history_guids();
169
test_bookmark_guids();