toolkit/components/contentprefs/tests/unit/test_unusedGroupsAndSettings.js

branch
TOR_BUG_9701
changeset 14
925c144e1f1f
equal deleted inserted replaced
-1:000000000000 0:6900391731e3
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 var cps = new ContentPrefInstance(null);
6
7 function run_test() {
8 var uri1 = ContentPrefTest.getURI("http://www.domain1.com/");
9 var uri2 = ContentPrefTest.getURI("http://foo.domain1.com/");
10 var uri3 = ContentPrefTest.getURI("http://domain1.com/");
11 var uri4 = ContentPrefTest.getURI("http://www.domain2.com/");
12
13 cps.setPref(uri1, "one", 1);
14 cps.setPref(uri1, "two", 2);
15 cps.setPref(uri2, "one", 4);
16 cps.setPref(uri3, "three", 8);
17 cps.setPref(uri4, "two", 16);
18
19 cps.removePref(uri3, "three"); // uri3 should be removed now
20 checkForUnusedGroups();
21 checkForUnusedSettings();
22
23 cps.removePrefsByName("two"); // uri4 should be removed now
24 checkForUnusedGroups();
25 checkForUnusedSettings();
26
27 cps.removeGroupedPrefs();
28 checkForUnusedGroups();
29 checkForUnusedSettings();
30 }
31
32 function checkForUnusedGroups() {
33 var stmt = cps.DBConnection.createStatement(
34 "SELECT COUNT(*) AS count FROM groups " +
35 "WHERE id NOT IN (SELECT DISTINCT groupID FROM prefs)"
36 );
37 stmt.executeStep();
38 do_check_eq(0, stmt.row.count);
39 stmt.reset();
40 stmt.finalize();
41 }
42
43 function checkForUnusedSettings() {
44 var stmt = cps.DBConnection.createStatement(
45 "SELECT COUNT(*) AS count FROM settings " +
46 "WHERE id NOT IN (SELECT DISTINCT settingID FROM prefs)"
47 );
48 stmt.executeStep();
49 do_check_eq(0, stmt.row.count);
50 stmt.reset();
51 stmt.finalize();
52 }

mercurial