gecko/toolkit/content/tests/browser/browser_browserDrop.js
Gavin Sharp 90b4228ae6 Bug 724161: simplify some javascript:/data: drop checks, r=dao
--HG--
extra : transplant_source : q%C4%92%1C%BA%11/%93%85f%9D%26%A1%8AE%A1O%07%C7b
2012-02-14 15:08:35 -08:00

62 lines
1.9 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
function test() {
waitForExplicitFinish();
let newTab = gBrowser.selectedTab = gBrowser.addTab();
registerCleanupFunction(function () {
gBrowser.removeTab(newTab);
});
let scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
getService(Ci.mozIJSSubScriptLoader);
let chromeUtils = {};
scriptLoader.loadSubScript("chrome://mochikit/content/tests/SimpleTest/ChromeUtils.js", chromeUtils);
let browser = gBrowser.selectedBrowser;
var linkHandlerActivated = 0;
// Don't worry about clobbering the droppedLinkHandler, since we're closing
// this tab after the test anyways
browser.droppedLinkHandler = function dlh(e, url, name) {
linkHandlerActivated++;
ok(!/(javascript|data)/i.test(url), "javascript link should not be dropped");
}
var receivedDropCount = 0;
function dropListener() {
receivedDropCount++;
if (receivedDropCount == triggeredDropCount) {
// Wait for the browser's system-phase event handler to run.
executeSoon(function () {
is(linkHandlerActivated, validDropCount,
"link handler was called correct number of times");
finish();
})
}
}
browser.addEventListener("drop", dropListener, false);
registerCleanupFunction(function () {
browser.removeEventListener("drop", dropListener, false);
});
var triggeredDropCount = 0;
var validDropCount = 0;
function drop(text, valid) {
triggeredDropCount++;
if (valid)
validDropCount++;
executeSoon(function () {
chromeUtils.synthesizeDrop(browser, browser, [[{type: "text/plain", data: text}]], "copy", window, EventUtils);
});
}
drop("mochi.test/first", true);
drop("javascript:'bad'");
drop("jAvascript:'also bad'");
drop("mochi.test/second", true);
drop("data:text/html,bad");
drop("mochi.test/third", true);
}