Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Unified Diff: third_party/WebKit/LayoutTests/fast/dnd/resources/dropEffect-common.js

Issue 2729353002: Remove webkitdropzone. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/fast/dnd/resources/dropEffect-common.js
diff --git a/third_party/WebKit/LayoutTests/fast/dnd/resources/dropEffect-common.js b/third_party/WebKit/LayoutTests/fast/dnd/resources/dropEffect-common.js
new file mode 100644
index 0000000000000000000000000000000000000000..adbef51426d6b0b613e3b99f979f6c86e2c68c31
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/dnd/resources/dropEffect-common.js
@@ -0,0 +1,86 @@
+const mouseMoveToCenter = element => {
+ const clientRect = element.getBoundingClientRect();
+ const centerX = (clientRect.left + clientRect.right) / 2;
+ const centerY = (clientRect.top + clientRect.bottom) / 2;
+ eventSender.mouseMoveTo(centerX, centerY);
+};
+
+const dropEffectTest = testCase => {
+ let gotDrop = false;
+ promise_test(t => new Promise((resolve, reject) => {
+ document.querySelector('#test-description').textContent =
+ JSON.stringify(testCase);
+
+ const dragged = document.querySelector('.dragged');
+ if (dragged && !dragged.classList.contains('no-ondragstart')) {
+ dragged.ondragstart = t.step_func(event => {
+ event.dataTransfer.setData('text/plain', 'Needed to work in Firefox');
+ if ('allowed' in testCase)
+ event.dataTransfer.effectAllowed = testCase.allowed;
+ });
+ }
+
+ const dropZone = document.querySelector('.dropzone');
+ dropZone.ondragover = t.step_func(event => {
+ event.preventDefault();
+ if ('drop' in testCase)
+ event.dataTransfer.dropEffect = testCase.drop;
+ });
+ dropZone.ondrop = t.step_func(event => {
+ event.preventDefault();
+ gotDrop = true;
+ });
+
+ const doneButton = document.querySelector('.done');
+
+ if (dragged) {
+ dragged.ondragend = t.step_func(event => {
+ resolve(event.dataTransfer.dropEffect);
+ });
+ } else {
+ doneButton.onclick = t.step_func(() => {
+ resolve('none');
+ });
+ }
+
+ if (window.eventSender) {
+ if (dragged) {
+ mouseMoveToCenter(dragged);
+ eventSender.mouseDown();
+ } else {
+ eventSender.mouseMoveTo(0, 0);
+ eventSender.beginDragWithFiles(['resources/dragged-file.txt']);
+ }
+ setTimeout(() => {
+ mouseMoveToCenter(dropZone);
+ eventSender.mouseUp();
+ if (doneButton) {
+ setTimeout(() => {
+ const clickEvent = new Event('click');
+ doneButton.dispatchEvent(clickEvent);
+ }, 100);
+ }
+ }, 100);
+ }
+ }).then(dragOperation => {
+ if ('operation' in testCase) {
+ assert_true(gotDrop, 'drop target should have received a drop event');
+ assert_equals(dragOperation, testCase.operation);
+ } else {
+ assert_true(
+ !gotDrop, 'drop target should not have received a drop event');
+ assert_equals(dragOperation, 'none');
+ }
+ }), `effectAllowed: ${testCase.allowed} dropEffect: ${testCase.drop}`);
+};
+
+const dropEffectTests = testCases => {
+ for (let testCase of testCases)
+ dropEffectTest(testCase);
+
+ promise_test(t => {
+ return Promise.resolve().then(() => {
+ document.querySelector('#test-description').textContent = 'done';
+ });
+ }, 'all tests complete');
+}

Powered by Google App Engine
This is Rietveld 408576698