| 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/shell_window.h" |
| 6 #include "apps/shell_window_registry.h" | 6 #include "apps/shell_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/browser/apps/app_browsertest_util.h" | 9 #include "chrome/browser/apps/app_browsertest_util.h" |
| 10 #include "chrome/browser/extensions/extension_test_message_listener.h" | 10 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 if (first_click_) { | 135 if (first_click_) { |
| 136 mouse_click_result_ = ui_test_utils::SendMouseEventsSync(button, | 136 mouse_click_result_ = ui_test_utils::SendMouseEventsSync(button, |
| 137 state); | 137 state); |
| 138 first_click_ = false; | 138 first_click_ = false; |
| 139 } else { | 139 } else { |
| 140 ASSERT_EQ(mouse_click_result_, ui_test_utils::SendMouseEventsSync( | 140 ASSERT_EQ(mouse_click_result_, ui_test_utils::SendMouseEventsSync( |
| 141 button, state)); | 141 button, state)); |
| 142 } | 142 } |
| 143 } | 143 } |
| 144 | 144 |
| 145 enum TestServer { |
| 146 NEEDS_TEST_SERVER, |
| 147 NO_TEST_SERVER |
| 148 }; |
| 149 |
| 145 scoped_ptr<ExtensionTestMessageListener> RunAppHelper( | 150 scoped_ptr<ExtensionTestMessageListener> RunAppHelper( |
| 146 const std::string& test_name, | 151 const std::string& test_name, |
| 147 const std::string& app_location, | 152 const std::string& app_location, |
| 153 TestServer test_server, |
| 148 content::WebContents** embedder_web_contents) { | 154 content::WebContents** embedder_web_contents) { |
| 149 // For serving guest pages. | 155 // For serving guest pages. |
| 150 if (!StartEmbeddedTestServer()) { | 156 if ((test_server == NEEDS_TEST_SERVER) && !StartEmbeddedTestServer()) { |
| 151 LOG(ERROR) << "FAILED TO START TEST SERVER."; | 157 LOG(ERROR) << "FAILED TO START TEST SERVER."; |
| 152 return scoped_ptr<ExtensionTestMessageListener>(); | 158 return scoped_ptr<ExtensionTestMessageListener>(); |
| 153 } | 159 } |
| 154 | 160 |
| 155 ExtensionTestMessageListener launched_listener("Launched", false); | 161 ExtensionTestMessageListener launched_listener("Launched", false); |
| 156 LoadAndLaunchPlatformApp(app_location.c_str()); | 162 LoadAndLaunchPlatformApp(app_location.c_str()); |
| 157 if (!launched_listener.WaitUntilSatisfied()) { | 163 if (!launched_listener.WaitUntilSatisfied()) { |
| 158 LOG(ERROR) << "TEST DID NOT LAUNCH."; | 164 LOG(ERROR) << "TEST DID NOT LAUNCH."; |
| 159 return scoped_ptr<ExtensionTestMessageListener>(); | 165 return scoped_ptr<ExtensionTestMessageListener>(); |
| 160 } | 166 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 176 *embedder_web_contents, | 182 *embedder_web_contents, |
| 177 base::StringPrintf("runTest('%s')", test_name.c_str()))) { | 183 base::StringPrintf("runTest('%s')", test_name.c_str()))) { |
| 178 LOG(ERROR) << "UNABLE TO START TEST"; | 184 LOG(ERROR) << "UNABLE TO START TEST"; |
| 179 return scoped_ptr<ExtensionTestMessageListener>(); | 185 return scoped_ptr<ExtensionTestMessageListener>(); |
| 180 } | 186 } |
| 181 | 187 |
| 182 return done_listener.Pass(); | 188 return done_listener.Pass(); |
| 183 } | 189 } |
| 184 | 190 |
| 185 void TestHelper(const std::string& test_name, | 191 void TestHelper(const std::string& test_name, |
| 186 const std::string& app_location) { | 192 const std::string& app_location, |
| 193 TestServer test_server) { |
| 187 content::WebContents* embedder_web_contents = NULL; | 194 content::WebContents* embedder_web_contents = NULL; |
| 188 scoped_ptr<ExtensionTestMessageListener> done_listener( | 195 scoped_ptr<ExtensionTestMessageListener> done_listener( |
| 189 RunAppHelper(test_name, app_location, &embedder_web_contents)); | 196 RunAppHelper( |
| 197 test_name, app_location, test_server, &embedder_web_contents)); |
| 190 | 198 |
| 191 ASSERT_TRUE(done_listener); | 199 ASSERT_TRUE(done_listener); |
| 192 ASSERT_TRUE(done_listener->WaitUntilSatisfied()); | 200 ASSERT_TRUE(done_listener->WaitUntilSatisfied()); |
| 193 } | 201 } |
| 194 | 202 |
| 203 void RunTest(const std::string& app_name) { |
| 204 } |
| 195 void SetupTest(const std::string& app_name, | 205 void SetupTest(const std::string& app_name, |
| 196 const std::string& guest_url_spec) { | 206 const std::string& guest_url_spec) { |
| 197 ASSERT_TRUE(StartEmbeddedTestServer()); | 207 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 198 GURL::Replacements replace_host; | 208 GURL::Replacements replace_host; |
| 199 std::string host_str("localhost"); // Must stay in scope with replace_host. | 209 std::string host_str("localhost"); // Must stay in scope with replace_host. |
| 200 replace_host.SetHostStr(host_str); | 210 replace_host.SetHostStr(host_str); |
| 201 | 211 |
| 202 GURL guest_url = embedded_test_server()->GetURL(guest_url_spec); | 212 GURL guest_url = embedded_test_server()->GetURL(guest_url_spec); |
| 203 guest_url = guest_url.ReplaceComponents(replace_host); | 213 guest_url = guest_url.ReplaceComponents(replace_host); |
| 204 | 214 |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync( | 505 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync( |
| 496 gfx::Point(corner().x() + 51, corner().y() + 11))); | 506 gfx::Point(corner().x() + 51, corner().y() + 11))); |
| 497 ASSERT_TRUE(move_listener2.WaitUntilSatisfied()); | 507 ASSERT_TRUE(move_listener2.WaitUntilSatisfied()); |
| 498 } | 508 } |
| 499 } | 509 } |
| 500 | 510 |
| 501 #endif // (defined(OS_WIN) || defined(OS_LINUX)) | 511 #endif // (defined(OS_WIN) || defined(OS_LINUX)) |
| 502 | 512 |
| 503 // Tests that setting focus on the <webview> sets focus on the guest. | 513 // Tests that setting focus on the <webview> sets focus on the guest. |
| 504 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, Focus_FocusEvent) { | 514 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, Focus_FocusEvent) { |
| 505 TestHelper("testFocusEvent", "web_view/focus"); | 515 TestHelper("testFocusEvent", "web_view/focus", NO_TEST_SERVER); |
| 506 } | 516 } |
| 507 | 517 |
| 508 // Tests that setting focus on the <webview> sets focus on the guest. | 518 // Tests that setting focus on the <webview> sets focus on the guest. |
| 509 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, Focus_BlurEvent) { | 519 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, Focus_BlurEvent) { |
| 510 TestHelper("testBlurEvent", "web_view/focus"); | 520 TestHelper("testBlurEvent", "web_view/focus", NO_TEST_SERVER); |
| 511 } | 521 } |
| 512 | 522 |
| 513 // Tests that guests receive edit commands and respond appropriately. | 523 // Tests that guests receive edit commands and respond appropriately. |
| 514 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, EditCommands) { | 524 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, EditCommands) { |
| 515 SetupTest("web_view/edit_commands", | 525 ExtensionTestMessageListener guest_connected_listener("connected", false); |
| 516 "/extensions/platform_apps/web_view/edit_commands/guest.html"); | 526 LoadAndLaunchPlatformApp("web_view/edit_commands"); |
| 527 // Wait until the guest process reports that it has established a message |
| 528 // channel with the app. |
| 529 ASSERT_TRUE(guest_connected_listener.WaitUntilSatisfied()); |
| 517 | 530 |
| 518 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( | 531 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( |
| 519 GetPlatformAppWindow())); | 532 GetPlatformAppWindow())); |
| 520 | 533 |
| 521 // Flush any pending events to make sure we start with a clean slate. | 534 // Flush any pending events to make sure we start with a clean slate. |
| 522 content::RunAllPendingInMessageLoop(); | 535 content::RunAllPendingInMessageLoop(); |
| 523 | 536 |
| 524 ExtensionTestMessageListener copy_listener("copy", false); | 537 ExtensionTestMessageListener copy_listener("copy", false); |
| 525 SendCopyKeyPressToPlatformApp(); | 538 SendCopyKeyPressToPlatformApp(); |
| 526 | 539 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 541 content::RunAllPendingInMessageLoop(); | 554 content::RunAllPendingInMessageLoop(); |
| 542 | 555 |
| 543 ExtensionTestMessageListener start_of_line_listener("StartOfLine", false); | 556 ExtensionTestMessageListener start_of_line_listener("StartOfLine", false); |
| 544 SendStartOfLineKeyPressToPlatformApp(); | 557 SendStartOfLineKeyPressToPlatformApp(); |
| 545 // Wait for the guest to receive a 'copy' edit command. | 558 // Wait for the guest to receive a 'copy' edit command. |
| 546 ASSERT_TRUE(start_of_line_listener.WaitUntilSatisfied()); | 559 ASSERT_TRUE(start_of_line_listener.WaitUntilSatisfied()); |
| 547 } | 560 } |
| 548 | 561 |
| 549 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, | 562 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, |
| 550 NewWindow_NewWindowNameTakesPrecedence) { | 563 NewWindow_NewWindowNameTakesPrecedence) { |
| 551 TestHelper("testNewWindowNameTakesPrecedence", "web_view/newwindow"); | 564 TestHelper("testNewWindowNameTakesPrecedence", |
| 565 "web_view/newwindow", |
| 566 NEEDS_TEST_SERVER); |
| 552 } | 567 } |
| 553 | 568 |
| 554 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, | 569 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, |
| 555 NewWindow_WebViewNameTakesPrecedence) { | 570 NewWindow_WebViewNameTakesPrecedence) { |
| 556 TestHelper("testWebViewNameTakesPrecedence", "web_view/newwindow"); | 571 TestHelper("testWebViewNameTakesPrecedence", |
| 572 "web_view/newwindow", |
| 573 NEEDS_TEST_SERVER); |
| 557 } | 574 } |
| 558 | 575 |
| 559 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, NewWindow_NoName) { | 576 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, NewWindow_NoName) { |
| 560 TestHelper("testNoName", "web_view/newwindow"); | 577 TestHelper("testNoName", |
| 578 "web_view/newwindow", |
| 579 NEEDS_TEST_SERVER); |
| 561 } | 580 } |
| 562 | 581 |
| 563 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, NewWindow_Redirect) { | 582 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, NewWindow_Redirect) { |
| 564 TestHelper("testNewWindowRedirect", "web_view/newwindow"); | 583 TestHelper("testNewWindowRedirect", |
| 584 "web_view/newwindow", |
| 585 NEEDS_TEST_SERVER); |
| 565 } | 586 } |
| 566 | 587 |
| 567 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, NewWindow_Close) { | 588 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, NewWindow_Close) { |
| 568 TestHelper("testNewWindowClose", "web_view/newwindow"); | 589 TestHelper("testNewWindowClose", |
| 590 "web_view/newwindow", |
| 591 NEEDS_TEST_SERVER); |
| 569 } | 592 } |
| 570 | 593 |
| 571 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, NewWindow_ExecuteScript) { | 594 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, NewWindow_ExecuteScript) { |
| 572 TestHelper("testNewWindowExecuteScript", "web_view/newwindow"); | 595 TestHelper("testNewWindowExecuteScript", |
| 596 "web_view/newwindow", |
| 597 NEEDS_TEST_SERVER); |
| 573 } | 598 } |
| 574 | 599 |
| 575 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, NewWindow_WebRequest) { | 600 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, NewWindow_WebRequest) { |
| 576 TestHelper("testNewWindowWebRequest", "web_view/newwindow"); | 601 TestHelper("testNewWindowWebRequest", |
| 602 "web_view/newwindow", |
| 603 NEEDS_TEST_SERVER); |
| 577 } | 604 } |
| 578 | 605 |
| 579 // A custom elements bug needs to be addressed to enable this test: | 606 // A custom elements bug needs to be addressed to enable this test: |
| 580 // See http://crbug.com/282477 for more information. | 607 // See http://crbug.com/282477 for more information. |
| 581 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, | 608 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, |
| 582 DISABLED_NewWindow_WebRequestCloseWindow) { | 609 DISABLED_NewWindow_WebRequestCloseWindow) { |
| 583 TestHelper("testNewWindowWebRequestCloseWindow", "web_view/newwindow"); | 610 TestHelper("testNewWindowWebRequestCloseWindow", |
| 611 "web_view/newwindow", |
| 612 NEEDS_TEST_SERVER); |
| 584 } | 613 } |
| 585 | 614 |
| 586 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, | 615 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, |
| 587 NewWindow_WebRequestRemoveElement) { | 616 NewWindow_WebRequestRemoveElement) { |
| 588 TestHelper("testNewWindowWebRequestRemoveElement", "web_view/newwindow"); | 617 TestHelper("testNewWindowWebRequestRemoveElement", |
| 618 "web_view/newwindow", |
| 619 NEEDS_TEST_SERVER); |
| 589 } | 620 } |
| 590 | 621 |
| 591 // Tests that Ctrl+Click/Cmd+Click on a link fires up the newwindow API. | 622 // Tests that Ctrl+Click/Cmd+Click on a link fires up the newwindow API. |
| 592 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, NewWindow_OpenInNewTab) { | 623 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, NewWindow_OpenInNewTab) { |
| 593 content::WebContents* embedder_web_contents = NULL; | 624 content::WebContents* embedder_web_contents = NULL; |
| 594 | 625 |
| 595 ExtensionTestMessageListener loaded_listener("Loaded", false); | 626 ExtensionTestMessageListener loaded_listener("Loaded", false); |
| 596 scoped_ptr<ExtensionTestMessageListener> done_listener( | 627 scoped_ptr<ExtensionTestMessageListener> done_listener( |
| 597 RunAppHelper("testNewWindowOpenInNewTab", | 628 RunAppHelper("testNewWindowOpenInNewTab", |
| 598 "web_view/newwindow", | 629 "web_view/newwindow", |
| 630 NEEDS_TEST_SERVER, |
| 599 &embedder_web_contents)); | 631 &embedder_web_contents)); |
| 600 | 632 |
| 601 loaded_listener.WaitUntilSatisfied(); | 633 loaded_listener.WaitUntilSatisfied(); |
| 602 #if defined(OS_MACOSX) | 634 #if defined(OS_MACOSX) |
| 603 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync( | 635 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync( |
| 604 GetPlatformAppWindow(), ui::VKEY_RETURN, | 636 GetPlatformAppWindow(), ui::VKEY_RETURN, |
| 605 false, false, false, true /* cmd */)); | 637 false, false, false, true /* cmd */)); |
| 606 #else | 638 #else |
| 607 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync( | 639 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync( |
| 608 GetPlatformAppWindow(), ui::VKEY_RETURN, | 640 GetPlatformAppWindow(), ui::VKEY_RETURN, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 quit_closure_ = run_loop.QuitClosure(); | 698 quit_closure_ = run_loop.QuitClosure(); |
| 667 base::MessageLoop::current()->PostTask( | 699 base::MessageLoop::current()->PostTask( |
| 668 FROM_HERE, | 700 FROM_HERE, |
| 669 base::Bind(&WebViewInteractiveTest::DragTestStep1, | 701 base::Bind(&WebViewInteractiveTest::DragTestStep1, |
| 670 base::Unretained(this))); | 702 base::Unretained(this))); |
| 671 run_loop.Run(); | 703 run_loop.Run(); |
| 672 } | 704 } |
| 673 #endif // (defined(OS_CHROMEOS)) | 705 #endif // (defined(OS_CHROMEOS)) |
| 674 | 706 |
| 675 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, Navigation) { | 707 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, Navigation) { |
| 676 TestHelper("testNavigation", "web_view/navigation"); | 708 TestHelper("testNavigation", "web_view/navigation", NO_TEST_SERVER); |
| 677 } | 709 } |
| 678 | 710 |
| 679 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, Navigation_BackForwardKeys) { | 711 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, Navigation_BackForwardKeys) { |
| 680 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages. | |
| 681 ExtensionTestMessageListener launched_listener("Launched", false); | 712 ExtensionTestMessageListener launched_listener("Launched", false); |
| 682 LoadAndLaunchPlatformApp("web_view/navigation"); | 713 LoadAndLaunchPlatformApp("web_view/navigation"); |
| 683 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 714 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 684 | 715 |
| 685 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( | 716 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( |
| 686 GetPlatformAppWindow())); | 717 GetPlatformAppWindow())); |
| 687 // Flush any pending events to make sure we start with a clean slate. | 718 // Flush any pending events to make sure we start with a clean slate. |
| 688 content::RunAllPendingInMessageLoop(); | 719 content::RunAllPendingInMessageLoop(); |
| 689 | 720 |
| 690 content::WebContents* embedder_web_contents = | 721 content::WebContents* embedder_web_contents = |
| (...skipping 14 matching lines...) Expand all Loading... |
| 705 | 736 |
| 706 ASSERT_TRUE(ready_back_key_listener.WaitUntilSatisfied()); | 737 ASSERT_TRUE(ready_back_key_listener.WaitUntilSatisfied()); |
| 707 SendBackShortcutToPlatformApp(); | 738 SendBackShortcutToPlatformApp(); |
| 708 | 739 |
| 709 ASSERT_TRUE(ready_forward_key_listener.WaitUntilSatisfied()); | 740 ASSERT_TRUE(ready_forward_key_listener.WaitUntilSatisfied()); |
| 710 SendForwardShortcutToPlatformApp(); | 741 SendForwardShortcutToPlatformApp(); |
| 711 | 742 |
| 712 ASSERT_TRUE(done_listener.WaitUntilSatisfied()); | 743 ASSERT_TRUE(done_listener.WaitUntilSatisfied()); |
| 713 } | 744 } |
| 714 | 745 |
| 715 // Fail at least once a day on Windows. See http://crbug.com/293445. | |
| 716 #if defined(OS_WIN) | |
| 717 #define MAYBE_PointerLock_PointerLockLostWithFocus \ | |
| 718 DISABLED_PointerLock_PointerLockLostWithFocus | |
| 719 #else | |
| 720 #define MAYBE_PointerLock_PointerLockLostWithFocus \ | |
| 721 PointerLock_PointerLockLostWithFocus | |
| 722 #endif | |
| 723 | |
| 724 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, | 746 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, |
| 725 MAYBE_PointerLock_PointerLockLostWithFocus) { | 747 PointerLock_PointerLockLostWithFocus) { |
| 726 TestHelper("testPointerLockLostWithFocus", "web_view/pointerlock"); | 748 TestHelper("testPointerLockLostWithFocus", |
| 749 "web_view/pointerlock", |
| 750 NO_TEST_SERVER); |
| 727 } | 751 } |
| OLD | NEW |