toolkit/mozapps/extensions/test/xpcshell/test_migrateAddonRepository.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial