| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/memory/singleton.h" | 6 #include "base/memory/singleton.h" |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "base/strings/string_split.h" | 8 #include "base/strings/string_split.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/test/test_timeouts.h" | 11 #include "base/test/test_timeouts.h" |
| 12 #include "content/browser/browser_plugin/browser_plugin_embedder.h" | 12 #include "content/browser/browser_plugin/browser_plugin_embedder.h" |
| 13 #include "content/browser/browser_plugin/browser_plugin_guest.h" | 13 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
| 14 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" | 14 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" |
| 15 #include "content/browser/browser_plugin/test_browser_plugin_guest.h" | 15 #include "content/browser/browser_plugin/test_browser_plugin_guest.h" |
| 16 #include "content/browser/browser_plugin/test_browser_plugin_guest_delegate.h" | 16 #include "content/browser/browser_plugin/test_browser_plugin_guest_delegate.h" |
| 17 #include "content/browser/browser_plugin/test_browser_plugin_guest_manager.h" | |
| 18 #include "content/browser/browser_plugin/test_guest_manager_delegate.h" | 17 #include "content/browser/browser_plugin/test_guest_manager_delegate.h" |
| 19 #include "content/browser/child_process_security_policy_impl.h" | 18 #include "content/browser/child_process_security_policy_impl.h" |
| 20 #include "content/browser/frame_host/render_frame_host_impl.h" | 19 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 21 #include "content/browser/frame_host/render_widget_host_view_guest.h" | 20 #include "content/browser/frame_host/render_widget_host_view_guest.h" |
| 22 #include "content/browser/renderer_host/render_view_host_impl.h" | 21 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 23 #include "content/browser/web_contents/web_contents_impl.h" | 22 #include "content/browser/web_contents/web_contents_impl.h" |
| 24 #include "content/common/browser_plugin/browser_plugin_messages.h" | 23 #include "content/common/browser_plugin/browser_plugin_messages.h" |
| 25 #include "content/common/view_messages.h" | 24 #include "content/common/view_messages.h" |
| 26 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
| 27 #include "content/public/browser/notification_types.h" | 26 #include "content/public/browser/notification_types.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 } | 95 } |
| 97 | 96 |
| 98 private: | 97 private: |
| 99 DISALLOW_COPY_AND_ASSIGN(TestBrowserPluginEmbedder); | 98 DISALLOW_COPY_AND_ASSIGN(TestBrowserPluginEmbedder); |
| 100 }; | 99 }; |
| 101 | 100 |
| 102 // Test factory for creating test instances of BrowserPluginEmbedder and | 101 // Test factory for creating test instances of BrowserPluginEmbedder and |
| 103 // BrowserPluginGuest. | 102 // BrowserPluginGuest. |
| 104 class TestBrowserPluginHostFactory : public BrowserPluginHostFactory { | 103 class TestBrowserPluginHostFactory : public BrowserPluginHostFactory { |
| 105 public: | 104 public: |
| 106 virtual BrowserPluginGuestManager* | |
| 107 CreateBrowserPluginGuestManager(BrowserContext* context) OVERRIDE { | |
| 108 guest_manager_instance_count_++; | |
| 109 if (message_loop_runner_) | |
| 110 message_loop_runner_->Quit(); | |
| 111 return new TestBrowserPluginGuestManager(context); | |
| 112 } | |
| 113 | |
| 114 virtual BrowserPluginGuest* CreateBrowserPluginGuest( | 105 virtual BrowserPluginGuest* CreateBrowserPluginGuest( |
| 115 int instance_id, | 106 int instance_id, |
| 116 WebContentsImpl* web_contents) OVERRIDE { | 107 WebContentsImpl* web_contents) OVERRIDE { |
| 117 return new TestBrowserPluginGuest(instance_id, web_contents); | 108 return new TestBrowserPluginGuest(instance_id, web_contents); |
| 118 } | 109 } |
| 119 | 110 |
| 120 // Also keeps track of number of instances created. | 111 // Also keeps track of number of instances created. |
| 121 virtual BrowserPluginEmbedder* CreateBrowserPluginEmbedder( | 112 virtual BrowserPluginEmbedder* CreateBrowserPluginEmbedder( |
| 122 WebContentsImpl* web_contents) OVERRIDE { | 113 WebContentsImpl* web_contents) OVERRIDE { |
| 123 | 114 |
| 124 return new TestBrowserPluginEmbedder(web_contents); | 115 return new TestBrowserPluginEmbedder(web_contents); |
| 125 } | 116 } |
| 126 | 117 |
| 127 // Singleton getter. | 118 // Singleton getter. |
| 128 static TestBrowserPluginHostFactory* GetInstance() { | 119 static TestBrowserPluginHostFactory* GetInstance() { |
| 129 return Singleton<TestBrowserPluginHostFactory>::get(); | 120 return Singleton<TestBrowserPluginHostFactory>::get(); |
| 130 } | 121 } |
| 131 | 122 |
| 132 // Waits for at least one embedder to be created in the test. Returns true if | |
| 133 // we have a guest, false if waiting times out. | |
| 134 void WaitForGuestManagerCreation() { | |
| 135 // Check if already have created an instance. | |
| 136 if (guest_manager_instance_count_ > 0) | |
| 137 return; | |
| 138 // Wait otherwise. | |
| 139 message_loop_runner_ = new MessageLoopRunner(); | |
| 140 message_loop_runner_->Run(); | |
| 141 } | |
| 142 | |
| 143 protected: | 123 protected: |
| 144 TestBrowserPluginHostFactory() : guest_manager_instance_count_(0) {} | 124 TestBrowserPluginHostFactory() {} |
| 145 virtual ~TestBrowserPluginHostFactory() {} | 125 virtual ~TestBrowserPluginHostFactory() {} |
| 146 | 126 |
| 147 private: | 127 private: |
| 148 // For Singleton. | 128 // For Singleton. |
| 149 friend struct DefaultSingletonTraits<TestBrowserPluginHostFactory>; | 129 friend struct DefaultSingletonTraits<TestBrowserPluginHostFactory>; |
| 150 | 130 |
| 151 scoped_refptr<MessageLoopRunner> message_loop_runner_; | 131 scoped_refptr<MessageLoopRunner> message_loop_runner_; |
| 152 int guest_manager_instance_count_; | |
| 153 | 132 |
| 154 DISALLOW_COPY_AND_ASSIGN(TestBrowserPluginHostFactory); | 133 DISALLOW_COPY_AND_ASSIGN(TestBrowserPluginHostFactory); |
| 155 }; | 134 }; |
| 156 | 135 |
| 157 // Test factory class for browser plugin that creates guests with short hang | 136 // Test factory class for browser plugin that creates guests with short hang |
| 158 // timeout. | 137 // timeout. |
| 159 class TestShortHangTimeoutGuestFactory : public TestBrowserPluginHostFactory { | 138 class TestShortHangTimeoutGuestFactory : public TestBrowserPluginHostFactory { |
| 160 public: | 139 public: |
| 161 virtual BrowserPluginGuest* CreateBrowserPluginGuest( | 140 virtual BrowserPluginGuest* CreateBrowserPluginGuest( |
| 162 int instance_id, WebContentsImpl* web_contents) OVERRIDE { | 141 int instance_id, WebContentsImpl* web_contents) OVERRIDE { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 : test_embedder_(NULL), | 208 : test_embedder_(NULL), |
| 230 test_guest_(NULL), | 209 test_guest_(NULL), |
| 231 test_guest_manager_(NULL) {} | 210 test_guest_manager_(NULL) {} |
| 232 | 211 |
| 233 virtual void SetUp() OVERRIDE { | 212 virtual void SetUp() OVERRIDE { |
| 234 // Override factory to create tests instances of BrowserPlugin*. | 213 // Override factory to create tests instances of BrowserPlugin*. |
| 235 BrowserPluginEmbedder::set_factory_for_testing( | 214 BrowserPluginEmbedder::set_factory_for_testing( |
| 236 TestBrowserPluginHostFactory::GetInstance()); | 215 TestBrowserPluginHostFactory::GetInstance()); |
| 237 BrowserPluginGuest::set_factory_for_testing( | 216 BrowserPluginGuest::set_factory_for_testing( |
| 238 TestBrowserPluginHostFactory::GetInstance()); | 217 TestBrowserPluginHostFactory::GetInstance()); |
| 239 BrowserPluginGuestManager::set_factory_for_testing( | |
| 240 TestBrowserPluginHostFactory::GetInstance()); | |
| 241 ContentBrowserTest::SetUp(); | 218 ContentBrowserTest::SetUp(); |
| 242 } | 219 } |
| 243 virtual void TearDown() OVERRIDE { | 220 virtual void TearDown() OVERRIDE { |
| 244 BrowserPluginEmbedder::set_factory_for_testing(NULL); | 221 BrowserPluginEmbedder::set_factory_for_testing(NULL); |
| 245 BrowserPluginGuest::set_factory_for_testing(NULL); | 222 BrowserPluginGuest::set_factory_for_testing(NULL); |
| 246 | 223 |
| 247 ContentBrowserTest::TearDown(); | 224 ContentBrowserTest::TearDown(); |
| 248 } | 225 } |
| 249 | 226 |
| 250 static void SimulateSpaceKeyPress(WebContents* web_contents) { | 227 static void SimulateSpaceKeyPress(WebContents* web_contents) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 | 283 |
| 307 if (!is_guest_data_url) { | 284 if (!is_guest_data_url) { |
| 308 test_url = embedded_test_server()->GetURL(guest_url); | 285 test_url = embedded_test_server()->GetURL(guest_url); |
| 309 ExecuteSyncJSFunction( | 286 ExecuteSyncJSFunction( |
| 310 rfh, base::StringPrintf("SetSrc('%s');", test_url.spec().c_str())); | 287 rfh, base::StringPrintf("SetSrc('%s');", test_url.spec().c_str())); |
| 311 } else { | 288 } else { |
| 312 ExecuteSyncJSFunction( | 289 ExecuteSyncJSFunction( |
| 313 rfh, base::StringPrintf("SetSrc('%s');", guest_url.c_str())); | 290 rfh, base::StringPrintf("SetSrc('%s');", guest_url.c_str())); |
| 314 } | 291 } |
| 315 | 292 |
| 316 // Wait to make sure embedder is created/attached to WebContents. | |
| 317 TestBrowserPluginHostFactory::GetInstance()->WaitForGuestManagerCreation(); | |
| 318 | |
| 319 test_embedder_ = static_cast<TestBrowserPluginEmbedder*>( | 293 test_embedder_ = static_cast<TestBrowserPluginEmbedder*>( |
| 320 embedder_web_contents->GetBrowserPluginEmbedder()); | 294 embedder_web_contents->GetBrowserPluginEmbedder()); |
| 321 ASSERT_TRUE(test_embedder_); | 295 ASSERT_TRUE(test_embedder_); |
| 322 | 296 |
| 323 test_guest_manager_ = static_cast<TestBrowserPluginGuestManager*>( | 297 test_guest_manager_ = |
| 324 BrowserPluginGuestManager::FromBrowserContext( | 298 static_cast<TestGuestManagerDelegate*>( |
| 325 test_embedder_->GetWebContents()->GetBrowserContext())); | 299 embedder_web_contents->GetBrowserContext()-> |
| 326 ASSERT_TRUE(test_guest_manager_); | 300 GetGuestManagerDelegate()); |
| 327 | 301 |
| 328 WebContentsImpl* test_guest_web_contents = static_cast<WebContentsImpl*>( | 302 WebContentsImpl* test_guest_web_contents = |
| 329 test_guest_manager_->WaitForGuestAdded()); | 303 test_guest_manager_->WaitForGuestAdded(); |
| 330 | 304 |
| 331 test_guest_ = static_cast<TestBrowserPluginGuest*>( | 305 test_guest_ = static_cast<TestBrowserPluginGuest*>( |
| 332 test_guest_web_contents->GetBrowserPluginGuest()); | 306 test_guest_web_contents->GetBrowserPluginGuest()); |
| 333 test_guest_->WaitForLoadStop(); | 307 test_guest_->WaitForLoadStop(); |
| 334 } | 308 } |
| 335 | 309 |
| 336 TestBrowserPluginEmbedder* test_embedder() const { return test_embedder_; } | 310 TestBrowserPluginEmbedder* test_embedder() const { return test_embedder_; } |
| 337 TestBrowserPluginGuest* test_guest() const { return test_guest_; } | 311 TestBrowserPluginGuest* test_guest() const { return test_guest_; } |
| 338 TestBrowserPluginGuestManager* test_guest_manager() const { | 312 TestGuestManagerDelegate* test_guest_manager() const { |
| 339 return test_guest_manager_; | 313 return test_guest_manager_; |
| 340 } | 314 } |
| 341 | 315 |
| 342 private: | 316 private: |
| 343 TestBrowserPluginEmbedder* test_embedder_; | 317 TestBrowserPluginEmbedder* test_embedder_; |
| 344 TestBrowserPluginGuest* test_guest_; | 318 TestBrowserPluginGuest* test_guest_; |
| 345 TestBrowserPluginGuestManager* test_guest_manager_; | 319 TestGuestManagerDelegate* test_guest_manager_; |
| 346 DISALLOW_COPY_AND_ASSIGN(BrowserPluginHostTest); | 320 DISALLOW_COPY_AND_ASSIGN(BrowserPluginHostTest); |
| 347 }; | 321 }; |
| 348 | 322 |
| 349 // This test ensures that if guest isn't there and we resize the guest (from | 323 // This test ensures that if guest isn't there and we resize the guest (from |
| 350 // js), it remembers the size correctly. | 324 // js), it remembers the size correctly. |
| 351 // | 325 // |
| 352 // Initially we load an embedder with a guest without a src attribute (which has | 326 // Initially we load an embedder with a guest without a src attribute (which has |
| 353 // dimension 640x480), resize it to 100x200, and then we set the source to a | 327 // dimension 640x480), resize it to 100x200, and then we set the source to a |
| 354 // sample guest. In the end we verify that the correct size has been set. | 328 // sample guest. In the end we verify that the correct size has been set. |
| 355 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, NavigateAfterResize) { | 329 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, NavigateAfterResize) { |
| (...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1049 scoped_ptr<base::Value> value = | 1023 scoped_ptr<base::Value> value = |
| 1050 content::ExecuteScriptAndGetValue( | 1024 content::ExecuteScriptAndGetValue( |
| 1051 guest_rfh, "document.getElementById('input1').value"); | 1025 guest_rfh, "document.getElementById('input1').value"); |
| 1052 std::string actual_value; | 1026 std::string actual_value; |
| 1053 ASSERT_TRUE(value->GetAsString(&actual_value)); | 1027 ASSERT_TRUE(value->GetAsString(&actual_value)); |
| 1054 EXPECT_EQ(base::UTF16ToUTF8(expected_value), actual_value); | 1028 EXPECT_EQ(base::UTF16ToUTF8(expected_value), actual_value); |
| 1055 } | 1029 } |
| 1056 } | 1030 } |
| 1057 | 1031 |
| 1058 } // namespace content | 1032 } // namespace content |
| OLD | NEW |