~ubuntu-branches/ubuntu/trusty/enigmail/trusty-updates

« back to all changes in this revision

Viewing changes to services/sync/tests/unit/test_places_guid_downgrade.js

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2011-06-07 14:35:53 UTC
  • mfrom: (0.12.1 upstream)
  • Revision ID: package-import@ubuntu.com-20110607143553-fbgqhhvh8g8h6j1y
Tags: 2:1.2~a2~cvs20110606t2200-0ubuntu1
* Update to latest trunk snapshot for Thunderbird beta compat

* Remove build/pgo/profileserver.py from debian/clean. The new build
  system has a target depending on this
  - update debian/clean
* Drop debian/patches/autoconf.diff, just generate this at build time
* Refresh debian/patches/build_system_dont_link_libxul.diff
* libipc seems to be renamed to libipc-pipe. Fix genxpi and chrome.manifest
  to fix this 
  - add debian/patches/ipc-pipe_rename.diff
  - update debian/patches/series
* The makefiles in extensions/enigmail/ipc have an incorrect DEPTH
  attribute. Fix this so that they can find the rest of the build system
  - add debian/patches/makefile_depth.diff
  - update debian/patches/series
* Drop debian/patches/makefile-in-empty-xpcom-fix.diff - fixed in the
  current version
* Don't register a class ID multiple times, as this breaks enigmail entirely
  - add debian/patches/dont_register_cids_multiple_times.diff
  - update debian/patches/series
* Look for the Thunderbird 5 SDK
  - update debian/rules
  - update debian/control
* Run autoconf2.13 at build time
  - update debian/rules
  - update debian/control
* Add useless mesa-common-dev build-dep, just to satisfy the build system.
  We should just patch this out entirely really, but that's for another upload
  - update debian/control

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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");
 
5
 
 
6
const kDBName = "places.sqlite";
 
7
const storageSvc = Cc["@mozilla.org/storage/service;1"]
 
8
                     .getService(Ci.mozIStorageService);
 
9
 
 
10
const fxuri = Utils.makeURI("http://getfirefox.com/");
 
11
const tburi = Utils.makeURI("http://getthunderbird.com/");
 
12
 
 
13
function setPlacesDatabase(aFileName) {
 
14
  removePlacesDatabase();
 
15
  _("Copying over places.sqlite.");
 
16
  let file = do_get_file(aFileName);
 
17
  file.copyTo(gProfD, kDBName);
 
18
}
 
19
 
 
20
function removePlacesDatabase() {
 
21
  _("Removing places.sqlite.");
 
22
  let file = gProfD.clone();
 
23
  file.append(kDBName);
 
24
  try {
 
25
    file.remove(false);
 
26
  } catch (ex) {
 
27
    // Windows is awesome. NOT.
 
28
  }
 
29
}
 
30
 
 
31
Svc.Obs.add("places-shutdown", function () {
 
32
  do_timeout(0, removePlacesDatabase);
 
33
});
 
34
 
 
35
 
 
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
 
39
  // it to be.
 
40
  let dbFile = gProfD.clone();
 
41
  dbFile.append(kDBName);
 
42
  let db = storageSvc.openUnsharedDatabase(dbFile);
 
43
 
 
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
 
47
  // down to v10.
 
48
  do_check_neq(stmt.getString(0).toLowerCase(), "wal");
 
49
  stmt.finalize();
 
50
 
 
51
  do_check_true(db.indexExists("moz_bookmarks_guid_uniqueindex"));
 
52
  do_check_true(db.indexExists("moz_places_guid_uniqueindex"));
 
53
 
 
54
  // There should be a non-zero amount of bookmarks without a guid.
 
55
  stmt = db.createStatement(
 
56
    "SELECT COUNT(1) "
 
57
  + "FROM moz_bookmarks "
 
58
  + "WHERE guid IS NULL "
 
59
  );
 
