OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/memory/singleton.h" | 5 #include "base/memory/singleton.h" |
6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
7 #include "base/test/test_timeouts.h" | 7 #include "base/test/test_timeouts.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "content/browser/browser_plugin/browser_plugin_guest.h" | 9 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
10 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" | 10 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
473 // Wait for the guest to send an UpdateRectMsg, meaning it is ready. | 473 // Wait for the guest to send an UpdateRectMsg, meaning it is ready. |
474 test_guest->WaitForUpdateRectMsg(); | 474 test_guest->WaitForUpdateRectMsg(); |
475 | 475 |
476 // Hide the embedder. | 476 // Hide the embedder. |
477 embedder_web_contents->WasHidden(); | 477 embedder_web_contents->WasHidden(); |
478 | 478 |
479 // Make sure that hiding the embedder also hides the guest. | 479 // Make sure that hiding the embedder also hides the guest. |
480 test_guest->WaitUntilHidden(); | 480 test_guest->WaitUntilHidden(); |
481 } | 481 } |
482 | 482 |
483 // This test verifies that calling the reload method reloads the guest. | |
484 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, ReloadGuest) { | |
485 ASSERT_TRUE(test_server()->Start()); | |
486 GURL test_url(test_server()->GetURL( | |
487 "files/browser_plugin_embedder.html")); | |
488 NavigateToURL(shell(), test_url); | |
489 | |
490 WebContentsImpl* embedder_web_contents = static_cast<WebContentsImpl*>( | |
491 shell()->web_contents()); | |
492 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | |
493 embedder_web_contents->GetRenderViewHost()); | |
494 | |
495 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( | |
496 StringPrintf("SetSrc('%s');", kHTMLForGuest))); | |
497 | |
498 // Wait to make sure embedder is created/attached to WebContents. | |
499 TestBrowserPluginHostFactory::GetInstance()->WaitForEmbedderCreation(); | |
500 | |
501 TestBrowserPluginEmbedder* test_embedder = | |
502 static_cast<TestBrowserPluginEmbedder*>( | |
503 embedder_web_contents->GetBrowserPluginEmbedder()); | |
504 ASSERT_TRUE(test_embedder); | |
505 test_embedder->WaitForGuestAdded(); | |
Charlie Reis
2012/09/19 22:17:09
Does this work if the guest has already been added
Fady Samuel
2012/09/19 23:29:20
Yes, this returns immediately if a guest has alrea
| |
506 | |
507 // Verify that we have exactly one guest. | |
508 const BrowserPluginEmbedder::ContainerInstanceMap& instance_map = | |
509 test_embedder->guest_web_contents_for_testing(); | |
510 EXPECT_EQ(1u, instance_map.size()); | |
511 | |
512 WebContentsImpl* test_guest_web_contents = static_cast<WebContentsImpl*>( | |
513 instance_map.begin()->second); | |
514 TestBrowserPluginGuest* test_guest = static_cast<TestBrowserPluginGuest*>( | |
515 test_guest_web_contents->GetBrowserPluginGuest()); | |
516 test_guest->WaitForUpdateRectMsg(); | |
517 test_guest->ResetUpdateRectCount(); | |
518 | |
519 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( | |
520 "document.getElementById('plugin').reload()")); | |
521 // A successful reload will force the page to repaint itself as well, and | |
522 // thereby issue a ViewHostMsg_UpdateRect message. | |
523 test_guest->WaitForUpdateRectMsg(); | |
Charlie Reis
2012/09/19 22:17:09
Couldn't other things cause this message (like an
Fady Samuel
2012/09/19 23:29:20
Done. Implemented WaitForReload()
| |
524 } | |
525 | |
526 // This test verifies that calling the stop method forwards the stop request | |
527 // to the guest's WebContents. | |
528 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, StopGuest) { | |
529 ASSERT_TRUE(test_server()->Start()); | |
530 GURL test_url(test_server()->GetURL( | |
531 "files/browser_plugin_embedder.html")); | |
532 NavigateToURL(shell(), test_url); | |
533 | |
534 WebContentsImpl* embedder_web_contents = static_cast<WebContentsImpl*>( | |
535 shell()->web_contents()); | |
536 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | |
537 embedder_web_contents->GetRenderViewHost()); | |
538 | |
539 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( | |
540 StringPrintf("SetSrc('%s');", kHTMLForGuest))); | |
541 | |
542 // Wait to make sure embedder is created/attached to WebContents. | |
543 TestBrowserPluginHostFactory::GetInstance()->WaitForEmbedderCreation(); | |
544 | |
545 TestBrowserPluginEmbedder* test_embedder = | |
546 static_cast<TestBrowserPluginEmbedder*>( | |
547 embedder_web_contents->GetBrowserPluginEmbedder()); | |
548 ASSERT_TRUE(test_embedder); | |
549 test_embedder->WaitForGuestAdded(); | |
550 | |
551 // Verify that we have exactly one guest. | |
552 const BrowserPluginEmbedder::ContainerInstanceMap& instance_map = | |
553 test_embedder->guest_web_contents_for_testing(); | |
554 EXPECT_EQ(1u, instance_map.size()); | |
555 | |
556 WebContentsImpl* test_guest_web_contents = static_cast<WebContentsImpl*>( | |
557 instance_map.begin()->second); | |
558 TestBrowserPluginGuest* test_guest = static_cast<TestBrowserPluginGuest*>( | |
559 test_guest_web_contents->GetBrowserPluginGuest()); | |
560 test_guest->WaitForUpdateRectMsg(); | |
561 | |
562 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( | |
563 "document.getElementById('plugin').stop()")); | |
564 test_guest->WaitForStop(); | |
565 } | |
566 | |
483 } // namespace content | 567 } // namespace content |
OLD | NEW |