fune/browser/base/content/test/urlbar/browser_pasteAndGo.js
Harry Twyford 93f19f1f25 Bug 1460097 - Autocompleted URLs are trimmed. r=mak
MozReview-Commit-ID: 6y26a9Nhm3b

--HG--
extra : rebase_source : 7b56edf0185f4d15e989d6f71b259eae16c4e099
2018-05-16 14:12:16 -04:00

67 lines
2.7 KiB
JavaScript

"use strict";
let clipboardHelper = Cc["@mozilla.org/widget/clipboardhelper;1"].getService(Ci.nsIClipboardHelper);
add_task(async function() {
const kURLs = [
"http://example.com/1",
"http://example.org/2\n",
"http://\nexample.com/3\n",
];
for (let url of kURLs) {
await BrowserTestUtils.withNewTab("about:blank", async function(browser) {
gURLBar.focus();
await new Promise((resolve, reject) => {
waitForClipboard(url, function() {
clipboardHelper.copyString(url);
}, resolve,
() => reject(new Error(`Failed to copy string '${url}' to clipboard`))
);
});
let textBox = document.getAnonymousElementByAttribute(gURLBar,
"anonid", "textbox-input-box");
let cxmenu = document.getAnonymousElementByAttribute(textBox,
"anonid", "input-box-contextmenu");
let cxmenuPromise = BrowserTestUtils.waitForEvent(cxmenu, "popupshown");
EventUtils.synthesizeMouseAtCenter(gURLBar, {type: "contextmenu", button: 2});
await cxmenuPromise;
let menuitem = document.getAnonymousElementByAttribute(textBox,
"anonid", "paste-and-go");
let browserLoadedPromise = BrowserTestUtils.browserLoaded(browser, false, url.replace(/\n/g, ""));
EventUtils.synthesizeMouseAtCenter(menuitem, {});
// Using toSource in order to get the newlines escaped:
info("Paste and go, loading " + url.toSource());
await browserLoadedPromise;
ok(true, "Successfully loaded " + url);
});
}
});
add_task(async function() {
const url = "http://example.com/4\u2028";
await BrowserTestUtils.withNewTab("about:blank", async function(browser) {
gURLBar.focus();
await new Promise((resolve, reject) => {
waitForClipboard(url, function() {
clipboardHelper.copyString(url);
}, resolve,
() => reject(new Error(`Failed to copy string '${url}' to clipboard`))
);
});
let textBox = document.getAnonymousElementByAttribute(gURLBar,
"anonid", "textbox-input-box");
let cxmenu = document.getAnonymousElementByAttribute(textBox,
"anonid", "input-box-contextmenu");
let cxmenuPromise = BrowserTestUtils.waitForEvent(cxmenu, "popupshown");
EventUtils.synthesizeMouseAtCenter(gURLBar, {type: "contextmenu", button: 2});
await cxmenuPromise;
let menuitem = document.getAnonymousElementByAttribute(textBox,
"anonid", "paste-and-go");
let browserLoadedPromise = BrowserTestUtils.browserLoaded(browser, false, url.replace(/\u2028/g, ""));
EventUtils.synthesizeMouseAtCenter(menuitem, {});
// Using toSource in order to get the newlines escaped:
info("Paste and go, loading " + url.toSource());
await browserLoadedPromise;
ok(true, "Successfully loaded " + url);
});
});