browser/base/content/test/general/browser_bug575561.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 function test() {
michael@0 2 waitForExplicitFinish();
michael@0 3
michael@0 4 // Pinned: Link to the same domain should not open a new tab
michael@0 5 // Tests link to http://example.com/browser/browser/base/content/test/general/dummy_page.html
michael@0 6 testLink(0, true, false, function() {
michael@0 7 // Pinned: Link to a different subdomain should open a new tab
michael@0 8 // Tests link to http://test1.example.com/browser/browser/base/content/test/general/dummy_page.html
michael@0 9 testLink(1, true, true, function() {
michael@0 10 // Pinned: Link to a different domain should open a new tab
michael@0 11 // Tests link to http://example.org/browser/browser/base/content/test/general/dummy_page.html
michael@0 12 testLink(2, true, true, function() {
michael@0 13 // Not Pinned: Link to a different domain should not open a new tab
michael@0 14 // Tests link to http://example.org/browser/browser/base/content/test/general/dummy_page.html
michael@0 15 testLink(2, false, false, function() {
michael@0 16 // Pinned: Targetted link should open a new tab
michael@0 17 // Tests link to http://example.org/browser/browser/base/content/test/general/dummy_page.html with target="foo"
michael@0 18 testLink(3, true, true, function() {
michael@0 19 // Pinned: Link in a subframe should not open a new tab
michael@0 20 // Tests link to http://example.org/browser/browser/base/content/test/general/dummy_page.html in subframe
michael@0 21 testLink(0, true, false, function() {
michael@0 22 // Pinned: Link to the same domain (with www prefix) should not open a new tab
michael@0 23 // Tests link to http://www.example.com/browser/browser/base/content/test/general/dummy_page.html
michael@0 24 testLink(4, true, false, function() {
michael@0 25 // Pinned: Link to a data: URI should not open a new tab
michael@0 26 // Tests link to data:text/html,<!DOCTYPE html><html><body>Another Page</body></html>
michael@0 27 testLink(5, true, false, function() {
michael@0 28 // Pinned: Link to an about: URI should not open a new tab
michael@0 29 // Tests link to about:mozilla
michael@0 30 testLink(6, true, false, finish);
michael@0 31 });
michael@0 32 });
michael@0 33 }, true);
michael@0 34 });
michael@0 35 });
michael@0 36 });
michael@0 37 });
michael@0 38 });
michael@0 39 }
michael@0 40
michael@0 41 function testLink(aLinkIndex, pinTab, expectNewTab, nextTest, testSubFrame) {
michael@0 42 let appTab = gBrowser.addTab("http://example.com/browser/browser/base/content/test/general/app_bug575561.html", {skipAnimation: true});
michael@0 43 if (pinTab)
michael@0 44 gBrowser.pinTab(appTab);
michael@0 45 gBrowser.selectedTab = appTab;
michael@0 46 appTab.linkedBrowser.addEventListener("load", onLoad, true);
michael@0 47
michael@0 48 let loadCount = 0;
michael@0 49 function onLoad() {
michael@0 50 loadCount++;
michael@0 51 if (loadCount < 2)
michael@0 52 return;
michael@0 53
michael@0 54 appTab.linkedBrowser.removeEventListener("load", onLoad, true);
michael@0 55
michael@0 56 let browser = gBrowser.getBrowserForTab(appTab);
michael@0 57 if (testSubFrame)
michael@0 58 browser = browser.contentDocument.getElementsByTagName("iframe")[0];
michael@0 59
michael@0 60 let links = browser.contentDocument.getElementsByTagName("a");
michael@0 61
michael@0 62 if (expectNewTab)
michael@0 63 gBrowser.tabContainer.addEventListener("TabOpen", onTabOpen, true);
michael@0 64 else
michael@0 65 browser.addEventListener("load", onPageLoad, true);
michael@0 66
michael@0 67 info("Clicking " + links[aLinkIndex].textContent);
michael@0 68 EventUtils.sendMouseEvent({type:"click"}, links[aLinkIndex], browser.contentWindow);
michael@0 69 let linkLocation = links[aLinkIndex].href;
michael@0 70
michael@0 71 function onPageLoad() {
michael@0 72 browser.removeEventListener("load", onPageLoad, true);
michael@0 73 is(browser.contentDocument.location.href, linkLocation, "Link should not open in a new tab");
michael@0 74 executeSoon(function(){
michael@0 75 gBrowser.removeTab(appTab);
michael@0 76 nextTest();
michael@0 77 });
michael@0 78 }
michael@0 79
michael@0 80 function onTabOpen(event) {
michael@0 81 gBrowser.tabContainer.removeEventListener("TabOpen", onTabOpen, true);
michael@0 82 ok(true, "Link should open a new tab");
michael@0 83 executeSoon(function(){
michael@0 84 gBrowser.removeTab(appTab);
michael@0 85 gBrowser.removeCurrentTab();
michael@0 86 nextTest();
michael@0 87 });
michael@0 88 }
michael@0 89 }
michael@0 90 }

mercurial