| 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" | 17 #include "content/browser/browser_plugin/test_browser_plugin_guest_manager.h" |
| 18 #include "content/browser/browser_plugin/test_guest_manager_delegate.h" |
| 18 #include "content/browser/child_process_security_policy_impl.h" | 19 #include "content/browser/child_process_security_policy_impl.h" |
| 19 #include "content/browser/frame_host/render_frame_host_impl.h" | 20 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 20 #include "content/browser/frame_host/render_widget_host_view_guest.h" | 21 #include "content/browser/frame_host/render_widget_host_view_guest.h" |
| 21 #include "content/browser/renderer_host/render_view_host_impl.h" | 22 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 22 #include "content/browser/web_contents/web_contents_impl.h" | 23 #include "content/browser/web_contents/web_contents_impl.h" |
| 23 #include "content/common/browser_plugin/browser_plugin_messages.h" | 24 #include "content/common/browser_plugin/browser_plugin_messages.h" |
| 24 #include "content/common/view_messages.h" | 25 #include "content/common/view_messages.h" |
| 25 #include "content/public/browser/notification_service.h" | 26 #include "content/public/browser/notification_service.h" |
| 26 #include "content/public/browser/notification_types.h" | 27 #include "content/public/browser/notification_types.h" |
| 27 #include "content/public/browser/render_frame_host.h" | 28 #include "content/public/browser/render_frame_host.h" |
| 28 #include "content/public/browser/render_widget_host_view.h" | 29 #include "content/public/browser/render_widget_host_view.h" |
| 29 #include "content/public/browser/web_contents_observer.h" | 30 #include "content/public/browser/web_contents_observer.h" |
| 30 #include "content/public/common/content_switches.h" | 31 #include "content/public/common/content_switches.h" |
| 31 #include "content/public/common/drop_data.h" | 32 #include "content/public/common/drop_data.h" |
| 32 #include "content/public/common/url_constants.h" | 33 #include "content/public/common/url_constants.h" |
| 33 #include "content/public/test/browser_test_utils.h" | 34 #include "content/public/test/browser_test_utils.h" |
| 34 #include "content/public/test/content_browser_test.h" | 35 #include "content/public/test/content_browser_test.h" |
| 35 #include "content/public/test/content_browser_test_utils.h" | 36 #include "content/public/test/content_browser_test_utils.h" |
| 36 #include "content/public/test/test_utils.h" | 37 #include "content/public/test/test_utils.h" |
| 37 #include "content/shell/browser/shell.h" | 38 #include "content/shell/browser/shell.h" |
| 39 #include "content/shell/browser/shell_browser_context.h" |
| 38 #include "net/base/net_util.h" | 40 #include "net/base/net_util.h" |
| 39 #include "net/test/embedded_test_server/embedded_test_server.h" | 41 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 40 #include "net/test/embedded_test_server/http_request.h" | 42 #include "net/test/embedded_test_server/http_request.h" |
| 41 #include "net/test/embedded_test_server/http_response.h" | 43 #include "net/test/embedded_test_server/http_response.h" |
| 42 #include "net/test/spawned_test_server/spawned_test_server.h" | 44 #include "net/test/spawned_test_server/spawned_test_server.h" |
| 43 #include "third_party/WebKit/public/web/WebInputEvent.h" | 45 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 44 | 46 |
| 45 using base::ASCIIToUTF16; | 47 using base::ASCIIToUTF16; |
| 46 using blink::WebInputEvent; | 48 using blink::WebInputEvent; |
| 47 using blink::WebMouseEvent; | 49 using blink::WebMouseEvent; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 | 97 |
| 96 private: | 98 private: |
| 97 DISALLOW_COPY_AND_ASSIGN(TestBrowserPluginEmbedder); | 99 DISALLOW_COPY_AND_ASSIGN(TestBrowserPluginEmbedder); |
| 98 }; | 100 }; |
| 99 | 101 |
| 100 // Test factory for creating test instances of BrowserPluginEmbedder and | 102 // Test factory for creating test instances of BrowserPluginEmbedder and |
| 101 // BrowserPluginGuest. | 103 // BrowserPluginGuest. |
| 102 class TestBrowserPluginHostFactory : public BrowserPluginHostFactory { | 104 class TestBrowserPluginHostFactory : public BrowserPluginHostFactory { |
| 103 public: | 105 public: |
| 104 virtual BrowserPluginGuestManager* | 106 virtual BrowserPluginGuestManager* |
| 105 CreateBrowserPluginGuestManager() OVERRIDE { | 107 CreateBrowserPluginGuestManager(BrowserContext* context) OVERRIDE { |
| 106 guest_manager_instance_count_++; | 108 guest_manager_instance_count_++; |
| 107 if (message_loop_runner_) | 109 if (message_loop_runner_) |
| 108 message_loop_runner_->Quit(); | 110 message_loop_runner_->Quit(); |
| 109 return new TestBrowserPluginGuestManager(); | 111 return new TestBrowserPluginGuestManager(context); |
| 110 } | 112 } |
| 111 | 113 |
| 112 virtual BrowserPluginGuest* CreateBrowserPluginGuest( | 114 virtual BrowserPluginGuest* CreateBrowserPluginGuest( |
| 113 int instance_id, | 115 int instance_id, |
| 114 WebContentsImpl* web_contents) OVERRIDE { | 116 WebContentsImpl* web_contents) OVERRIDE { |
| 115 return new TestBrowserPluginGuest(instance_id, web_contents); | 117 return new TestBrowserPluginGuest(instance_id, web_contents); |
| 116 } | 118 } |
| 117 | 119 |
| 118 // Also keeps track of number of instances created. | 120 // Also keeps track of number of instances created. |
| 119 virtual BrowserPluginEmbedder* CreateBrowserPluginEmbedder( | 121 virtual BrowserPluginEmbedder* CreateBrowserPluginEmbedder( |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 | 225 |
| 224 class BrowserPluginHostTest : public ContentBrowserTest { | 226 class BrowserPluginHostTest : public ContentBrowserTest { |
| 225 public: | 227 public: |
| 226 BrowserPluginHostTest() | 228 BrowserPluginHostTest() |
| 227 : test_embedder_(NULL), | 229 : test_embedder_(NULL), |
| 228 test_guest_(NULL), | 230 test_guest_(NULL), |
| 229 test_guest_manager_(NULL) {} | 231 test_guest_manager_(NULL) {} |
| 230 | 232 |
| 231 virtual void SetUp() OVERRIDE { | 233 virtual void SetUp() OVERRIDE { |
| 232 // Override factory to create tests instances of BrowserPlugin*. | 234 // Override factory to create tests instances of BrowserPlugin*. |
| 233 content::BrowserPluginEmbedder::set_factory_for_testing( | 235 BrowserPluginEmbedder::set_factory_for_testing( |
| 234 TestBrowserPluginHostFactory::GetInstance()); | 236 TestBrowserPluginHostFactory::GetInstance()); |
| 235 content::BrowserPluginGuest::set_factory_for_testing( | 237 BrowserPluginGuest::set_factory_for_testing( |
| 236 TestBrowserPluginHostFactory::GetInstance()); | 238 TestBrowserPluginHostFactory::GetInstance()); |
| 237 content::BrowserPluginGuestManager::set_factory_for_testing( | 239 BrowserPluginGuestManager::set_factory_for_testing( |
| 238 TestBrowserPluginHostFactory::GetInstance()); | 240 TestBrowserPluginHostFactory::GetInstance()); |
| 241 ShellBrowserContext::set_guest_manager_delegate_for_testing( |
| 242 TestGuestManagerDelegate::GetInstance()); |
| 239 ContentBrowserTest::SetUp(); | 243 ContentBrowserTest::SetUp(); |
| 240 } | 244 } |
| 241 virtual void TearDown() OVERRIDE { | 245 virtual void TearDown() OVERRIDE { |
| 242 content::BrowserPluginEmbedder::set_factory_for_testing(NULL); | 246 BrowserPluginEmbedder::set_factory_for_testing(NULL); |
| 243 content::BrowserPluginGuest::set_factory_for_testing(NULL); | 247 BrowserPluginGuest::set_factory_for_testing(NULL); |
| 244 | 248 |
| 245 ContentBrowserTest::TearDown(); | 249 ContentBrowserTest::TearDown(); |
| 246 } | 250 } |
| 247 | 251 |
| 248 static void SimulateSpaceKeyPress(WebContents* web_contents) { | 252 static void SimulateSpaceKeyPress(WebContents* web_contents) { |
| 249 SimulateKeyPress(web_contents, | 253 SimulateKeyPress(web_contents, |
| 250 ui::VKEY_SPACE, | 254 ui::VKEY_SPACE, |
| 251 false, // control. | 255 false, // control. |
| 252 false, // shift. | 256 false, // shift. |
| 253 false, // alt. | 257 false, // alt. |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 } | 312 } |
| 309 | 313 |
| 310 // Wait to make sure embedder is created/attached to WebContents. | 314 // Wait to make sure embedder is created/attached to WebContents. |
| 311 TestBrowserPluginHostFactory::GetInstance()->WaitForGuestManagerCreation(); | 315 TestBrowserPluginHostFactory::GetInstance()->WaitForGuestManagerCreation(); |
| 312 | 316 |
| 313 test_embedder_ = static_cast<TestBrowserPluginEmbedder*>( | 317 test_embedder_ = static_cast<TestBrowserPluginEmbedder*>( |
| 314 embedder_web_contents->GetBrowserPluginEmbedder()); | 318 embedder_web_contents->GetBrowserPluginEmbedder()); |
| 315 ASSERT_TRUE(test_embedder_); | 319 ASSERT_TRUE(test_embedder_); |
| 316 | 320 |
| 317 test_guest_manager_ = static_cast<TestBrowserPluginGuestManager*>( | 321 test_guest_manager_ = static_cast<TestBrowserPluginGuestManager*>( |
| 318 embedder_web_contents->GetBrowserPluginGuestManager()); | 322 BrowserPluginGuestManager::FromBrowserContext( |
| 323 test_embedder_->GetWebContents()->GetBrowserContext())); |
| 319 ASSERT_TRUE(test_guest_manager_); | 324 ASSERT_TRUE(test_guest_manager_); |
| 320 | 325 |
| 321 test_guest_manager_->WaitForGuestAdded(); | 326 WebContentsImpl* test_guest_web_contents = static_cast<WebContentsImpl*>( |
| 327 test_guest_manager_->WaitForGuestAdded()); |
| 322 | 328 |
| 323 // Verify that we have exactly one guest. | |
| 324 const TestBrowserPluginGuestManager::GuestInstanceMap& instance_map = | |
| 325 test_guest_manager_->guest_web_contents_for_testing(); | |
| 326 EXPECT_EQ(1u, instance_map.size()); | |
| 327 | |
| 328 WebContentsImpl* test_guest_web_contents = static_cast<WebContentsImpl*>( | |
| 329 instance_map.begin()->second); | |
| 330 test_guest_ = static_cast<TestBrowserPluginGuest*>( | 329 test_guest_ = static_cast<TestBrowserPluginGuest*>( |
| 331 test_guest_web_contents->GetBrowserPluginGuest()); | 330 test_guest_web_contents->GetBrowserPluginGuest()); |
| 332 test_guest_->WaitForLoadStop(); | 331 test_guest_->WaitForLoadStop(); |
| 333 } | 332 } |
| 334 | 333 |
| 335 TestBrowserPluginEmbedder* test_embedder() const { return test_embedder_; } | 334 TestBrowserPluginEmbedder* test_embedder() const { return test_embedder_; } |
| 336 TestBrowserPluginGuest* test_guest() const { return test_guest_; } | 335 TestBrowserPluginGuest* test_guest() const { return test_guest_; } |
| 337 TestBrowserPluginGuestManager* test_guest_manager() const { | 336 TestBrowserPluginGuestManager* test_guest_manager() const { |
| 338 return test_guest_manager_; | 337 return test_guest_manager_; |
| 339 } | 338 } |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | 533 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
| 535 expected_title); | 534 expected_title); |
| 536 | 535 |
| 537 test_embedder()->web_contents()->GetController().Reload(false); | 536 test_embedder()->web_contents()->GetController().Reload(false); |
| 538 base::string16 actual_title = title_watcher.WaitAndGetTitle(); | 537 base::string16 actual_title = title_watcher.WaitAndGetTitle(); |
| 539 EXPECT_EQ(expected_title, actual_title); | 538 EXPECT_EQ(expected_title, actual_title); |
| 540 | 539 |
| 541 ExecuteSyncJSFunction( | 540 ExecuteSyncJSFunction( |
| 542 test_embedder()->web_contents()->GetMainFrame(), | 541 test_embedder()->web_contents()->GetMainFrame(), |
| 543 base::StringPrintf("SetSrc('%s');", kHTMLForGuest)); | 542 base::StringPrintf("SetSrc('%s');", kHTMLForGuest)); |
| 544 test_guest_manager()->WaitForGuestAdded(); | |
| 545 | 543 |
| 546 const TestBrowserPluginGuestManager::GuestInstanceMap& instance_map = | |
| 547 test_guest_manager()->guest_web_contents_for_testing(); | |
| 548 WebContentsImpl* test_guest_web_contents = static_cast<WebContentsImpl*>( | 544 WebContentsImpl* test_guest_web_contents = static_cast<WebContentsImpl*>( |
| 549 instance_map.begin()->second); | 545 test_guest_manager()->WaitForGuestAdded()); |
| 550 TestBrowserPluginGuest* new_test_guest = | 546 TestBrowserPluginGuest* new_test_guest = |
| 551 static_cast<TestBrowserPluginGuest*>( | 547 static_cast<TestBrowserPluginGuest*>( |
| 552 test_guest_web_contents->GetBrowserPluginGuest()); | 548 test_guest_web_contents->GetBrowserPluginGuest()); |
| 553 ASSERT_TRUE(new_test_guest != NULL); | 549 ASSERT_TRUE(new_test_guest != NULL); |
| 554 | 550 |
| 555 // Wait for the guest to send an UpdateRectMsg, meaning it is ready. | 551 // Wait for the guest to send an UpdateRectMsg, meaning it is ready. |
| 556 new_test_guest->WaitForUpdateRectMsg(); | 552 new_test_guest->WaitForUpdateRectMsg(); |
| 557 } | 553 } |
| 558 } | 554 } |
| 559 | 555 |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1051 scoped_ptr<base::Value> value = | 1047 scoped_ptr<base::Value> value = |
| 1052 content::ExecuteScriptAndGetValue( | 1048 content::ExecuteScriptAndGetValue( |
| 1053 guest_rfh, "document.getElementById('input1').value"); | 1049 guest_rfh, "document.getElementById('input1').value"); |
| 1054 std::string actual_value; | 1050 std::string actual_value; |
| 1055 ASSERT_TRUE(value->GetAsString(&actual_value)); | 1051 ASSERT_TRUE(value->GetAsString(&actual_value)); |
| 1056 EXPECT_EQ(base::UTF16ToUTF8(expected_value), actual_value); | 1052 EXPECT_EQ(base::UTF16ToUTF8(expected_value), actual_value); |
| 1057 } | 1053 } |
| 1058 } | 1054 } |
| 1059 | 1055 |
| 1060 } // namespace content | 1056 } // namespace content |
| OLD | NEW |