diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /browser/base/content/test/general/browser_homeDrop.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/base/content/test/general/browser_homeDrop.js')
-rw-r--r-- | browser/base/content/test/general/browser_homeDrop.js | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/browser/base/content/test/general/browser_homeDrop.js b/browser/base/content/test/general/browser_homeDrop.js new file mode 100644 index 0000000000..4362f3456e --- /dev/null +++ b/browser/base/content/test/general/browser_homeDrop.js @@ -0,0 +1,111 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +add_task(async function setupHomeButton() { + // Put the home button in the pre-proton placement to test focus states. + CustomizableUI.addWidgetToArea( + "home-button", + "nav-bar", + CustomizableUI.getPlacementOfWidget("stop-reload-button").position + 1 + ); + CustomizableUI.addWidgetToArea("sidebar-button", "nav-bar"); + registerCleanupFunction(async function resetToolbar() { + await CustomizableUI.reset(); + }); +}); + +add_task(async function () { + let HOMEPAGE_PREF = "browser.startup.homepage"; + + await pushPrefs([HOMEPAGE_PREF, "about:mozilla"]); + + // Since synthesizeDrop triggers the srcElement, need to use another button + // that should be visible. + let dragSrcElement = document.getElementById("sidebar-button"); + ok(dragSrcElement, "Sidebar button exists"); + let homeButton = document.getElementById("home-button"); + ok(homeButton, "home button present"); + + async function drop(dragData, homepage) { + let setHomepageDialogPromise = + BrowserTestUtils.promiseAlertDialogOpen("accept"); + let setHomepagePromise = TestUtils.waitForPrefChange( + HOMEPAGE_PREF, + newVal => newVal == homepage + ); + + EventUtils.synthesizeDrop( + dragSrcElement, + homeButton, + dragData, + "copy", + window + ); + + // Ensure dnd suppression is cleared. + EventUtils.synthesizeMouseAtCenter(homeButton, { type: "mouseup" }, window); + + await setHomepageDialogPromise; + ok(true, "dialog appeared in response to home button drop"); + + await setHomepagePromise; + + let modified = Services.prefs.getStringPref(HOMEPAGE_PREF); + is(modified, homepage, "homepage is set correctly"); + Services.prefs.setStringPref(HOMEPAGE_PREF, "about:mozilla;"); + } + + function dropInvalidURI() { + return new Promise(resolve => { + let consoleListener = { + observe(m) { + if (m.message.includes("NS_ERROR_DOM_BAD_URI")) { + ok(true, "drop was blocked"); + resolve(); + } + }, + }; + Services.console.registerListener(consoleListener); + registerCleanupFunction(function () { + Services.console.unregisterListener(consoleListener); + }); + + executeSoon(function () { + info("Attempting second drop, of a javascript: URI"); + // The drop handler throws an exception when dragging URIs that inherit + // principal, e.g. javascript: + expectUncaughtException(); + EventUtils.synthesizeDrop( + dragSrcElement, + homeButton, + [[{ type: "text/plain", data: "javascript:8888" }]], + "copy", + window + ); + // Ensure dnd suppression is cleared. + EventUtils.synthesizeMouseAtCenter( + homeButton, + { type: "mouseup" }, + window + ); + }); + }); + } + + await drop( + [[{ type: "text/plain", data: "http://mochi.test:8888/" }]], + "http://mochi.test:8888/" + ); + await drop( + [ + [ + { + type: "text/plain", + data: "http://mochi.test:8888/\nhttp://mochi.test:8888/b\nhttp://mochi.test:8888/c", + }, + ], + ], + "http://mochi.test:8888/|http://mochi.test:8888/b|http://mochi.test:8888/c" + ); + await dropInvalidURI(); +}); |