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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/places/tests/browser/browser_bug399606.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,77 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +gBrowser.selectedTab = gBrowser.addTab();
     1.9 +
    1.10 +function test() {
    1.11 +  waitForExplicitFinish();
    1.12 +
    1.13 +  var URIs = [
    1.14 +    "http://example.com/tests/toolkit/components/places/tests/browser/399606-window.location.href.html",
    1.15 +    "http://example.com/tests/toolkit/components/places/tests/browser/399606-history.go-0.html",
    1.16 +    "http://example.com/tests/toolkit/components/places/tests/browser/399606-location.replace.html",
    1.17 +    "http://example.com/tests/toolkit/components/places/tests/browser/399606-location.reload.html",
    1.18 +    "http://example.com/tests/toolkit/components/places/tests/browser/399606-httprefresh.html",
    1.19 +    "http://example.com/tests/toolkit/components/places/tests/browser/399606-window.location.html",
    1.20 +  ];
    1.21 +  var hs = Cc["@mozilla.org/browser/nav-history-service;1"].
    1.22 +           getService(Ci.nsINavHistoryService);
    1.23 +
    1.24 +  // Create and add history observer.
    1.25 +  var historyObserver = {
    1.26 +    visitCount: Array(),
    1.27 +    onBeginUpdateBatch: function () {},
    1.28 +    onEndUpdateBatch: function () {},
    1.29 +    onVisit: function (aURI, aVisitID, aTime, aSessionID, aReferringID,
    1.30 +                      aTransitionType) {
    1.31 +      info("Received onVisit: " + aURI.spec);
    1.32 +      if (aURI.spec in this.visitCount)
    1.33 +        this.visitCount[aURI.spec]++;
    1.34 +      else
    1.35 +        this.visitCount[aURI.spec] = 1;
    1.36 +    },
    1.37 +    onTitleChanged: function () {},
    1.38 +    onDeleteURI: function () {},
    1.39 +    onClearHistory: function () {},
    1.40 +    onPageChanged: function () {},
    1.41 +    onDeleteVisits: function () {},
    1.42 +    QueryInterface: XPCOMUtils.generateQI([Ci.nsINavHistoryObserver])
    1.43 +  };
    1.44 +  hs.addObserver(historyObserver, false);
    1.45 +
    1.46 +  function confirm_results() {
    1.47 +    gBrowser.removeCurrentTab();
    1.48 +    hs.removeObserver(historyObserver, false);
    1.49 +    for (let aURI in historyObserver.visitCount) {
    1.50 +      is(historyObserver.visitCount[aURI], 1,
    1.51 +         "onVisit has been received right number of times for " + aURI);
    1.52 +    }
    1.53 +    promiseClearHistory().then(finish);
    1.54 +  }
    1.55 +
    1.56 +  var loadCount = 0;
    1.57 +  function handleLoad(aEvent) {
    1.58 +    loadCount++;
    1.59 +    info("new load count is " + loadCount);
    1.60 +
    1.61 +    if (loadCount == 3) {
    1.62 +      gBrowser.removeEventListener("DOMContentLoaded", handleLoad, true);
    1.63 +      content.location.href = "about:blank";
    1.64 +      executeSoon(check_next_uri);
    1.65 +    }
    1.66 +  }
    1.67 +
    1.68 +  function check_next_uri() {
    1.69 +    if (URIs.length) {
    1.70 +      let uri = URIs.shift();
    1.71 +      loadCount = 0;
    1.72 +      gBrowser.addEventListener("DOMContentLoaded", handleLoad, true);
    1.73 +      content.location.href = uri;
    1.74 +    }
    1.75 +    else {
    1.76 +      confirm_results();
    1.77 +    }
    1.78 +  }
    1.79 +  executeSoon(check_next_uri);
    1.80 +}

mercurial