1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/places/tests/browser/browser_visituri_nohistory.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,65 @@ 1.4 +/** 1.5 + * Any copyright is dedicated to the Public Domain. 1.6 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.7 + */ 1.8 + 1.9 +const INITIAL_URL = "http://example.com/tests/toolkit/components/places/tests/browser/begin.html"; 1.10 +const FINAL_URL = "http://example.com/tests/toolkit/components/places/tests/browser/final.html"; 1.11 + 1.12 +let gTab = gBrowser.selectedTab = gBrowser.addTab(); 1.13 + 1.14 +/** 1.15 + * One-time observer callback. 1.16 + */ 1.17 +function waitForObserve(name, callback) 1.18 +{ 1.19 + let observer = { 1.20 + QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]), 1.21 + observe: function(subject, topic, data) 1.22 + { 1.23 + Services.obs.removeObserver(observer, name); 1.24 + callback(subject, topic, data); 1.25 + } 1.26 + }; 1.27 + 1.28 + Services.obs.addObserver(observer, name, false); 1.29 +} 1.30 + 1.31 +/** 1.32 + * One-time DOMContentLoaded callback. 1.33 + */ 1.34 +function waitForLoad(callback) 1.35 +{ 1.36 + gTab.linkedBrowser.addEventListener("load", function() 1.37 + { 1.38 + gTab.linkedBrowser.removeEventListener("load", arguments.callee, true); 1.39 + callback(); 1.40 + }, true); 1.41 +} 1.42 + 1.43 +function test() 1.44 +{ 1.45 + waitForExplicitFinish(); 1.46 + 1.47 + Services.prefs.setBoolPref("places.history.enabled", false); 1.48 + 1.49 + waitForObserve("uri-visit-saved", function(subject, topic, data) 1.50 + { 1.51 + let uri = subject.QueryInterface(Ci.nsIURI); 1.52 + is(uri.spec, FINAL_URL, "received expected visit"); 1.53 + if (uri.spec != FINAL_URL) 1.54 + return; 1.55 + gBrowser.removeCurrentTab(); 1.56 + promiseClearHistory().then(finish); 1.57 + }); 1.58 + 1.59 + Services.prefs.setBoolPref("places.history.enabled", false); 1.60 + content.location.href = INITIAL_URL; 1.61 + waitForLoad(function() 1.62 + { 1.63 + try { 1.64 + Services.prefs.clearUserPref("places.history.enabled"); 1.65 + } catch(ex) {} 1.66 + content.location.href = FINAL_URL; 1.67 + }); 1.68 +}