mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-15 03:00:30 +00:00
Bug 676619 - Tests for a[download]. r=smaug
This commit is contained in:
parent
9271842e43
commit
71b98ef85a
@ -293,6 +293,8 @@ _BROWSER_FILES = \
|
||||
social_flyout.html \
|
||||
social_window.html \
|
||||
social_worker.js \
|
||||
browser_bug676619.js \
|
||||
download_page.html \
|
||||
$(NULL)
|
||||
|
||||
ifneq (cocoa,$(MOZ_WIDGET_TOOLKIT))
|
||||
|
109
browser/base/content/test/browser_bug676619.js
Normal file
109
browser/base/content/test/browser_bug676619.js
Normal file
@ -0,0 +1,109 @@
|
||||
function test () {
|
||||
waitForExplicitFinish();
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
gBrowser.selectedBrowser.addEventListener("load", function () {
|
||||
gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
|
||||
let doc = gBrowser.contentDocument;
|
||||
|
||||
|
||||
function testLocation(link, url, next) {
|
||||
var tabOpenListener = new TabOpenListener(url, function () {
|
||||
gBrowser.removeTab(this.tab);
|
||||
}, function () {
|
||||
next();
|
||||
});
|
||||
|
||||
doc.getElementById(link).click();
|
||||
}
|
||||
|
||||
function testLink(link, name, next) {
|
||||
addWindowListener("chrome://mozapps/content/downloads/unknownContentType.xul", function (win) {
|
||||
is(win.document.getElementById("location").value, name, "file name should match");
|
||||
win.close();
|
||||
next();
|
||||
});
|
||||
|
||||
doc.getElementById(link).click();
|
||||
}
|
||||
|
||||
testLink("link1", "test.txt",
|
||||
testLink.bind(null, "link2", "video.ogg",
|
||||
testLink.bind(null, "link3", "just some video",
|
||||
testLink.bind(null, "link4", "with-target.txt",
|
||||
testLink.bind(null, "link5", "javascript.txt",
|
||||
testLink.bind(null, "link6", "test.blob",
|
||||
testLocation.bind(null, "link7", "http://example.com/",
|
||||
function () {
|
||||
gBrowser.removeCurrentTab();
|
||||
finish();
|
||||
})))))));
|
||||
|
||||
}, true);
|
||||
|
||||
content.location = "http://mochi.test:8888/browser/browser/base/content/test/download_page.html";
|
||||
}
|
||||
|
||||
|
||||
function addWindowListener(aURL, aCallback) {
|
||||
Services.wm.addListener({
|
||||
onOpenWindow: function(aXULWindow) {
|
||||
info("window opened, waiting for focus");
|
||||
Services.wm.removeListener(this);
|
||||
|
||||
var domwindow = aXULWindow.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIDOMWindow);
|
||||
waitForFocus(function() {
|
||||
is(domwindow.document.location.href, aURL, "should have seen the right window open");
|
||||
aCallback(domwindow);
|
||||
}, domwindow);
|
||||
},
|
||||
onCloseWindow: function(aXULWindow) { },
|
||||
onWindowTitleChange: function(aXULWindow, aNewTitle) { }
|
||||
});
|
||||
}
|
||||
|
||||
// This listens for the next opened tab and checks it is of the right url.
|
||||
// opencallback is called when the new tab is fully loaded
|
||||
// closecallback is called when the tab is closed
|
||||
function TabOpenListener(url, opencallback, closecallback) {
|
||||
this.url = url;
|
||||
this.opencallback = opencallback;
|
||||
this.closecallback = closecallback;
|
||||
|
||||
gBrowser.tabContainer.addEventListener("TabOpen", this, false);
|
||||
}
|
||||
|
||||
TabOpenListener.prototype = {
|
||||
url: null,
|
||||
opencallback: null,
|
||||
closecallback: null,
|
||||
tab: null,
|
||||
browser: null,
|
||||
|
||||
handleEvent: function(event) {
|
||||
if (event.type == "TabOpen") {
|
||||
gBrowser.tabContainer.removeEventListener("TabOpen", this, false);
|
||||
this.tab = event.originalTarget;
|
||||
this.browser = this.tab.linkedBrowser;
|
||||
gBrowser.addEventListener("pageshow", this, false);
|
||||
} else if (event.type == "pageshow") {
|
||||
if (event.target.location.href != this.url)
|
||||
return;
|
||||
gBrowser.removeEventListener("pageshow", this, false);
|
||||
this.tab.addEventListener("TabClose", this, false);
|
||||
var url = this.browser.contentDocument.location.href;
|
||||
is(url, this.url, "Should have opened the correct tab");
|
||||
this.opencallback(this.tab, this.browser.contentWindow);
|
||||
} else if (event.type == "TabClose") {
|
||||
if (event.originalTarget != this.tab)
|
||||
return;
|
||||
this.tab.removeEventListener("TabClose", this, false);
|
||||
this.opencallback = null;
|
||||
this.tab = null;
|
||||
this.browser = null;
|
||||
// Let the window close complete
|
||||
executeSoon(this.closecallback);
|
||||
this.closecallback = null;
|
||||
}
|
||||
}
|
||||
};
|
42
browser/base/content/test/download_page.html
Normal file
42
browser/base/content/test/download_page.html
Normal file
@ -0,0 +1,42 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=676619
|
||||
-->
|
||||
<head>
|
||||
<title>Test for the download attribute</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=676619">Bug 676619</a>
|
||||
<br/>
|
||||
<ul>
|
||||
<li><a href="data:text/plain,Hey What are you looking for?"
|
||||
download="test.txt" id="link1">Download "test.txt"</a></li>
|
||||
<li><a href="http://mochi.test:8888/browser/browser/base/content/test/video.ogg"
|
||||
download id="link2">Download "video.ogg"</a></li>
|
||||
<li><a href="http://mochi.test:8888/browser/browser/base/content/test/video.ogg"
|
||||
download="just some video" id="link3">Download "just some video"</a></li>
|
||||
<li><a href="data:text/plain,test"
|
||||
download="with-target.txt" id="link4">Download "with-target.txt"</a></li>
|
||||
<li><a href="javascript:1+2"
|
||||
download="javascript.txt" id="link5">Download "javascript.txt"</a></li>
|
||||
</ul>
|
||||
<script>
|
||||
var li = document.createElement('li');
|
||||
var a = document.createElement('a');
|
||||
|
||||
a.href = window.URL.createObjectURL(new Blob(["just text"])) ;
|
||||
a.download = "test.blob";
|
||||
a.id = "link6";
|
||||
a.textContent = 'Download "test.blob"';
|
||||
|
||||
li.appendChild(a);
|
||||
document.getElementsByTagName('ul')[0].appendChild(li);
|
||||
</script>
|
||||
<ul>
|
||||
<li><a href="http://example.com/"
|
||||
download="example.com" id="link7" target="_blank">Download "example.com"</a></li>
|
||||
<ul>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user