docshell/test/browser/browser_bug420605.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Test for Bug 420605
michael@0 2 * https://bugzilla.mozilla.org/show_bug.cgi?id=420605
michael@0 3 */
michael@0 4
michael@0 5 function test() {
michael@0 6 waitForExplicitFinish();
michael@0 7
michael@0 8 var pageurl = "http://mochi.test:8888/browser/docshell/test/browser/file_bug420605.html";
michael@0 9 var fragmenturl = "http://mochi.test:8888/browser/docshell/test/browser/file_bug420605.html#firefox";
michael@0 10
michael@0 11 var historyService = Cc["@mozilla.org/browser/nav-history-service;1"]
michael@0 12 .getService(Ci.nsINavHistoryService);
michael@0 13
michael@0 14 /* Queries nsINavHistoryService and returns a single history entry
michael@0 15 * for a given URI */
michael@0 16 function getNavHistoryEntry(aURI) {
michael@0 17 var options = historyService.getNewQueryOptions();
michael@0 18 options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_HISTORY;
michael@0 19 options.maxResults = 1;
michael@0 20
michael@0 21 var query = historyService.getNewQuery();
michael@0 22 query.uri = aURI;
michael@0 23
michael@0 24 var result = historyService.executeQuery(query, options);
michael@0 25 result.root.containerOpen = true;
michael@0 26
michael@0 27 if (!result.root.childCount) {
michael@0 28 return null;
michael@0 29 }
michael@0 30 return result.root.getChild(0);
michael@0 31 }
michael@0 32
michael@0 33 // We'll save the favicon URL of the orignal page here and check that the
michael@0 34 // page with a hash has the same favicon.
michael@0 35 var originalFavicon;
michael@0 36
michael@0 37 // Control flow in this test is a bit complicated.
michael@0 38 //
michael@0 39 // When the page loads, onPageLoad (the DOMContentLoaded handler) and
michael@0 40 // historyObserver::onPageChanged are both called, in some order. Once
michael@0 41 // they've both run, we click a fragment link in the content page
michael@0 42 // (clickLinkIfReady), which should trigger another onPageChanged event,
michael@0 43 // this time for the fragment's URL.
michael@0 44
michael@0 45 var _clickLinkTimes = 0;
michael@0 46 function clickLinkIfReady() {
michael@0 47 _clickLinkTimes++;
michael@0 48 if (_clickLinkTimes == 2) {
michael@0 49 EventUtils.sendMouseEvent({type:'click'}, 'firefox-link',
michael@0 50 gBrowser.selectedBrowser.contentWindow);
michael@0 51 }
michael@0 52 }
michael@0 53
michael@0 54 /* Global history observer that triggers for the two test URLs above. */
michael@0 55 var historyObserver = {
michael@0 56 onBeginUpdateBatch: function() {},
michael@0 57 onEndUpdateBatch: function() {},
michael@0 58 onVisit: function(aURI, aVisitID, aTime, aSessionId, aReferringId,
michael@0 59 aTransitionType, _added) {},
michael@0 60 onTitleChanged: function(aURI, aPageTitle) {},
michael@0 61 onDeleteURI: function(aURI) {},
michael@0 62 onClearHistory: function() {},
michael@0 63 onPageChanged: function(aURI, aWhat, aValue) {
michael@0 64 if (aWhat != Ci.nsINavHistoryObserver.ATTRIBUTE_FAVICON) {
michael@0 65 return;
michael@0 66 }
michael@0 67 aURI = aURI.spec;
michael@0 68 switch (aURI) {
michael@0 69 case pageurl:
michael@0 70 ok(aValue, "Favicon value is not null for page without fragment.");
michael@0 71 originalFavicon = aValue;
michael@0 72
michael@0 73 // Now that the favicon has loaded, click on fragment link.
michael@0 74 // This should trigger the |case fragmenturl| below.
michael@0 75 clickLinkIfReady();
michael@0 76
michael@0 77 return;
michael@0 78 case fragmenturl:
michael@0 79 // If the fragment URL's favicon isn't set, this branch won't
michael@0 80 // be called and the test will time out.
michael@0 81
michael@0 82 is(aValue, originalFavicon, "New favicon should be same as original favicon.");
michael@0 83
michael@0 84 // Let's explicitly check that we can get the favicon
michael@0 85 // from nsINavHistoryService now.
michael@0 86 let info = getNavHistoryEntry(makeURI(aURI));
michael@0 87 ok(info, "There must be a history entry for the fragment.");
michael@0 88 ok(info.icon, "The history entry must have an associated favicon.");
michael@0 89 historyService.removeObserver(historyObserver, false);
michael@0 90 gBrowser.removeCurrentTab();
michael@0 91 finish();
michael@0 92 }
michael@0 93 },
michael@0 94 onPageExpired: function(aURI, aVisitTime, aWholeEntry) {},
michael@0 95 QueryInterface: function(iid) {
michael@0 96 if (iid.equals(Ci.nsINavHistoryObserver) ||
michael@0 97 iid.equals(Ci.nsISupports)) {
michael@0 98 return this;
michael@0 99 }
michael@0 100 throw Cr.NS_ERROR_NO_INTERFACE;
michael@0 101 }
michael@0 102 };
michael@0 103 historyService.addObserver(historyObserver, false);
michael@0 104
michael@0 105 function onPageLoad() {
michael@0 106 gBrowser.selectedBrowser
michael@0 107 .removeEventListener("DOMContentLoaded", arguments.callee, true);
michael@0 108 clickLinkIfReady();
michael@0 109 }
michael@0 110
michael@0 111 // Make sure neither of the test pages haven't been loaded before.
michael@0 112 var info = getNavHistoryEntry(makeURI(pageurl));
michael@0 113 ok(!info, "The test page must not have been visited already.");
michael@0 114 info = getNavHistoryEntry(makeURI(fragmenturl));
michael@0 115 ok(!info, "The fragment test page must not have been visited already.");
michael@0 116
michael@0 117 // Now open the test page in a new tab.
michael@0 118 gBrowser.selectedTab = gBrowser.addTab();
michael@0 119 gBrowser.selectedBrowser.addEventListener(
michael@0 120 "DOMContentLoaded", onPageLoad, true);
michael@0 121 content.location = pageurl;
michael@0 122 }

mercurial