browser/base/content/test/general/browser_bug676619.js

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

mercurial