|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 Components.utils.import("resource://gre/modules/PlacesUtils.jsm"); |
|
5 Components.utils.import("resource://gre/modules/NetUtil.jsm"); |
|
6 Components.utils.import("resource://gre/modules/ForgetAboutSite.jsm"); |
|
7 |
|
8 const ABOUT_PERMISSIONS_SPEC = "about:permissions"; |
|
9 |
|
10 const TEST_URI_1 = NetUtil.newURI("http://mozilla.com/"); |
|
11 const TEST_URI_2 = NetUtil.newURI("http://mozilla.org/"); |
|
12 const TEST_URI_3 = NetUtil.newURI("http://wikipedia.org/"); |
|
13 |
|
14 // values from DefaultPermissions object |
|
15 const PERM_UNKNOWN = 0; |
|
16 const PERM_ALLOW = 1; |
|
17 const PERM_DENY = 2; |
|
18 |
|
19 // used to set permissions on test sites |
|
20 const TEST_PERMS = { |
|
21 "password": PERM_ALLOW, |
|
22 "cookie": PERM_ALLOW, |
|
23 "geo": PERM_UNKNOWN, |
|
24 "indexedDB": PERM_UNKNOWN, |
|
25 "popup": PERM_DENY |
|
26 }; |
|
27 |
|
28 function test() { |
|
29 waitForExplicitFinish(); |
|
30 registerCleanupFunction(cleanUp); |
|
31 setup(function() { |
|
32 runNextTest(); |
|
33 }); |
|
34 } |
|
35 |
|
36 function setup(aCallback) { |
|
37 // add test history visit |
|
38 addVisits(TEST_URI_1, function() { |
|
39 // set permissions ourselves to avoid problems with different defaults |
|
40 // from test harness configuration |
|
41 for (let type in TEST_PERMS) { |
|
42 if (type == "password") { |
|
43 Services.logins.setLoginSavingEnabled(TEST_URI_2.prePath, true); |
|
44 } else { |
|
45 // set permissions on a site without history visits to test enumerateServices |
|
46 Services.perms.add(TEST_URI_2, type, TEST_PERMS[type]); |
|
47 } |
|
48 } |
|
49 |
|
50 Services.perms.add(TEST_URI_3, "popup", TEST_PERMS["popup"]); |
|
51 aCallback(); |
|
52 }); |
|
53 } |
|
54 |
|
55 function cleanUp() { |
|
56 for (let type in TEST_PERMS) { |
|
57 if (type != "password") { |
|
58 Services.perms.remove(TEST_URI_1.host, type); |
|
59 Services.perms.remove(TEST_URI_2.host, type); |
|
60 Services.perms.remove(TEST_URI_3.host, type); |
|
61 } |
|
62 } |
|
63 } |
|
64 |
|
65 function runNextTest() { |
|
66 if (gTestIndex == tests.length) { |
|
67 waitForClearHistory(finish); |
|
68 return; |
|
69 } |
|
70 |
|
71 let nextTest = tests[gTestIndex++]; |
|
72 info(nextTest.desc); |
|
73 |
|
74 function preinit_observer() { |
|
75 Services.obs.removeObserver(preinit_observer, "browser-permissions-preinit"); |
|
76 nextTest.preInit(); |
|
77 } |
|
78 Services.obs.addObserver(preinit_observer, "browser-permissions-preinit", false); |
|
79 |
|
80 function init_observer() { |
|
81 Services.obs.removeObserver(init_observer, "browser-permissions-initialized"); |
|
82 nextTest.run(); |
|
83 } |
|
84 Services.obs.addObserver(init_observer, "browser-permissions-initialized", false); |
|
85 |
|
86 // open about:permissions |
|
87 let tab = gBrowser.selectedTab = gBrowser.addTab("about:permissions"); |
|
88 registerCleanupFunction(function() { |
|
89 gBrowser.removeTab(tab); |
|
90 }); |
|
91 } |
|
92 |
|
93 var gSitesList; |
|
94 |
|
95 var gTestIndex = 0; |
|
96 var tests = [ |
|
97 // 'preInit' occurs after opening about:permissions, before sites-list is populated |
|
98 // 'run' occurs after sites-list is populated |
|
99 { |
|
100 desc: "test filtering before sites-list is fully constructed.", |
|
101 preInit: function() { |
|
102 let sitesFilter = gBrowser.contentDocument.getElementById("sites-filter"); |
|
103 sitesFilter.value = TEST_URI_2.host; |
|
104 sitesFilter.doCommand(); |
|
105 }, |
|
106 run: function() { |
|
107 let testSite1 = getSiteItem(TEST_URI_1.host); |
|
108 ok(testSite1.collapsed, "test site 1 is collapsed after early filtering"); |
|
109 let testSite2 = getSiteItem(TEST_URI_2.host); |
|
110 ok(!testSite2.collapsed, "test site 2 is not collapsed after early filtering"); |
|
111 let testSite3 = getSiteItem(TEST_URI_3.host); |
|
112 ok(testSite3.collapsed, "test site 3 is collapsed after early filtering"); |
|
113 |
|
114 runNextTest(); |
|
115 } |
|
116 }, |
|
117 { |
|
118 desc: "test removing from sites-list before it is fully constructed.", |
|
119 preInit: function() { |
|
120 ForgetAboutSite.removeDataFromDomain(TEST_URI_2.host); |
|
121 }, |
|
122 run: function() { |
|
123 let testSite1 = getSiteItem(TEST_URI_1.host); |
|
124 ok(!testSite2, "test site 1 was not removed from sites list"); |
|
125 let testSite2 = getSiteItem(TEST_URI_2.host); |
|
126 ok(!testSite2, "test site 2 was pre-removed from sites list"); |
|
127 let testSite3 = getSiteItem(TEST_URI_3.host); |
|
128 ok(!testSite2, "test site 3 was not removed from sites list"); |
|
129 |
|
130 runNextTest(); |
|
131 } |
|
132 } |
|
133 ]; |
|
134 |
|
135 function getSiteItem(aHost) { |
|
136 return gBrowser.contentDocument. |
|
137 querySelector(".site[value='" + aHost + "']"); |
|
138 } |
|
139 |
|
140 // copied from toolkit/components/places/tests/head_common.js |
|
141 function waitForClearHistory(aCallback) { |
|
142 let observer = { |
|
143 observe: function(aSubject, aTopic, aData) { |
|
144 Services.obs.removeObserver(this, PlacesUtils.TOPIC_EXPIRATION_FINISHED); |
|
145 aCallback(); |
|
146 } |
|
147 }; |
|
148 Services.obs.addObserver(observer, PlacesUtils.TOPIC_EXPIRATION_FINISHED, false); |
|
149 PlacesUtils.bhistory.removeAllPages(); |
|
150 } |