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" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 | 95 |
96 private: | 96 private: |
97 DISALLOW_COPY_AND_ASSIGN(TestBrowserPluginEmbedder); | 97 DISALLOW_COPY_AND_ASSIGN(TestBrowserPluginEmbedder); |
98 }; | 98 }; |
99 | 99 |
100 // Test factory for creating test instances of BrowserPluginEmbedder and | 100 // Test factory for creating test instances of BrowserPluginEmbedder and |
101 // BrowserPluginGuest. | 101 // BrowserPluginGuest. |
102 class TestBrowserPluginHostFactory : public BrowserPluginHostFactory { | 102 class TestBrowserPluginHostFactory : public BrowserPluginHostFactory { |
103 public: | 103 public: |
104 virtual BrowserPluginGuestManager* | 104 virtual BrowserPluginGuestManager* |
105 CreateBrowserPluginGuestManager() OVERRIDE { | 105 CreateBrowserPluginGuestManager(BrowserContext* context) OVERRIDE { |
106 guest_manager_instance_count_++; | 106 guest_manager_instance_count_++; |
107 if (message_loop_runner_) | 107 if (message_loop_runner_) |
108 message_loop_runner_->Quit(); | 108 message_loop_runner_->Quit(); |
109 return new TestBrowserPluginGuestManager(); | 109 return new TestBrowserPluginGuestManager(context); |
110 } | 110 } |
111 | 111 |
112 virtual BrowserPluginGuest* CreateBrowserPluginGuest( | 112 virtual BrowserPluginGuest* CreateBrowserPluginGuest( |
113 int instance_id, | 113 int instance_id, |
114 WebContentsImpl* web_contents) OVERRIDE { | 114 WebContentsImpl* web_contents) OVERRIDE { |
115 return new TestBrowserPluginGuest(instance_id, web_contents); | 115 return new TestBrowserPluginGuest(instance_id, web_contents); |
116 } | 116 } |
117 | 117 |
118 // Also keeps track of number of instances created. | 118 // Also keeps track of number of instances created. |
119 virtual BrowserPluginEmbedder* CreateBrowserPluginEmbedder( | 119 virtual BrowserPluginEmbedder* CreateBrowserPluginEmbedder( |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 } | 308 } |
309 | 309 |
310 // Wait to make sure embedder is created/attached to WebContents. | 310 // Wait to make sure embedder is created/attached to WebContents. |
311 TestBrowserPluginHostFactory::GetInstance()->WaitForGuestManagerCreation(); | 311 TestBrowserPluginHostFactory::GetInstance()->WaitForGuestManagerCreation(); |
312 | 312 |
313 test_embedder_ = static_cast<TestBrowserPluginEmbedder*>( | 313 test_embedder_ = static_cast<TestBrowserPluginEmbedder*>( |
314 embedder_web_contents->GetBrowserPluginEmbedder()); | 314 embedder_web_contents->GetBrowserPluginEmbedder()); |
315 ASSERT_TRUE(test_embedder_); | 315 ASSERT_TRUE(test_embedder_); |
316 | 316 |
317 test_guest_manager_ = static_cast<TestBrowserPluginGuestManager*>( | 317 test_guest_manager_ = static_cast<TestBrowserPluginGuestManager*>( |
318 embedder_web_contents->GetBrowserPluginGuestManager()); | 318 BrowserPluginGuestManager::FromBrowserContext( |
| 319 test_embedder_->GetWebContents()->GetBrowserContext())); |
319 ASSERT_TRUE(test_guest_manager_); | 320 ASSERT_TRUE(test_guest_manager_); |
320 | 321 |
321 test_guest_manager_->WaitForGuestAdded(); | 322 WebContentsImpl* test_guest_web_contents = static_cast<WebContentsImpl*>( |
| 323 test_guest_manager_->WaitForGuestAdded()); |
322 | 324 |
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*>( | 325 test_guest_ = static_cast<TestBrowserPluginGuest*>( |
331 test_guest_web_contents->GetBrowserPluginGuest()); | 326 test_guest_web_contents->GetBrowserPluginGuest()); |
332 test_guest_->WaitForLoadStop(); | 327 test_guest_->WaitForLoadStop(); |
333 } | 328 } |
334 | 329 |
335 TestBrowserPluginEmbedder* test_embedder() const { return test_embedder_; } | 330 TestBrowserPluginEmbedder* test_embedder() const { return test_embedder_; } |
336 TestBrowserPluginGuest* test_guest() const { return test_guest_; } | 331 TestBrowserPluginGuest* test_guest() const { return test_guest_; } |
337 TestBrowserPluginGuestManager* test_guest_manager() const { | 332 TestBrowserPluginGuestManager* test_guest_manager() const { |
338 return test_guest_manager_; | 333 return test_guest_manager_; |
339 } | 334 } |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | 529 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
535 expected_title); | 530 expected_title); |
536 | 531 |
537 test_embedder()->web_contents()->GetController().Reload(false); | 532 test_embedder()->web_contents()->GetController().Reload(false); |
538 base::string16 actual_title = title_watcher.WaitAndGetTitle(); | 533 base::string16 actual_title = title_watcher.WaitAndGetTitle(); |
539 EXPECT_EQ(expected_title, actual_title); | 534 EXPECT_EQ(expected_title, actual_title); |
540 | 535 |
541 ExecuteSyncJSFunction( | 536 ExecuteSyncJSFunction( |
542 test_embedder()->web_contents()->GetMainFrame(), | 537 test_embedder()->web_contents()->GetMainFrame(), |
543 base::StringPrintf("SetSrc('%s');", kHTMLForGuest)); | 538 base::StringPrintf("SetSrc('%s');", kHTMLForGuest)); |
544 test_guest_manager()->WaitForGuestAdded(); | |
545 | 539 |
546 const TestBrowserPluginGuestManager::GuestInstanceMap& instance_map = | |
547 test_guest_manager()->guest_web_contents_for_testing(); | |
548 WebContentsImpl* test_guest_web_contents = static_cast<WebContentsImpl*>( | 540 WebContentsImpl* test_guest_web_contents = static_cast<WebContentsImpl*>( |
549 instance_map.begin()->second); | 541 test_guest_manager()->WaitForGuestAdded()); |
550 TestBrowserPluginGuest* new_test_guest = | 542 TestBrowserPluginGuest* new_test_guest = |
551 static_cast<TestBrowserPluginGuest*>( | 543 static_cast<TestBrowserPluginGuest*>( |
552 test_guest_web_contents->GetBrowserPluginGuest()); | 544 test_guest_web_contents->GetBrowserPluginGuest()); |
553 ASSERT_TRUE(new_test_guest != NULL); | 545 ASSERT_TRUE(new_test_guest != NULL); |
554 | 546 |
555 // Wait for the guest to send an UpdateRectMsg, meaning it is ready. | 547 // Wait for the guest to send an UpdateRectMsg, meaning it is ready. |
556 new_test_guest->WaitForUpdateRectMsg(); | 548 new_test_guest->WaitForUpdateRectMsg(); |
557 } | 549 } |
558 } | 550 } |
559 | 551 |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1051 scoped_ptr<base::Value> value = | 1043 scoped_ptr<base::Value> value = |
1052 content::ExecuteScriptAndGetValue( | 1044 content::ExecuteScriptAndGetValue( |
1053 guest_rfh, "document.getElementById('input1').value"); | 1045 guest_rfh, "document.getElementById('input1').value"); |
1054 std::string actual_value; | 1046 std::string actual_value; |
1055 ASSERT_TRUE(value->GetAsString(&actual_value)); | 1047 ASSERT_TRUE(value->GetAsString(&actual_value)); |
1056 EXPECT_EQ(base::UTF16ToUTF8(expected_value), actual_value); | 1048 EXPECT_EQ(base::UTF16ToUTF8(expected_value), actual_value); |
1057 } | 1049 } |
1058 } | 1050 } |
1059 | 1051 |
1060 } // namespace content | 1052 } // namespace content |
OLD | NEW |