michael@0: /* Test for Bug 503832 michael@0: * https://bugzilla.mozilla.org/show_bug.cgi?id=503832 michael@0: */ michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: var pagetitle = "Page Title for Bug 503832"; michael@0: var pageurl = "http://mochi.test:8888/browser/docshell/test/browser/file_bug503832.html"; michael@0: var fragmenturl = "http://mochi.test:8888/browser/docshell/test/browser/file_bug503832.html#firefox"; michael@0: michael@0: /* Global history observer that triggers for the two test URLs above. */ michael@0: var historyObserver = { michael@0: onBeginUpdateBatch: function() {}, michael@0: onEndUpdateBatch: function() {}, michael@0: onVisit: function(aURI, aVisitID, aTime, aSessionId, aReferringId, michael@0: aTransitionType, _added) {}, michael@0: onTitleChanged: function(aURI, aPageTitle) { michael@0: aURI = aURI.spec; michael@0: switch (aURI) { michael@0: case pageurl: michael@0: is(aPageTitle, pagetitle, "Correct page title for " + aURI); michael@0: return; michael@0: case fragmenturl: michael@0: is(aPageTitle, pagetitle, "Correct page title for " + aURI); michael@0: // If titles for fragment URLs aren't set, this code michael@0: // branch won't be called and the test will timeout, michael@0: // resulting in a failure michael@0: historyService.removeObserver(historyObserver, false); michael@0: michael@0: gBrowser.removeCurrentTab(); michael@0: michael@0: finish(); michael@0: } michael@0: }, michael@0: onDeleteURI: function(aURI) {}, michael@0: onClearHistory: function() {}, michael@0: onPageChanged: function(aURI, aWhat, aValue) {}, michael@0: onDeleteVisits: function () {}, michael@0: QueryInterface: function(iid) { michael@0: if (iid.equals(Ci.nsINavHistoryObserver) || michael@0: iid.equals(Ci.nsISupports)) { michael@0: return this; michael@0: } michael@0: throw Cr.NS_ERROR_NO_INTERFACE; michael@0: } michael@0: }; michael@0: michael@0: var historyService = Cc["@mozilla.org/browser/nav-history-service;1"] michael@0: .getService(Ci.nsINavHistoryService); michael@0: historyService.addObserver(historyObserver, false); michael@0: michael@0: /* Queries nsINavHistoryService and returns a single history entry michael@0: * for a given URI */ michael@0: function getNavHistoryEntry(aURI) { michael@0: var options = historyService.getNewQueryOptions(); michael@0: options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_HISTORY; michael@0: options.maxResults = 1; michael@0: michael@0: var query = historyService.getNewQuery(); michael@0: query.uri = aURI; michael@0: michael@0: var result = historyService.executeQuery(query, options); michael@0: result.root.containerOpen = true; michael@0: michael@0: if (!result.root.childCount) { michael@0: return null; michael@0: } michael@0: var node = result.root.getChild(0); michael@0: result.root.containerOpen = false; michael@0: return node; michael@0: } michael@0: michael@0: michael@0: function onPageLoad() { michael@0: gBrowser.selectedBrowser.removeEventListener( michael@0: "DOMContentLoaded", onPageLoad, true); michael@0: michael@0: // Now that the page is loaded, click on fragment link michael@0: EventUtils.sendMouseEvent({type:'click'}, 'firefox-link', michael@0: gBrowser.selectedBrowser.contentWindow); michael@0: michael@0: // Test finishes in historyObserver.onTitleChanged() above michael@0: } michael@0: michael@0: // Make sure neither of the test pages haven't been loaded before. michael@0: var info = getNavHistoryEntry(makeURI(pageurl)); michael@0: ok(!info, "The test page must not have been visited already."); michael@0: info = getNavHistoryEntry(makeURI(fragmenturl)); michael@0: ok(!info, "The fragment test page must not have been visited already."); michael@0: michael@0: // Now open the test page in a new tab michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: gBrowser.selectedBrowser.addEventListener( michael@0: "DOMContentLoaded", onPageLoad, true); michael@0: content.location = pageurl; michael@0: }