Bug 1833585 - don't try to search for whitespace-only clipboard contents when middle-clicking new tab, r=dao
Differential Revision: https://phabricator.services.mozilla.com/D178292
This commit is contained in:
@@ -2871,20 +2871,19 @@ function BrowserOpenTab({ event, url } = {}) {
|
||||
Services.obs.notifyObservers(
|
||||
{
|
||||
wrappedJSObject: new Promise(resolve => {
|
||||
let options = {
|
||||
relatedToCurrent,
|
||||
resolveOnNewTabCreated: resolve,
|
||||
};
|
||||
if (!werePassedURL && searchClipboard) {
|
||||
let clipboard = readFromClipboard();
|
||||
clipboard = UrlbarUtils.stripUnsafeProtocolOnPaste(clipboard);
|
||||
openTrustedLinkIn(clipboard, where, {
|
||||
relatedToCurrent,
|
||||
resolveOnNewTabCreated: resolve,
|
||||
allowThirdPartyFixup: true,
|
||||
});
|
||||
} else {
|
||||
openTrustedLinkIn(url, where, {
|
||||
relatedToCurrent,
|
||||
resolveOnNewTabCreated: resolve,
|
||||
});
|
||||
clipboard = UrlbarUtils.stripUnsafeProtocolOnPaste(clipboard).trim();
|
||||
if (clipboard) {
|
||||
url = clipboard;
|
||||
options.allowThirdPartyFixup = true;
|
||||
}
|
||||
}
|
||||
openTrustedLinkIn(url, where, options);
|
||||
}),
|
||||
},
|
||||
"browser-open-newtab-start"
|
||||
|
||||
@@ -10,7 +10,14 @@ const { SearchTestUtils } = ChromeUtils.importESModule(
|
||||
);
|
||||
|
||||
add_setup(async function() {
|
||||
await SpecialPowers.pushPrefEnv({ set: [[searchclipboardforPref, true]] });
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [
|
||||
[searchclipboardforPref, true],
|
||||
// set preloading to false so we can await the new tab being opened.
|
||||
["browser.newtab.preload", false],
|
||||
],
|
||||
});
|
||||
NewTabPagePreloading.removePreloadedBrowser(window);
|
||||
// Create an engine to use for the test.
|
||||
SearchTestUtils.init(this);
|
||||
await SearchTestUtils.installSearchExtension(
|
||||
@@ -57,14 +64,10 @@ add_task(async function middleclick_tabs_newtab_button_with_url_in_clipboard() {
|
||||
safeUrl,
|
||||
true
|
||||
);
|
||||
try {
|
||||
EventUtils.synthesizeMouseAtCenter(
|
||||
document.getElementById("tabs-newtab-button"),
|
||||
{ button: 1 }
|
||||
);
|
||||
} catch (error) {
|
||||
info(error);
|
||||
}
|
||||
EventUtils.synthesizeMouseAtCenter(
|
||||
document.getElementById("tabs-newtab-button"),
|
||||
{ button: 1 }
|
||||
);
|
||||
|
||||
await promiseTabLoaded;
|
||||
is(gBrowser.tabs.length, previousTabsLength + 1, "We created a tab");
|
||||
@@ -106,17 +109,12 @@ add_task(
|
||||
searchUrl,
|
||||
true
|
||||
);
|
||||
try {
|
||||
EventUtils.synthesizeMouseAtCenter(
|
||||
document.getElementById("tabs-newtab-button"),
|
||||
{ button: 1 }
|
||||
);
|
||||
} catch (error) {
|
||||
info(error);
|
||||
}
|
||||
EventUtils.synthesizeMouseAtCenter(
|
||||
document.getElementById("tabs-newtab-button"),
|
||||
{ button: 1 }
|
||||
);
|
||||
|
||||
await promiseTabLoaded;
|
||||
info(gBrowser.currentURI.spec);
|
||||
is(gBrowser.tabs.length, previousTabsLength + 1, "We created a tab");
|
||||
is(
|
||||
gBrowser.currentURI.spec,
|
||||
@@ -161,14 +159,10 @@ add_task(async function middleclick_new_tab_button_with_url_in_clipboard() {
|
||||
safeUrl,
|
||||
true
|
||||
);
|
||||
try {
|
||||
EventUtils.synthesizeMouseAtCenter(
|
||||
document.getElementById("new-tab-button"),
|
||||
{ button: 1 }
|
||||
);
|
||||
} catch (error) {
|
||||
info(error);
|
||||
}
|
||||
EventUtils.synthesizeMouseAtCenter(
|
||||
document.getElementById("new-tab-button"),
|
||||
{ button: 1 }
|
||||
);
|
||||
|
||||
await promiseTabLoaded;
|
||||
is(gBrowser.tabs.length, previousTabsLength + 1, "We created a tab");
|
||||
@@ -209,17 +203,12 @@ add_task(async function middleclick_new_tab_button_with_word_in_clipboard() {
|
||||
searchUrl,
|
||||
true
|
||||
);
|
||||
try {
|
||||
EventUtils.synthesizeMouseAtCenter(
|
||||
document.getElementById("new-tab-button"),
|
||||
{ button: 1 }
|
||||
);
|
||||
} catch (error) {
|
||||
info(error);
|
||||
}
|
||||
EventUtils.synthesizeMouseAtCenter(
|
||||
document.getElementById("new-tab-button"),
|
||||
{ button: 1 }
|
||||
);
|
||||
|
||||
await promiseTabLoaded;
|
||||
info(gBrowser.currentURI.spec);
|
||||
is(gBrowser.tabs.length, previousTabsLength + 1, "We created a tab");
|
||||
is(
|
||||
gBrowser.currentURI.spec,
|
||||
@@ -229,3 +218,38 @@ add_task(async function middleclick_new_tab_button_with_word_in_clipboard() {
|
||||
|
||||
BrowserTestUtils.removeTab(gBrowser.selectedTab);
|
||||
});
|
||||
|
||||
add_task(async function middleclick_new_tab_button_with_spaces_in_clipboard() {
|
||||
let spaces = " \n ";
|
||||
await new Promise((resolve, reject) => {
|
||||
SimpleTest.waitForClipboard(
|
||||
spaces,
|
||||
() => {
|
||||
Cc["@mozilla.org/widget/clipboardhelper;1"]
|
||||
.getService(Ci.nsIClipboardHelper)
|
||||
.copyString(spaces);
|
||||
},
|
||||
resolve,
|
||||
() => {
|
||||
ok(false, "Clipboard copy failed");
|
||||
reject();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
info("Middle clicking 'new tab' button");
|
||||
let promiseTabOpened = BrowserTestUtils.waitForNewTab(gBrowser);
|
||||
EventUtils.synthesizeMouseAtCenter(
|
||||
document.getElementById("new-tab-button"),
|
||||
{ button: 1 }
|
||||
);
|
||||
|
||||
await promiseTabOpened;
|
||||
is(
|
||||
gBrowser.currentURI.spec,
|
||||
"about:newtab",
|
||||
"New Tab URL is the regular new tab page."
|
||||
);
|
||||
|
||||
BrowserTestUtils.removeTab(gBrowser.selectedTab);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user