| OLD | NEW |
| 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 20 matching lines...) Expand all Loading... |
| 31 #include "net/test/embedded_test_server/embedded_test_server.h" | 31 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 32 #include "testing/gmock/include/gmock/gmock.h" | 32 #include "testing/gmock/include/gmock/gmock.h" |
| 33 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
| 34 #include "ui/aura/client/drag_drop_client.h" | 34 #include "ui/aura/client/drag_drop_client.h" |
| 35 #include "ui/aura/client/drag_drop_delegate.h" | 35 #include "ui/aura/client/drag_drop_delegate.h" |
| 36 #include "ui/aura/client/screen_position_client.h" | 36 #include "ui/aura/client/screen_position_client.h" |
| 37 #include "ui/aura/window.h" | 37 #include "ui/aura/window.h" |
| 38 #include "ui/base/dragdrop/drag_drop_types.h" | 38 #include "ui/base/dragdrop/drag_drop_types.h" |
| 39 #include "ui/base/dragdrop/drop_target_event.h" | 39 #include "ui/base/dragdrop/drop_target_event.h" |
| 40 #include "ui/base/dragdrop/os_exchange_data.h" | 40 #include "ui/base/dragdrop/os_exchange_data.h" |
| 41 #include "ui/base/test/ui_controls.h" |
| 41 #include "ui/gfx/geometry/point.h" | 42 #include "ui/gfx/geometry/point.h" |
| 42 #include "ui/gfx/geometry/rect.h" | 43 #include "ui/gfx/geometry/rect.h" |
| 43 #include "url/gurl.h" | 44 #include "url/gurl.h" |
| 44 | 45 |
| 45 namespace chrome { | 46 namespace chrome { |
| 46 | 47 |
| 47 namespace { | 48 namespace { |
| 48 | 49 |
| 49 // TODO(lukasza): Support testing on non-Aura platforms (i.e. Android + Mac?). | 50 // TODO(lukasza): Support testing on non-Aura platforms (i.e. Android + Mac?). |
| 50 // | 51 // |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 }; | 377 }; |
| 377 | 378 |
| 378 const char kTestPagePath[] = "/drag_and_drop/page.html"; | 379 const char kTestPagePath[] = "/drag_and_drop/page.html"; |
| 379 | 380 |
| 380 } // namespace | 381 } // namespace |
| 381 | 382 |
| 382 class DragAndDropBrowserTest : public InProcessBrowserTest { | 383 class DragAndDropBrowserTest : public InProcessBrowserTest { |
| 383 public: | 384 public: |
| 384 DragAndDropBrowserTest(){}; | 385 DragAndDropBrowserTest(){}; |
| 385 | 386 |
| 387 // Declarations of test continuations. |
| 388 void DragImageToOtherFrame_Step2(const std::string& frame_site, |
| 389 const std::string& text, |
| 390 const std::string& html, |
| 391 int operation, |
| 392 bool did_originate_from_renderer); |
| 393 |
| 386 protected: | 394 protected: |
| 387 void SetUpOnMainThread() override { | 395 void SetUpOnMainThread() override { |
| 388 host_resolver()->AddRule("*", "127.0.0.1"); | 396 host_resolver()->AddRule("*", "127.0.0.1"); |
| 389 ASSERT_TRUE(embedded_test_server()->Start()); | 397 ASSERT_TRUE(embedded_test_server()->Start()); |
| 390 content::SetupCrossSiteRedirector(embedded_test_server()); | 398 content::SetupCrossSiteRedirector(embedded_test_server()); |
| 391 drag_simulator_.reset(new DragAndDropSimulator(web_contents())); | 399 drag_simulator_.reset(new DragAndDropSimulator(web_contents())); |
| 392 } | 400 } |
| 393 | 401 |
| 394 content::RenderFrameHost* left_frame() { | 402 content::RenderFrameHost* left_frame() { |
| 395 AssertTestPageIsLoaded(); | 403 AssertTestPageIsLoaded(); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 return drag_simulator_->SimulateDragEnter(kMiddleOfRightFrame, text); | 472 return drag_simulator_->SimulateDragEnter(kMiddleOfRightFrame, text); |
| 465 } | 473 } |
| 466 | 474 |
| 467 bool SimulateDropInRightFrame() { | 475 bool SimulateDropInRightFrame() { |
| 468 AssertTestPageIsLoaded(); | 476 AssertTestPageIsLoaded(); |
| 469 return drag_simulator_->SimulateDrop(kMiddleOfRightFrame); | 477 return drag_simulator_->SimulateDrop(kMiddleOfRightFrame); |
| 470 } | 478 } |
| 471 | 479 |
| 472 private: | 480 private: |
| 473 bool SimulateMouseDown() { | 481 bool SimulateMouseDown() { |
| 474 return ui_test_utils::SendMouseEventsSync(ui_controls::LEFT, | 482 return ui_controls::SendMouseEvents(ui_controls::LEFT, ui_controls::DOWN); |
| 475 ui_controls::DOWN); | 483 } |
| 484 |
| 485 gfx::Point GetScreenCoordinates( |
| 486 const gfx::Point& location_inside_web_contents) { |
| 487 gfx::Rect bounds = web_contents()->GetContainerBounds(); |
| 488 return gfx::Point(bounds.x() + location_inside_web_contents.x(), |
| 489 bounds.y() + location_inside_web_contents.y()); |
| 476 } | 490 } |
| 477 | 491 |
| 478 bool SimulateMouseMove(const gfx::Point& location_inside_web_contents) { | 492 bool SimulateMouseMove(const gfx::Point& location_inside_web_contents) { |
| 479 gfx::Rect bounds = web_contents()->GetContainerBounds(); | |
| 480 return ui_test_utils::SendMouseMoveSync( | 493 return ui_test_utils::SendMouseMoveSync( |
| 481 gfx::Point(bounds.x() + location_inside_web_contents.x(), | 494 GetScreenCoordinates(location_inside_web_contents)); |
| 482 bounds.y() + location_inside_web_contents.y())); | 495 } |
| 496 |
| 497 bool SimulateMouseMoveNotifyWhenDone( |
| 498 const gfx::Point& location_inside_web_contents, |
| 499 const base::Closure& done_callback) { |
| 500 gfx::Point screen_location = GetScreenCoordinates(location_inside_web_conten
ts); |
| 501 return ui_controls::SendMouseMoveNotifyWhenDone( |
| 502 screen_location.x(), screen_location.y(), done_callback); |
| 483 } | 503 } |
| 484 | 504 |
| 485 bool NavigateNamedFrame(const std::string& frame_name, | 505 bool NavigateNamedFrame(const std::string& frame_name, |
| 486 const std::string& origin, | 506 const std::string& origin, |
| 487 const std::string& filename) { | 507 const std::string& filename) { |
| 488 content::RenderFrameHost* frame = GetFrameByName(frame_name); | 508 content::RenderFrameHost* frame = GetFrameByName(frame_name); |
| 489 if (!frame) | 509 if (!frame) |
| 490 return false; | 510 return false; |
| 491 | 511 |
| 492 std::string script; | 512 std::string script; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 { | 602 { |
| 583 DOMDragEventWaiter drop_waiter("drop", right_frame()); | 603 DOMDragEventWaiter drop_waiter("drop", right_frame()); |
| 584 ASSERT_TRUE(SimulateDropInRightFrame()); | 604 ASSERT_TRUE(SimulateDropInRightFrame()); |
| 585 | 605 |
| 586 std::string drop_event; | 606 std::string drop_event; |
| 587 ASSERT_TRUE(drop_waiter.WaitForNextMatchingEvent(&drop_event)); | 607 ASSERT_TRUE(drop_waiter.WaitForNextMatchingEvent(&drop_event)); |
| 588 EXPECT_THAT(drop_event, expected_dom_event_data.Matches()); | 608 EXPECT_THAT(drop_event, expected_dom_event_data.Matches()); |
| 589 } | 609 } |
| 590 } | 610 } |
| 591 | 611 |
| 592 // The test is disabled on Ozone because of trouble with mouse simulation | 612 struct DragImageToOtherFrame_TestState { |
| 593 // during the test - see https://crbug.com/665042. | 613 std::string frame_site; |
| 594 #if defined(USE_OZONE) | 614 |
| 595 #define MAYBE_DragStartInFrame DISABLED_DragStartInFrame | 615 std::string expected_text; |
| 596 #else | 616 std::string expected_html_regex; |
| 597 #define MAYBE_DragStartInFrame DragStartInFrame | 617 int expected_operation; |
| 598 #endif | 618 |
| 619 std::string expected_drop_effect; |
| 620 std::string expected_effect_allowed; |
| 621 std::string expected_mime_types; |
| 622 |
| 623 std::unique_ptr<DOMDragEventWaiter> dragend_event_waiter; |
| 624 }; |
| 625 |
| 626 testing::Matcher<std::string> MatchesTestExpectations( |
| 627 const DragImageToOtherFrame_TestState& test) { |
| 628 auto matches_expected_drop_effect = testing::HasSubstr(base::StringPrintf( |
| 629 "\"drop_effect\":\"%s\"", test.expected_drop_effect.c_str())); |
| 630 |
| 631 auto matches_expected_effect_allowed = testing::HasSubstr(base::StringPrintf( |
| 632 "\"effect_allowed\":\"%s\"", test.expected_effect_allowed.c_str())); |
| 633 |
| 634 auto matches_expected_mime_types = testing::HasSubstr(base::StringPrintf( |
| 635 "\"mime_types\":\"%s\"", test.expected_mime_types.c_str())); |
| 636 |
| 637 return testing::AllOf(matches_expected_drop_effect, |
| 638 matches_expected_mime_types); |
| 639 } |
| 640 |
| 599 IN_PROC_BROWSER_TEST_F(DragAndDropBrowserTest, MAYBE_DragStartInFrame) { | 641 IN_PROC_BROWSER_TEST_F(DragAndDropBrowserTest, MAYBE_DragStartInFrame) { |
| 600 std::string frame_site = "b.com"; | 642 std::string frame_site = "b.com"; |
| 601 ASSERT_TRUE(NavigateToTestPage("a.com")); | 643 ASSERT_TRUE(NavigateToTestPage("a.com")); |
| 644 |
| 645 // Drag-and-drop is not allowed between cross-origin frames in the same page |
| 646 // (see https://crbug.com/59081) - this is why left and right frame have to |
| 647 // come from the same origin below. |
| 602 ASSERT_TRUE(NavigateLeftFrame(frame_site, "image_source.html")); | 648 ASSERT_TRUE(NavigateLeftFrame(frame_site, "image_source.html")); |
| 649 ASSERT_TRUE(NavigateRightFrame(frame_site, "drop_target.html")); |
| 603 | 650 |
| 604 // Setup test expectations. | 651 LOG(ERROR) << "Starting message loop for interactive UI..."; |
| 605 // (dragstart event handler in image_source.html is asking for "copy" only). | 652 (new content::MessageLoopRunner)->Run(); |
| 606 DOMDragEventVerifier expected_dom_event_data; | |
| 607 expected_dom_event_data.set_expected_drop_effect("none"); | |
| 608 expected_dom_event_data.set_expected_effect_allowed("copy"); | |
| 609 expected_dom_event_data.set_expected_mime_types( | |
| 610 "Files,text/html,text/uri-list"); | |
| 611 | |
| 612 // Start the drag in the left frame. | |
| 613 DragStartWaiter drag_start_waiter(web_contents()); | |
| 614 DOMDragEventWaiter dragstart_event_waiter("dragstart", left_frame()); | |
| 615 EXPECT_TRUE(SimulateMouseDownAndDragStartInLeftFrame()); | |
| 616 | |
| 617 // Verify Javascript event data. | |
| 618 { | |
| 619 std::string dragstart_event; | |
| 620 EXPECT_TRUE( | |
| 621 dragstart_event_waiter.WaitForNextMatchingEvent(&dragstart_event)); | |
| 622 EXPECT_THAT(dragstart_event, expected_dom_event_data.Matches()); | |
| 623 } | |
| 624 | |
| 625 // Verify data being passed to the OS. | |
| 626 { | |
| 627 std::string text; | |
| 628 std::string html; | |
| 629 int operation = 0; | |
| 630 gfx::Point location_inside_web_contents; | |
| 631 drag_start_waiter.WaitUntilDragStartIsIntercepted( | |
| 632 &text, &html, &operation, &location_inside_web_contents); | |
| 633 EXPECT_EQ(embedded_test_server()->GetURL(frame_site, | |
| 634 "/image_decoding/droids.jpg"), | |
| 635 text); | |
| 636 EXPECT_THAT(html, | |
| 637 testing::MatchesRegex("<img .*src=\"" | |
| 638 "http://.*/image_decoding/droids.jpg" | |
| 639 "\">")); | |
| 640 EXPECT_EQ(expected_location_of_drag_start_in_left_frame(), | |
| 641 location_inside_web_contents); | |
| 642 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, operation); | |
| 643 } | |
| 644 | |
| 645 // Try to leave everything in a clean state. | |
| 646 SimulateMouseUp(); | |
| 647 } | 653 } |
| 648 | 654 |
| 649 } // namespace chrome | 655 } // namespace chrome |
| OLD | NEW |