60
  do_check_true(stmt.executeStep());
 
61
  do_check_neq(stmt.getInt32(0), 0);
 
62
  stmt.finalize();
 
63
 
 
64
  // There should be a non-zero amount of places without a guid.
 
65
  stmt = db.createStatement(
 
66
    "SELECT COUNT(1) "
 
67
  + "FROM moz_places "
 
68
  + "WHERE guid IS NULL "
 
69
  );
 
70
  do_check_true(stmt.executeStep());
 
71
  do_check_neq(stmt.getInt32(0), 0);
 
72
  stmt.finalize();
 
73
 
 
74
  // Check our schema version to make sure it is actually at 10.
 
75
  do_check_eq(db.schemaVersion, 10);
 
76
 
 
77
  db.close();
 
78
}
 
79
 
 
80
function test_history_guids() {
 
81
  let engine = new HistoryEngine();
 
82
  let store = engine._store;
 
83
 
 
84
  Svc.History.addPageWithDetails(fxuri, "Get Firefox!", Date.now() * 1000);
 
85
  Svc.History.addPageWithDetails(tburi, "Get Thunderbird!", Date.now() * 1000);
 
86
 
 
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");
 
91
 
 
92
  let fxguid = store.GUIDForUri(fxuri, true);
 
93
  let tbguid = store.GUIDForUri(tburi, true);
 
94
  dump("fxguid: " + fxguid + "\n");
 
95
  dump("tbguid: " + tbguid + "\n");
 
96
 
 
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");
 
100
 
 
101
  stmt.params.guid = fxguid;
 
102
  let result = Utils.queryAsync(stmt, ["id"]);
 
103
  do_check_eq(result.length, 1);
 
104
 
 
105
  stmt.params.guid = tbguid;
 
106
  result = Utils.queryAsync(stmt, ["id"]);
 
107
  do_check_eq(result.length, 1);
 
108
 
 
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");
 
112
 
 
113
  stmt.params.guid = fxguid;
 
114
  result = Utils.queryAsync(stmt, ["guid"]);
 
115
  do_check_eq(result.length, 0);
 
116
 
 
117
  stmt.params.guid = tbguid;
 
118
  result = Utils.queryAsync(stmt, ["guid"]);
 
119
  do_check_eq(result.length, 0);
 
120
}
 
121
 
 
122
function test_bookmark_guids() {
 
123
  let engine = new BookmarksEngine();
 
124
  let store = engine._store;
 
125
 
 
126
  let fxid = Svc.Bookmark.insertBookmark(
 
127
    Svc.Bookmark.toolbarFolder, fxuri, Svc.Bookmark.DEFAULT_INDEX,
 
128
    "Get Firefox!");
 
129
  let tbid = Svc.Bookmark.insertBookmark(
 
130
    Svc.Bookmark.toolbarFolder, tburi, Svc.Bookmark.DEFAULT_INDEX,
 
131
    "Get Thunderbird!");
 
132
 
 
133
  let fxguid = store.GUIDForId(fxid);
 
134
  let tbguid = store.GUIDForId(tbid);
 
135
 
 
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");
 
139
 
 
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);
 
144
 
 
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);
 
149
 
 
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");
 
153
 
 
154
  stmt.params.guid = fxguid;
 
155
  result = Utils.queryAsync(stmt, ["guid"]);
 
156
  do_check_eq(result.length, 0);
 
157
 
 
158
  stmt.params.guid = tbguid;
 
159
  result = Utils.queryAsync(stmt, ["guid"]);
 
160
  do_check_eq(result.length, 0);
 
161
}
 
162
 
 
163
function run_test() {
 
164
  setPlacesDatabase("places_v10_from_v11.sqlite");
 
165
 
 
166
  _("Verify initial setup: v11 database is available");
 
167
  test_initial_state();
 
168
  test_history_guids();
 
169
  test_bookmark_guids();
 
170
}