toolkit/components/places/tests/browser/browser_visituri_nohistory.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /**
     2  * Any copyright is dedicated to the Public Domain.
     3  * http://creativecommons.org/publicdomain/zero/1.0/
     4  */
     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";
     9 let gTab = gBrowser.selectedTab = gBrowser.addTab();
    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   };
    25   Services.obs.addObserver(observer, name, false);
    26 }
    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 }
    40 function test()
    41 {
    42   waitForExplicitFinish();
    44   Services.prefs.setBoolPref("places.history.enabled", false);
    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   });
    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 }

mercurial