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