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 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 const char kEmbedderURL[] = "/browser_plugin_embedder.html"; | 474 const char kEmbedderURL[] = "/browser_plugin_embedder.html"; |
475 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); | 475 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); |
476 | 476 |
477 // Hide the embedder. | 477 // Hide the embedder. |
478 test_embedder()->web_contents()->WasHidden(); | 478 test_embedder()->web_contents()->WasHidden(); |
479 | 479 |
480 // Make sure that hiding the embedder also hides the guest. | 480 // Make sure that hiding the embedder also hides the guest. |
481 test_guest()->WaitUntilHidden(); | 481 test_guest()->WaitUntilHidden(); |
482 } | 482 } |
483 | 483 |
| 484 namespace { |
| 485 |
| 486 bool IsAttributeNull(RenderFrameHost* rfh, const std::string& attribute) { |
| 487 scoped_ptr<base::Value> value = content::ExecuteScriptAndGetValue( |
| 488 rfh, |
| 489 "document.getElementById('plugin').getAttribute('" + attribute + "');"); |
| 490 return value->GetType() == base::Value::TYPE_NULL; |
| 491 } |
| 492 |
| 493 } // namespace |
| 494 |
| 495 // Verifies that setting the src attribute prior to DOM attachment works, i.e. |
| 496 // that the BrowserPlugin is created without having a renderer. |
| 497 const char kHTMLForGuestLateAttach[] = |
| 498 "data:text/html,<html><title>late attach</title>" |
| 499 "<body>hello world</body></html>"; |
| 500 |
| 501 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, PluginCreatedWithoutRenderer) { |
| 502 const char kEmbedderURL[] = "/browser_plugin_embedder_late_attach.html"; |
| 503 StartBrowserPluginTest( |
| 504 kEmbedderURL, kHTMLForGuestLateAttach, true, std::string()); |
| 505 |
| 506 // Attach the browser plugin to the dom. We don't pass this to |
| 507 // StartBrowserPluginTest since we want it to execute after the src parameter |
| 508 // is set. |
| 509 ExecuteSyncJSFunction(shell()->web_contents()->GetMainFrame(), |
| 510 "attachPlugin();"); |
| 511 |
| 512 // Verify attachment with src attribute intact. |
| 513 EXPECT_FALSE( |
| 514 IsAttributeNull(shell()->web_contents()->GetMainFrame(), "src")); |
| 515 |
| 516 // Verify page loaded properly by checking title. |
| 517 const base::string16 expected_title = ASCIIToUTF16("late attach"); |
| 518 EXPECT_EQ(expected_title, test_guest()->web_contents()->GetTitle()); |
| 519 } |
| 520 |
| 521 // Verifies that browser-plugin state survives setting "display = none", i.e. |
| 522 // that the BrowserPlugin object is persisted. |
| 523 const char kHTMLForGuestPersisted[] = |
| 524 "data:text/html,<html><title>persisted</title>" |
| 525 "<body>hello world</body></html>"; |
| 526 |
| 527 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, PluginPersists) { |
| 528 const char kEmbedderURL[] = "/browser_plugin_embedder.html"; |
| 529 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); |
| 530 |
| 531 const char kGuestTitle[] = "persisted"; |
| 532 const char kGuestTitleModified[] = "still persisted"; |
| 533 |
| 534 // Verify title is seen. |
| 535 const base::string16 expected_title = ASCIIToUTF16(kGuestTitle); |
| 536 { |
| 537 content::TitleWatcher title_watcher(test_guest()->web_contents(), |
| 538 expected_title); |
| 539 ExecuteSyncJSFunction( |
| 540 test_embedder()->web_contents()->GetMainFrame(), |
| 541 base::StringPrintf("SetSrc('%s');", kHTMLForGuestPersisted)); |
| 542 base::string16 actual_title = title_watcher.WaitAndGetTitle(); |
| 543 EXPECT_EQ(expected_title, actual_title); |
| 544 } |
| 545 |
| 546 // Set display none, verify title not seen. |
| 547 ExecuteSyncJSFunction( |
| 548 shell()->web_contents()->GetMainFrame(), |
| 549 "document.getElementById('plugin').style.display = 'none'"); |
| 550 |
| 551 ExecuteSyncJSFunction( |
| 552 test_guest()->web_contents()->GetMainFrame(), |
| 553 base::StringPrintf("document.title = '%s'", kGuestTitleModified)); |
| 554 |
| 555 // Clear display none. |
| 556 ExecuteSyncJSFunction( |
| 557 shell()->web_contents()->GetMainFrame(), |
| 558 "document.getElementById('plugin').style.display = 'block'"); |
| 559 |
| 560 // The guest title should have survived the display:none. |
| 561 const base::string16 expected_title_modified = |
| 562 ASCIIToUTF16(kGuestTitleModified); |
| 563 EXPECT_EQ(test_guest()->web_contents()->GetTitle(), expected_title_modified); |
| 564 } |
| 565 |
484 // Verifies that installing/uninstalling touch-event handlers in the guest | 566 // Verifies that installing/uninstalling touch-event handlers in the guest |
485 // plugin correctly updates the touch-event handling state in the embedder. | 567 // plugin correctly updates the touch-event handling state in the embedder. |
486 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, AcceptTouchEvents) { | 568 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, AcceptTouchEvents) { |
487 const char kEmbedderURL[] = "/browser_plugin_embedder.html"; | 569 const char kEmbedderURL[] = "/browser_plugin_embedder.html"; |
488 StartBrowserPluginTest( | 570 StartBrowserPluginTest( |
489 kEmbedderURL, kHTMLForGuestTouchHandler, true, std::string()); | 571 kEmbedderURL, kHTMLForGuestTouchHandler, true, std::string()); |
490 | 572 |
491 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 573 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
492 test_embedder()->web_contents()->GetRenderViewHost()); | 574 test_embedder()->web_contents()->GetRenderViewHost()); |
493 // The embedder should not have any touch event handlers at this point. | 575 // The embedder should not have any touch event handlers at this point. |
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1057 scoped_ptr<base::Value> value = | 1139 scoped_ptr<base::Value> value = |
1058 content::ExecuteScriptAndGetValue( | 1140 content::ExecuteScriptAndGetValue( |
1059 guest_rfh, "document.getElementById('input1').value"); | 1141 guest_rfh, "document.getElementById('input1').value"); |
1060 std::string actual_value; | 1142 std::string actual_value; |
1061 ASSERT_TRUE(value->GetAsString(&actual_value)); | 1143 ASSERT_TRUE(value->GetAsString(&actual_value)); |
1062 EXPECT_EQ(base::UTF16ToUTF8(expected_value), actual_value); | 1144 EXPECT_EQ(base::UTF16ToUTF8(expected_value), actual_value); |
1063 } | 1145 } |
1064 } | 1146 } |
1065 | 1147 |
1066 } // namespace content | 1148 } // namespace content |
OLD | NEW |