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/ui/native_app_window.h" | 5 #include "apps/ui/native_app_window.h" |
6 #include "base/path_service.h" | 6 #include "base/path_service.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/chrome_content_browser_client.h" | 11 #include "chrome/browser/chrome_content_browser_client.h" |
12 #include "chrome/browser/extensions/extension_test_message_listener.h" | 12 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 13 #include "chrome/browser/guest_view/guest_view_manager.h" |
| 14 #include "chrome/browser/guest_view/guest_view_manager_factory.h" |
13 #include "chrome/browser/prerender/prerender_link_manager.h" | 15 #include "chrome/browser/prerender/prerender_link_manager.h" |
14 #include "chrome/browser/prerender/prerender_link_manager_factory.h" | 16 #include "chrome/browser/prerender/prerender_link_manager_factory.h" |
15 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" | 18 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" |
17 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti
l.h" | 19 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti
l.h" |
18 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" | 20 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" |
19 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
20 #include "chrome/browser/ui/browser_dialogs.h" | 22 #include "chrome/browser/ui/browser_dialogs.h" |
21 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 23 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
22 #include "chrome/test/base/ui_test_utils.h" | 24 #include "chrome/test/base/ui_test_utils.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 }; | 87 }; |
86 | 88 |
87 class TestInterstitialPageDelegate : public content::InterstitialPageDelegate { | 89 class TestInterstitialPageDelegate : public content::InterstitialPageDelegate { |
88 public: | 90 public: |
89 TestInterstitialPageDelegate() { | 91 TestInterstitialPageDelegate() { |
90 } | 92 } |
91 virtual ~TestInterstitialPageDelegate() {} | 93 virtual ~TestInterstitialPageDelegate() {} |
92 virtual std::string GetHTMLContents() OVERRIDE { return std::string(); } | 94 virtual std::string GetHTMLContents() OVERRIDE { return std::string(); } |
93 }; | 95 }; |
94 | 96 |
95 // Used to get notified when a guest is created. | 97 class TestGuestViewManager : public GuestViewManager { |
96 class GuestContentBrowserClient : public chrome::ChromeContentBrowserClient { | |
97 public: | 98 public: |
98 GuestContentBrowserClient() : web_contents_(NULL) {} | 99 explicit TestGuestViewManager(content::BrowserContext* context) : |
| 100 GuestViewManager(context), |
| 101 web_contents_(NULL) {} |
99 | 102 |
100 content::WebContents* WaitForGuestCreated() { | 103 content::WebContents* WaitForGuestCreated() { |
101 if (web_contents_) | 104 if (web_contents_) |
102 return web_contents_; | 105 return web_contents_; |
103 | 106 |
104 message_loop_runner_ = new content::MessageLoopRunner; | 107 message_loop_runner_ = new content::MessageLoopRunner; |
105 message_loop_runner_->Run(); | 108 message_loop_runner_->Run(); |
106 return web_contents_; | 109 return web_contents_; |
107 } | 110 } |
108 | 111 |
109 private: | 112 private: |
110 // ChromeContentBrowserClient implementation: | 113 // GuestViewManager override: |
111 virtual void GuestWebContentsAttached( | 114 virtual void AddGuest(int guest_instance_id, |
112 content::WebContents* guest_web_contents, | 115 content::WebContents* guest_web_contents) OVERRIDE{ |
113 content::WebContents* embedder_web_contents, | 116 GuestViewManager::AddGuest(guest_instance_id, guest_web_contents); |
114 const base::DictionaryValue& extra_params) OVERRIDE { | |
115 ChromeContentBrowserClient::GuestWebContentsAttached( | |
116 guest_web_contents, embedder_web_contents, extra_params); | |
117 web_contents_ = guest_web_contents; | 117 web_contents_ = guest_web_contents; |
118 | 118 |
119 if (message_loop_runner_) | 119 if (message_loop_runner_) |
120 message_loop_runner_->Quit(); | 120 message_loop_runner_->Quit(); |
121 } | 121 } |
122 | 122 |
123 content::WebContents* web_contents_; | 123 content::WebContents* web_contents_; |
124 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | 124 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
125 }; | 125 }; |
126 | 126 |
| 127 // Test factory for creating test instances of GuestViewManager. |
| 128 class TestGuestViewManagerFactory : public GuestViewManagerFactory { |
| 129 public: |
| 130 TestGuestViewManagerFactory() : |
| 131 test_guest_view_manager_(NULL) {} |
| 132 |
| 133 virtual ~TestGuestViewManagerFactory() {} |
| 134 |
| 135 virtual GuestViewManager* CreateGuestViewManager( |
| 136 content::BrowserContext* context) OVERRIDE { |
| 137 return GetManager(context); |
| 138 } |
| 139 |
| 140 TestGuestViewManager* GetManager(content::BrowserContext* context) { |
| 141 if (!test_guest_view_manager_) { |
| 142 test_guest_view_manager_ = new TestGuestViewManager(context); |
| 143 } |
| 144 return test_guest_view_manager_; |
| 145 } |
| 146 |
| 147 private: |
| 148 TestGuestViewManager* test_guest_view_manager_; |
| 149 |
| 150 DISALLOW_COPY_AND_ASSIGN(TestGuestViewManagerFactory); |
| 151 }; |
| 152 |
127 class WebContentsHiddenObserver : public content::WebContentsObserver { | 153 class WebContentsHiddenObserver : public content::WebContentsObserver { |
128 public: | 154 public: |
129 WebContentsHiddenObserver(content::WebContents* web_contents, | 155 WebContentsHiddenObserver(content::WebContents* web_contents, |
130 const base::Closure& hidden_callback) | 156 const base::Closure& hidden_callback) |
131 : WebContentsObserver(web_contents), | 157 : WebContentsObserver(web_contents), |
132 hidden_callback_(hidden_callback), | 158 hidden_callback_(hidden_callback), |
133 hidden_observed_(false) { | 159 hidden_observed_(false) { |
134 } | 160 } |
135 | 161 |
136 // WebContentsObserver. | 162 // WebContentsObserver. |
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 scoped_refptr<content::MessageLoopRunner> loop_runner( | 670 scoped_refptr<content::MessageLoopRunner> loop_runner( |
645 new content::MessageLoopRunner); | 671 new content::MessageLoopRunner); |
646 InterstitialObserver observer(web_contents, | 672 InterstitialObserver observer(web_contents, |
647 loop_runner->QuitClosure(), | 673 loop_runner->QuitClosure(), |
648 base::Closure()); | 674 base::Closure()); |
649 if (!content::InterstitialPage::GetInterstitialPage(web_contents)) | 675 if (!content::InterstitialPage::GetInterstitialPage(web_contents)) |
650 loop_runner->Run(); | 676 loop_runner->Run(); |
651 } | 677 } |
652 | 678 |
653 void LoadAppWithGuest(const std::string& app_path) { | 679 void LoadAppWithGuest(const std::string& app_path) { |
654 GuestContentBrowserClient new_client; | |
655 content::ContentBrowserClient* old_client = | |
656 SetBrowserClientForTesting(&new_client); | |
657 | 680 |
658 ExtensionTestMessageListener launched_listener("WebViewTest.LAUNCHED", | 681 ExtensionTestMessageListener launched_listener("WebViewTest.LAUNCHED", |
659 false); | 682 false); |
660 launched_listener.set_failure_message("WebViewTest.FAILURE"); | 683 launched_listener.set_failure_message("WebViewTest.FAILURE"); |
661 LoadAndLaunchPlatformApp(app_path.c_str(), &launched_listener); | 684 LoadAndLaunchPlatformApp(app_path.c_str(), &launched_listener); |
662 | 685 |
663 guest_web_contents_ = new_client.WaitForGuestCreated(); | 686 guest_web_contents_ = GetGuestViewManager()->WaitForGuestCreated(); |
664 SetBrowserClientForTesting(old_client); | |
665 } | 687 } |
666 | 688 |
667 void SendMessageToEmbedder(const std::string& message) { | 689 void SendMessageToEmbedder(const std::string& message) { |
668 EXPECT_TRUE( | 690 EXPECT_TRUE( |
669 content::ExecuteScript( | 691 content::ExecuteScript( |
670 GetEmbedderWebContents(), | 692 GetEmbedderWebContents(), |
671 base::StringPrintf("onAppCommand('%s');", message.c_str()))); | 693 base::StringPrintf("onAppCommand('%s');", message.c_str()))); |
672 } | 694 } |
673 | 695 |
674 void SendMessageToGuestAndWait(const std::string& message, | 696 void SendMessageToGuestAndWait(const std::string& message, |
(...skipping 17 matching lines...) Expand all Loading... |
692 return guest_web_contents_; | 714 return guest_web_contents_; |
693 } | 715 } |
694 | 716 |
695 content::WebContents* GetEmbedderWebContents() { | 717 content::WebContents* GetEmbedderWebContents() { |
696 if (!embedder_web_contents_) { | 718 if (!embedder_web_contents_) { |
697 embedder_web_contents_ = GetFirstAppWindowWebContents(); | 719 embedder_web_contents_ = GetFirstAppWindowWebContents(); |
698 } | 720 } |
699 return embedder_web_contents_; | 721 return embedder_web_contents_; |
700 } | 722 } |
701 | 723 |
| 724 TestGuestViewManager* GetGuestViewManager() { |
| 725 return factory_.GetManager(browser()->profile()); |
| 726 } |
| 727 |
702 WebViewTest() : guest_web_contents_(NULL), | 728 WebViewTest() : guest_web_contents_(NULL), |
703 embedder_web_contents_(NULL) { | 729 embedder_web_contents_(NULL) { |
| 730 GuestViewManager::set_factory_for_testing(&factory_); |
704 } | 731 } |
705 | 732 |
706 private: | 733 private: |
707 bool UsesFakeSpeech() { | 734 bool UsesFakeSpeech() { |
708 const testing::TestInfo* const test_info = | 735 const testing::TestInfo* const test_info = |
709 testing::UnitTest::GetInstance()->current_test_info(); | 736 testing::UnitTest::GetInstance()->current_test_info(); |
710 | 737 |
711 // SpeechRecognition test specific SetUp. | 738 // SpeechRecognition test specific SetUp. |
712 return !strcmp(test_info->name(), | 739 return !strcmp(test_info->name(), |
713 "SpeechRecognitionAPI_HasPermissionAllow"); | 740 "SpeechRecognitionAPI_HasPermissionAllow"); |
714 } | 741 } |
715 | 742 |
716 scoped_ptr<content::FakeSpeechRecognitionManager> | 743 scoped_ptr<content::FakeSpeechRecognitionManager> |
717 fake_speech_recognition_manager_; | 744 fake_speech_recognition_manager_; |
718 | 745 |
| 746 TestGuestViewManagerFactory factory_; |
719 // Note that these are only set if you launch app using LoadAppWithGuest(). | 747 // Note that these are only set if you launch app using LoadAppWithGuest(). |
720 content::WebContents* guest_web_contents_; | 748 content::WebContents* guest_web_contents_; |
721 content::WebContents* embedder_web_contents_; | 749 content::WebContents* embedder_web_contents_; |
722 }; | 750 }; |
723 | 751 |
724 // This test verifies that hiding the guest triggers WebContents::WasHidden(). | 752 // This test verifies that hiding the guest triggers WebContents::WasHidden(). |
725 IN_PROC_BROWSER_TEST_F(WebViewTest, GuestVisibilityChanged) { | 753 IN_PROC_BROWSER_TEST_F(WebViewTest, GuestVisibilityChanged) { |
726 LoadAppWithGuest("web_view/visibility_changed"); | 754 LoadAppWithGuest("web_view/visibility_changed"); |
727 | 755 |
728 scoped_refptr<content::MessageLoopRunner> loop_runner( | 756 scoped_refptr<content::MessageLoopRunner> loop_runner( |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1174 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME; | 1202 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME; |
1175 net::SpawnedTestServer https_server( | 1203 net::SpawnedTestServer https_server( |
1176 net::SpawnedTestServer::TYPE_HTTPS, ssl_options, | 1204 net::SpawnedTestServer::TYPE_HTTPS, ssl_options, |
1177 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 1205 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); |
1178 ASSERT_TRUE(https_server.Start()); | 1206 ASSERT_TRUE(https_server.Start()); |
1179 | 1207 |
1180 net::HostPortPair host_and_port = https_server.host_port_pair(); | 1208 net::HostPortPair host_and_port = https_server.host_port_pair(); |
1181 | 1209 |
1182 LoadAndLaunchPlatformApp("web_view/interstitial_teardown", "EmbedderLoaded"); | 1210 LoadAndLaunchPlatformApp("web_view/interstitial_teardown", "EmbedderLoaded"); |
1183 | 1211 |
1184 GuestContentBrowserClient new_client; | |
1185 content::ContentBrowserClient* old_client = | |
1186 SetBrowserClientForTesting(&new_client); | |
1187 | |
1188 // Now load the guest. | 1212 // Now load the guest. |
1189 content::WebContents* embedder_web_contents = GetFirstAppWindowWebContents(); | 1213 content::WebContents* embedder_web_contents = GetFirstAppWindowWebContents(); |
1190 ExtensionTestMessageListener second("GuestAddedToDom", false); | 1214 ExtensionTestMessageListener second("GuestAddedToDom", false); |
1191 EXPECT_TRUE(content::ExecuteScript( | 1215 EXPECT_TRUE(content::ExecuteScript( |
1192 embedder_web_contents, | 1216 embedder_web_contents, |
1193 base::StringPrintf("loadGuest(%d);\n", host_and_port.port()))); | 1217 base::StringPrintf("loadGuest(%d);\n", host_and_port.port()))); |
1194 ASSERT_TRUE(second.WaitUntilSatisfied()); | 1218 ASSERT_TRUE(second.WaitUntilSatisfied()); |
1195 | 1219 |
1196 // Wait for interstitial page to be shown in guest. | 1220 // Wait for interstitial page to be shown in guest. |
1197 content::WebContents* guest_web_contents = new_client.WaitForGuestCreated(); | 1221 content::WebContents* guest_web_contents = |
1198 SetBrowserClientForTesting(old_client); | 1222 GetGuestViewManager()->WaitForGuestCreated(); |
1199 ASSERT_TRUE(guest_web_contents->GetRenderProcessHost()->IsIsolatedGuest()); | 1223 ASSERT_TRUE(guest_web_contents->GetRenderProcessHost()->IsIsolatedGuest()); |
1200 WaitForInterstitial(guest_web_contents); | 1224 WaitForInterstitial(guest_web_contents); |
1201 | 1225 |
1202 // Now close the app while interstitial page being shown in guest. | 1226 // Now close the app while interstitial page being shown in guest. |
1203 apps::AppWindow* window = GetFirstAppWindow(); | 1227 apps::AppWindow* window = GetFirstAppWindow(); |
1204 window->GetBaseWindow()->Close(); | 1228 window->GetBaseWindow()->Close(); |
1205 } | 1229 } |
1206 | 1230 |
1207 IN_PROC_BROWSER_TEST_F(WebViewTest, ShimSrcAttribute) { | 1231 IN_PROC_BROWSER_TEST_F(WebViewTest, ShimSrcAttribute) { |
1208 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/src_attribute")) | 1232 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/src_attribute")) |
(...skipping 955 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2164 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestFindAPI_findupdate) { | 2188 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestFindAPI_findupdate) { |
2165 TestHelper("testFindAPI_findupdate", "web_view/shim", NO_TEST_SERVER); | 2189 TestHelper("testFindAPI_findupdate", "web_view/shim", NO_TEST_SERVER); |
2166 } | 2190 } |
2167 | 2191 |
2168 // <webview> screenshot capture fails with ubercomp. | 2192 // <webview> screenshot capture fails with ubercomp. |
2169 // See http://crbug.com/327035. | 2193 // See http://crbug.com/327035. |
2170 IN_PROC_BROWSER_TEST_F(WebViewCaptureTest, | 2194 IN_PROC_BROWSER_TEST_F(WebViewCaptureTest, |
2171 DISABLED_Shim_ScreenshotCapture) { | 2195 DISABLED_Shim_ScreenshotCapture) { |
2172 TestHelper("testScreenshotCapture", "web_view/shim", NO_TEST_SERVER); | 2196 TestHelper("testScreenshotCapture", "web_view/shim", NO_TEST_SERVER); |
2173 } | 2197 } |
OLD | NEW |