1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/general/browser_bug575561.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,90 @@ 1.4 +function test() { 1.5 + waitForExplicitFinish(); 1.6 + 1.7 + // Pinned: Link to the same domain should not open a new tab 1.8 + // Tests link to http://example.com/browser/browser/base/content/test/general/dummy_page.html 1.9 + testLink(0, true, false, function() { 1.10 + // Pinned: Link to a different subdomain should open a new tab 1.11 + // Tests link to http://test1.example.com/browser/browser/base/content/test/general/dummy_page.html 1.12 + testLink(1, true, true, function() { 1.13 + // Pinned: Link to a different domain should open a new tab 1.14 + // Tests link to http://example.org/browser/browser/base/content/test/general/dummy_page.html 1.15 + testLink(2, true, true, function() { 1.16 + // Not Pinned: Link to a different domain should not open a new tab 1.17 + // Tests link to http://example.org/browser/browser/base/content/test/general/dummy_page.html 1.18 + testLink(2, false, false, function() { 1.19 + // Pinned: Targetted link should open a new tab 1.20 + // Tests link to http://example.org/browser/browser/base/content/test/general/dummy_page.html with target="foo" 1.21 + testLink(3, true, true, function() { 1.22 + // Pinned: Link in a subframe should not open a new tab 1.23 + // Tests link to http://example.org/browser/browser/base/content/test/general/dummy_page.html in subframe 1.24 + testLink(0, true, false, function() { 1.25 + // Pinned: Link to the same domain (with www prefix) should not open a new tab 1.26 + // Tests link to http://www.example.com/browser/browser/base/content/test/general/dummy_page.html 1.27 + testLink(4, true, false, function() { 1.28 + // Pinned: Link to a data: URI should not open a new tab 1.29 + // Tests link to data:text/html,<!DOCTYPE html><html><body>Another Page</body></html> 1.30 + testLink(5, true, false, function() { 1.31 + // Pinned: Link to an about: URI should not open a new tab 1.32 + // Tests link to about:mozilla 1.33 + testLink(6, true, false, finish); 1.34 + }); 1.35 + }); 1.36 + }, true); 1.37 + }); 1.38 + }); 1.39 + }); 1.40 + }); 1.41 + }); 1.42 +} 1.43 + 1.44 +function testLink(aLinkIndex, pinTab, expectNewTab, nextTest, testSubFrame) { 1.45 + let appTab = gBrowser.addTab("http://example.com/browser/browser/base/content/test/general/app_bug575561.html", {skipAnimation: true}); 1.46 + if (pinTab) 1.47 + gBrowser.pinTab(appTab); 1.48 + gBrowser.selectedTab = appTab; 1.49 + appTab.linkedBrowser.addEventListener("load", onLoad, true); 1.50 + 1.51 + let loadCount = 0; 1.52 + function onLoad() { 1.53 + loadCount++; 1.54 + if (loadCount < 2) 1.55 + return; 1.56 + 1.57 + appTab.linkedBrowser.removeEventListener("load", onLoad, true); 1.58 + 1.59 + let browser = gBrowser.getBrowserForTab(appTab); 1.60 + if (testSubFrame) 1.61 + browser = browser.contentDocument.getElementsByTagName("iframe")[0]; 1.62 + 1.63 + let links = browser.contentDocument.getElementsByTagName("a"); 1.64 + 1.65 + if (expectNewTab) 1.66 + gBrowser.tabContainer.addEventListener("TabOpen", onTabOpen, true); 1.67 + else 1.68 + browser.addEventListener("load", onPageLoad, true); 1.69 + 1.70 + info("Clicking " + links[aLinkIndex].textContent); 1.71 + EventUtils.sendMouseEvent({type:"click"}, links[aLinkIndex], browser.contentWindow); 1.72 + let linkLocation = links[aLinkIndex].href; 1.73 + 1.74 + function onPageLoad() { 1.75 + browser.removeEventListener("load", onPageLoad, true); 1.76 + is(browser.contentDocument.location.href, linkLocation, "Link should not open in a new tab"); 1.77 + executeSoon(function(){ 1.78 + gBrowser.removeTab(appTab); 1.79 + nextTest(); 1.80 + }); 1.81 + } 1.82 + 1.83 + function onTabOpen(event) { 1.84 + gBrowser.tabContainer.removeEventListener("TabOpen", onTabOpen, true); 1.85 + ok(true, "Link should open a new tab"); 1.86 + executeSoon(function(){ 1.87 + gBrowser.removeTab(appTab); 1.88 + gBrowser.removeCurrentTab(); 1.89 + nextTest(); 1.90 + }); 1.91 + } 1.92 + } 1.93 +}