summaryrefslogtreecommitdiffstats
path: root/toolkit/components/places/tests/migration/test_current_from_v31.js
blob: 6b9131daa351cc4034fa36d50a80f3a93439ab3f (plain)
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
// Add pages.
let shorturl = "http://example.com/" + "a".repeat(1981);
let longurl = "http://example.com/" + "a".repeat(1982);
let bmurl = "http://example.com/" + "a".repeat(1983);

add_task(function* setup() {
  yield setupPlacesDatabase("places_v31.sqlite");
  // Setup database contents to be migrated.
  let path = OS.Path.join(OS.Constants.Path.profileDir, DB_FILENAME);
  let db = yield Sqlite.openConnection({ path });

  yield db.execute(`INSERT INTO moz_places (url, guid, foreign_count)
                    VALUES (:shorturl, "test1_______", 0)
                         , (:longurl, "test2_______", 0)
                         , (:bmurl, "test3_______", 1)
                   `, { shorturl, longurl, bmurl });
  // Add visits.
  yield db.execute(`INSERT INTO moz_historyvisits (place_id)
                    VALUES ((SELECT id FROM moz_places WHERE url = :shorturl))
                         , ((SELECT id FROM moz_places WHERE url = :longurl))
                   `, { shorturl, longurl });
  yield db.close();
});

add_task(function* database_is_valid() {
  Assert.equal(PlacesUtils.history.databaseStatus,
               PlacesUtils.history.DATABASE_STATUS_UPGRADED);

  let db = yield PlacesUtils.promiseDBConnection();
  Assert.equal((yield db.getSchemaVersion()), CURRENT_SCHEMA_VERSION);
});

add_task(function* test_longurls() {
  let db = yield PlacesUtils.promiseDBConnection();
  let rows = yield db.execute(`SELECT 1 FROM moz_places where url = :longurl`,
                              { longurl });
  Assert.equal(rows.length, 0, "Long url should have been removed");
  rows = yield db.execute(`SELECT 1 FROM moz_places where url = :shorturl`,
                          { shorturl });
  Assert.equal(rows.length, 1, "Short url should have been retained");
  rows = yield db.execute(`SELECT 1 FROM moz_places where url = :bmurl`,
                          { bmurl });
  Assert.equal(rows.length, 1, "Bookmarked url should have been retained");
  rows = yield db.execute(`SELECT count(*) FROM moz_historyvisits`);
  Assert.equal(rows.length, 1, "Orphan visists should have been removed");
});