1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/contentprefs/tests/unit/test_unusedGroupsAndSettings.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,52 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +var cps = new ContentPrefInstance(null); 1.9 + 1.10 +function run_test() { 1.11 + var uri1 = ContentPrefTest.getURI("http://www.domain1.com/"); 1.12 + var uri2 = ContentPrefTest.getURI("http://foo.domain1.com/"); 1.13 + var uri3 = ContentPrefTest.getURI("http://domain1.com/"); 1.14 + var uri4 = ContentPrefTest.getURI("http://www.domain2.com/"); 1.15 + 1.16 + cps.setPref(uri1, "one", 1); 1.17 + cps.setPref(uri1, "two", 2); 1.18 + cps.setPref(uri2, "one", 4); 1.19 + cps.setPref(uri3, "three", 8); 1.20 + cps.setPref(uri4, "two", 16); 1.21 + 1.22 + cps.removePref(uri3, "three"); // uri3 should be removed now 1.23 + checkForUnusedGroups(); 1.24 + checkForUnusedSettings(); 1.25 + 1.26 + cps.removePrefsByName("two"); // uri4 should be removed now 1.27 + checkForUnusedGroups(); 1.28 + checkForUnusedSettings(); 1.29 + 1.30 + cps.removeGroupedPrefs(); 1.31 + checkForUnusedGroups(); 1.32 + checkForUnusedSettings(); 1.33 +} 1.34 + 1.35 +function checkForUnusedGroups() { 1.36 + var stmt = cps.DBConnection.createStatement( 1.37 + "SELECT COUNT(*) AS count FROM groups " + 1.38 + "WHERE id NOT IN (SELECT DISTINCT groupID FROM prefs)" 1.39 + ); 1.40 + stmt.executeStep(); 1.41 + do_check_eq(0, stmt.row.count); 1.42 + stmt.reset(); 1.43 + stmt.finalize(); 1.44 +} 1.45 + 1.46 +function checkForUnusedSettings() { 1.47 + var stmt = cps.DBConnection.createStatement( 1.48 + "SELECT COUNT(*) AS count FROM settings " + 1.49 + "WHERE id NOT IN (SELECT DISTINCT settingID FROM prefs)" 1.50 + ); 1.51 + stmt.executeStep(); 1.52 + do_check_eq(0, stmt.row.count); 1.53 + stmt.reset(); 1.54 + stmt.finalize(); 1.55 +}