browser/components/places/tests/unit/test_browserGlue_distribution.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 /**
michael@0 5 * Tests that nsBrowserGlue correctly imports bookmarks from distribution.ini.
michael@0 6 */
michael@0 7
michael@0 8 const PREF_SMART_BOOKMARKS_VERSION = "browser.places.smartBookmarksVersion";
michael@0 9 const PREF_BMPROCESSED = "distribution.516444.bookmarksProcessed";
michael@0 10 const PREF_DISTRIBUTION_ID = "distribution.id";
michael@0 11
michael@0 12 const TOPICDATA_DISTRIBUTION_CUSTOMIZATION = "force-distribution-customization";
michael@0 13 const TOPIC_CUSTOMIZATION_COMPLETE = "distribution-customization-complete";
michael@0 14 const TOPIC_BROWSERGLUE_TEST = "browser-glue-test";
michael@0 15
michael@0 16 function run_test()
michael@0 17 {
michael@0 18 do_test_pending();
michael@0 19
michael@0 20 // Set special pref to load distribution.ini from the profile folder.
michael@0 21 Services.prefs.setBoolPref("distribution.testing.loadFromProfile", true);
michael@0 22 // Copy distribution.ini file to the profile dir.
michael@0 23 let distroDir = gProfD.clone();
michael@0 24 distroDir.leafName = "distribution";
michael@0 25 let iniFile = distroDir.clone();
michael@0 26 iniFile.append("distribution.ini");
michael@0 27 if (iniFile.exists()) {
michael@0 28 iniFile.remove(false);
michael@0 29 print("distribution.ini already exists, did some test forget to cleanup?");
michael@0 30 }
michael@0 31 let testDistributionFile = gTestDir.clone();
michael@0 32 testDistributionFile.append("distribution.ini");
michael@0 33 testDistributionFile.copyTo(distroDir, "distribution.ini");
michael@0 34 do_check_true(testDistributionFile.exists());
michael@0 35
michael@0 36 // Disable Smart Bookmarks creation.
michael@0 37 Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, -1);
michael@0 38
michael@0 39 // Initialize Places through the History Service and check that a new
michael@0 40 // database has been created.
michael@0 41 do_check_eq(PlacesUtils.history.databaseStatus,
michael@0 42 PlacesUtils.history.DATABASE_STATUS_CREATE);
michael@0 43
michael@0 44 // Force distribution.
michael@0 45 Cc["@mozilla.org/browser/browserglue;1"].
michael@0 46 getService(Ci.nsIObserver).observe(null,
michael@0 47 TOPIC_BROWSERGLUE_TEST,
michael@0 48 TOPICDATA_DISTRIBUTION_CUSTOMIZATION);
michael@0 49
michael@0 50 // Test will continue on customization complete notification.
michael@0 51 Services.obs.addObserver(function(aSubject, aTopic, aData) {
michael@0 52 Services.obs.removeObserver(arguments.callee,
michael@0 53 TOPIC_CUSTOMIZATION_COMPLETE,
michael@0 54 false);
michael@0 55 do_execute_soon(onCustomizationComplete);
michael@0 56 }, TOPIC_CUSTOMIZATION_COMPLETE, false);
michael@0 57 }
michael@0 58
michael@0 59 function onCustomizationComplete()
michael@0 60 {
michael@0 61 // Check the custom bookmarks exist on menu.
michael@0 62 let menuItemId =
michael@0 63 PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, 0);
michael@0 64 do_check_neq(menuItemId, -1);
michael@0 65 do_check_eq(PlacesUtils.bookmarks.getItemTitle(menuItemId),
michael@0 66 "Menu Link Before");
michael@0 67 menuItemId =
michael@0 68 PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId,
michael@0 69 1 + DEFAULT_BOOKMARKS_ON_MENU);
michael@0 70 do_check_neq(menuItemId, -1);
michael@0 71 do_check_eq(PlacesUtils.bookmarks.getItemTitle(menuItemId),
michael@0 72 "Menu Link After");
michael@0 73
michael@0 74 // Check the custom bookmarks exist on toolbar.
michael@0 75 let toolbarItemId =
michael@0 76 PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0);
michael@0 77 do_check_neq(toolbarItemId, -1);
michael@0 78 do_check_eq(PlacesUtils.bookmarks.getItemTitle(toolbarItemId),
michael@0 79 "Toolbar Link Before");
michael@0 80 toolbarItemId =
michael@0 81 PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId,
michael@0 82 1 + DEFAULT_BOOKMARKS_ON_TOOLBAR);
michael@0 83 do_check_neq(toolbarItemId, -1);
michael@0 84 do_check_eq(PlacesUtils.bookmarks.getItemTitle(toolbarItemId),
michael@0 85 "Toolbar Link After");
michael@0 86
michael@0 87 // Check the bmprocessed pref has been created.
michael@0 88 do_check_true(Services.prefs.getBoolPref(PREF_BMPROCESSED));
michael@0 89
michael@0 90 // Check distribution prefs have been created.
michael@0 91 do_check_eq(Services.prefs.getCharPref(PREF_DISTRIBUTION_ID), "516444");
michael@0 92
michael@0 93 do_test_finished();
michael@0 94 }
michael@0 95
michael@0 96 do_register_cleanup(function() {
michael@0 97 // Remove the distribution file, even if the test failed, otherwise all
michael@0 98 // next tests will import it.
michael@0 99 let iniFile = gProfD.clone();
michael@0 100 iniFile.leafName = "distribution";
michael@0 101 iniFile.append("distribution.ini");
michael@0 102 if (iniFile.exists())
michael@0 103 iniFile.remove(false);
michael@0 104 do_check_false(iniFile.exists());
michael@0 105 });

mercurial