michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: var cps = new ContentPrefInstance(null); michael@0: michael@0: function run_test() { michael@0: var uri1 = ContentPrefTest.getURI("http://www.domain1.com/"); michael@0: var uri2 = ContentPrefTest.getURI("http://foo.domain1.com/"); michael@0: var uri3 = ContentPrefTest.getURI("http://domain1.com/"); michael@0: var uri4 = ContentPrefTest.getURI("http://www.domain2.com/"); michael@0: michael@0: cps.setPref(uri1, "one", 1); michael@0: cps.setPref(uri1, "two", 2); michael@0: cps.setPref(uri2, "one", 4); michael@0: cps.setPref(uri3, "three", 8); michael@0: cps.setPref(uri4, "two", 16); michael@0: michael@0: cps.removePref(uri3, "three"); // uri3 should be removed now michael@0: checkForUnusedGroups(); michael@0: checkForUnusedSettings(); michael@0: michael@0: cps.removePrefsByName("two"); // uri4 should be removed now michael@0: checkForUnusedGroups(); michael@0: checkForUnusedSettings(); michael@0: michael@0: cps.removeGroupedPrefs(); michael@0: checkForUnusedGroups(); michael@0: checkForUnusedSettings(); michael@0: } michael@0: michael@0: function checkForUnusedGroups() { michael@0: var stmt = cps.DBConnection.createStatement( michael@0: "SELECT COUNT(*) AS count FROM groups " + michael@0: "WHERE id NOT IN (SELECT DISTINCT groupID FROM prefs)" michael@0: ); michael@0: stmt.executeStep(); michael@0: do_check_eq(0, stmt.row.count); michael@0: stmt.reset(); michael@0: stmt.finalize(); michael@0: } michael@0: michael@0: function checkForUnusedSettings() { michael@0: var stmt = cps.DBConnection.createStatement( michael@0: "SELECT COUNT(*) AS count FROM settings " + michael@0: "WHERE id NOT IN (SELECT DISTINCT settingID FROM prefs)" michael@0: ); michael@0: stmt.executeStep(); michael@0: do_check_eq(0, stmt.row.count); michael@0: stmt.reset(); michael@0: stmt.finalize(); michael@0: }