2007-09-19 05:47:51 -07:00
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cc = Components.classes;
|
|
|
|
|
2009-01-22 03:19:42 -08:00
|
|
|
const kUrlBarElm = document.getElementById('urlbar');
|
|
|
|
const kSearchBarElm = document.getElementById('searchbar');
|
|
|
|
const kTestString = " hello hello \n world\nworld ";
|
|
|
|
|
2007-09-19 05:47:51 -07:00
|
|
|
function testPaste(name, element, expected) {
|
|
|
|
element.focus();
|
2009-01-22 03:19:42 -08:00
|
|
|
listener.expected = expected;
|
|
|
|
listener.name = name;
|
2009-02-05 05:11:54 -08:00
|
|
|
// Pasting is async because the Accel+V codepath ends up going through
|
|
|
|
// DocumentViewerImpl::FireClipboardEvent.
|
2007-09-19 05:47:51 -07:00
|
|
|
EventUtils.synthesizeKey("v", { accelKey: true });
|
2009-01-22 03:19:42 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
var listener = {
|
|
|
|
expected: "",
|
|
|
|
name: "",
|
|
|
|
handleEvent: function(event) {
|
|
|
|
var element = event.target;
|
|
|
|
is(element.value, this.expected, this.name);
|
|
|
|
switch (element) {
|
|
|
|
case kUrlBarElm:
|
|
|
|
continue_test();
|
|
|
|
case kSearchBarElm:
|
|
|
|
finish_test();
|
|
|
|
}
|
|
|
|
}
|
2007-09-19 05:47:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// test bug 23485 and bug 321000
|
|
|
|
// urlbar should strip newlines,
|
|
|
|
// search bar should replace newlines with spaces
|
|
|
|
function test() {
|
2009-01-22 03:19:42 -08:00
|
|
|
waitForExplicitFinish();
|
|
|
|
|
|
|
|
// register listeners
|
|
|
|
kUrlBarElm.addEventListener("input", listener, true);
|
|
|
|
kSearchBarElm.addEventListener("input", listener, true);
|
|
|
|
|
2007-09-19 05:47:51 -07:00
|
|
|
// Put a multi-line string in the clipboard
|
|
|
|
Components.classes["@mozilla.org/widget/clipboardhelper;1"]
|
|
|
|
.getService(Components.interfaces.nsIClipboardHelper)
|
2009-01-22 03:19:42 -08:00
|
|
|
.copyString(kTestString);
|
2009-02-05 05:11:54 -08:00
|
|
|
|
|
|
|
// Setting the clipboard value is an async OS operation, so we need to poll
|
|
|
|
// the clipboard for valid data before going on.
|
|
|
|
setTimeout(poll_clipboard, 100);
|
|
|
|
}
|
|
|
|
|
|
|
|
var runCount = 0;
|
|
|
|
function poll_clipboard() {
|
|
|
|
// Poll for a maximum of 5s
|
|
|
|
if (++runCount > 50) {
|
|
|
|
// Log the failure
|
|
|
|
ok(false, "Timed out while polling clipboard for pasted data");
|
|
|
|
// Cleanup and interrupt the test
|
|
|
|
finish_test();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var clip = Components.classes["@mozilla.org/widget/clipboard;1"].
|
|
|
|
getService(Components.interfaces.nsIClipboard);
|
|
|
|
var trans = Components.classes["@mozilla.org/widget/transferable;1"].
|
|
|
|
createInstance(Components.interfaces.nsITransferable);
|
|
|
|
trans.addDataFlavor("text/unicode");
|
|
|
|
var str = new Object();
|
|
|
|
try {
|
|
|
|
// This code could throw if the clipboard is not set
|
|
|
|
clip.getData(trans,clip.kGlobalClipboard);
|
|
|
|
trans.getTransferData("text/unicode",str,{});
|
|
|
|
str = str.value.QueryInterface(Components.interfaces.nsISupportsString);
|
|
|
|
} catch (ex) {}
|
|
|
|
|
|
|
|
if (kTestString == str) {
|
|
|
|
testPaste('urlbar strips newlines and surrounding whitespace',
|
|
|
|
kUrlBarElm,
|
|
|
|
kTestString.replace(/\s*\n\s*/g,''));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
setTimeout(poll_clipboard, 100);
|
2009-01-22 03:19:42 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
function continue_test() {
|
2007-09-19 05:47:51 -07:00
|
|
|
testPaste('searchbar replaces newlines with spaces',
|
2009-01-22 03:19:42 -08:00
|
|
|
kSearchBarElm,
|
|
|
|
kTestString.replace('\n',' ','g'));
|
|
|
|
}
|
|
|
|
|
|
|
|
function finish_test() {
|
|
|
|
kUrlBarElm.removeEventListener("input", listener, true);
|
|
|
|
kSearchBarElm.removeEventListener("input", listener, true);
|
2009-02-05 05:11:54 -08:00
|
|
|
// Clear the clipboard, emptyClipboard would not clear the native one, so
|
|
|
|
// setting it to an empty string.
|
|
|
|
Components.classes["@mozilla.org/widget/clipboardhelper;1"]
|
|
|
|
.getService(Components.interfaces.nsIClipboardHelper)
|
|
|
|
.copyString("");
|
2009-01-22 03:19:42 -08:00
|
|
|
// Clear fields
|
|
|
|
kUrlBarElm.value="";
|
|
|
|
kSearchBarElm.value="";
|
|
|
|
finish();
|
2007-09-19 05:47:51 -07:00
|
|
|
}
|