| 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 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 std::string expected_effect_allowed_ = "<no expectation>"; | 372 std::string expected_effect_allowed_ = "<no expectation>"; |
| 373 std::string expected_mime_types_ = "<no expectation>"; | 373 std::string expected_mime_types_ = "<no expectation>"; |
| 374 | 374 |
| 375 DISALLOW_COPY_AND_ASSIGN(DOMDragEventVerifier); | 375 DISALLOW_COPY_AND_ASSIGN(DOMDragEventVerifier); |
| 376 }; | 376 }; |
| 377 | 377 |
| 378 const char kTestPagePath[] = "/drag_and_drop/page.html"; | 378 const char kTestPagePath[] = "/drag_and_drop/page.html"; |
| 379 | 379 |
| 380 } // namespace | 380 } // namespace |
| 381 | 381 |
| 382 class DragAndDropBrowserTest : public InProcessBrowserTest { | 382 class DragAndDropBrowserTest : public InProcessBrowserTest, |
| 383 public testing::WithParamInterface<bool> { |
| 383 public: | 384 public: |
| 384 DragAndDropBrowserTest(){}; | 385 DragAndDropBrowserTest(){}; |
| 385 | 386 |
| 386 protected: | 387 protected: |
| 387 void SetUpOnMainThread() override { | 388 void SetUpOnMainThread() override { |
| 388 host_resolver()->AddRule("*", "127.0.0.1"); | 389 host_resolver()->AddRule("*", "127.0.0.1"); |
| 389 ASSERT_TRUE(embedded_test_server()->Start()); | 390 ASSERT_TRUE(embedded_test_server()->Start()); |
| 390 content::SetupCrossSiteRedirector(embedded_test_server()); | 391 content::SetupCrossSiteRedirector(embedded_test_server()); |
| 391 drag_simulator_.reset(new DragAndDropSimulator(web_contents())); | 392 drag_simulator_.reset(new DragAndDropSimulator(web_contents())); |
| 392 } | 393 } |
| 393 | 394 |
| 395 bool use_cross_site_subframe() { |
| 396 // This is controlled by gtest's test param from INSTANTIATE_TEST_CASE_P. |
| 397 return GetParam(); |
| 398 } |
| 399 |
| 394 content::RenderFrameHost* left_frame() { | 400 content::RenderFrameHost* left_frame() { |
| 395 AssertTestPageIsLoaded(); | 401 AssertTestPageIsLoaded(); |
| 396 return GetFrameByName("left"); | 402 return GetFrameByName("left"); |
| 397 } | 403 } |
| 398 | 404 |
| 399 content::RenderFrameHost* right_frame() { | 405 content::RenderFrameHost* right_frame() { |
| 400 AssertTestPageIsLoaded(); | 406 AssertTestPageIsLoaded(); |
| 401 return GetFrameByName("right"); | 407 return GetFrameByName("right"); |
| 402 } | 408 } |
| 403 | 409 |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 | 557 |
| 552 std::unique_ptr<DragAndDropSimulator> drag_simulator_; | 558 std::unique_ptr<DragAndDropSimulator> drag_simulator_; |
| 553 | 559 |
| 554 // Constants with coordinates within content/test/data/drag_and_drop/page.html | 560 // Constants with coordinates within content/test/data/drag_and_drop/page.html |
| 555 const gfx::Point kMiddleOfLeftFrame = gfx::Point(200, 200); | 561 const gfx::Point kMiddleOfLeftFrame = gfx::Point(200, 200); |
| 556 const gfx::Point kMiddleOfRightFrame = gfx::Point(400, 200); | 562 const gfx::Point kMiddleOfRightFrame = gfx::Point(400, 200); |
| 557 | 563 |
| 558 DISALLOW_COPY_AND_ASSIGN(DragAndDropBrowserTest); | 564 DISALLOW_COPY_AND_ASSIGN(DragAndDropBrowserTest); |
| 559 }; | 565 }; |
| 560 | 566 |
| 561 IN_PROC_BROWSER_TEST_F(DragAndDropBrowserTest, DropTextFromOutside) { | 567 IN_PROC_BROWSER_TEST_P(DragAndDropBrowserTest, DropTextFromOutside) { |
| 568 std::string frame_site = use_cross_site_subframe() ? "b.com" : "a.com"; |
| 562 ASSERT_TRUE(NavigateToTestPage("a.com")); | 569 ASSERT_TRUE(NavigateToTestPage("a.com")); |
| 563 ASSERT_TRUE(NavigateRightFrame("b.com", "drop_target.html")); | 570 ASSERT_TRUE(NavigateRightFrame(frame_site, "drop_target.html")); |
| 564 | 571 |
| 565 // Setup test expectations. | 572 // Setup test expectations. |
| 566 DOMDragEventVerifier expected_dom_event_data; | 573 DOMDragEventVerifier expected_dom_event_data; |
| 567 expected_dom_event_data.set_expected_drop_effect("none"); | 574 expected_dom_event_data.set_expected_drop_effect("none"); |
| 568 expected_dom_event_data.set_expected_effect_allowed("all"); | 575 expected_dom_event_data.set_expected_effect_allowed("all"); |
| 569 expected_dom_event_data.set_expected_mime_types("text/plain"); | 576 expected_dom_event_data.set_expected_mime_types("text/plain"); |
| 570 | 577 |
| 571 // Drag text from outside the browser into/over the right frame. | 578 // Drag text from outside the browser into/over the right frame. |
| 572 { | 579 { |
| 573 DOMDragEventWaiter dragover_waiter("dragover", right_frame()); | 580 DOMDragEventWaiter dragover_waiter("dragover", right_frame()); |
| 574 ASSERT_TRUE(SimulateDragEnterToRightFrame("Dragged test text")); | 581 ASSERT_TRUE(SimulateDragEnterToRightFrame("Dragged test text")); |
| 575 | 582 |
| 576 std::string dragover_event; | 583 std::string dragover_event; |
| 577 ASSERT_TRUE(dragover_waiter.WaitForNextMatchingEvent(&dragover_event)); | 584 ASSERT_TRUE(dragover_waiter.WaitForNextMatchingEvent(&dragover_event)); |
| 578 EXPECT_THAT(dragover_event, expected_dom_event_data.Matches()); | 585 EXPECT_THAT(dragover_event, expected_dom_event_data.Matches()); |
| 579 } | 586 } |
| 580 | 587 |
| 581 // Drop into the right frame. | 588 // Drop into the right frame. |
| 582 { | 589 { |
| 583 DOMDragEventWaiter drop_waiter("drop", right_frame()); | 590 DOMDragEventWaiter drop_waiter("drop", right_frame()); |
| 584 ASSERT_TRUE(SimulateDropInRightFrame()); | 591 ASSERT_TRUE(SimulateDropInRightFrame()); |
| 585 | 592 |
| 586 std::string drop_event; | 593 std::string drop_event; |
| 587 ASSERT_TRUE(drop_waiter.WaitForNextMatchingEvent(&drop_event)); | 594 ASSERT_TRUE(drop_waiter.WaitForNextMatchingEvent(&drop_event)); |
| 588 EXPECT_THAT(drop_event, expected_dom_event_data.Matches()); | 595 EXPECT_THAT(drop_event, expected_dom_event_data.Matches()); |
| 589 } | 596 } |
| 590 } | 597 } |
| 591 | 598 |
| 592 IN_PROC_BROWSER_TEST_F(DragAndDropBrowserTest, DragStartInFrame) { | 599 IN_PROC_BROWSER_TEST_P(DragAndDropBrowserTest, DragStartInFrame) { |
| 593 std::string frame_site = "b.com"; | 600 std::string frame_site = use_cross_site_subframe() ? "b.com" : "a.com"; |
| 594 ASSERT_TRUE(NavigateToTestPage("a.com")); | 601 ASSERT_TRUE(NavigateToTestPage("a.com")); |
| 595 ASSERT_TRUE(NavigateLeftFrame(frame_site, "image_source.html")); | 602 ASSERT_TRUE(NavigateLeftFrame(frame_site, "image_source.html")); |
| 596 | 603 |
| 597 // Setup test expectations. | 604 // Setup test expectations. |
| 598 // (dragstart event handler in image_source.html is asking for "copy" only). | 605 // (dragstart event handler in image_source.html is asking for "copy" only). |
| 599 DOMDragEventVerifier expected_dom_event_data; | 606 DOMDragEventVerifier expected_dom_event_data; |
| 600 expected_dom_event_data.set_expected_drop_effect("none"); | 607 expected_dom_event_data.set_expected_drop_effect("none"); |
| 601 expected_dom_event_data.set_expected_effect_allowed("copy"); | 608 expected_dom_event_data.set_expected_effect_allowed("copy"); |
| 602 expected_dom_event_data.set_expected_mime_types( | 609 expected_dom_event_data.set_expected_mime_types( |
| 603 "Files,text/html,text/uri-list"); | 610 "Files,text/html,text/uri-list"); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 632 "\">")); | 639 "\">")); |
| 633 EXPECT_EQ(expected_location_of_drag_start_in_left_frame(), | 640 EXPECT_EQ(expected_location_of_drag_start_in_left_frame(), |
| 634 location_inside_web_contents); | 641 location_inside_web_contents); |
| 635 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, operation); | 642 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, operation); |
| 636 } | 643 } |
| 637 | 644 |
| 638 // Try to leave everything in a clean state. | 645 // Try to leave everything in a clean state. |
| 639 SimulateMouseUp(); | 646 SimulateMouseUp(); |
| 640 } | 647 } |
| 641 | 648 |
| 649 INSTANTIATE_TEST_CASE_P( |
| 650 SameSiteSubframe, DragAndDropBrowserTest, ::testing::Values(false)); |
| 651 |
| 652 INSTANTIATE_TEST_CASE_P( |
| 653 CrossSiteSubframe, DragAndDropBrowserTest, ::testing::Values(true)); |
| 654 |
| 642 } // namespace chrome | 655 } // namespace chrome |
| OLD | NEW |