| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "apps/shell_window.h" | 5 #include "apps/app_window.h" |
| 6 #include "apps/shell_window_registry.h" | 6 #include "apps/app_window_registry.h" |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
| 10 #include "chrome/browser/apps/app_browsertest_util.h" | 10 #include "chrome/browser/apps/app_browsertest_util.h" |
| 11 #include "chrome/browser/extensions/extension_test_message_listener.h" | 11 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/tab_contents/render_view_context_menu_browsertest_util.
h" | 13 #include "chrome/browser/tab_contents/render_view_context_menu_browsertest_util.
h" |
| 14 #include "chrome/browser/tab_contents/render_view_context_menu_test_util.h" | 14 #include "chrome/browser/tab_contents/render_view_context_menu_test_util.h" |
| 15 #include "chrome/test/base/interactive_test_utils.h" | 15 #include "chrome/test/base/interactive_test_utils.h" |
| 16 #include "chrome/test/base/test_launcher_utils.h" | 16 #include "chrome/test/base/test_launcher_utils.h" |
| 17 #include "chrome/test/base/ui_test_utils.h" | 17 #include "chrome/test/base/ui_test_utils.h" |
| 18 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
| 19 #include "content/public/browser/render_process_host.h" | 19 #include "content/public/browser/render_process_host.h" |
| 20 #include "content/public/browser/render_view_host.h" | 20 #include "content/public/browser/render_view_host.h" |
| 21 #include "content/public/browser/render_widget_host_view.h" | 21 #include "content/public/browser/render_widget_host_view.h" |
| 22 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 23 #include "content/public/browser/web_contents_view.h" | 23 #include "content/public/browser/web_contents_view.h" |
| 24 #include "content/public/common/content_switches.h" | 24 #include "content/public/common/content_switches.h" |
| 25 #include "content/public/test/browser_test_utils.h" | 25 #include "content/public/test/browser_test_utils.h" |
| 26 #include "net/test/embedded_test_server/embedded_test_server.h" | 26 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 27 #include "ui/base/test/ui_controls.h" | 27 #include "ui/base/test/ui_controls.h" |
| 28 #include "ui/events/keycodes/keyboard_codes.h" | 28 #include "ui/events/keycodes/keyboard_codes.h" |
| 29 | 29 |
| 30 using apps::ShellWindow; | 30 using apps::AppWindow; |
| 31 | 31 |
| 32 class WebViewInteractiveTest | 32 class WebViewInteractiveTest |
| 33 : public extensions::PlatformAppBrowserTest { | 33 : public extensions::PlatformAppBrowserTest { |
| 34 public: | 34 public: |
| 35 WebViewInteractiveTest() | 35 WebViewInteractiveTest() |
| 36 : corner_(gfx::Point()), | 36 : corner_(gfx::Point()), |
| 37 mouse_click_result_(false), | 37 mouse_click_result_(false), |
| 38 first_click_(true) {} | 38 first_click_(true) {} |
| 39 | 39 |
| 40 void MoveMouseInsideWindowWithListener(gfx::Point point, | 40 void MoveMouseInsideWindowWithListener(gfx::Point point, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 56 SendMouseEvent(button, ui_controls::DOWN); | 56 SendMouseEvent(button, ui_controls::DOWN); |
| 57 SendMouseEvent(button, ui_controls::UP); | 57 SendMouseEvent(button, ui_controls::UP); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void MoveMouseInsideWindow(const gfx::Point& point) { | 60 void MoveMouseInsideWindow(const gfx::Point& point) { |
| 61 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync( | 61 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync( |
| 62 gfx::Point(corner_.x() + point.x(), corner_.y() + point.y()))); | 62 gfx::Point(corner_.x() + point.x(), corner_.y() + point.y()))); |
| 63 } | 63 } |
| 64 | 64 |
| 65 gfx::NativeWindow GetPlatformAppWindow() { | 65 gfx::NativeWindow GetPlatformAppWindow() { |
| 66 const apps::ShellWindowRegistry::ShellWindowList& shell_windows = | 66 const apps::AppWindowRegistry::AppWindowList& app_windows = |
| 67 apps::ShellWindowRegistry::Get( | 67 apps::AppWindowRegistry::Get(browser()->profile())->app_windows(); |
| 68 browser()->profile())->shell_windows(); | 68 return (*app_windows.begin())->GetNativeWindow(); |
| 69 return (*shell_windows.begin())->GetNativeWindow(); | |
| 70 } | 69 } |
| 71 | 70 |
| 72 void SendKeyPressToPlatformApp(ui::KeyboardCode key) { | 71 void SendKeyPressToPlatformApp(ui::KeyboardCode key) { |
| 73 ASSERT_EQ(1U, GetShellWindowCount()); | 72 ASSERT_EQ(1U, GetAppWindowCount()); |
| 74 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync( | 73 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync( |
| 75 GetPlatformAppWindow(), key, false, false, false, false)); | 74 GetPlatformAppWindow(), key, false, false, false, false)); |
| 76 } | 75 } |
| 77 | 76 |
| 78 void SendCopyKeyPressToPlatformApp() { | 77 void SendCopyKeyPressToPlatformApp() { |
| 79 ASSERT_EQ(1U, GetShellWindowCount()); | 78 ASSERT_EQ(1U, GetAppWindowCount()); |
| 80 #if defined(OS_MACOSX) | 79 #if defined(OS_MACOSX) |
| 81 // Send Cmd+C on MacOSX. | 80 // Send Cmd+C on MacOSX. |
| 82 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync( | 81 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync( |
| 83 GetPlatformAppWindow(), ui::VKEY_C, false, false, false, true)); | 82 GetPlatformAppWindow(), ui::VKEY_C, false, false, false, true)); |
| 84 #else | 83 #else |
| 85 // Send Ctrl+C on Windows and Linux/ChromeOS. | 84 // Send Ctrl+C on Windows and Linux/ChromeOS. |
| 86 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync( | 85 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync( |
| 87 GetPlatformAppWindow(), ui::VKEY_C, true, false, false, false)); | 86 GetPlatformAppWindow(), ui::VKEY_C, true, false, false, false)); |
| 88 #endif | 87 #endif |
| 89 } | 88 } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 } | 161 } |
| 163 | 162 |
| 164 if (!ui_test_utils::ShowAndFocusNativeWindow(GetPlatformAppWindow())) { | 163 if (!ui_test_utils::ShowAndFocusNativeWindow(GetPlatformAppWindow())) { |
| 165 LOG(ERROR) << "UNABLE TO FOCUS TEST WINDOW."; | 164 LOG(ERROR) << "UNABLE TO FOCUS TEST WINDOW."; |
| 166 return scoped_ptr<ExtensionTestMessageListener>(); | 165 return scoped_ptr<ExtensionTestMessageListener>(); |
| 167 } | 166 } |
| 168 | 167 |
| 169 // Flush any pending events to make sure we start with a clean slate. | 168 // Flush any pending events to make sure we start with a clean slate. |
| 170 content::RunAllPendingInMessageLoop(); | 169 content::RunAllPendingInMessageLoop(); |
| 171 | 170 |
| 172 *embedder_web_contents = GetFirstShellWindowWebContents(); | 171 *embedder_web_contents = GetFirstAppWindowWebContents(); |
| 173 | 172 |
| 174 scoped_ptr<ExtensionTestMessageListener> done_listener( | 173 scoped_ptr<ExtensionTestMessageListener> done_listener( |
| 175 new ExtensionTestMessageListener("TEST_PASSED", false)); | 174 new ExtensionTestMessageListener("TEST_PASSED", false)); |
| 176 done_listener->AlsoListenForFailureMessage("TEST_FAILED"); | 175 done_listener->AlsoListenForFailureMessage("TEST_FAILED"); |
| 177 if (!content::ExecuteScript( | 176 if (!content::ExecuteScript( |
| 178 *embedder_web_contents, | 177 *embedder_web_contents, |
| 179 base::StringPrintf("runTest('%s')", test_name.c_str()))) { | 178 base::StringPrintf("runTest('%s')", test_name.c_str()))) { |
| 180 LOG(ERROR) << "UNABLE TO START TEST"; | 179 LOG(ERROR) << "UNABLE TO START TEST"; |
| 181 return scoped_ptr<ExtensionTestMessageListener>(); | 180 return scoped_ptr<ExtensionTestMessageListener>(); |
| 182 } | 181 } |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 title_watcher.AlsoWaitForTitle(error_title); | 328 title_watcher.AlsoWaitForTitle(error_title); |
| 330 EXPECT_TRUE(content::ExecuteScript(guest_web_contents(), | 329 EXPECT_TRUE(content::ExecuteScript(guest_web_contents(), |
| 331 "changeTitle();")); | 330 "changeTitle();")); |
| 332 ASSERT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 331 ASSERT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
| 333 | 332 |
| 334 gfx::Rect popup_bounds = popup_rwh->GetView()->GetViewBounds(); | 333 gfx::Rect popup_bounds = popup_rwh->GetView()->GetViewBounds(); |
| 335 // (2, 2) is expected to lie on the first datalist element. | 334 // (2, 2) is expected to lie on the first datalist element. |
| 336 SimulateRWHMouseClick(popup_rwh, blink::WebMouseEvent::ButtonLeft, 2, 2); | 335 SimulateRWHMouseClick(popup_rwh, blink::WebMouseEvent::ButtonLeft, 2, 2); |
| 337 | 336 |
| 338 content::RenderViewHost* embedder_rvh = | 337 content::RenderViewHost* embedder_rvh = |
| 339 GetFirstShellWindowWebContents()->GetRenderViewHost(); | 338 GetFirstAppWindowWebContents()->GetRenderViewHost(); |
| 340 gfx::Rect embedder_bounds = embedder_rvh->GetView()->GetViewBounds(); | 339 gfx::Rect embedder_bounds = embedder_rvh->GetView()->GetViewBounds(); |
| 341 gfx::Vector2d diff = popup_bounds.origin() - embedder_bounds.origin(); | 340 gfx::Vector2d diff = popup_bounds.origin() - embedder_bounds.origin(); |
| 342 LOG(INFO) << "DIFF: x = " << diff.x() << ", y = " << diff.y(); | 341 LOG(INFO) << "DIFF: x = " << diff.x() << ", y = " << diff.y(); |
| 343 | 342 |
| 344 const int left_spacing = 40 + padding.x(); // div.style.paddingLeft = 40px. | 343 const int left_spacing = 40 + padding.x(); // div.style.paddingLeft = 40px. |
| 345 // div.style.paddingTop = 50px + (input box height = 26px). | 344 // div.style.paddingTop = 50px + (input box height = 26px). |
| 346 const int top_spacing = 50 + 26 + padding.y(); | 345 const int top_spacing = 50 + 26 + padding.y(); |
| 347 | 346 |
| 348 // If the popup is placed within |threshold_px| of the expected position, | 347 // If the popup is placed within |threshold_px| of the expected position, |
| 349 // then we consider the test as a pass. | 348 // then we consider the test as a pass. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 | 384 |
| 386 quit_closure_.Run(); | 385 quit_closure_.Run(); |
| 387 | 386 |
| 388 // Note that following ExtensionTestMessageListener and ExecuteScript* | 387 // Note that following ExtensionTestMessageListener and ExecuteScript* |
| 389 // call must be after we quit |quit_closure_|. Otherwise the class | 388 // call must be after we quit |quit_closure_|. Otherwise the class |
| 390 // here won't be able to receive messages sent by chrome.test.sendMessage. | 389 // here won't be able to receive messages sent by chrome.test.sendMessage. |
| 391 // This is because of the nature of drag and drop code (esp. the | 390 // This is because of the nature of drag and drop code (esp. the |
| 392 // MessageLoop) in it. | 391 // MessageLoop) in it. |
| 393 | 392 |
| 394 // Now check if we got a drop and read the drop data. | 393 // Now check if we got a drop and read the drop data. |
| 395 embedder_web_contents_ = GetFirstShellWindowWebContents(); | 394 embedder_web_contents_ = GetFirstAppWindowWebContents(); |
| 396 ExtensionTestMessageListener drop_listener("guest-got-drop", false); | 395 ExtensionTestMessageListener drop_listener("guest-got-drop", false); |
| 397 EXPECT_TRUE(content::ExecuteScript(embedder_web_contents_, | 396 EXPECT_TRUE(content::ExecuteScript(embedder_web_contents_, |
| 398 "window.checkIfGuestGotDrop()")); | 397 "window.checkIfGuestGotDrop()")); |
| 399 EXPECT_TRUE(drop_listener.WaitUntilSatisfied()); | 398 EXPECT_TRUE(drop_listener.WaitUntilSatisfied()); |
| 400 | 399 |
| 401 std::string last_drop_data; | 400 std::string last_drop_data; |
| 402 EXPECT_TRUE(content::ExecuteScriptAndExtractString( | 401 EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
| 403 embedder_web_contents_, | 402 embedder_web_contents_, |
| 404 "window.domAutomationController.send(getLastDropData())", | 403 "window.domAutomationController.send(getLastDropData())", |
| 405 &last_drop_data)); | 404 &last_drop_data)); |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 // of simulating mouse drag code's dependency on platforms. | 680 // of simulating mouse drag code's dependency on platforms. |
| 682 #if defined(OS_CHROMEOS) | 681 #if defined(OS_CHROMEOS) |
| 683 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, DragDropWithinWebView) { | 682 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, DragDropWithinWebView) { |
| 684 ExtensionTestMessageListener guest_connected_listener("connected", false); | 683 ExtensionTestMessageListener guest_connected_listener("connected", false); |
| 685 LoadAndLaunchPlatformApp("web_view/dnd_within_webview"); | 684 LoadAndLaunchPlatformApp("web_view/dnd_within_webview"); |
| 686 ASSERT_TRUE(guest_connected_listener.WaitUntilSatisfied()); | 685 ASSERT_TRUE(guest_connected_listener.WaitUntilSatisfied()); |
| 687 | 686 |
| 688 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(GetPlatformAppWindow())); | 687 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(GetPlatformAppWindow())); |
| 689 | 688 |
| 690 gfx::Rect offset; | 689 gfx::Rect offset; |
| 691 embedder_web_contents_ = GetFirstShellWindowWebContents(); | 690 embedder_web_contents_ = GetFirstAppWindowWebContents(); |
| 692 embedder_web_contents_->GetView()->GetContainerBounds(&offset); | 691 embedder_web_contents_->GetView()->GetContainerBounds(&offset); |
| 693 corner_ = gfx::Point(offset.x(), offset.y()); | 692 corner_ = gfx::Point(offset.x(), offset.y()); |
| 694 | 693 |
| 695 // In the drag drop test we add 20px padding to the page body because on | 694 // In the drag drop test we add 20px padding to the page body because on |
| 696 // windows if we get too close to the edge of the window the resize cursor | 695 // windows if we get too close to the edge of the window the resize cursor |
| 697 // appears and we start dragging the window edge. | 696 // appears and we start dragging the window edge. |
| 698 corner_.Offset(20, 20); | 697 corner_.Offset(20, 20); |
| 699 | 698 |
| 700 // Flush any pending events to make sure we start with a clean slate. | 699 // Flush any pending events to make sure we start with a clean slate. |
| 701 content::RunAllPendingInMessageLoop(); | 700 content::RunAllPendingInMessageLoop(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 730 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, Navigation_BackForwardKeys) { | 729 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, Navigation_BackForwardKeys) { |
| 731 ExtensionTestMessageListener launched_listener("Launched", false); | 730 ExtensionTestMessageListener launched_listener("Launched", false); |
| 732 LoadAndLaunchPlatformApp("web_view/navigation"); | 731 LoadAndLaunchPlatformApp("web_view/navigation"); |
| 733 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 732 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 734 | 733 |
| 735 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( | 734 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( |
| 736 GetPlatformAppWindow())); | 735 GetPlatformAppWindow())); |
| 737 // Flush any pending events to make sure we start with a clean slate. | 736 // Flush any pending events to make sure we start with a clean slate. |
| 738 content::RunAllPendingInMessageLoop(); | 737 content::RunAllPendingInMessageLoop(); |
| 739 | 738 |
| 740 content::WebContents* embedder_web_contents = | 739 content::WebContents* embedder_web_contents = GetFirstAppWindowWebContents(); |
| 741 GetFirstShellWindowWebContents(); | |
| 742 ASSERT_TRUE(embedder_web_contents); | 740 ASSERT_TRUE(embedder_web_contents); |
| 743 | 741 |
| 744 ExtensionTestMessageListener done_listener( | 742 ExtensionTestMessageListener done_listener( |
| 745 "TEST_PASSED", false); | 743 "TEST_PASSED", false); |
| 746 done_listener.AlsoListenForFailureMessage("TEST_FAILED"); | 744 done_listener.AlsoListenForFailureMessage("TEST_FAILED"); |
| 747 ExtensionTestMessageListener ready_back_key_listener( | 745 ExtensionTestMessageListener ready_back_key_listener( |
| 748 "ReadyForBackKey", false); | 746 "ReadyForBackKey", false); |
| 749 ExtensionTestMessageListener ready_forward_key_listener( | 747 ExtensionTestMessageListener ready_forward_key_listener( |
| 750 "ReadyForForwardKey", false); | 748 "ReadyForForwardKey", false); |
| 751 | 749 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 | 784 |
| 787 // Now verify that the selection text propagates properly to RWHV. | 785 // Now verify that the selection text propagates properly to RWHV. |
| 788 content::RenderWidgetHostView* guest_rwhv = | 786 content::RenderWidgetHostView* guest_rwhv = |
| 789 guest_web_contents()->GetRenderWidgetHostView(); | 787 guest_web_contents()->GetRenderWidgetHostView(); |
| 790 ASSERT_TRUE(guest_rwhv); | 788 ASSERT_TRUE(guest_rwhv); |
| 791 std::string selected_text = base::UTF16ToUTF8(guest_rwhv->GetSelectedText()); | 789 std::string selected_text = base::UTF16ToUTF8(guest_rwhv->GetSelectedText()); |
| 792 ASSERT_TRUE(selected_text.size() >= 10u); | 790 ASSERT_TRUE(selected_text.size() >= 10u); |
| 793 ASSERT_EQ("AAAAAAAAAA", selected_text.substr(0, 10)); | 791 ASSERT_EQ("AAAAAAAAAA", selected_text.substr(0, 10)); |
| 794 } | 792 } |
| 795 #endif | 793 #endif |
| OLD | NEW |