Backed out 2 changesets (bug 1725487) for causing mochitest failures on browser_toolbar_drop_bookmarklet.js CLOSED TREE

Backed out changeset 1564124c0309 (bug 1725487)
Backed out changeset ae5ab5c447c3 (bug 1725487)
This commit is contained in:
Cristian Tuns 2022-01-13 07:23:29 -05:00
parent aa7a01ca92
commit f93b09eb34
4 changed files with 1 additions and 310 deletions

View File

@ -1531,16 +1531,6 @@ var PlacesControllerDragHelper = {
parentId = PlacesUtils.bookmarks.getFolderIdForItem(parentId);
}
}
// Disallow the dropping of multiple bookmarks if they include
// a javascript: bookmarklet
if (
!flavor.startsWith("text/x-moz-place") &&
(nodes.length > 1 || dropCount > 1) &&
nodes.some(n => n.uri?.startsWith("javascript:"))
) {
return false;
}
}
}
return true;
@ -1552,7 +1542,7 @@ var PlacesControllerDragHelper = {
* @param {object} insertionPoint The insertion point where the items should
* be dropped.
* @param {object} dt The dataTransfer information for the drop.
* @param {object} [view] The view or the tree element. This allows
* @param {object} view The view or the tree element. This allows
* batching to take place.
*/
async onDrop(insertionPoint, dt, view) {
@ -1569,7 +1559,6 @@ var PlacesControllerDragHelper = {
// DataTransfer is only valid during the synchronous handling of the `drop`
// event handler callback.
let nodes = [];
let externalDrag = false;
for (let i = 0; i < dropCount; ++i) {
let flavor = this.getFirstValidFlavor(dt.mozTypesAt(i));
if (!flavor) {
@ -1585,11 +1574,6 @@ var PlacesControllerDragHelper = {
handled.add(data);
}
// Check that the drag/drop is not internal
if (i == 0 && !flavor.startsWith("text/x-moz-place")) {
externalDrag = true;
}
if (flavor != TAB_DROP_TYPE) {
nodes = [...nodes, ...PlacesUtils.unwrapNodes(data, flavor)];
} else if (
@ -1609,51 +1593,6 @@ var PlacesControllerDragHelper = {
}
}
// If a multiple urls are being dropped from the urlbar or an external source,
// and they include javascript url, not bookmark any of them
if (
externalDrag &&
(nodes.length > 1 || dropCount > 1) &&
nodes.some(n => n.uri?.startsWith("javascript:"))
) {
throw new Error("Javascript bookmarklet passed with uris");
}
// If a single javascript url is being dropped from the urlbar or an external source,
// show the bookmark dialog as a speedbump protection against malicious cases.
if (
nodes.length == 1 &&
externalDrag &&
nodes[0].uri?.startsWith("javascript")
) {
let uri;
try {
uri = Services.io.newURI(nodes[0].uri);
} catch (ex) {
// Invalid uri, we skip this code and the entry will be discarded later.
}
if (uri) {
let bookmarkGuid = await PlacesUIUtils.showBookmarkDialog(
{
action: "add",
type: "bookmark",
defaultInsertionPoint: insertionPoint,
hiddenRows: ["folderPicker"],
title: nodes[0].title,
uri,
},
BrowserWindowTracker.getTopWindow() // `window` may be the Library.
);
if (bookmarkGuid && view) {
view.selectItems([bookmarkGuid], false);
}
return;
}
}
await PlacesUIUtils.handleTransferItems(
nodes,
insertionPoint,

View File

@ -129,8 +129,6 @@ skip-if = os == "linux" && (tsan || asan) # Bug 1714384
skip-if = (os == "mac" && debug) # Bug 1467049
[browser_sort_in_library.js]
[browser_stayopenmenu.js]
[browser_toolbar_drop_bookmarklet.js]
[browser_toolbar_drop_multiple_with_bookmarklet.js]
[browser_toolbar_drop_text.js]
skip-if = os == "linux" && (tsan || asan) # Bug 1714384
[browser_toolbar_library_open_recent.js]

View File

@ -1,196 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
const { sinon } = ChromeUtils.import("resource://testing-common/Sinon.jsm");
const sandbox = sinon.createSandbox();
const URL1 = "https://example.com/1/";
const URL2 = "https://example.com/2/";
const BOOKMARKLET_URL = `javascript: (() => {alert('Hello, World!');})();`;
let bookmarks;
registerCleanupFunction(async function() {
sandbox.restore();
});
add_task(async function test() {
// Make sure the bookmarks bar is visible and restore its state on cleanup.
let toolbar = document.getElementById("PersonalToolbar");
ok(toolbar, "PersonalToolbar should not be null");
await PlacesUtils.bookmarks.eraseEverything();
if (toolbar.collapsed) {
await promiseSetToolbarVisibility(toolbar, true);
registerCleanupFunction(function() {
return promiseSetToolbarVisibility(toolbar, false);
});
}
// Setup the node we will use to be dropped. The actual node used does not
// matter because we will set its data, effect, and mimeType manually.
let placesItems = document.getElementById("PlacesToolbarItems");
Assert.ok(placesItems, "PlacesToolbarItems should not be null");
/**
* Simulates a drop of a bookmarklet URI onto the bookmarks bar.
*
* @param {string} aEffect
* The effect to use for the drop operation: move, copy, or link.
* @param {string} aMimeType
* The mime type to use for the drop operation.
*/
let simulateDragDrop = async function(aEffect) {
info("Simulates drag/drop of a new javascript:URL to the bookmarks");
await withBookmarksDialog(
true,
function openDialog() {
EventUtils.synthesizeDrop(
toolbar,
placesItems,
[[{ type: "text/x-moz-url", data: BOOKMARKLET_URL }]],
aEffect,
window
);
},
async function testNameField(dialogWin) {
info("Checks that there is a javascript:URL in ShowBookmarksDialog");
let location = dialogWin.document.getElementById(
"editBMPanel_locationField"
).value;
Assert.equal(
location,
BOOKMARKLET_URL,
"Should have opened the ShowBookmarksDialog with the correct bookmarklet url to be bookmarked"
);
}
);
info("Simulates drag/drop of a new URL to the bookmarks");
let spy = sandbox
.stub(PlacesUIUtils, "showBookmarkDialog")
.returns(Promise.resolve());
let promise = PlacesTestUtils.waitForNotification(
"bookmark-added",
events => events.some(({ url }) => url == URL1),
"places"
);
EventUtils.synthesizeDrop(
toolbar,
placesItems,
[[{ type: "text/x-moz-url", data: URL1 }]],
aEffect,
window
);
await promise;
Assert.ok(spy.notCalled, "ShowBookmarksDialog on drop not called for url");
sandbox.restore();
};
let effects = ["copy", "link"];
for (let effect of effects) {
await simulateDragDrop(effect);
}
info("Move of existing bookmark / bookmarklet on toolbar");
//clean previous bookmarks to ensure right ids count
await PlacesUtils.bookmarks.eraseEverything();
info("Insert list of bookamrks to have bookamrks (ids) for moving");
bookmarks = await PlacesUtils.bookmarks.insertTree({
guid: PlacesUtils.bookmarks.toolbarGuid,
children: [
{
title: "bm1",
url: URL1,
},
{
title: "bm2",
url: URL2,
},
{
title: "bookmarklet",
url: BOOKMARKLET_URL,
},
],
});
let spy = sandbox
.stub(PlacesUIUtils, "showBookmarkDialog")
.returns(Promise.resolve());
info("Moving existing Bookmark from position [1] to [0] on Toolbar");
let urlMoveNotification = PlacesTestUtils.waitForNotification(
"bookmark-moved",
events =>
events.some(
e =>
e.parentGuid === PlacesUtils.bookmarks.toolbarGuid &&
e.oldParentGuid === PlacesUtils.bookmarks.toolbarGuid &&
e.oldIndex == 1 &&
e.index == 0
),
"places"
);
EventUtils.synthesizeDrop(
toolbar,
placesItems.childNodes[0],
[
[
{
type: "text/x-moz-place",
data: PlacesUtils.wrapNode(
placesItems.childNodes[1]._placesNode,
"text/x-moz-place"
),
},
],
],
"move",
window
);
await urlMoveNotification;
Assert.ok(spy.notCalled, "ShowBookmarksDialog not called on move for url");
info("Moving existing Bookmarklet from position [2] to [1] on Toolbar");
let bookmarkletMoveNotificatio = PlacesTestUtils.waitForNotification(
"bookmark-moved",
events =>
events.some(
e =>
e.parentGuid === PlacesUtils.bookmarks.toolbarGuid &&
e.oldParentGuid === PlacesUtils.bookmarks.toolbarGuid &&
e.oldIndex == 2 &&
e.index == 1
),
"places"
);
EventUtils.synthesizeDrop(
toolbar,
placesItems.childNodes[1],
[
[
{
type: "text/x-moz-place",
data: PlacesUtils.wrapNode(
placesItems.childNodes[2]._placesNode,
"text/x-moz-place"
),
},
],
],
"move",
window
);
await bookmarkletMoveNotificatio;
Assert.ok(spy.notCalled, "ShowBookmarksDialog not called on move for url");
sandbox.restore();
});

View File

@ -1,50 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
add_task(async function test() {
// Make sure the bookmarks bar is visible and restore its state on cleanup.
let toolbar = document.getElementById("PersonalToolbar");
ok(toolbar, "PersonalToolbar should not be null");
await PlacesUtils.bookmarks.eraseEverything();
if (toolbar.collapsed) {
await promiseSetToolbarVisibility(toolbar, true);
registerCleanupFunction(function() {
return promiseSetToolbarVisibility(toolbar, false);
});
}
// Setup the node we will use to be dropped. The actual node used does not
// matter because we will set its data, effect, and mimeType manually.
let placesItems = document.getElementById("PlacesToolbarItems");
Assert.ok(placesItems, "PlacesToolbarItems should not be null");
let simulateDragDrop = async function(aEffect, aMimeType) {
let urls = [
"https://example.com/1/",
`javascript: (() => {alert('Hello, World!');})();`,
"https://example.com/2/",
];
let data = urls.map(spec => spec + "\n" + spec).join("\n");
EventUtils.synthesizeDrop(
toolbar,
placesItems,
[[{ type: aMimeType, data }]],
aEffect,
window
);
await PlacesTestUtils.promiseAsyncUpdates();
for (let url of urls) {
let bookmark = await PlacesUtils.bookmarks.fetch({ url });
Assert.ok(!bookmark, "There should be no bookmark");
}
};
// Simulate a bookmark drop for all of the mime types and effects.
let mimeType = ["text/x-moz-url"];
let effects = ["copy", "link"];
for (let effect of effects) {
await simulateDragDrop(effect, mimeType);
}
});