michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * Tests that nsBrowserGlue correctly imports bookmarks from distribution.ini. michael@0: */ michael@0: michael@0: const PREF_SMART_BOOKMARKS_VERSION = "browser.places.smartBookmarksVersion"; michael@0: const PREF_BMPROCESSED = "distribution.516444.bookmarksProcessed"; michael@0: const PREF_DISTRIBUTION_ID = "distribution.id"; michael@0: michael@0: const TOPICDATA_DISTRIBUTION_CUSTOMIZATION = "force-distribution-customization"; michael@0: const TOPIC_CUSTOMIZATION_COMPLETE = "distribution-customization-complete"; michael@0: const TOPIC_BROWSERGLUE_TEST = "browser-glue-test"; michael@0: michael@0: function run_test() michael@0: { michael@0: do_test_pending(); michael@0: michael@0: // Set special pref to load distribution.ini from the profile folder. michael@0: Services.prefs.setBoolPref("distribution.testing.loadFromProfile", true); michael@0: // Copy distribution.ini file to the profile dir. michael@0: let distroDir = gProfD.clone(); michael@0: distroDir.leafName = "distribution"; michael@0: let iniFile = distroDir.clone(); michael@0: iniFile.append("distribution.ini"); michael@0: if (iniFile.exists()) { michael@0: iniFile.remove(false); michael@0: print("distribution.ini already exists, did some test forget to cleanup?"); michael@0: } michael@0: let testDistributionFile = gTestDir.clone(); michael@0: testDistributionFile.append("distribution.ini"); michael@0: testDistributionFile.copyTo(distroDir, "distribution.ini"); michael@0: do_check_true(testDistributionFile.exists()); michael@0: michael@0: // Disable Smart Bookmarks creation. michael@0: Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, -1); michael@0: michael@0: // Initialize Places through the History Service and check that a new michael@0: // database has been created. michael@0: do_check_eq(PlacesUtils.history.databaseStatus, michael@0: PlacesUtils.history.DATABASE_STATUS_CREATE); michael@0: michael@0: // Force distribution. michael@0: Cc["@mozilla.org/browser/browserglue;1"]. michael@0: getService(Ci.nsIObserver).observe(null, michael@0: TOPIC_BROWSERGLUE_TEST, michael@0: TOPICDATA_DISTRIBUTION_CUSTOMIZATION); michael@0: michael@0: // Test will continue on customization complete notification. michael@0: Services.obs.addObserver(function(aSubject, aTopic, aData) { michael@0: Services.obs.removeObserver(arguments.callee, michael@0: TOPIC_CUSTOMIZATION_COMPLETE, michael@0: false); michael@0: do_execute_soon(onCustomizationComplete); michael@0: }, TOPIC_CUSTOMIZATION_COMPLETE, false); michael@0: } michael@0: michael@0: function onCustomizationComplete() michael@0: { michael@0: // Check the custom bookmarks exist on menu. michael@0: let menuItemId = michael@0: PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, 0); michael@0: do_check_neq(menuItemId, -1); michael@0: do_check_eq(PlacesUtils.bookmarks.getItemTitle(menuItemId), michael@0: "Menu Link Before"); michael@0: menuItemId = michael@0: PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, michael@0: 1 + DEFAULT_BOOKMARKS_ON_MENU); michael@0: do_check_neq(menuItemId, -1); michael@0: do_check_eq(PlacesUtils.bookmarks.getItemTitle(menuItemId), michael@0: "Menu Link After"); michael@0: michael@0: // Check the custom bookmarks exist on toolbar. michael@0: let toolbarItemId = michael@0: PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0); michael@0: do_check_neq(toolbarItemId, -1); michael@0: do_check_eq(PlacesUtils.bookmarks.getItemTitle(toolbarItemId), michael@0: "Toolbar Link Before"); michael@0: toolbarItemId = michael@0: PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, michael@0: 1 + DEFAULT_BOOKMARKS_ON_TOOLBAR); michael@0: do_check_neq(toolbarItemId, -1); michael@0: do_check_eq(PlacesUtils.bookmarks.getItemTitle(toolbarItemId), michael@0: "Toolbar Link After"); michael@0: michael@0: // Check the bmprocessed pref has been created. michael@0: do_check_true(Services.prefs.getBoolPref(PREF_BMPROCESSED)); michael@0: michael@0: // Check distribution prefs have been created. michael@0: do_check_eq(Services.prefs.getCharPref(PREF_DISTRIBUTION_ID), "516444"); michael@0: michael@0: do_test_finished(); michael@0: } michael@0: michael@0: do_register_cleanup(function() { michael@0: // Remove the distribution file, even if the test failed, otherwise all michael@0: // next tests will import it. michael@0: let iniFile = gProfD.clone(); michael@0: iniFile.leafName = "distribution"; michael@0: iniFile.append("distribution.ini"); michael@0: if (iniFile.exists()) michael@0: iniFile.remove(false); michael@0: do_check_false(iniFile.exists()); michael@0: });