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