Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/
3 */
5 const EXPECTED_SCHEMA_VERSION = 4;
6 let dbfile;
8 function run_test() {
9 do_test_pending();
10 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
12 // Write out a minimal database.
13 dbfile = gProfD.clone();
14 dbfile.append("addons.sqlite");
15 let db = AM_Cc["@mozilla.org/storage/service;1"].
16 getService(AM_Ci.mozIStorageService).
17 openDatabase(dbfile);
19 db.createTable("addon",
20 "internal_id INTEGER PRIMARY KEY AUTOINCREMENT, " +
21 "id TEXT UNIQUE, " +
22 "type TEXT, " +
23 "name TEXT, " +
24 "version TEXT, " +
25 "creator TEXT, " +
26 "creatorURL TEXT, " +
27 "description TEXT, " +
28 "fullDescription TEXT, " +
29 "developerComments TEXT, " +
30 "eula TEXT, " +
31 "iconURL TEXT, " +
32 "homepageURL TEXT, " +
33 "supportURL TEXT, " +
34 "contributionURL TEXT, " +
35 "contributionAmount TEXT, " +
36 "averageRating INTEGER, " +
37 "reviewCount INTEGER, " +
38 "reviewURL TEXT, " +
39 "totalDownloads INTEGER, " +
40 "weeklyDownloads INTEGER, " +
41 "dailyUsers INTEGER, " +
42 "sourceURI TEXT, " +
43 "repositoryStatus INTEGER, " +
44 "size INTEGER, " +
45 "updateDate INTEGER");
47 db.createTable("developer",
48 "addon_internal_id INTEGER, " +
49 "num INTEGER, " +
50 "name TEXT, " +
51 "url TEXT, " +
52 "PRIMARY KEY (addon_internal_id, num)");
54 db.createTable("screenshot",
55 "addon_internal_id INTEGER, " +
56 "num INTEGER, " +
57 "url TEXT, " +
58 "thumbnailURL TEXT, " +
59 "caption TEXT, " +
60 "PRIMARY KEY (addon_internal_id, num)");
62 let stmt = db.createStatement("INSERT INTO addon (id) VALUES (:id)");
63 stmt.params.id = "test1@tests.mozilla.org";
64 stmt.execute();
65 stmt.finalize();
67 stmt = db.createStatement("INSERT INTO screenshot VALUES " +
68 "(:addon_internal_id, :num, :url, :thumbnailURL, :caption)");
70 stmt.params.addon_internal_id = 1;
71 stmt.params.num = 0;
72 stmt.params.url = "http://localhost/full1-1.png";
73 stmt.params.thumbnailURL = "http://localhost/thumbnail1-1.png";
74 stmt.params.caption = "Caption 1 - 1";
75 stmt.execute();
76 stmt.finalize();
78 db.schemaVersion = 1;
79 db.close();
82 Services.prefs.setBoolPref("extensions.getAddons.cache.enabled", true);
83 AddonRepository.getCachedAddonByID("test1@tests.mozilla.org", function (aAddon) {
84 do_check_neq(aAddon, null);
85 do_check_eq(aAddon.screenshots.length, 1);
86 do_check_true(aAddon.screenshots[0].width === null);
87 do_check_true(aAddon.screenshots[0].height === null);
88 do_check_true(aAddon.screenshots[0].thumbnailWidth === null);
89 do_check_true(aAddon.screenshots[0].thumbnailHeight === null);
90 do_check_eq(aAddon.iconURL, undefined);
91 do_check_eq(JSON.stringify(aAddon.icons), "{}");
92 AddonRepository.shutdown().then(
93 function checkAfterRepoShutdown() {
94 // Check the DB schema has changed once AddonRepository has freed it.
95 db = AM_Cc["@mozilla.org/storage/service;1"].
96 getService(AM_Ci.mozIStorageService).
97 openDatabase(dbfile);
98 do_check_eq(db.schemaVersion, EXPECTED_SCHEMA_VERSION);
99 do_check_true(db.indexExists("developer_idx"));
100 do_check_true(db.indexExists("screenshot_idx"));
101 do_check_true(db.indexExists("compatibility_override_idx"));
102 do_check_true(db.tableExists("compatibility_override"));
103 do_check_true(db.indexExists("icon_idx"));
104 do_check_true(db.tableExists("icon"));
106 // Check the trigger is working
107 db.executeSimpleSQL("INSERT INTO addon (id, type, name) VALUES('test_addon', 'extension', 'Test Addon')");
108 let internalID = db.lastInsertRowID;
109 db.executeSimpleSQL("INSERT INTO compatibility_override (addon_internal_id, num, type) VALUES('" + internalID + "', '1', 'incompatible')");
111 let stmt = db.createStatement("SELECT COUNT(*) AS count FROM compatibility_override");
112 stmt.executeStep();
113 do_check_eq(stmt.row.count, 1);
114 stmt.reset();
116 db.executeSimpleSQL("DELETE FROM addon");
117 stmt.executeStep();
118 do_check_eq(stmt.row.count, 0);
119 stmt.finalize();
121 db.close();
122 do_test_finished();
123 },
124 do_report_unexpected_exception
125 );
126 });
127 }