Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: content/browser/browser_plugin/browser_plugin_host_browsertest.cc

Issue 258373002: Towards moving guest management to chrome: Introduce GuestViewManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Android build Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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());
239 ContentBrowserTest::SetUp(); 241 ContentBrowserTest::SetUp();
240 } 242 }
241 virtual void TearDown() OVERRIDE { 243 virtual void TearDown() OVERRIDE {
242 content::BrowserPluginEmbedder::set_factory_for_testing(NULL); 244 BrowserPluginEmbedder::set_factory_for_testing(NULL);
243 content::BrowserPluginGuest::set_factory_for_testing(NULL); 245 BrowserPluginGuest::set_factory_for_testing(NULL);
244 246
245 ContentBrowserTest::TearDown(); 247 ContentBrowserTest::TearDown();
246 } 248 }
247 249
248 static void SimulateSpaceKeyPress(WebContents* web_contents) { 250 static void SimulateSpaceKeyPress(WebContents* web_contents) {
249 SimulateKeyPress(web_contents, 251 SimulateKeyPress(web_contents,
250 ui::VKEY_SPACE, 252 ui::VKEY_SPACE,
251 false, // control. 253 false, // control.
252 false, // shift. 254 false, // shift.
253 false, // alt. 255 false, // alt.
(...skipping 24 matching lines...) Expand all
278 void StartBrowserPluginTest(const std::string& embedder_url, 280 void StartBrowserPluginTest(const std::string& embedder_url,
279 const std::string& guest_url, 281 const std::string& guest_url,
280 bool is_guest_data_url, 282 bool is_guest_data_url,
281 const std::string& embedder_code) { 283 const std::string& embedder_code) {
282 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 284 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
283 GURL test_url(embedded_test_server()->GetURL(embedder_url)); 285 GURL test_url(embedded_test_server()->GetURL(embedder_url));
284 NavigateToURL(shell(), test_url); 286 NavigateToURL(shell(), test_url);
285 287
286 WebContentsImpl* embedder_web_contents = static_cast<WebContentsImpl*>( 288 WebContentsImpl* embedder_web_contents = static_cast<WebContentsImpl*>(
287 shell()->web_contents()); 289 shell()->web_contents());
290 static_cast<ShellBrowserContext*>(
291 embedder_web_contents->GetBrowserContext())->
292 set_guest_manager_delegate_for_testing(
293 TestGuestManagerDelegate::GetInstance());
288 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( 294 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
289 embedder_web_contents->GetRenderViewHost()); 295 embedder_web_contents->GetRenderViewHost());
290 RenderFrameHost* rfh = embedder_web_contents->GetMainFrame(); 296 RenderFrameHost* rfh = embedder_web_contents->GetMainFrame();
291 // Focus the embedder. 297 // Focus the embedder.
292 rvh->Focus(); 298 rvh->Focus();
293 // Activative IME. 299 // Activative IME.
294 rvh->SetInputMethodActive(true); 300 rvh->SetInputMethodActive(true);
295 301
296 // Allow the test to do some operations on the embedder before we perform 302 // Allow the test to do some operations on the embedder before we perform
297 // the first navigation of the guest. 303 // the first navigation of the guest.
(...skipping 10 matching lines...) Expand all
308 } 314 }
309 315
310 // Wait to make sure embedder is created/attached to WebContents. 316 // Wait to make sure embedder is created/attached to WebContents.
311 TestBrowserPluginHostFactory::GetInstance()->WaitForGuestManagerCreation(); 317 TestBrowserPluginHostFactory::GetInstance()->WaitForGuestManagerCreation();
312 318
313 test_embedder_ = static_cast<TestBrowserPluginEmbedder*>( 319 test_embedder_ = static_cast<TestBrowserPluginEmbedder*>(
314 embedder_web_contents->GetBrowserPluginEmbedder()); 320 embedder_web_contents->GetBrowserPluginEmbedder());
315 ASSERT_TRUE(test_embedder_); 321 ASSERT_TRUE(test_embedder_);
316 322
317 test_guest_manager_ = static_cast<TestBrowserPluginGuestManager*>( 323 test_guest_manager_ = static_cast<TestBrowserPluginGuestManager*>(
318 embedder_web_contents->GetBrowserPluginGuestManager()); 324 BrowserPluginGuestManager::FromBrowserContext(
325 test_embedder_->GetWebContents()->GetBrowserContext()));
319 ASSERT_TRUE(test_guest_manager_); 326 ASSERT_TRUE(test_guest_manager_);
320 327
321 test_guest_manager_->WaitForGuestAdded(); 328 WebContentsImpl* test_guest_web_contents = static_cast<WebContentsImpl*>(
329 test_guest_manager_->WaitForGuestAdded());
322 330
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*>( 331 test_guest_ = static_cast<TestBrowserPluginGuest*>(
331 test_guest_web_contents->GetBrowserPluginGuest()); 332 test_guest_web_contents->GetBrowserPluginGuest());
332 test_guest_->WaitForLoadStop(); 333 test_guest_->WaitForLoadStop();
333 } 334 }
334 335
335 TestBrowserPluginEmbedder* test_embedder() const { return test_embedder_; } 336 TestBrowserPluginEmbedder* test_embedder() const { return test_embedder_; }
336 TestBrowserPluginGuest* test_guest() const { return test_guest_; } 337 TestBrowserPluginGuest* test_guest() const { return test_guest_; }
337 TestBrowserPluginGuestManager* test_guest_manager() const { 338 TestBrowserPluginGuestManager* test_guest_manager() const {
338 return test_guest_manager_; 339 return test_guest_manager_;
339 } 340 }
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 content::TitleWatcher title_watcher(test_embedder()->web_contents(), 535 content::TitleWatcher title_watcher(test_embedder()->web_contents(),
535 expected_title); 536 expected_title);
536 537
537 test_embedder()->web_contents()->GetController().Reload(false); 538 test_embedder()->web_contents()->GetController().Reload(false);
538 base::string16 actual_title = title_watcher.WaitAndGetTitle(); 539 base::string16 actual_title = title_watcher.WaitAndGetTitle();
539 EXPECT_EQ(expected_title, actual_title); 540 EXPECT_EQ(expected_title, actual_title);
540 541
541 ExecuteSyncJSFunction( 542 ExecuteSyncJSFunction(
542 test_embedder()->web_contents()->GetMainFrame(), 543 test_embedder()->web_contents()->GetMainFrame(),
543 base::StringPrintf("SetSrc('%s');", kHTMLForGuest)); 544 base::StringPrintf("SetSrc('%s');", kHTMLForGuest));
544 test_guest_manager()->WaitForGuestAdded();
545 545
546 const TestBrowserPluginGuestManager::GuestInstanceMap& instance_map =
547 test_guest_manager()->guest_web_contents_for_testing();
548 WebContentsImpl* test_guest_web_contents = static_cast<WebContentsImpl*>( 546 WebContentsImpl* test_guest_web_contents = static_cast<WebContentsImpl*>(
549 instance_map.begin()->second); 547 test_guest_manager()->WaitForGuestAdded());
550 TestBrowserPluginGuest* new_test_guest = 548 TestBrowserPluginGuest* new_test_guest =
551 static_cast<TestBrowserPluginGuest*>( 549 static_cast<TestBrowserPluginGuest*>(
552 test_guest_web_contents->GetBrowserPluginGuest()); 550 test_guest_web_contents->GetBrowserPluginGuest());
553 ASSERT_TRUE(new_test_guest != NULL); 551 ASSERT_TRUE(new_test_guest != NULL);
554 552
555 // Wait for the guest to send an UpdateRectMsg, meaning it is ready. 553 // Wait for the guest to send an UpdateRectMsg, meaning it is ready.
556 new_test_guest->WaitForUpdateRectMsg(); 554 new_test_guest->WaitForUpdateRectMsg();
557 } 555 }
558 } 556 }
559 557
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
1051 scoped_ptr<base::Value> value = 1049 scoped_ptr<base::Value> value =
1052 content::ExecuteScriptAndGetValue( 1050 content::ExecuteScriptAndGetValue(
1053 guest_rfh, "document.getElementById('input1').value"); 1051 guest_rfh, "document.getElementById('input1').value");
1054 std::string actual_value; 1052 std::string actual_value;
1055 ASSERT_TRUE(value->GetAsString(&actual_value)); 1053 ASSERT_TRUE(value->GetAsString(&actual_value));
1056 EXPECT_EQ(base::UTF16ToUTF8(expected_value), actual_value); 1054 EXPECT_EQ(base::UTF16ToUTF8(expected_value), actual_value);
1057 } 1055 }
1058 } 1056 }
1059 1057
1060 } // namespace content 1058 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698