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/memory/singleton.h" | |
lazyboy
2014/06/13 17:40:01
Do you need this?
Fady Samuel
2014/06/16 14:35:40
No removed.
| |
6 #include "base/path_service.h" | 7 #include "base/path_service.h" |
7 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
8 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
10 #include "chrome/browser/apps/app_browsertest_util.h" | 11 #include "chrome/browser/apps/app_browsertest_util.h" |
11 #include "chrome/browser/chrome_content_browser_client.h" | 12 #include "chrome/browser/chrome_content_browser_client.h" |
12 #include "chrome/browser/extensions/extension_test_message_listener.h" | 13 #include "chrome/browser/extensions/extension_test_message_listener.h" |
14 #include "chrome/browser/guest_view/guest_view_manager.h" | |
15 #include "chrome/browser/guest_view/guest_view_manager_factory.h" | |
13 #include "chrome/browser/prerender/prerender_link_manager.h" | 16 #include "chrome/browser/prerender/prerender_link_manager.h" |
14 #include "chrome/browser/prerender/prerender_link_manager_factory.h" | 17 #include "chrome/browser/prerender/prerender_link_manager_factory.h" |
15 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" | 19 #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" | 20 #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" | 21 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" |
19 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
20 #include "chrome/browser/ui/browser_dialogs.h" | 23 #include "chrome/browser/ui/browser_dialogs.h" |
21 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 24 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
22 #include "chrome/test/base/ui_test_utils.h" | 25 #include "chrome/test/base/ui_test_utils.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 }; | 88 }; |
86 | 89 |
87 class TestInterstitialPageDelegate : public content::InterstitialPageDelegate { | 90 class TestInterstitialPageDelegate : public content::InterstitialPageDelegate { |
88 public: | 91 public: |
89 TestInterstitialPageDelegate() { | 92 TestInterstitialPageDelegate() { |
90 } | 93 } |
91 virtual ~TestInterstitialPageDelegate() {} | 94 virtual ~TestInterstitialPageDelegate() {} |
92 virtual std::string GetHTMLContents() OVERRIDE { return std::string(); } | 95 virtual std::string GetHTMLContents() OVERRIDE { return std::string(); } |
93 }; | 96 }; |
94 | 97 |
95 // Used to get notified when a guest is created. | 98 class TestGuestViewManager : public GuestViewManager { |
96 class GuestContentBrowserClient : public chrome::ChromeContentBrowserClient { | |
97 public: | 99 public: |
98 GuestContentBrowserClient() : web_contents_(NULL) {} | 100 explicit TestGuestViewManager(content::BrowserContext* context) : |
101 GuestViewManager(context), | |
102 web_contents_(NULL) {} | |
99 | 103 |
100 content::WebContents* WaitForGuestCreated() { | 104 content::WebContents* WaitForGuestCreated() { |
101 if (web_contents_) | 105 if (web_contents_) |
102 return web_contents_; | 106 return web_contents_; |
103 | 107 |
104 message_loop_runner_ = new content::MessageLoopRunner; | 108 message_loop_runner_ = new content::MessageLoopRunner; |
105 message_loop_runner_->Run(); | 109 message_loop_runner_->Run(); |
106 return web_contents_; | 110 return web_contents_; |
107 } | 111 } |
108 | 112 |
109 private: | 113 private: |
110 // ChromeContentBrowserClient implementation: | 114 // GuestViewManager override: |
111 virtual void GuestWebContentsAttached( | 115 virtual void AddGuest(int guest_instance_id, |
112 content::WebContents* guest_web_contents, | 116 content::WebContents* guest_web_contents) OVERRIDE{ |
113 content::WebContents* embedder_web_contents, | 117 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; | 118 web_contents_ = guest_web_contents; |
118 | 119 |
119 if (message_loop_runner_) | 120 if (message_loop_runner_) |
120 message_loop_runner_->Quit(); | 121 message_loop_runner_->Quit(); |
121 } | 122 } |
122 | 123 |
123 content::WebContents* web_contents_; | 124 content::WebContents* web_contents_; |
124 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | 125 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
125 }; | 126 }; |
126 | 127 |
128 // Test factory for creating test instances of GuestViewManager. | |
129 class TestGuestViewManagerFactory : public GuestViewManagerFactory { | |
130 public: | |
131 TestGuestViewManagerFactory() : | |
132 test_guest_view_manager_(NULL) {} | |
133 | |
134 virtual ~TestGuestViewManagerFactory() {} | |
135 | |
136 virtual GuestViewManager* CreateGuestViewManager( | |
137 content::BrowserContext* context) OVERRIDE { | |
138 return GetManager(context); | |
139 } | |
140 | |
141 TestGuestViewManager* GetManager(content::BrowserContext* context) { | |
142 if (!test_guest_view_manager_) { | |
143 test_guest_view_manager_ = new TestGuestViewManager(context); | |
144 } | |
145 return test_guest_view_manager_; | |
146 } | |
147 | |
148 private: | |
149 TestGuestViewManager* test_guest_view_manager_; | |
150 | |
151 DISALLOW_COPY_AND_ASSIGN(TestGuestViewManagerFactory); | |
152 }; | |
153 | |
127 class WebContentsHiddenObserver : public content::WebContentsObserver { | 154 class WebContentsHiddenObserver : public content::WebContentsObserver { |
128 public: | 155 public: |
129 WebContentsHiddenObserver(content::WebContents* web_contents, | 156 WebContentsHiddenObserver(content::WebContents* web_contents, |
130 const base::Closure& hidden_callback) | 157 const base::Closure& hidden_callback) |
131 : WebContentsObserver(web_contents), | 158 : WebContentsObserver(web_contents), |
132 hidden_callback_(hidden_callback), | 159 hidden_callback_(hidden_callback), |
133 hidden_observed_(false) { | 160 hidden_observed_(false) { |
134 } | 161 } |
135 | 162 |
136 // WebContentsObserver. | 163 // WebContentsObserver. |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
656 scoped_refptr<content::MessageLoopRunner> loop_runner( | 683 scoped_refptr<content::MessageLoopRunner> loop_runner( |
657 new content::MessageLoopRunner); | 684 new content::MessageLoopRunner); |
658 InterstitialObserver observer(web_contents, | 685 InterstitialObserver observer(web_contents, |
659 loop_runner->QuitClosure(), | 686 loop_runner->QuitClosure(), |
660 base::Closure()); | 687 base::Closure()); |
661 if (!content::InterstitialPage::GetInterstitialPage(web_contents)) | 688 if (!content::InterstitialPage::GetInterstitialPage(web_contents)) |
662 loop_runner->Run(); | 689 loop_runner->Run(); |
663 } | 690 } |
664 | 691 |
665 void LoadAppWithGuest(const std::string& app_path) { | 692 void LoadAppWithGuest(const std::string& app_path) { |
666 GuestContentBrowserClient new_client; | |
667 content::ContentBrowserClient* old_client = | |
668 SetBrowserClientForTesting(&new_client); | |
669 | 693 |
670 ExtensionTestMessageListener launched_listener("WebViewTest.LAUNCHED", | 694 ExtensionTestMessageListener launched_listener("WebViewTest.LAUNCHED", |
671 false); | 695 false); |
672 launched_listener.set_failure_message("WebViewTest.FAILURE"); | 696 launched_listener.set_failure_message("WebViewTest.FAILURE"); |
673 LoadAndLaunchPlatformApp(app_path.c_str()); | 697 LoadAndLaunchPlatformApp(app_path.c_str()); |
674 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 698 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
675 | 699 |
676 guest_web_contents_ = new_client.WaitForGuestCreated(); | 700 guest_web_contents_ = GetGuestViewManager()->WaitForGuestCreated(); |
677 SetBrowserClientForTesting(old_client); | |
678 } | 701 } |
679 | 702 |
680 void SendMessageToEmbedder(const std::string& message) { | 703 void SendMessageToEmbedder(const std::string& message) { |
681 EXPECT_TRUE( | 704 EXPECT_TRUE( |
682 content::ExecuteScript( | 705 content::ExecuteScript( |
683 GetEmbedderWebContents(), | 706 GetEmbedderWebContents(), |
684 base::StringPrintf("onAppCommand('%s');", message.c_str()))); | 707 base::StringPrintf("onAppCommand('%s');", message.c_str()))); |
685 } | 708 } |
686 | 709 |
687 void SendMessageToGuestAndWait(const std::string& message, | 710 void SendMessageToGuestAndWait(const std::string& message, |
(...skipping 17 matching lines...) Expand all Loading... | |
705 return guest_web_contents_; | 728 return guest_web_contents_; |
706 } | 729 } |
707 | 730 |
708 content::WebContents* GetEmbedderWebContents() { | 731 content::WebContents* GetEmbedderWebContents() { |
709 if (!embedder_web_contents_) { | 732 if (!embedder_web_contents_) { |
710 embedder_web_contents_ = GetFirstAppWindowWebContents(); | 733 embedder_web_contents_ = GetFirstAppWindowWebContents(); |
711 } | 734 } |
712 return embedder_web_contents_; | 735 return embedder_web_contents_; |
713 } | 736 } |
714 | 737 |
738 TestGuestViewManager* GetGuestViewManager() { | |
739 return factory_.GetManager(browser()->profile()); | |
740 } | |
741 | |
715 WebViewTest() : guest_web_contents_(NULL), | 742 WebViewTest() : guest_web_contents_(NULL), |
716 embedder_web_contents_(NULL) { | 743 embedder_web_contents_(NULL) { |
744 GuestViewManager::set_factory_for_testing(&factory_); | |
717 } | 745 } |
718 | 746 |
719 private: | 747 private: |
720 bool UsesFakeSpeech() { | 748 bool UsesFakeSpeech() { |
721 const testing::TestInfo* const test_info = | 749 const testing::TestInfo* const test_info = |
722 testing::UnitTest::GetInstance()->current_test_info(); | 750 testing::UnitTest::GetInstance()->current_test_info(); |
723 | 751 |
724 // SpeechRecognition test specific SetUp. | 752 // SpeechRecognition test specific SetUp. |
725 return !strcmp(test_info->name(), | 753 return !strcmp(test_info->name(), |
726 "SpeechRecognitionAPI_HasPermissionAllow"); | 754 "SpeechRecognitionAPI_HasPermissionAllow"); |
727 } | 755 } |
728 | 756 |
729 scoped_ptr<content::FakeSpeechRecognitionManager> | 757 scoped_ptr<content::FakeSpeechRecognitionManager> |
730 fake_speech_recognition_manager_; | 758 fake_speech_recognition_manager_; |
731 | 759 |
760 TestGuestViewManagerFactory factory_; | |
732 // Note that these are only set if you launch app using LoadAppWithGuest(). | 761 // Note that these are only set if you launch app using LoadAppWithGuest(). |
733 content::WebContents* guest_web_contents_; | 762 content::WebContents* guest_web_contents_; |
734 content::WebContents* embedder_web_contents_; | 763 content::WebContents* embedder_web_contents_; |
735 }; | 764 }; |
736 | 765 |
737 // This test verifies that hiding the guest triggers WebContents::WasHidden(). | 766 // This test verifies that hiding the guest triggers WebContents::WasHidden(). |
738 IN_PROC_BROWSER_TEST_F(WebViewTest, GuestVisibilityChanged) { | 767 IN_PROC_BROWSER_TEST_F(WebViewTest, GuestVisibilityChanged) { |
739 LoadAppWithGuest("web_view/visibility_changed"); | 768 LoadAppWithGuest("web_view/visibility_changed"); |
740 | 769 |
741 scoped_refptr<content::MessageLoopRunner> loop_runner( | 770 scoped_refptr<content::MessageLoopRunner> loop_runner( |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1202 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 1231 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); |
1203 ASSERT_TRUE(https_server.Start()); | 1232 ASSERT_TRUE(https_server.Start()); |
1204 | 1233 |
1205 net::HostPortPair host_and_port = https_server.host_port_pair(); | 1234 net::HostPortPair host_and_port = https_server.host_port_pair(); |
1206 | 1235 |
1207 ExtensionTestMessageListener embedder_loaded_listener("EmbedderLoaded", | 1236 ExtensionTestMessageListener embedder_loaded_listener("EmbedderLoaded", |
1208 false); | 1237 false); |
1209 LoadAndLaunchPlatformApp("web_view/interstitial_teardown"); | 1238 LoadAndLaunchPlatformApp("web_view/interstitial_teardown"); |
1210 ASSERT_TRUE(embedder_loaded_listener.WaitUntilSatisfied()); | 1239 ASSERT_TRUE(embedder_loaded_listener.WaitUntilSatisfied()); |
1211 | 1240 |
1212 GuestContentBrowserClient new_client; | |
1213 content::ContentBrowserClient* old_client = | |
1214 SetBrowserClientForTesting(&new_client); | |
1215 | |
1216 // Now load the guest. | 1241 // Now load the guest. |
1217 content::WebContents* embedder_web_contents = GetFirstAppWindowWebContents(); | 1242 content::WebContents* embedder_web_contents = GetFirstAppWindowWebContents(); |
1218 ExtensionTestMessageListener second("GuestAddedToDom", false); | 1243 ExtensionTestMessageListener second("GuestAddedToDom", false); |
1219 EXPECT_TRUE(content::ExecuteScript( | 1244 EXPECT_TRUE(content::ExecuteScript( |
1220 embedder_web_contents, | 1245 embedder_web_contents, |
1221 base::StringPrintf("loadGuest(%d);\n", host_and_port.port()))); | 1246 base::StringPrintf("loadGuest(%d);\n", host_and_port.port()))); |
1222 ASSERT_TRUE(second.WaitUntilSatisfied()); | 1247 ASSERT_TRUE(second.WaitUntilSatisfied()); |
1223 | 1248 |
1224 // Wait for interstitial page to be shown in guest. | 1249 // Wait for interstitial page to be shown in guest. |
1225 content::WebContents* guest_web_contents = new_client.WaitForGuestCreated(); | 1250 content::WebContents* guest_web_contents = |
1226 SetBrowserClientForTesting(old_client); | 1251 GetGuestViewManager()->WaitForGuestCreated(); |
1227 ASSERT_TRUE(guest_web_contents->GetRenderProcessHost()->IsIsolatedGuest()); | 1252 ASSERT_TRUE(guest_web_contents->GetRenderProcessHost()->IsIsolatedGuest()); |
1228 WaitForInterstitial(guest_web_contents); | 1253 WaitForInterstitial(guest_web_contents); |
1229 | 1254 |
1230 // Now close the app while interstitial page being shown in guest. | 1255 // Now close the app while interstitial page being shown in guest. |
1231 apps::AppWindow* window = GetFirstAppWindow(); | 1256 apps::AppWindow* window = GetFirstAppWindow(); |
1232 window->GetBaseWindow()->Close(); | 1257 window->GetBaseWindow()->Close(); |
1233 } | 1258 } |
1234 | 1259 |
1235 IN_PROC_BROWSER_TEST_F(WebViewTest, ShimSrcAttribute) { | 1260 IN_PROC_BROWSER_TEST_F(WebViewTest, ShimSrcAttribute) { |
1236 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/src_attribute")) | 1261 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/src_attribute")) |
(...skipping 964 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2201 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestFindAPI_findupdate) { | 2226 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestFindAPI_findupdate) { |
2202 TestHelper("testFindAPI_findupdate", "web_view/shim", NO_TEST_SERVER); | 2227 TestHelper("testFindAPI_findupdate", "web_view/shim", NO_TEST_SERVER); |
2203 } | 2228 } |
2204 | 2229 |
2205 // <webview> screenshot capture fails with ubercomp. | 2230 // <webview> screenshot capture fails with ubercomp. |
2206 // See http://crbug.com/327035. | 2231 // See http://crbug.com/327035. |
2207 IN_PROC_BROWSER_TEST_F(WebViewCaptureTest, | 2232 IN_PROC_BROWSER_TEST_F(WebViewCaptureTest, |
2208 DISABLED_Shim_ScreenshotCapture) { | 2233 DISABLED_Shim_ScreenshotCapture) { |
2209 TestHelper("testScreenshotCapture", "web_view/shim", NO_TEST_SERVER); | 2234 TestHelper("testScreenshotCapture", "web_view/shim", NO_TEST_SERVER); |
2210 } | 2235 } |
OLD | NEW |