| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <initializer_list> | 6 #include <initializer_list> |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 bool SimulateMouseMove(const gfx::Point& location_inside_web_contents) { | 663 bool SimulateMouseMove(const gfx::Point& location_inside_web_contents) { |
| 664 gfx::Rect bounds = web_contents()->GetContainerBounds(); | 664 gfx::Rect bounds = web_contents()->GetContainerBounds(); |
| 665 return ui_test_utils::SendMouseMoveSync( | 665 return ui_test_utils::SendMouseMoveSync( |
| 666 gfx::Point(bounds.x() + location_inside_web_contents.x(), | 666 gfx::Point(bounds.x() + location_inside_web_contents.x(), |
| 667 bounds.y() + location_inside_web_contents.y())); | 667 bounds.y() + location_inside_web_contents.y())); |
| 668 } | 668 } |
| 669 | 669 |
| 670 bool NavigateNamedFrame(const std::string& frame_name, | 670 bool NavigateNamedFrame(const std::string& frame_name, |
| 671 const std::string& origin, | 671 const std::string& origin, |
| 672 const std::string& filename) { | 672 const std::string& filename) { |
| 673 LOG(ERROR) << "Navigating " << frame_name << " frame ..."; |
| 673 content::RenderFrameHost* frame = GetFrameByName(frame_name); | 674 content::RenderFrameHost* frame = GetFrameByName(frame_name); |
| 674 if (!frame) | 675 if (!frame) |
| 675 return false; | 676 return false; |
| 676 | 677 |
| 677 std::string script; | 678 std::string script; |
| 678 int response = 0; | 679 int response = 0; |
| 679 | 680 |
| 680 // Navigate the frame and wait for the load event. | 681 // Navigate the frame and wait for the load event. |
| 681 script = base::StringPrintf( | 682 script = base::StringPrintf( |
| 682 "location.href = '/cross-site/%s/drag_and_drop/%s';\n" | 683 "location.href = '/cross-site/%s/drag_and_drop/%s';\n" |
| 683 "setTimeout(function() { domAutomationController.send(42); }, 0);", | 684 "setTimeout(function() { domAutomationController.send(42); }, 0);", |
| 684 origin.c_str(), filename.c_str()); | 685 origin.c_str(), filename.c_str()); |
| 685 content::TestFrameNavigationObserver observer(frame); | 686 content::TestFrameNavigationObserver observer(frame); |
| 686 if (!content::ExecuteScriptAndExtractInt(frame, script, &response)) | 687 if (!content::ExecuteScriptAndExtractInt(frame, script, &response)) |
| 687 return false; | 688 return false; |
| 688 if (response != 42) | 689 if (response != 42) |
| 689 return false; | 690 return false; |
| 690 observer.Wait(); | 691 observer.Wait(); |
| 691 | 692 |
| 692 // |frame| might have been swapped-out during a cross-site navigation, | 693 // |frame| might have been swapped-out during a cross-site navigation, |
| 693 // therefore we need to get the current RenderFrameHost to work against | 694 // therefore we need to get the current RenderFrameHost to work against |
| 694 // going forward. | 695 // going forward. |
| 695 frame = GetFrameByName(frame_name); | 696 frame = GetFrameByName(frame_name); |
| 696 DCHECK(frame); | 697 DCHECK(frame); |
| 697 | 698 |
| 698 // Wait until frame contents (e.g. images) have painted (which should happen | 699 // Wait until frame contents have painted and are ready for hit testing. |
| 699 // in the animation frame that *starts* after the onload event - therefore | 700 WaitForChildFrameSurfaceReady(frame); |
| 700 // we need to wait for 2 animation frames). | |
| 701 script = std::string( | |
| 702 "requestAnimationFrame(function() {\n" | |
| 703 " requestAnimationFrame(function() {\n" | |
| 704 " domAutomationController.send(43);\n" | |
| 705 " });\n" | |
| 706 "});\n"); | |
| 707 if (!content::ExecuteScriptAndExtractInt(frame, script, &response)) | |
| 708 return false; | |
| 709 if (response != 43) | |
| 710 return false; | |
| 711 | 701 |
| 702 LOG(ERROR) << "Navigating " << frame_name << " frame ... done."; |
| 712 return true; | 703 return true; |
| 713 } | 704 } |
| 714 | 705 |
| 715 content::RenderFrameHost* GetFrameByName(const std::string& name_to_find) { | 706 content::RenderFrameHost* GetFrameByName(const std::string& name_to_find) { |
| 716 content::RenderFrameHost* result = nullptr; | 707 content::RenderFrameHost* result = nullptr; |
| 717 for (content::RenderFrameHost* rfh : web_contents()->GetAllFrames()) { | 708 for (content::RenderFrameHost* rfh : web_contents()->GetAllFrames()) { |
| 718 if (rfh->GetFrameName() == name_to_find) { | 709 if (rfh->GetFrameName() == name_to_find) { |
| 719 if (result) { | 710 if (result) { |
| 720 ADD_FAILURE() << "More than one frame named " | 711 ADD_FAILURE() << "More than one frame named " |
| 721 << "'" << name_to_find << "'"; | 712 << "'" << name_to_find << "'"; |
| (...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1284 // of a drag operation, and cross-site drags should be allowed across a | 1275 // of a drag operation, and cross-site drags should be allowed across a |
| 1285 // navigation. | 1276 // navigation. |
| 1286 | 1277 |
| 1287 INSTANTIATE_TEST_CASE_P( | 1278 INSTANTIATE_TEST_CASE_P( |
| 1288 SameSiteSubframe, DragAndDropBrowserTest, ::testing::Values(false)); | 1279 SameSiteSubframe, DragAndDropBrowserTest, ::testing::Values(false)); |
| 1289 | 1280 |
| 1290 INSTANTIATE_TEST_CASE_P( | 1281 INSTANTIATE_TEST_CASE_P( |
| 1291 CrossSiteSubframe, DragAndDropBrowserTest, ::testing::Values(true)); | 1282 CrossSiteSubframe, DragAndDropBrowserTest, ::testing::Values(true)); |
| 1292 | 1283 |
| 1293 } // namespace chrome | 1284 } // namespace chrome |
| OLD | NEW |