2 * https://bugzilla.mozilla.org/show_bug.cgi?id=503832
6 waitForExplicitFinish();
8 var pagetitle
= "Page Title for Bug 503832";
9 var pageurl
= "http://mochi.test:8888/browser/docshell/test/browser/file_bug503832.html";
10 var fragmenturl
= "http://mochi.test:8888/browser/docshell/test/browser/file_bug503832.html#firefox";
12 /* Global history observer that triggers for the two test URLs above. */
13 var historyObserver
= {
14 onBeginUpdateBatch: function() {},
15 onEndUpdateBatch: function() {},
16 onVisit: function(aURI
, aVisitID
, aTime
, aSessionId
, aReferringId
,
17 aTransitionType
, _added
) {},
18 onTitleChanged: function(aURI
, aPageTitle
) {
22 is(aPageTitle
, pagetitle
, "Correct page title for " + aURI
);
25 is(aPageTitle
, pagetitle
, "Correct page title for " + aURI
);
26 // If titles for fragment URLs aren't set, this code
27 // branch won't be called and the test will timeout,
28 // resulting in a failure
29 historyService
.removeObserver(historyObserver
, false);
31 gBrowser
.removeCurrentTab();
36 onBeforeDeleteURI: function(aURI
) {},
37 onDeleteURI: function(aURI
) {},
38 onClearHistory: function() {},
39 onPageChanged: function(aURI
, aWhat
, aValue
) {},
40 onDeleteVisits: function () {},
41 QueryInterface: function(iid
) {
42 if (iid
.equals(Ci
.nsINavHistoryObserver
) ||
43 iid
.equals(Ci
.nsISupports
)) {
46 throw Cr
.NS_ERROR_NO_INTERFACE
;
50 var historyService
= Cc
["@mozilla.org/browser/nav-history-service;1"]
51 .getService(Ci
.nsINavHistoryService
);
52 historyService
.addObserver(historyObserver
, false);
54 /* Queries nsINavHistoryService and returns a single history entry
56 function getNavHistoryEntry(aURI
) {
57 var options
= historyService
.getNewQueryOptions();
58 options
.queryType
= Ci
.nsINavHistoryQueryOptions
.QUERY_TYPE_HISTORY
;
59 options
.maxResults
= 1;
61 var query
= historyService
.getNewQuery();
64 var result
= historyService
.executeQuery(query
, options
);
65 result
.root
.containerOpen
= true;
67 if (!result
.root
.childCount
) {
70 return result
.root
.getChild(0);
74 function onPageLoad() {
75 gBrowser
.selectedBrowser
.removeEventListener(
76 "DOMContentLoaded", onPageLoad
, true);
78 // Now that the page is loaded, click on fragment link
79 EventUtils
.sendMouseEvent({type
:'click'}, 'firefox-link',
80 gBrowser
.selectedBrowser
.contentWindow
);
82 // Test finishes in historyObserver.onTitleChanged() above
85 // Make sure neither of the test pages haven't been loaded before.
86 var info
= getNavHistoryEntry(makeURI(pageurl
));
87 ok(!info
, "The test page must not have been visited already.");
88 info
= getNavHistoryEntry(makeURI(fragmenturl
));
89 ok(!info
, "The fragment test page must not have been visited already.");
91 // Now open the test page in a new tab
92 gBrowser
.selectedTab
= gBrowser
.addTab();
93 gBrowser
.selectedBrowser
.addEventListener(
94 "DOMContentLoaded", onPageLoad
, true);
95 content
.location
= pageurl
;