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

mercurial