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.
michael@0 | 1 | function test () { |
michael@0 | 2 | waitForExplicitFinish(); |
michael@0 | 3 | |
michael@0 | 4 | var isHTTPS = false; |
michael@0 | 5 | |
michael@0 | 6 | gBrowser.selectedTab = gBrowser.addTab(); |
michael@0 | 7 | gBrowser.selectedBrowser.addEventListener("load", function () { |
michael@0 | 8 | if (isHTTPS) { |
michael@0 | 9 | gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true); |
michael@0 | 10 | } |
michael@0 | 11 | let doc = gBrowser.contentDocument; |
michael@0 | 12 | |
michael@0 | 13 | |
michael@0 | 14 | function testLocation(link, url, next) { |
michael@0 | 15 | var tabOpenListener = new TabOpenListener(url, function () { |
michael@0 | 16 | gBrowser.removeTab(this.tab); |
michael@0 | 17 | }, function () { |
michael@0 | 18 | next(); |
michael@0 | 19 | }); |
michael@0 | 20 | |
michael@0 | 21 | doc.getElementById(link).click(); |
michael@0 | 22 | } |
michael@0 | 23 | |
michael@0 | 24 | function testLink(link, name, next) { |
michael@0 | 25 | addWindowListener("chrome://mozapps/content/downloads/unknownContentType.xul", function (win) { |
michael@0 | 26 | is(doc.getElementById("unload-flag").textContent, "Okay", "beforeunload shouldn't have fired"); |
michael@0 | 27 | is(win.document.getElementById("location").value, name, "file name should match"); |
michael@0 | 28 | win.close(); |
michael@0 | 29 | next(); |
michael@0 | 30 | }); |
michael@0 | 31 | |
michael@0 | 32 | doc.getElementById(link).click(); |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | testLink("link1", "test.txt", |
michael@0 | 36 | testLink.bind(null, "link2", "video.ogg", |
michael@0 | 37 | testLink.bind(null, "link3", "just some video", |
michael@0 | 38 | testLink.bind(null, "link4", "with-target.txt", |
michael@0 | 39 | testLink.bind(null, "link5", "javascript.txt", |
michael@0 | 40 | testLink.bind(null, "link6", "test.blob", |
michael@0 | 41 | testLocation.bind(null, "link7", "http://example.com/", |
michael@0 | 42 | function () { |
michael@0 | 43 | if (isHTTPS) { |
michael@0 | 44 | gBrowser.removeCurrentTab(); |
michael@0 | 45 | finish(); |
michael@0 | 46 | } else { |
michael@0 | 47 | // same test again with https: |
michael@0 | 48 | isHTTPS = true; |
michael@0 | 49 | content.location = "https://example.com:443/browser/browser/base/content/test/general/download_page.html"; |
michael@0 | 50 | } |
michael@0 | 51 | }))))))); |
michael@0 | 52 | |
michael@0 | 53 | }, true); |
michael@0 | 54 | |
michael@0 | 55 | content.location = "http://mochi.test:8888/browser/browser/base/content/test/general/download_page.html"; |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | |
michael@0 | 59 | function addWindowListener(aURL, aCallback) { |
michael@0 | 60 | Services.wm.addListener({ |
michael@0 | 61 | onOpenWindow: function(aXULWindow) { |
michael@0 | 62 | info("window opened, waiting for focus"); |
michael@0 | 63 | Services.wm.removeListener(this); |
michael@0 | 64 | |
michael@0 | 65 | var domwindow = aXULWindow.QueryInterface(Ci.nsIInterfaceRequestor) |
michael@0 | 66 | .getInterface(Ci.nsIDOMWindow); |
michael@0 | 67 | waitForFocus(function() { |
michael@0 | 68 | is(domwindow.document.location.href, aURL, "should have seen the right window open"); |
michael@0 | 69 | aCallback(domwindow); |
michael@0 | 70 | }, domwindow); |
michael@0 | 71 | }, |
michael@0 | 72 | onCloseWindow: function(aXULWindow) { }, |
michael@0 | 73 | onWindowTitleChange: function(aXULWindow, aNewTitle) { } |
michael@0 | 74 | }); |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | // This listens for the next opened tab and checks it is of the right url. |
michael@0 | 78 | // opencallback is called when the new tab is fully loaded |
michael@0 | 79 | // closecallback is called when the tab is closed |
michael@0 | 80 | function TabOpenListener(url, opencallback, closecallback) { |
michael@0 | 81 | this.url = url; |
michael@0 | 82 | this.opencallback = opencallback; |
michael@0 | 83 | this.closecallback = closecallback; |
michael@0 | 84 | |
michael@0 | 85 | gBrowser.tabContainer.addEventListener("TabOpen", this, false); |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | TabOpenListener.prototype = { |
michael@0 | 89 | url: null, |
michael@0 | 90 | opencallback: null, |
michael@0 | 91 | closecallback: null, |
michael@0 | 92 | tab: null, |
michael@0 | 93 | browser: null, |
michael@0 | 94 | |
michael@0 | 95 | handleEvent: function(event) { |
michael@0 | 96 | if (event.type == "TabOpen") { |
michael@0 | 97 | gBrowser.tabContainer.removeEventListener("TabOpen", this, false); |
michael@0 | 98 | this.tab = event.originalTarget; |
michael@0 | 99 | this.browser = this.tab.linkedBrowser; |
michael@0 | 100 | gBrowser.addEventListener("pageshow", this, false); |
michael@0 | 101 | } else if (event.type == "pageshow") { |
michael@0 | 102 | if (event.target.location.href != this.url) |
michael@0 | 103 | return; |
michael@0 | 104 | gBrowser.removeEventListener("pageshow", this, false); |
michael@0 | 105 | this.tab.addEventListener("TabClose", this, false); |
michael@0 | 106 | var url = this.browser.contentDocument.location.href; |
michael@0 | 107 | is(url, this.url, "Should have opened the correct tab"); |
michael@0 | 108 | this.opencallback(this.tab, this.browser.contentWindow); |
michael@0 | 109 | } else if (event.type == "TabClose") { |
michael@0 | 110 | if (event.originalTarget != this.tab) |
michael@0 | 111 | return; |
michael@0 | 112 | this.tab.removeEventListener("TabClose", this, false); |
michael@0 | 113 | this.opencallback = null; |
michael@0 | 114 | this.tab = null; |
michael@0 | 115 | this.browser = null; |
michael@0 | 116 | // Let the window close complete |
michael@0 | 117 | executeSoon(this.closecallback); |
michael@0 | 118 | this.closecallback = null; |
michael@0 | 119 | } |
michael@0 | 120 | } |
michael@0 | 121 | }; |