2011-05-17 07:39:59 -07:00
|
|
|
/* vim:set ts=2 sw=2 sts=2 et: */
|
|
|
|
/* Any copyright is dedicated to the Public Domain.
|
|
|
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
|
2012-03-24 04:34:42 -07:00
|
|
|
const TEST_URI = "data:text/html;charset=utf-8,<p>test for bug 642615";
|
2011-05-17 07:39:59 -07:00
|
|
|
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "clipboardHelper",
|
|
|
|
"@mozilla.org/widget/clipboardhelper;1",
|
|
|
|
"nsIClipboardHelper");
|
2014-05-21 15:34:00 -07:00
|
|
|
let WebConsoleUtils = require("devtools/toolkit/webconsole/utils").Utils;
|
2011-05-17 07:39:59 -07:00
|
|
|
|
2012-05-25 03:28:47 -07:00
|
|
|
function consoleOpened(HUD) {
|
2011-05-17 07:39:59 -07:00
|
|
|
let jsterm = HUD.jsterm;
|
|
|
|
let stringToCopy = "foobazbarBug642615";
|
|
|
|
|
|
|
|
jsterm.clearOutput();
|
|
|
|
|
2011-05-17 08:07:33 -07:00
|
|
|
ok(!jsterm.completeNode.value, "no completeNode.value");
|
2011-05-17 07:39:59 -07:00
|
|
|
|
|
|
|
jsterm.setInputValue("doc");
|
|
|
|
|
2012-05-25 03:28:47 -07:00
|
|
|
let completionValue;
|
2012-05-25 06:44:17 -07:00
|
|
|
|
2012-05-25 03:28:47 -07:00
|
|
|
// wait for key "u"
|
|
|
|
function onCompletionValue() {
|
|
|
|
completionValue = jsterm.completeNode.value;
|
2011-05-17 07:39:59 -07:00
|
|
|
|
|
|
|
// Arguments: expected, setup, success, failure.
|
|
|
|
waitForClipboard(
|
|
|
|
stringToCopy,
|
|
|
|
function() {
|
2012-04-16 19:14:01 -07:00
|
|
|
clipboardHelper.copyString(stringToCopy, document);
|
2011-05-17 07:39:59 -07:00
|
|
|
},
|
2012-05-25 03:28:47 -07:00
|
|
|
onClipboardCopy,
|
|
|
|
finishTest);
|
|
|
|
}
|
|
|
|
|
|
|
|
function onClipboardCopy() {
|
2014-05-21 15:34:00 -07:00
|
|
|
testSelfXss();
|
|
|
|
|
|
|
|
jsterm.setInputValue("docu");
|
2014-01-16 08:08:08 -08:00
|
|
|
info("wait for completion update after clipboard paste");
|
2014-05-21 15:34:00 -07:00
|
|
|
updateEditUIVisibility();
|
2014-01-16 08:08:08 -08:00
|
|
|
jsterm.once("autocomplete-updated", onClipboardPaste);
|
2014-05-21 15:34:00 -07:00
|
|
|
goDoCommand("cmd_paste");
|
|
|
|
}
|
|
|
|
|
2014-01-16 08:08:08 -08:00
|
|
|
|
2014-05-21 15:34:00 -07:00
|
|
|
// Self xss prevention tests (bug 994134)
|
|
|
|
function testSelfXss(){
|
|
|
|
info("Self-xss paste tests")
|
|
|
|
WebConsoleUtils.usageCount = 0;
|
|
|
|
is(WebConsoleUtils.usageCount, 0, "Test for usage count getter")
|
|
|
|
// Input some commands to check if usage counting is working
|
2014-07-31 19:05:00 -07:00
|
|
|
for(let i = 0; i <= 3; i++){
|
2014-05-21 15:34:00 -07:00
|
|
|
jsterm.setInputValue(i);
|
|
|
|
jsterm.execute();
|
|
|
|
}
|
2014-07-31 19:05:00 -07:00
|
|
|
is(WebConsoleUtils.usageCount, 4, "Usage count incremented")
|
2014-05-21 15:34:00 -07:00
|
|
|
WebConsoleUtils.usageCount = 0;
|
2012-05-25 03:28:47 -07:00
|
|
|
updateEditUIVisibility();
|
2014-05-21 15:34:00 -07:00
|
|
|
|
|
|
|
let oldVal = jsterm.inputNode.value;
|
2012-05-25 03:28:47 -07:00
|
|
|
goDoCommand("cmd_paste");
|
2014-05-21 15:34:00 -07:00
|
|
|
let notificationbox = jsterm.hud.document.getElementById("webconsole-notificationbox");
|
|
|
|
let notification = notificationbox.getNotificationWithValue('selfxss-notification');
|
|
|
|
ok(notification, "Self-xss notification shown");
|
|
|
|
is(oldVal, jsterm.inputNode.value, "Paste blocked by self-xss prevention");
|
2012-05-25 03:28:47 -07:00
|
|
|
|
2014-05-21 15:34:00 -07:00
|
|
|
// Allow pasting
|
|
|
|
jsterm.inputNode.value = "allow pasting";
|
|
|
|
var evt = document.createEvent("KeyboardEvent");
|
|
|
|
evt.initKeyEvent ("keyup", true, true, window,
|
|
|
|
0, 0, 0, 0,
|
|
|
|
0, " ".charCodeAt(0));
|
|
|
|
jsterm.inputNode.dispatchEvent(evt);
|
|
|
|
jsterm.inputNode.value = "";
|
|
|
|
goDoCommand("cmd_paste");
|
|
|
|
isnot("", jsterm.inputNode.value, "Paste works");
|
|
|
|
}
|
2012-05-25 03:28:47 -07:00
|
|
|
function onClipboardPaste() {
|
2014-01-16 08:08:08 -08:00
|
|
|
ok(!jsterm.completeNode.value, "no completion value after paste");
|
|
|
|
|
|
|
|
info("wait for completion update after undo");
|
|
|
|
jsterm.once("autocomplete-updated", onCompletionValueAfterUndo);
|
|
|
|
|
|
|
|
// Get out of the webconsole event loop.
|
|
|
|
executeSoon(() => {
|
|
|
|
goDoCommand("cmd_undo");
|
2012-05-25 03:28:47 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function onCompletionValueAfterUndo() {
|
|
|
|
is(jsterm.completeNode.value, completionValue,
|
|
|
|
"same completeNode.value after undo");
|
|
|
|
|
2014-01-16 08:08:08 -08:00
|
|
|
info("wait for completion update after clipboard paste (ctrl-v)");
|
|
|
|
jsterm.once("autocomplete-updated", () => {
|
|
|
|
ok(!jsterm.completeNode.value, "no completion value after paste (ctrl-v)");
|
|
|
|
|
|
|
|
// using executeSoon() to get out of the webconsole event loop.
|
|
|
|
executeSoon(finishTest);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Get out of the webconsole event loop.
|
|
|
|
executeSoon(() => {
|
|
|
|
EventUtils.synthesizeKey("v", {accelKey: true});
|
2012-05-25 03:28:47 -07:00
|
|
|
});
|
|
|
|
}
|
2011-05-17 07:39:59 -07:00
|
|
|
|
2014-01-16 08:08:08 -08:00
|
|
|
info("wait for completion value after typing 'docu'");
|
|
|
|
jsterm.once("autocomplete-updated", onCompletionValue);
|
2012-05-25 03:28:47 -07:00
|
|
|
|
2014-01-16 08:08:08 -08:00
|
|
|
EventUtils.synthesizeKey("u", {});
|
2011-05-17 07:39:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function test() {
|
|
|
|
addTab(TEST_URI);
|
2012-05-25 03:28:47 -07:00
|
|
|
browser.addEventListener("load", function onLoad() {
|
|
|
|
browser.removeEventListener("load", onLoad, true);
|
|
|
|
openConsole(null, consoleOpened);
|
|
|
|
}, true);
|
2011-05-17 07:39:59 -07:00
|
|
|
}
|