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

Side by Side Diff: chrome/browser/ui/views/drag_and_drop_interactive_uitest.cc

Issue 2505183002: Have tests verify clientX/Y and pageX/Y properties in drag-and-drop DOM events. (Closed)
Patch Set: Created 4 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/test/data/drag_and_drop/event_monitoring.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <memory> 5 #include <memory>
6 #include <string> 6 #include <string>
7 7
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 void CalculateEventLocations(gfx::Point web_contents_relative_location, 143 void CalculateEventLocations(gfx::Point web_contents_relative_location,
144 gfx::Point* out_event_location, 144 gfx::Point* out_event_location,
145 gfx::Point* out_event_root_location) { 145 gfx::Point* out_event_root_location) {
146 gfx::NativeView view = web_contents_->GetNativeView(); 146 gfx::NativeView view = web_contents_->GetNativeView();
147 147
148 *out_event_location = web_contents_relative_location; 148 *out_event_location = web_contents_relative_location;
149 149
150 gfx::Point root_location = web_contents_relative_location; 150 gfx::Point root_location = web_contents_relative_location;
151 aura::Window::ConvertPointToTarget(view, view->GetRootWindow(), 151 aura::Window::ConvertPointToTarget(view, view->GetRootWindow(),
152 &root_location); 152 &root_location);
153 *out_event_location = root_location; 153 *out_event_root_location = root_location;
Łukasz Anforowicz 2016/11/16 23:02:38 Ooops... :->
154 } 154 }
155 155
156 // These are ui::DropTargetEvent::source_operations_ being sent when manually 156 // These are ui::DropTargetEvent::source_operations_ being sent when manually
157 // trying out drag&drop of an image file from Nemo (Ubuntu's file explorer) 157 // trying out drag&drop of an image file from Nemo (Ubuntu's file explorer)
158 // into a content_shell. 158 // into a content_shell.
159 static constexpr int kDefaultSourceOperations = ui::DragDropTypes::DRAG_MOVE | 159 static constexpr int kDefaultSourceOperations = ui::DragDropTypes::DRAG_MOVE |
160 ui::DragDropTypes::DRAG_COPY | 160 ui::DragDropTypes::DRAG_COPY |
161 ui::DragDropTypes::DRAG_LINK; 161 ui::DragDropTypes::DRAG_LINK;
162 162
163 content::WebContents* web_contents_; 163 content::WebContents* web_contents_;
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 content::DOMMessageQueue dom_message_queue_; 328 content::DOMMessageQueue dom_message_queue_;
329 329
330 DISALLOW_COPY_AND_ASSIGN(DOMDragEventWaiter); 330 DISALLOW_COPY_AND_ASSIGN(DOMDragEventWaiter);
331 }; 331 };
332 332
333 // Helper for verifying contents of DOM events associated with drag-and-drop. 333 // Helper for verifying contents of DOM events associated with drag-and-drop.
334 class DOMDragEventVerifier { 334 class DOMDragEventVerifier {
335 public: 335 public:
336 DOMDragEventVerifier() {} 336 DOMDragEventVerifier() {}
337 337
338 void set_expected_client_position(const std::string& value) {
339 expected_client_position_ = value;
340 }
341
338 void set_expected_drop_effect(const std::string& value) { 342 void set_expected_drop_effect(const std::string& value) {
339 expected_drop_effect_ = value; 343 expected_drop_effect_ = value;
340 } 344 }
341 345
342 void set_expected_effect_allowed(const std::string& value) { 346 void set_expected_effect_allowed(const std::string& value) {
343 expected_effect_allowed_ = value; 347 expected_effect_allowed_ = value;
344 } 348 }
345 349
346 void set_expected_mime_types(const std::string& value) { 350 void set_expected_mime_types(const std::string& value) {
347 expected_mime_types_ = value; 351 expected_mime_types_ = value;
348 } 352 }
349 353
354 void set_expected_page_position(const std::string& value) {
355 expected_page_position_ = value;
356 }
357
350 // Returns a matcher that will match a std::string (drag event data - e.g. 358 // Returns a matcher that will match a std::string (drag event data - e.g.
351 // one returned by DOMDragEventWaiter::WaitForNextMatchingEvent) if it matches 359 // one returned by DOMDragEventWaiter::WaitForNextMatchingEvent) if it matches
352 // the expectations of this DOMDragEventVerifier. 360 // the expectations of this DOMDragEventVerifier.
353 testing::Matcher<std::string> Matches() const { 361 testing::Matcher<std::string> Matches() const {
354 return testing::AllOf( 362 return testing::AllOf(
363 FieldMatches("client_position", expected_client_position_),
355 FieldMatches("drop_effect", expected_drop_effect_), 364 FieldMatches("drop_effect", expected_drop_effect_),
356 FieldMatches("effect_allowed", expected_effect_allowed_), 365 FieldMatches("effect_allowed", expected_effect_allowed_),
357 FieldMatches("mime_types", expected_mime_types_)); 366 FieldMatches("mime_types", expected_mime_types_),
367 FieldMatches("page_position", expected_page_position_));
358 } 368 }
359 369
360 private: 370 private:
361 static testing::Matcher<std::string> FieldMatches( 371 static testing::Matcher<std::string> FieldMatches(
362 const std::string& field_name, 372 const std::string& field_name,
363 const std::string& expected_value) { 373 const std::string& expected_value) {
364 if (expected_value == "<no expectation>") 374 if (expected_value == "<no expectation>")
365 return testing::A<std::string>(); 375 return testing::A<std::string>();
366 376
367 return testing::HasSubstr(base::StringPrintf( 377 return testing::HasSubstr(base::StringPrintf(
368 "\"%s\":\"%s\"", field_name.c_str(), expected_value.c_str())); 378 "\"%s\":\"%s\"", field_name.c_str(), expected_value.c_str()));
369 } 379 }
370 380
371 std::string expected_drop_effect_ = "<no expectation>"; 381 std::string expected_drop_effect_ = "<no expectation>";
372 std::string expected_effect_allowed_ = "<no expectation>"; 382 std::string expected_effect_allowed_ = "<no expectation>";
373 std::string expected_mime_types_ = "<no expectation>"; 383 std::string expected_mime_types_ = "<no expectation>";
384 std::string expected_client_position_ = "<no expectation>";
385 std::string expected_page_position_ = "<no expectation>";
374 386
375 DISALLOW_COPY_AND_ASSIGN(DOMDragEventVerifier); 387 DISALLOW_COPY_AND_ASSIGN(DOMDragEventVerifier);
376 }; 388 };
377 389
378 const char kTestPagePath[] = "/drag_and_drop/page.html"; 390 const char kTestPagePath[] = "/drag_and_drop/page.html";
379 391
380 } // namespace 392 } // namespace
381 393
382 class DragAndDropBrowserTest : public InProcessBrowserTest, 394 class DragAndDropBrowserTest : public InProcessBrowserTest,
383 public testing::WithParamInterface<bool> { 395 public testing::WithParamInterface<bool> {
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 DISALLOW_COPY_AND_ASSIGN(DragAndDropBrowserTest); 576 DISALLOW_COPY_AND_ASSIGN(DragAndDropBrowserTest);
565 }; 577 };
566 578
567 IN_PROC_BROWSER_TEST_P(DragAndDropBrowserTest, DropTextFromOutside) { 579 IN_PROC_BROWSER_TEST_P(DragAndDropBrowserTest, DropTextFromOutside) {
568 std::string frame_site = use_cross_site_subframe() ? "b.com" : "a.com"; 580 std::string frame_site = use_cross_site_subframe() ? "b.com" : "a.com";
569 ASSERT_TRUE(NavigateToTestPage("a.com")); 581 ASSERT_TRUE(NavigateToTestPage("a.com"));
570 ASSERT_TRUE(NavigateRightFrame(frame_site, "drop_target.html")); 582 ASSERT_TRUE(NavigateRightFrame(frame_site, "drop_target.html"));
571 583
572 // Setup test expectations. 584 // Setup test expectations.
573 DOMDragEventVerifier expected_dom_event_data; 585 DOMDragEventVerifier expected_dom_event_data;
586 expected_dom_event_data.set_expected_client_position("(100, 100)");
574 expected_dom_event_data.set_expected_drop_effect("none"); 587 expected_dom_event_data.set_expected_drop_effect("none");
575 expected_dom_event_data.set_expected_effect_allowed("all"); 588 expected_dom_event_data.set_expected_effect_allowed("all");
576 expected_dom_event_data.set_expected_mime_types("text/plain"); 589 expected_dom_event_data.set_expected_mime_types("text/plain");
590 expected_dom_event_data.set_expected_page_position("(100, 100)");
577 591
578 // Drag text from outside the browser into/over the right frame. 592 // Drag text from outside the browser into/over the right frame.
579 { 593 {
580 DOMDragEventWaiter dragover_waiter("dragover", right_frame()); 594 DOMDragEventWaiter dragover_waiter("dragover", right_frame());
581 ASSERT_TRUE(SimulateDragEnterToRightFrame("Dragged test text")); 595 ASSERT_TRUE(SimulateDragEnterToRightFrame("Dragged test text"));
582 596
583 std::string dragover_event; 597 std::string dragover_event;
584 ASSERT_TRUE(dragover_waiter.WaitForNextMatchingEvent(&dragover_event)); 598 ASSERT_TRUE(dragover_waiter.WaitForNextMatchingEvent(&dragover_event));
585 EXPECT_THAT(dragover_event, expected_dom_event_data.Matches()); 599 EXPECT_THAT(dragover_event, expected_dom_event_data.Matches());
586 } 600 }
(...skipping 10 matching lines...) Expand all
597 } 611 }
598 612
599 IN_PROC_BROWSER_TEST_P(DragAndDropBrowserTest, DragStartInFrame) { 613 IN_PROC_BROWSER_TEST_P(DragAndDropBrowserTest, DragStartInFrame) {
600 std::string frame_site = use_cross_site_subframe() ? "b.com" : "a.com"; 614 std::string frame_site = use_cross_site_subframe() ? "b.com" : "a.com";
601 ASSERT_TRUE(NavigateToTestPage("a.com")); 615 ASSERT_TRUE(NavigateToTestPage("a.com"));
602 ASSERT_TRUE(NavigateLeftFrame(frame_site, "image_source.html")); 616 ASSERT_TRUE(NavigateLeftFrame(frame_site, "image_source.html"));
603 617
604 // Setup test expectations. 618 // Setup test expectations.
605 // (dragstart event handler in image_source.html is asking for "copy" only). 619 // (dragstart event handler in image_source.html is asking for "copy" only).
606 DOMDragEventVerifier expected_dom_event_data; 620 DOMDragEventVerifier expected_dom_event_data;
621 expected_dom_event_data.set_expected_client_position("(100, 100)");
607 expected_dom_event_data.set_expected_drop_effect("none"); 622 expected_dom_event_data.set_expected_drop_effect("none");
608 expected_dom_event_data.set_expected_effect_allowed("copy"); 623 expected_dom_event_data.set_expected_effect_allowed("copy");
609 expected_dom_event_data.set_expected_mime_types( 624 expected_dom_event_data.set_expected_mime_types(
610 "Files,text/html,text/uri-list"); 625 "Files,text/html,text/uri-list");
626 expected_dom_event_data.set_expected_page_position("(100, 100)");
611 627
612 // Start the drag in the left frame. 628 // Start the drag in the left frame.
613 DragStartWaiter drag_start_waiter(web_contents()); 629 DragStartWaiter drag_start_waiter(web_contents());
614 DOMDragEventWaiter dragstart_event_waiter("dragstart", left_frame()); 630 DOMDragEventWaiter dragstart_event_waiter("dragstart", left_frame());
615 EXPECT_TRUE(SimulateMouseDownAndDragStartInLeftFrame()); 631 EXPECT_TRUE(SimulateMouseDownAndDragStartInLeftFrame());
616 632
617 // Verify Javascript event data. 633 // Verify Javascript event data.
618 { 634 {
619 std::string dragstart_event; 635 std::string dragstart_event;
620 EXPECT_TRUE( 636 EXPECT_TRUE(
(...skipping 25 matching lines...) Expand all
646 SimulateMouseUp(); 662 SimulateMouseUp();
647 } 663 }
648 664
649 INSTANTIATE_TEST_CASE_P( 665 INSTANTIATE_TEST_CASE_P(
650 SameSiteSubframe, DragAndDropBrowserTest, ::testing::Values(false)); 666 SameSiteSubframe, DragAndDropBrowserTest, ::testing::Values(false));
651 667
652 INSTANTIATE_TEST_CASE_P( 668 INSTANTIATE_TEST_CASE_P(
653 CrossSiteSubframe, DragAndDropBrowserTest, ::testing::Values(true)); 669 CrossSiteSubframe, DragAndDropBrowserTest, ::testing::Values(true));
654 670
655 } // namespace chrome 671 } // namespace chrome
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/drag_and_drop/event_monitoring.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698