|
1 /* Test for Bug 503832 |
|
2 * https://bugzilla.mozilla.org/show_bug.cgi?id=503832 |
|
3 */ |
|
4 |
|
5 function test() { |
|
6 waitForExplicitFinish(); |
|
7 |
|
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"; |
|
11 |
|
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) { |
|
19 aURI = aURI.spec; |
|
20 switch (aURI) { |
|
21 case pageurl: |
|
22 is(aPageTitle, pagetitle, "Correct page title for " + aURI); |
|
23 return; |
|
24 case fragmenturl: |
|
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); |
|
30 |
|
31 gBrowser.removeCurrentTab(); |
|
32 |
|
33 finish(); |
|
34 } |
|
35 }, |
|
36 onDeleteURI: function(aURI) {}, |
|
37 onClearHistory: function() {}, |
|
38 onPageChanged: function(aURI, aWhat, aValue) {}, |
|
39 onDeleteVisits: function () {}, |
|
40 QueryInterface: function(iid) { |
|
41 if (iid.equals(Ci.nsINavHistoryObserver) || |
|
42 iid.equals(Ci.nsISupports)) { |
|
43 return this; |
|
44 } |
|
45 throw Cr.NS_ERROR_NO_INTERFACE; |
|
46 } |
|
47 }; |
|
48 |
|
49 var historyService = Cc["@mozilla.org/browser/nav-history-service;1"] |
|
50 .getService(Ci.nsINavHistoryService); |
|
51 historyService.addObserver(historyObserver, false); |
|
52 |
|
53 /* Queries nsINavHistoryService and returns a single history entry |
|
54 * for a given URI */ |
|
55 function getNavHistoryEntry(aURI) { |
|
56 var options = historyService.getNewQueryOptions(); |
|
57 options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_HISTORY; |
|
58 options.maxResults = 1; |
|
59 |
|
60 var query = historyService.getNewQuery(); |
|
61 query.uri = aURI; |
|
62 |
|
63 var result = historyService.executeQuery(query, options); |
|
64 result.root.containerOpen = true; |
|
65 |
|
66 if (!result.root.childCount) { |
|
67 return null; |
|
68 } |
|
69 var node = result.root.getChild(0); |
|
70 result.root.containerOpen = false; |
|
71 return node; |
|
72 } |
|
73 |
|
74 |
|
75 function onPageLoad() { |
|
76 gBrowser.selectedBrowser.removeEventListener( |
|
77 "DOMContentLoaded", onPageLoad, true); |
|
78 |
|
79 // Now that the page is loaded, click on fragment link |
|
80 EventUtils.sendMouseEvent({type:'click'}, 'firefox-link', |
|
81 gBrowser.selectedBrowser.contentWindow); |
|
82 |
|
83 // Test finishes in historyObserver.onTitleChanged() above |
|
84 } |
|
85 |
|
86 // Make sure neither of the test pages haven't been loaded before. |
|
87 var info = getNavHistoryEntry(makeURI(pageurl)); |
|
88 ok(!info, "The test page must not have been visited already."); |
|
89 info = getNavHistoryEntry(makeURI(fragmenturl)); |
|
90 ok(!info, "The fragment test page must not have been visited already."); |
|
91 |
|
92 // Now open the test page in a new tab |
|
93 gBrowser.selectedTab = gBrowser.addTab(); |
|
94 gBrowser.selectedBrowser.addEventListener( |
|
95 "DOMContentLoaded", onPageLoad, true); |
|
96 content.location = pageurl; |
|
97 } |