toolkit/components/places/tests/browser/browser_visited_notfound.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_visited_notfound.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,51 @@
     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 file,
     1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +const TEST_URI = NetUtil.newURI("http://mochi.test:8888/notFoundPage.html");
     1.9 +
    1.10 +function test() {
    1.11 +  waitForExplicitFinish();
    1.12 +
    1.13 +  gBrowser.selectedTab = gBrowser.addTab();
    1.14 +  registerCleanupFunction(function() {
    1.15 +    gBrowser.removeCurrentTab();
    1.16 +  });
    1.17 +
    1.18 +  // First add a visit to the page, this will ensure that later we skip
    1.19 +  // updating the frecency for a newly not-found page.
    1.20 +  addVisits({ uri: TEST_URI }, window, () => {
    1.21 +    info("Added visit");
    1.22 +    fieldForUrl(TEST_URI, "frecency", aFrecency => {
    1.23 +      ok(aFrecency > 0, "Frecency should be > 0");
    1.24 +      continueTest(aFrecency);
    1.25 +    });
    1.26 +  });
    1.27 +}
    1.28 +
    1.29 +function continueTest(aOldFrecency) {
    1.30 +  // Used to verify errors are not marked as typed.
    1.31 +  PlacesUtils.history.markPageAsTyped(TEST_URI);
    1.32 +  gBrowser.selectedTab.linkedBrowser.loadURI(TEST_URI.spec);
    1.33 +
    1.34 +  // Create and add history observer.
    1.35 +  let historyObserver = {
    1.36 +    __proto__: NavHistoryObserver.prototype,
    1.37 +    onVisit: function (aURI, aVisitID, aTime, aSessionID, aReferringID,
    1.38 +                      aTransitionType) {
    1.39 +      PlacesUtils.history.removeObserver(historyObserver);
    1.40 +      info("Received onVisit: " + aURI.spec);
    1.41 +      fieldForUrl(aURI, "frecency", function (aFrecency) {
    1.42 +        is(aFrecency, aOldFrecency, "Frecency should be unchanged");
    1.43 +        fieldForUrl(aURI, "hidden", function (aHidden) {
    1.44 +          is(aHidden, 0, "Page should not be hidden");
    1.45 +          fieldForUrl(aURI, "typed", function (aTyped) {
    1.46 +            is(aTyped, 0, "page should not be marked as typed");
    1.47 +            promiseClearHistory().then(finish);
    1.48 +          });
    1.49 +        });
    1.50 +      });
    1.51 +    }
    1.52 +  };
    1.53 +  PlacesUtils.history.addObserver(historyObserver, false);
    1.54 +}

mercurial