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

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

     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/. */
     5 var cps = new ContentPrefInstance(null);
     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/");
    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);
    19   cps.removePref(uri3, "three"); // uri3 should be removed now
    20   checkForUnusedGroups();
    21   checkForUnusedSettings();
    23   cps.removePrefsByName("two"); // uri4 should be removed now
    24   checkForUnusedGroups();
    25   checkForUnusedSettings();
    27   cps.removeGroupedPrefs();
    28   checkForUnusedGroups();
    29   checkForUnusedSettings();
    30 }
    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 }
    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