|
1 /** |
|
2 * Any copyright is dedicated to the Public Domain. |
|
3 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
4 */ |
|
5 |
|
6 const INITIAL_URL = "http://example.com/tests/toolkit/components/places/tests/browser/begin.html"; |
|
7 const FINAL_URL = "http://example.com/tests/toolkit/components/places/tests/browser/final.html"; |
|
8 |
|
9 let gTab = gBrowser.selectedTab = gBrowser.addTab(); |
|
10 |
|
11 /** |
|
12 * One-time observer callback. |
|
13 */ |
|
14 function waitForObserve(name, callback) |
|
15 { |
|
16 let observer = { |
|
17 QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]), |
|
18 observe: function(subject, topic, data) |
|
19 { |
|
20 Services.obs.removeObserver(observer, name); |
|
21 callback(subject, topic, data); |
|
22 } |
|
23 }; |
|
24 |
|
25 Services.obs.addObserver(observer, name, false); |
|
26 } |
|
27 |
|
28 /** |
|
29 * One-time DOMContentLoaded callback. |
|
30 */ |
|
31 function waitForLoad(callback) |
|
32 { |
|
33 gTab.linkedBrowser.addEventListener("load", function() |
|
34 { |
|
35 gTab.linkedBrowser.removeEventListener("load", arguments.callee, true); |
|
36 callback(); |
|
37 }, true); |
|
38 } |
|
39 |
|
40 function test() |
|
41 { |
|
42 waitForExplicitFinish(); |
|
43 |
|
44 Services.prefs.setBoolPref("places.history.enabled", false); |
|
45 |
|
46 waitForObserve("uri-visit-saved", function(subject, topic, data) |
|
47 { |
|
48 let uri = subject.QueryInterface(Ci.nsIURI); |
|
49 is(uri.spec, FINAL_URL, "received expected visit"); |
|
50 if (uri.spec != FINAL_URL) |
|
51 return; |
|
52 gBrowser.removeCurrentTab(); |
|
53 promiseClearHistory().then(finish); |
|
54 }); |
|
55 |
|
56 Services.prefs.setBoolPref("places.history.enabled", false); |
|
57 content.location.href = INITIAL_URL; |
|
58 waitForLoad(function() |
|
59 { |
|
60 try { |
|
61 Services.prefs.clearUserPref("places.history.enabled"); |
|
62 } catch(ex) {} |
|
63 content.location.href = FINAL_URL; |
|
64 }); |
|
65 } |