michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: var URIs = [ michael@0: "http://example.com/tests/toolkit/components/places/tests/browser/399606-window.location.href.html", michael@0: "http://example.com/tests/toolkit/components/places/tests/browser/399606-history.go-0.html", michael@0: "http://example.com/tests/toolkit/components/places/tests/browser/399606-location.replace.html", michael@0: "http://example.com/tests/toolkit/components/places/tests/browser/399606-location.reload.html", michael@0: "http://example.com/tests/toolkit/components/places/tests/browser/399606-httprefresh.html", michael@0: "http://example.com/tests/toolkit/components/places/tests/browser/399606-window.location.html", michael@0: ]; michael@0: var hs = Cc["@mozilla.org/browser/nav-history-service;1"]. michael@0: getService(Ci.nsINavHistoryService); michael@0: michael@0: // Create and add history observer. michael@0: var historyObserver = { michael@0: visitCount: Array(), michael@0: onBeginUpdateBatch: function () {}, michael@0: onEndUpdateBatch: function () {}, michael@0: onVisit: function (aURI, aVisitID, aTime, aSessionID, aReferringID, michael@0: aTransitionType) { michael@0: info("Received onVisit: " + aURI.spec); michael@0: if (aURI.spec in this.visitCount) michael@0: this.visitCount[aURI.spec]++; michael@0: else michael@0: this.visitCount[aURI.spec] = 1; michael@0: }, michael@0: onTitleChanged: function () {}, michael@0: onDeleteURI: function () {}, michael@0: onClearHistory: function () {}, michael@0: onPageChanged: function () {}, michael@0: onDeleteVisits: function () {}, michael@0: QueryInterface: XPCOMUtils.generateQI([Ci.nsINavHistoryObserver]) michael@0: }; michael@0: hs.addObserver(historyObserver, false); michael@0: michael@0: function confirm_results() { michael@0: gBrowser.removeCurrentTab(); michael@0: hs.removeObserver(historyObserver, false); michael@0: for (let aURI in historyObserver.visitCount) { michael@0: is(historyObserver.visitCount[aURI], 1, michael@0: "onVisit has been received right number of times for " + aURI); michael@0: } michael@0: promiseClearHistory().then(finish); michael@0: } michael@0: michael@0: var loadCount = 0; michael@0: function handleLoad(aEvent) { michael@0: loadCount++; michael@0: info("new load count is " + loadCount); michael@0: michael@0: if (loadCount == 3) { michael@0: gBrowser.removeEventListener("DOMContentLoaded", handleLoad, true); michael@0: content.location.href = "about:blank"; michael@0: executeSoon(check_next_uri); michael@0: } michael@0: } michael@0: michael@0: function check_next_uri() { michael@0: if (URIs.length) { michael@0: let uri = URIs.shift(); michael@0: loadCount = 0; michael@0: gBrowser.addEventListener("DOMContentLoaded", handleLoad, true); michael@0: content.location.href = uri; michael@0: } michael@0: else { michael@0: confirm_results(); michael@0: } michael@0: } michael@0: executeSoon(check_next_uri); michael@0: }