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

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

Issue 11728003: Change ExecuteJavaScript* helper functions in browser_test_utils.{h,cc} (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adding files for gpu_tests and NaCl browser tests. Created 7 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « content/browser/bookmarklet_browsertest.cc ('k') | content/browser/database_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/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/test/test_timeouts.h" 8 #include "base/test/test_timeouts.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "content/browser/browser_plugin/browser_plugin_guest.h" 10 #include "content/browser/browser_plugin/browser_plugin_guest.h"
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 SimulateKeyPress(web_contents, 267 SimulateKeyPress(web_contents,
268 ui::VKEY_TAB, 268 ui::VKEY_TAB,
269 false, // control. 269 false, // control.
270 false, // shift. 270 false, // shift.
271 false, // alt. 271 false, // alt.
272 false); // command. 272 false); // command.
273 } 273 }
274 274
275 // Executes the javascript synchronously and makes sure the returned value is 275 // Executes the javascript synchronously and makes sure the returned value is
276 // freed properly. 276 // freed properly.
277 void ExecuteSyncJSFunction(RenderViewHost* rvh, const string16& jscript) { 277 void ExecuteSyncJSFunction(RenderViewHost* rvh, const std::string& jscript) {
278 scoped_ptr<base::Value> value(rvh->ExecuteJavascriptAndGetValue( 278 scoped_ptr<base::Value> value(rvh->ExecuteJavascriptAndGetValue(
279 string16(), jscript)); 279 string16(), UTF8ToUTF16(jscript)));
280 } 280 }
281 281
282 // This helper method does the following: 282 // This helper method does the following:
283 // 1. Start the test server and navigate the shell to |embedder_url|. 283 // 1. Start the test server and navigate the shell to |embedder_url|.
284 // 2. Execute custom pre-navigation |embedder_code| if provided. 284 // 2. Execute custom pre-navigation |embedder_code| if provided.
285 // 3. Navigate the guest to the |guest_url|. 285 // 3. Navigate the guest to the |guest_url|.
286 // 4. Verify that the guest has been created and has completed loading. 286 // 4. Verify that the guest has been created and has completed loading.
287 void StartBrowserPluginTest(const std::string& embedder_url, 287 void StartBrowserPluginTest(const std::string& embedder_url,
288 const std::string& guest_url, 288 const std::string& guest_url,
289 bool is_guest_data_url, 289 bool is_guest_data_url,
290 const std::string& embedder_code) { 290 const std::string& embedder_code) {
291 ASSERT_TRUE(test_server()->Start()); 291 ASSERT_TRUE(test_server()->Start());
292 GURL test_url(test_server()->GetURL(embedder_url)); 292 GURL test_url(test_server()->GetURL(embedder_url));
293 NavigateToURL(shell(), test_url); 293 NavigateToURL(shell(), test_url);
294 294
295 WebContentsImpl* embedder_web_contents = static_cast<WebContentsImpl*>( 295 WebContentsImpl* embedder_web_contents = static_cast<WebContentsImpl*>(
296 shell()->web_contents()); 296 shell()->web_contents());
297 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( 297 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
298 embedder_web_contents->GetRenderViewHost()); 298 embedder_web_contents->GetRenderViewHost());
299 // Focus the embedder. 299 // Focus the embedder.
300 rvh->Focus(); 300 rvh->Focus();
301 301
302 // 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
303 // the first navigation of the guest. 303 // the first navigation of the guest.
304 if (!embedder_code.empty()) 304 if (!embedder_code.empty())
305 ExecuteSyncJSFunction(rvh, ASCIIToUTF16(embedder_code)); 305 ExecuteSyncJSFunction(rvh, embedder_code);
306 306
307 if (!is_guest_data_url) { 307 if (!is_guest_data_url) {
308 test_url = test_server()->GetURL(guest_url); 308 test_url = test_server()->GetURL(guest_url);
309 ExecuteSyncJSFunction(rvh, 309 ExecuteSyncJSFunction(
310 ASCIIToUTF16(StringPrintf("SetSrc('%s');", test_url.spec().c_str()))); 310 rvh, StringPrintf("SetSrc('%s');", test_url.spec().c_str()));
311 } else { 311 } else {
312 ExecuteSyncJSFunction(rvh, 312 ExecuteSyncJSFunction(
313 ASCIIToUTF16(StringPrintf("SetSrc('%s');", guest_url.c_str()))); 313 rvh, StringPrintf("SetSrc('%s');", guest_url.c_str()));
314 } 314 }
315 315
316 // Wait to make sure embedder is created/attached to WebContents. 316 // Wait to make sure embedder is created/attached to WebContents.
317 TestBrowserPluginHostFactory::GetInstance()->WaitForEmbedderCreation(); 317 TestBrowserPluginHostFactory::GetInstance()->WaitForEmbedderCreation();
318 318
319 test_embedder_ = static_cast<TestBrowserPluginEmbedder*>( 319 test_embedder_ = static_cast<TestBrowserPluginEmbedder*>(
320 embedder_web_contents->GetBrowserPluginEmbedder()); 320 embedder_web_contents->GetBrowserPluginEmbedder());
321 ASSERT_TRUE(test_embedder_); 321 ASSERT_TRUE(test_embedder_);
322 test_embedder_->WaitForGuestAdded(); 322 test_embedder_->WaitForGuestAdded();
323 323
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 const char kEmbedderURL[] = 359 const char kEmbedderURL[] =
360 "files/browser_plugin_embedder_guest_unresponsive.html"; 360 "files/browser_plugin_embedder_guest_unresponsive.html";
361 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuestBusyLoop, true, ""); 361 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuestBusyLoop, true, "");
362 // Wait until the busy loop starts. 362 // Wait until the busy loop starts.
363 { 363 {
364 const string16 expected_title = ASCIIToUTF16("start"); 364 const string16 expected_title = ASCIIToUTF16("start");
365 content::TitleWatcher title_watcher(test_guest()->web_contents(), 365 content::TitleWatcher title_watcher(test_guest()->web_contents(),
366 expected_title); 366 expected_title);
367 // Hang the guest for a length of time. 367 // Hang the guest for a length of time.
368 int spin_time = 10 * TestTimeouts::tiny_timeout().InMilliseconds(); 368 int spin_time = 10 * TestTimeouts::tiny_timeout().InMilliseconds();
369 ExecuteSyncJSFunction(test_guest()->web_contents()->GetRenderViewHost(), 369 ExecuteSyncJSFunction(
370 ASCIIToUTF16(StringPrintf("StartPauseMs(%d);", spin_time).c_str())); 370 test_guest()->web_contents()->GetRenderViewHost(),
371 StringPrintf("StartPauseMs(%d);", spin_time).c_str());
371 372
372 string16 actual_title = title_watcher.WaitAndGetTitle(); 373 string16 actual_title = title_watcher.WaitAndGetTitle();
373 EXPECT_EQ(expected_title, actual_title); 374 EXPECT_EQ(expected_title, actual_title);
374 } 375 }
375 { 376 {
376 const string16 expected_title = ASCIIToUTF16("done"); 377 const string16 expected_title = ASCIIToUTF16("done");
377 content::TitleWatcher title_watcher(test_embedder()->web_contents(), 378 content::TitleWatcher title_watcher(test_embedder()->web_contents(),
378 expected_title); 379 expected_title);
379 380
380 // Send a mouse event to the guest. 381 // Send a mouse event to the guest.
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 } 504 }
504 505
505 // This test verifies that hiding the embedder also hides the guest. 506 // This test verifies that hiding the embedder also hides the guest.
506 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, BrowserPluginVisibilityChanged) { 507 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, BrowserPluginVisibilityChanged) {
507 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; 508 const char kEmbedderURL[] = "files/browser_plugin_embedder.html";
508 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, ""); 509 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, "");
509 510
510 // Hide the Browser Plugin. 511 // Hide the Browser Plugin.
511 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( 512 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
512 test_embedder()->web_contents()->GetRenderViewHost()); 513 test_embedder()->web_contents()->GetRenderViewHost());
513 ExecuteSyncJSFunction(rvh, ASCIIToUTF16( 514 ExecuteSyncJSFunction(
514 "document.getElementById('plugin').style.visibility = 'hidden'")); 515 rvh, "document.getElementById('plugin').style.visibility = 'hidden'");
515 516
516 // Make sure that the guest is hidden. 517 // Make sure that the guest is hidden.
517 test_guest()->WaitUntilHidden(); 518 test_guest()->WaitUntilHidden();
518 } 519 }
519 520
520 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, EmbedderVisibilityChanged) { 521 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, EmbedderVisibilityChanged) {
521 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; 522 const char kEmbedderURL[] = "files/browser_plugin_embedder.html";
522 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, ""); 523 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, "");
523 524
524 // Hide the embedder. 525 // Hide the embedder.
525 test_embedder()->web_contents()->WasHidden(); 526 test_embedder()->web_contents()->WasHidden();
526 527
527 // Make sure that hiding the embedder also hides the guest. 528 // Make sure that hiding the embedder also hides the guest.
528 test_guest()->WaitUntilHidden(); 529 test_guest()->WaitUntilHidden();
529 } 530 }
530 531
531 // This test verifies that calling the reload method reloads the guest. 532 // This test verifies that calling the reload method reloads the guest.
532 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, ReloadGuest) { 533 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, ReloadGuest) {
533 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; 534 const char kEmbedderURL[] = "files/browser_plugin_embedder.html";
534 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, ""); 535 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, "");
535 536
536 test_guest()->ResetUpdateRectCount(); 537 test_guest()->ResetUpdateRectCount();
537 538
538 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( 539 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
539 test_embedder()->web_contents()->GetRenderViewHost()); 540 test_embedder()->web_contents()->GetRenderViewHost());
540 ExecuteSyncJSFunction(rvh, ASCIIToUTF16( 541 ExecuteSyncJSFunction(rvh, "document.getElementById('plugin').reload()");
541 "document.getElementById('plugin').reload()"));
542 test_guest()->WaitForReload(); 542 test_guest()->WaitForReload();
543 } 543 }
544 544
545 // This test verifies that calling the stop method forwards the stop request 545 // This test verifies that calling the stop method forwards the stop request
546 // to the guest's WebContents. 546 // to the guest's WebContents.
547 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, StopGuest) { 547 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, StopGuest) {
548 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; 548 const char kEmbedderURL[] = "files/browser_plugin_embedder.html";
549 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, ""); 549 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, "");
550 550
551 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( 551 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
552 test_embedder()->web_contents()->GetRenderViewHost()); 552 test_embedder()->web_contents()->GetRenderViewHost());
553 ExecuteSyncJSFunction(rvh, ASCIIToUTF16( 553 ExecuteSyncJSFunction(rvh, "document.getElementById('plugin').stop()");
554 "document.getElementById('plugin').stop()"));
555 test_guest()->WaitForStop(); 554 test_guest()->WaitForStop();
556 } 555 }
557 556
558 // Verifies that installing/uninstalling touch-event handlers in the guest 557 // Verifies that installing/uninstalling touch-event handlers in the guest
559 // plugin correctly updates the touch-event handling state in the embedder. 558 // plugin correctly updates the touch-event handling state in the embedder.
560 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, AcceptTouchEvents) { 559 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, AcceptTouchEvents) {
561 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; 560 const char kEmbedderURL[] = "files/browser_plugin_embedder.html";
562 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuestTouchHandler, true, ""); 561 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuestTouchHandler, true, "");
563 562
564 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( 563 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
565 test_embedder()->web_contents()->GetRenderViewHost()); 564 test_embedder()->web_contents()->GetRenderViewHost());
566 // The embedder should not have any touch event handlers at this point. 565 // The embedder should not have any touch event handlers at this point.
567 EXPECT_FALSE(rvh->has_touch_handler()); 566 EXPECT_FALSE(rvh->has_touch_handler());
568 567
569 // Install the touch handler in the guest. This should cause the embedder to 568 // Install the touch handler in the guest. This should cause the embedder to
570 // start listening for touch events too. 569 // start listening for touch events too.
571 RenderViewHostMessageObserver observer(rvh, 570 RenderViewHostMessageObserver observer(rvh,
572 ViewHostMsg_HasTouchEventHandlers::ID); 571 ViewHostMsg_HasTouchEventHandlers::ID);
573 ExecuteSyncJSFunction(test_guest()->web_contents()->GetRenderViewHost(), 572 ExecuteSyncJSFunction(test_guest()->web_contents()->GetRenderViewHost(),
574 ASCIIToUTF16("InstallTouchHandler();")); 573 "InstallTouchHandler();");
575 observer.WaitUntilMessageReceived(); 574 observer.WaitUntilMessageReceived();
576 EXPECT_TRUE(rvh->has_touch_handler()); 575 EXPECT_TRUE(rvh->has_touch_handler());
577 576
578 // Uninstalling the touch-handler in guest should cause the embedder to stop 577 // Uninstalling the touch-handler in guest should cause the embedder to stop
579 // listening for touch events. 578 // listening for touch events.
580 observer.ResetState(); 579 observer.ResetState();
581 ExecuteSyncJSFunction(test_guest()->web_contents()->GetRenderViewHost(), 580 ExecuteSyncJSFunction(test_guest()->web_contents()->GetRenderViewHost(),
582 ASCIIToUTF16("UninstallTouchHandler();")); 581 "UninstallTouchHandler();");
583 observer.WaitUntilMessageReceived(); 582 observer.WaitUntilMessageReceived();
584 EXPECT_FALSE(rvh->has_touch_handler()); 583 EXPECT_FALSE(rvh->has_touch_handler());
585 } 584 }
586 585
587 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, Renavigate) { 586 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, Renavigate) {
588 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; 587 const char kEmbedderURL[] = "files/browser_plugin_embedder.html";
589 StartBrowserPluginTest( 588 StartBrowserPluginTest(
590 kEmbedderURL, GetHTMLForGuestWithTitle("P1"), true, ""); 589 kEmbedderURL, GetHTMLForGuestWithTitle("P1"), true, "");
591 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( 590 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
592 test_embedder()->web_contents()->GetRenderViewHost()); 591 test_embedder()->web_contents()->GetRenderViewHost());
593 592
594 // Navigate to P2 and verify that the navigation occurred. 593 // Navigate to P2 and verify that the navigation occurred.
595 { 594 {
596 const string16 expected_title = ASCIIToUTF16("P2"); 595 const string16 expected_title = ASCIIToUTF16("P2");
597 content::TitleWatcher title_watcher(test_guest()->web_contents(), 596 content::TitleWatcher title_watcher(test_guest()->web_contents(),
598 expected_title); 597 expected_title);
599 598
600 ExecuteSyncJSFunction(rvh, ASCIIToUTF16(StringPrintf("SetSrc('%s');", 599 ExecuteSyncJSFunction(
601 GetHTMLForGuestWithTitle("P2").c_str()))); 600 rvh,
601 StringPrintf("SetSrc('%s');", GetHTMLForGuestWithTitle("P2").c_str()));
602 602
603 string16 actual_title = title_watcher.WaitAndGetTitle(); 603 string16 actual_title = title_watcher.WaitAndGetTitle();
604 EXPECT_EQ(expected_title, actual_title); 604 EXPECT_EQ(expected_title, actual_title);
605 } 605 }
606 606
607 // Navigate to P3 and verify that the navigation occurred. 607 // Navigate to P3 and verify that the navigation occurred.
608 { 608 {
609 const string16 expected_title = ASCIIToUTF16("P3"); 609 const string16 expected_title = ASCIIToUTF16("P3");
610 content::TitleWatcher title_watcher(test_guest()->web_contents(), 610 content::TitleWatcher title_watcher(test_guest()->web_contents(),
611 expected_title); 611 expected_title);
612 612
613 ExecuteSyncJSFunction(rvh, ASCIIToUTF16(StringPrintf("SetSrc('%s');", 613 ExecuteSyncJSFunction(
614 GetHTMLForGuestWithTitle("P3").c_str()))); 614 rvh,
615 StringPrintf("SetSrc('%s');", GetHTMLForGuestWithTitle("P3").c_str()));
615 616
616 string16 actual_title = title_watcher.WaitAndGetTitle(); 617 string16 actual_title = title_watcher.WaitAndGetTitle();
617 EXPECT_EQ(expected_title, actual_title); 618 EXPECT_EQ(expected_title, actual_title);
618 } 619 }
619 620
620 // Go back and verify that we're back at P2. 621 // Go back and verify that we're back at P2.
621 { 622 {
622 const string16 expected_title = ASCIIToUTF16("P2"); 623 const string16 expected_title = ASCIIToUTF16("P2");
623 content::TitleWatcher title_watcher(test_guest()->web_contents(), 624 content::TitleWatcher title_watcher(test_guest()->web_contents(),
624 expected_title); 625 expected_title);
625 626
626 ExecuteSyncJSFunction(rvh, ASCIIToUTF16("Back();")); 627 ExecuteSyncJSFunction(rvh, "Back();");
627 string16 actual_title = title_watcher.WaitAndGetTitle(); 628 string16 actual_title = title_watcher.WaitAndGetTitle();
628 EXPECT_EQ(expected_title, actual_title); 629 EXPECT_EQ(expected_title, actual_title);
629 630
630 scoped_ptr<base::Value> value(rvh->ExecuteJavascriptAndGetValue(string16(), 631 scoped_ptr<base::Value> value(rvh->ExecuteJavascriptAndGetValue(string16(),
631 ASCIIToUTF16("CanGoBack()"))); 632 ASCIIToUTF16("CanGoBack()")));
632 bool result = false; 633 bool result = false;
633 ASSERT_TRUE(value->GetAsBoolean(&result)); 634 ASSERT_TRUE(value->GetAsBoolean(&result));
634 EXPECT_TRUE(result); 635 EXPECT_TRUE(result);
635 636
636 value.reset(rvh->ExecuteJavascriptAndGetValue(string16(), 637 value.reset(rvh->ExecuteJavascriptAndGetValue(string16(),
637 ASCIIToUTF16("CanGoForward()"))); 638 ASCIIToUTF16("CanGoForward()")));
638 result = false; 639 result = false;
639 ASSERT_TRUE(value->GetAsBoolean(&result)); 640 ASSERT_TRUE(value->GetAsBoolean(&result));
640 EXPECT_TRUE(result); 641 EXPECT_TRUE(result);
641 } 642 }
642 643
643 // Go forward and verify that we're back at P3. 644 // Go forward and verify that we're back at P3.
644 { 645 {
645 const string16 expected_title = ASCIIToUTF16("P3"); 646 const string16 expected_title = ASCIIToUTF16("P3");
646 content::TitleWatcher title_watcher(test_guest()->web_contents(), 647 content::TitleWatcher title_watcher(test_guest()->web_contents(),
647 expected_title); 648 expected_title);
648 649
649 ExecuteSyncJSFunction(rvh, ASCIIToUTF16("Forward();")); 650 ExecuteSyncJSFunction(rvh, "Forward();");
650 string16 actual_title = title_watcher.WaitAndGetTitle(); 651 string16 actual_title = title_watcher.WaitAndGetTitle();
651 EXPECT_EQ(expected_title, actual_title); 652 EXPECT_EQ(expected_title, actual_title);
652 653
653 scoped_ptr<base::Value> value(rvh->ExecuteJavascriptAndGetValue(string16(), 654 scoped_ptr<base::Value> value(rvh->ExecuteJavascriptAndGetValue(string16(),
654 ASCIIToUTF16("CanGoForward()"))); 655 ASCIIToUTF16("CanGoForward()")));
655 bool result = true; 656 bool result = true;
656 ASSERT_TRUE(value->GetAsBoolean(&result)); 657 ASSERT_TRUE(value->GetAsBoolean(&result));
657 EXPECT_FALSE(result); 658 EXPECT_FALSE(result);
658 } 659 }
659 660
660 // Go back two entries and verify that we're back at P1. 661 // Go back two entries and verify that we're back at P1.
661 { 662 {
662 const string16 expected_title = ASCIIToUTF16("P1"); 663 const string16 expected_title = ASCIIToUTF16("P1");
663 content::TitleWatcher title_watcher(test_guest()->web_contents(), 664 content::TitleWatcher title_watcher(test_guest()->web_contents(),
664 expected_title); 665 expected_title);
665 666
666 ExecuteSyncJSFunction(rvh, ASCIIToUTF16("Go(-2);")); 667 ExecuteSyncJSFunction(rvh, "Go(-2);");
667 string16 actual_title = title_watcher.WaitAndGetTitle(); 668 string16 actual_title = title_watcher.WaitAndGetTitle();
668 EXPECT_EQ(expected_title, actual_title); 669 EXPECT_EQ(expected_title, actual_title);
669 670
670 scoped_ptr<base::Value> value(rvh->ExecuteJavascriptAndGetValue(string16(), 671 scoped_ptr<base::Value> value(rvh->ExecuteJavascriptAndGetValue(string16(),
671 ASCIIToUTF16("CanGoBack()"))); 672 ASCIIToUTF16("CanGoBack()")));
672 bool result = true; 673 bool result = true;
673 ASSERT_TRUE(value->GetAsBoolean(&result)); 674 ASSERT_TRUE(value->GetAsBoolean(&result));
674 EXPECT_FALSE(result); 675 EXPECT_FALSE(result);
675 } 676 }
676 } 677 }
677 678
678 // This tests verifies that reloading the embedder does not crash the browser 679 // This tests verifies that reloading the embedder does not crash the browser
679 // and that the guest is reset. 680 // and that the guest is reset.
680 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, ReloadEmbedder) { 681 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, ReloadEmbedder) {
681 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; 682 const char kEmbedderURL[] = "files/browser_plugin_embedder.html";
682 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, ""); 683 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, "");
683 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( 684 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
684 test_embedder()->web_contents()->GetRenderViewHost()); 685 test_embedder()->web_contents()->GetRenderViewHost());
685 686
686 // Change the title of the page to 'modified' so that we know that 687 // Change the title of the page to 'modified' so that we know that
687 // the page has successfully reloaded when it goes back to 'embedder' 688 // the page has successfully reloaded when it goes back to 'embedder'
688 // in the next step. 689 // in the next step.
689 { 690 {
690 const string16 expected_title = ASCIIToUTF16("modified"); 691 const string16 expected_title = ASCIIToUTF16("modified");
691 content::TitleWatcher title_watcher(test_embedder()->web_contents(), 692 content::TitleWatcher title_watcher(test_embedder()->web_contents(),
692 expected_title); 693 expected_title);
693 694
694 ExecuteSyncJSFunction(rvh, ASCIIToUTF16(StringPrintf("SetTitle('%s');", 695 ExecuteSyncJSFunction(rvh, StringPrintf("SetTitle('%s');", "modified"));
695 "modified")));
696 696
697 string16 actual_title = title_watcher.WaitAndGetTitle(); 697 string16 actual_title = title_watcher.WaitAndGetTitle();
698 EXPECT_EQ(expected_title, actual_title); 698 EXPECT_EQ(expected_title, actual_title);
699 } 699 }
700 700
701 // Reload the embedder page, and verify that the reload was successful. 701 // Reload the embedder page, and verify that the reload was successful.
702 // Then navigate the guest to verify that the browser process does not crash. 702 // Then navigate the guest to verify that the browser process does not crash.
703 { 703 {
704 const string16 expected_title = ASCIIToUTF16("embedder"); 704 const string16 expected_title = ASCIIToUTF16("embedder");
705 content::TitleWatcher title_watcher(test_embedder()->web_contents(), 705 content::TitleWatcher title_watcher(test_embedder()->web_contents(),
706 expected_title); 706 expected_title);
707 707
708 test_embedder()->web_contents()->GetController().Reload(false); 708 test_embedder()->web_contents()->GetController().Reload(false);
709 string16 actual_title = title_watcher.WaitAndGetTitle(); 709 string16 actual_title = title_watcher.WaitAndGetTitle();
710 EXPECT_EQ(expected_title, actual_title); 710 EXPECT_EQ(expected_title, actual_title);
711 711
712 ExecuteSyncJSFunction(test_embedder()->web_contents()->GetRenderViewHost(), 712 ExecuteSyncJSFunction(
713 ASCIIToUTF16(StringPrintf("SetSrc('%s');", kHTMLForGuest))); 713 test_embedder()->web_contents()->GetRenderViewHost(),
714 StringPrintf("SetSrc('%s');", kHTMLForGuest));
714 715
715 const BrowserPluginEmbedder::ContainerInstanceMap& instance_map = 716 const BrowserPluginEmbedder::ContainerInstanceMap& instance_map =
716 test_embedder()->guest_web_contents_for_testing(); 717 test_embedder()->guest_web_contents_for_testing();
717 WebContentsImpl* test_guest_web_contents = static_cast<WebContentsImpl*>( 718 WebContentsImpl* test_guest_web_contents = static_cast<WebContentsImpl*>(
718 instance_map.begin()->second); 719 instance_map.begin()->second);
719 TestBrowserPluginGuest* new_test_guest = 720 TestBrowserPluginGuest* new_test_guest =
720 static_cast<TestBrowserPluginGuest*>( 721 static_cast<TestBrowserPluginGuest*>(
721 test_guest_web_contents->GetBrowserPluginGuest()); 722 test_guest_web_contents->GetBrowserPluginGuest());
722 723
723 // Wait for the guest to send an UpdateRectMsg, meaning it is ready. 724 // Wait for the guest to send an UpdateRectMsg, meaning it is ready.
724 new_test_guest->WaitForUpdateRectMsg(); 725 new_test_guest->WaitForUpdateRectMsg();
725 } 726 }
726 } 727 }
727 728
728 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, TerminateGuest) { 729 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, TerminateGuest) {
729 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; 730 const char kEmbedderURL[] = "files/browser_plugin_embedder.html";
730 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, ""); 731 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, "");
731 732
732 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( 733 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
733 test_embedder()->web_contents()->GetRenderViewHost()); 734 test_embedder()->web_contents()->GetRenderViewHost());
734 ExecuteSyncJSFunction(rvh, ASCIIToUTF16( 735 ExecuteSyncJSFunction(rvh, "document.getElementById('plugin').terminate()");
735 "document.getElementById('plugin').terminate()"));
736 736
737 // Expect the guest to crash. 737 // Expect the guest to crash.
738 test_guest()->WaitForExit(); 738 test_guest()->WaitForExit();
739 } 739 }
740 740
741 // This test verifies that the guest is responsive after crashing and going back 741 // This test verifies that the guest is responsive after crashing and going back
742 // to a previous navigation entry. 742 // to a previous navigation entry.
743 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, BackAfterTerminateGuest) { 743 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, BackAfterTerminateGuest) {
744 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; 744 const char* kEmbedderURL = "files/browser_plugin_embedder.html";
745 StartBrowserPluginTest( 745 StartBrowserPluginTest(
746 kEmbedderURL, GetHTMLForGuestWithTitle("P1"), true, ""); 746 kEmbedderURL, GetHTMLForGuestWithTitle("P1"), true, "");
747 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( 747 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
748 test_embedder()->web_contents()->GetRenderViewHost()); 748 test_embedder()->web_contents()->GetRenderViewHost());
749 749
750 // Navigate to P2 and verify that the navigation occurred. 750 // Navigate to P2 and verify that the navigation occurred.
751 { 751 {
752 const string16 expected_title = ASCIIToUTF16("P2"); 752 const string16 expected_title = ASCIIToUTF16("P2");
753 content::TitleWatcher title_watcher(test_guest()->web_contents(), 753 content::TitleWatcher title_watcher(test_guest()->web_contents(),
754 expected_title); 754 expected_title);
755 755
756 ExecuteSyncJSFunction(rvh, ASCIIToUTF16(StringPrintf("SetSrc('%s');", 756 ExecuteSyncJSFunction(
757 GetHTMLForGuestWithTitle("P2").c_str()))); 757 rvh,
758 StringPrintf("SetSrc('%s');", GetHTMLForGuestWithTitle("P2").c_str()));
758 759
759 string16 actual_title = title_watcher.WaitAndGetTitle(); 760 string16 actual_title = title_watcher.WaitAndGetTitle();
760 EXPECT_EQ(expected_title, actual_title); 761 EXPECT_EQ(expected_title, actual_title);
761 } 762 }
762 // Kill the guest. 763 // Kill the guest.
763 ExecuteSyncJSFunction(rvh, 764 ExecuteSyncJSFunction(rvh, "document.getElementById('plugin').terminate()");
764 ASCIIToUTF16("document.getElementById('plugin').terminate()"));
765 765
766 // Expect the guest to report that it crashed. 766 // Expect the guest to report that it crashed.
767 test_guest()->WaitForExit(); 767 test_guest()->WaitForExit();
768 // Go back and verify that we're back at P1. 768 // Go back and verify that we're back at P1.
769 { 769 {
770 const string16 expected_title = ASCIIToUTF16("P1"); 770 const string16 expected_title = ASCIIToUTF16("P1");
771 content::TitleWatcher title_watcher(test_guest()->web_contents(), 771 content::TitleWatcher title_watcher(test_guest()->web_contents(),
772 expected_title); 772 expected_title);
773 773
774 ExecuteSyncJSFunction(rvh, ASCIIToUTF16("Back();")); 774 ExecuteSyncJSFunction(rvh, "Back();");
775 775
776 string16 actual_title = title_watcher.WaitAndGetTitle(); 776 string16 actual_title = title_watcher.WaitAndGetTitle();
777 EXPECT_EQ(expected_title, actual_title); 777 EXPECT_EQ(expected_title, actual_title);
778 } 778 }
779 // Send an input event and verify that the guest receives the input. 779 // Send an input event and verify that the guest receives the input.
780 SimulateMouseClick(test_embedder()->web_contents(), 0, 780 SimulateMouseClick(test_embedder()->web_contents(), 0,
781 WebKit::WebMouseEvent::ButtonLeft); 781 WebKit::WebMouseEvent::ButtonLeft);
782 test_guest()->WaitForInput(); 782 test_guest()->WaitForInput();
783 } 783 }
784 784
785 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadStart) { 785 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadStart) {
786 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; 786 const char kEmbedderURL[] = "files/browser_plugin_embedder.html";
787 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, ""); 787 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, "");
788 788
789 const string16 expected_title = ASCIIToUTF16(kHTMLForGuest); 789 const string16 expected_title = ASCIIToUTF16(kHTMLForGuest);
790 content::TitleWatcher title_watcher(test_embedder()->web_contents(), 790 content::TitleWatcher title_watcher(test_embedder()->web_contents(),
791 expected_title); 791 expected_title);
792 // Renavigate the guest to |kHTMLForGuest|. 792 // Renavigate the guest to |kHTMLForGuest|.
793 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( 793 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
794 test_embedder()->web_contents()->GetRenderViewHost()); 794 test_embedder()->web_contents()->GetRenderViewHost());
795 ExecuteSyncJSFunction(rvh, ASCIIToUTF16( 795 ExecuteSyncJSFunction(rvh, StringPrintf("SetSrc('%s');", kHTMLForGuest));
796 StringPrintf("SetSrc('%s');", kHTMLForGuest)));
797 796
798 string16 actual_title = title_watcher.WaitAndGetTitle(); 797 string16 actual_title = title_watcher.WaitAndGetTitle();
799 EXPECT_EQ(expected_title, actual_title); 798 EXPECT_EQ(expected_title, actual_title);
800 } 799 }
801 800
802 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadAbort) { 801 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadAbort) {
803 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; 802 const char kEmbedderURL[] = "files/browser_plugin_embedder.html";
804 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, ""); 803 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, "");
805 804
806 { 805 {
807 // Navigate the guest to "close-socket". 806 // Navigate the guest to "close-socket".
808 const string16 expected_title = ASCIIToUTF16("ERR_EMPTY_RESPONSE"); 807 const string16 expected_title = ASCIIToUTF16("ERR_EMPTY_RESPONSE");
809 content::TitleWatcher title_watcher(test_embedder()->web_contents(), 808 content::TitleWatcher title_watcher(test_embedder()->web_contents(),
810 expected_title); 809 expected_title);
811 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( 810 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
812 test_embedder()->web_contents()->GetRenderViewHost()); 811 test_embedder()->web_contents()->GetRenderViewHost());
813 GURL test_url = test_server()->GetURL("close-socket"); 812 GURL test_url = test_server()->GetURL("close-socket");
814 ExecuteSyncJSFunction(rvh, ASCIIToUTF16( 813 ExecuteSyncJSFunction(
815 StringPrintf("SetSrc('%s');", test_url.spec().c_str()))); 814 rvh, StringPrintf("SetSrc('%s');", test_url.spec().c_str()));
816 string16 actual_title = title_watcher.WaitAndGetTitle(); 815 string16 actual_title = title_watcher.WaitAndGetTitle();
817 EXPECT_EQ(expected_title, actual_title); 816 EXPECT_EQ(expected_title, actual_title);
818 } 817 }
819 818
820 { 819 {
821 // Navigate the guest to an illegal chrome:// URL. 820 // Navigate the guest to an illegal chrome:// URL.
822 const string16 expected_title = ASCIIToUTF16("ERR_FAILED"); 821 const string16 expected_title = ASCIIToUTF16("ERR_FAILED");
823 content::TitleWatcher title_watcher(test_embedder()->web_contents(), 822 content::TitleWatcher title_watcher(test_embedder()->web_contents(),
824 expected_title); 823 expected_title);
825 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( 824 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
826 test_embedder()->web_contents()->GetRenderViewHost()); 825 test_embedder()->web_contents()->GetRenderViewHost());
827 GURL test_url("chrome://newtab"); 826 GURL test_url("chrome://newtab");
828 ExecuteSyncJSFunction(rvh, ASCIIToUTF16( 827 ExecuteSyncJSFunction(
829 StringPrintf("SetSrc('%s');", test_url.spec().c_str()))); 828 rvh, StringPrintf("SetSrc('%s');", test_url.spec().c_str()));
830 string16 actual_title = title_watcher.WaitAndGetTitle(); 829 string16 actual_title = title_watcher.WaitAndGetTitle();
831 EXPECT_EQ(expected_title, actual_title); 830 EXPECT_EQ(expected_title, actual_title);
832 } 831 }
833 832
834 { 833 {
835 // Navigate the guest to an illegal file:// URL. 834 // Navigate the guest to an illegal file:// URL.
836 const string16 expected_title = ASCIIToUTF16("ERR_ABORTED"); 835 const string16 expected_title = ASCIIToUTF16("ERR_ABORTED");
837 content::TitleWatcher title_watcher(test_embedder()->web_contents(), 836 content::TitleWatcher title_watcher(test_embedder()->web_contents(),
838 expected_title); 837 expected_title);
839 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( 838 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
840 test_embedder()->web_contents()->GetRenderViewHost()); 839 test_embedder()->web_contents()->GetRenderViewHost());
841 GURL test_url("file://foo"); 840 GURL test_url("file://foo");
842 ExecuteSyncJSFunction(rvh, ASCIIToUTF16( 841 ExecuteSyncJSFunction(
843 StringPrintf("SetSrc('%s');", test_url.spec().c_str()))); 842 rvh, StringPrintf("SetSrc('%s');", test_url.spec().c_str()));
844 string16 actual_title = title_watcher.WaitAndGetTitle(); 843 string16 actual_title = title_watcher.WaitAndGetTitle();
845 EXPECT_EQ(expected_title, actual_title); 844 EXPECT_EQ(expected_title, actual_title);
846 } 845 }
847 } 846 }
848 847
849 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadRedirect) { 848 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadRedirect) {
850 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; 849 const char kEmbedderURL[] = "files/browser_plugin_embedder.html";
851 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, ""); 850 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, "");
852 851
853 const string16 expected_title = ASCIIToUTF16("redirected"); 852 const string16 expected_title = ASCIIToUTF16("redirected");
854 content::TitleWatcher title_watcher(test_embedder()->web_contents(), 853 content::TitleWatcher title_watcher(test_embedder()->web_contents(),
855 expected_title); 854 expected_title);
856 855
857 // Navigate with a redirect and wait until the title changes. 856 // Navigate with a redirect and wait until the title changes.
858 GURL redirect_url(test_server()->GetURL( 857 GURL redirect_url(test_server()->GetURL(
859 "server-redirect?files/title1.html")); 858 "server-redirect?files/title1.html"));
860 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( 859 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
861 test_embedder()->web_contents()->GetRenderViewHost()); 860 test_embedder()->web_contents()->GetRenderViewHost());
862 ExecuteSyncJSFunction(rvh, ASCIIToUTF16( 861 ExecuteSyncJSFunction(
863 StringPrintf("SetSrc('%s');", redirect_url.spec().c_str()))); 862 rvh, StringPrintf("SetSrc('%s');", redirect_url.spec().c_str()));
864 863
865 string16 actual_title = title_watcher.WaitAndGetTitle(); 864 string16 actual_title = title_watcher.WaitAndGetTitle();
866 EXPECT_EQ(expected_title, actual_title); 865 EXPECT_EQ(expected_title, actual_title);
867 866
868 // Verify that we heard a loadRedirect during the navigation. 867 // Verify that we heard a loadRedirect during the navigation.
869 scoped_ptr<base::Value> value(rvh->ExecuteJavascriptAndGetValue( 868 scoped_ptr<base::Value> value(rvh->ExecuteJavascriptAndGetValue(
870 string16(), ASCIIToUTF16("redirectOldUrl"))); 869 string16(), ASCIIToUTF16("redirectOldUrl")));
871 std::string result; 870 std::string result;
872 EXPECT_TRUE(value->GetAsString(&result)); 871 EXPECT_TRUE(value->GetAsString(&result));
873 EXPECT_EQ(redirect_url.spec().c_str(), result); 872 EXPECT_EQ(redirect_url.spec().c_str(), result);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 StartBrowserPluginTest(kEmbedderURL, kGuestURL, false, ""); 941 StartBrowserPluginTest(kEmbedderURL, kGuestURL, false, "");
943 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( 942 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
944 test_embedder()->web_contents()->GetRenderViewHost()); 943 test_embedder()->web_contents()->GetRenderViewHost());
945 { 944 {
946 const string16 expected_title = ASCIIToUTF16("main guest"); 945 const string16 expected_title = ASCIIToUTF16("main guest");
947 content::TitleWatcher title_watcher(test_embedder()->web_contents(), 946 content::TitleWatcher title_watcher(test_embedder()->web_contents(),
948 expected_title); 947 expected_title);
949 948
950 // By the time we get here 'contentWindow' should be ready because the 949 // By the time we get here 'contentWindow' should be ready because the
951 // guest has completed loading. 950 // guest has completed loading.
952 ExecuteSyncJSFunction(rvh, 951 ExecuteSyncJSFunction(
953 ASCIIToUTF16(StringPrintf("PostMessage('%s, false');", kTesting))); 952 rvh, StringPrintf("PostMessage('%s, false');", kTesting));
954 953
955 // The title will be updated to "main guest" at the last stage of the 954 // The title will be updated to "main guest" at the last stage of the
956 // process described above. 955 // process described above.
957 string16 actual_title = title_watcher.WaitAndGetTitle(); 956 string16 actual_title = title_watcher.WaitAndGetTitle();
958 EXPECT_EQ(expected_title, actual_title); 957 EXPECT_EQ(expected_title, actual_title);
959 } 958 }
960 } 959 }
961 960
962 // This is the same as BrowserPluginHostTest.PostMessage but also 961 // This is the same as BrowserPluginHostTest.PostMessage but also
963 // posts a message to an iframe. 962 // posts a message to an iframe.
964 // TODO(fsamuel): This test should replace the previous test once postMessage 963 // TODO(fsamuel): This test should replace the previous test once postMessage
965 // iframe targeting is fixed (see http://crbug.com/153701). 964 // iframe targeting is fixed (see http://crbug.com/153701).
966 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, DISABLED_PostMessageToIFrame) { 965 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, DISABLED_PostMessageToIFrame) {
967 const char* kTesting = "testing123"; 966 const char* kTesting = "testing123";
968 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; 967 const char* kEmbedderURL = "files/browser_plugin_embedder.html";
969 const char* kGuestURL = "files/browser_plugin_post_message_guest.html"; 968 const char* kGuestURL = "files/browser_plugin_post_message_guest.html";
970 StartBrowserPluginTest(kEmbedderURL, kGuestURL, false, ""); 969 StartBrowserPluginTest(kEmbedderURL, kGuestURL, false, "");
971 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( 970 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
972 test_embedder()->web_contents()->GetRenderViewHost()); 971 test_embedder()->web_contents()->GetRenderViewHost());
973 { 972 {
974 const string16 expected_title = ASCIIToUTF16("main guest"); 973 const string16 expected_title = ASCIIToUTF16("main guest");
975 content::TitleWatcher title_watcher(test_embedder()->web_contents(), 974 content::TitleWatcher title_watcher(test_embedder()->web_contents(),
976 expected_title); 975 expected_title);
977 976
978 ExecuteSyncJSFunction(rvh, 977 ExecuteSyncJSFunction(
979 ASCIIToUTF16(StringPrintf("PostMessage('%s, false');", kTesting))); 978 rvh, StringPrintf("PostMessage('%s, false');", kTesting));
980 979
981 // The title will be updated to "main guest" at the last stage of the 980 // The title will be updated to "main guest" at the last stage of the
982 // process described above. 981 // process described above.
983 string16 actual_title = title_watcher.WaitAndGetTitle(); 982 string16 actual_title = title_watcher.WaitAndGetTitle();
984 EXPECT_EQ(expected_title, actual_title); 983 EXPECT_EQ(expected_title, actual_title);
985 } 984 }
986 { 985 {
987 content::TitleWatcher ready_watcher(test_embedder()->web_contents(), 986 content::TitleWatcher ready_watcher(test_embedder()->web_contents(),
988 ASCIIToUTF16("ready")); 987 ASCIIToUTF16("ready"));
989 988
990 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( 989 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>(
991 test_guest()->web_contents()->GetRenderViewHost()); 990 test_guest()->web_contents()->GetRenderViewHost());
992 GURL test_url = test_server()->GetURL( 991 GURL test_url = test_server()->GetURL(
993 "files/browser_plugin_post_message_guest.html"); 992 "files/browser_plugin_post_message_guest.html");
994 ExecuteSyncJSFunction(guest_rvh, 993 ExecuteSyncJSFunction(
995 ASCIIToUTF16(StringPrintf("CreateChildFrame('%s');", 994 guest_rvh,
996 test_url.spec().c_str()))); 995 StringPrintf("CreateChildFrame('%s');", test_url.spec().c_str()));
997 996
998 string16 actual_title = ready_watcher.WaitAndGetTitle(); 997 string16 actual_title = ready_watcher.WaitAndGetTitle();
999 EXPECT_EQ(ASCIIToUTF16("ready"), actual_title); 998 EXPECT_EQ(ASCIIToUTF16("ready"), actual_title);
1000 999
1001 content::TitleWatcher iframe_watcher(test_embedder()->web_contents(), 1000 content::TitleWatcher iframe_watcher(test_embedder()->web_contents(),
1002 ASCIIToUTF16("iframe")); 1001 ASCIIToUTF16("iframe"));
1003 ExecuteSyncJSFunction(rvh, 1002 ExecuteSyncJSFunction(
1004 ASCIIToUTF16(StringPrintf("PostMessage('%s', true);", kTesting))); 1003 rvh, StringPrintf("PostMessage('%s', true);", kTesting));
1005 1004
1006 // The title will be updated to "iframe" at the last stage of the 1005 // The title will be updated to "iframe" at the last stage of the
1007 // process described above. 1006 // process described above.
1008 actual_title = iframe_watcher.WaitAndGetTitle(); 1007 actual_title = iframe_watcher.WaitAndGetTitle();
1009 EXPECT_EQ(ASCIIToUTF16("iframe"), actual_title); 1008 EXPECT_EQ(ASCIIToUTF16("iframe"), actual_title);
1010 } 1009 }
1011 } 1010 }
1012 1011
1013 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadStop) { 1012 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadStop) {
1014 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; 1013 const char* kEmbedderURL = "files/browser_plugin_embedder.html";
1015 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, ""); 1014 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, "");
1016 1015
1017 const string16 expected_title = ASCIIToUTF16("loadStop"); 1016 const string16 expected_title = ASCIIToUTF16("loadStop");
1018 content::TitleWatcher title_watcher( 1017 content::TitleWatcher title_watcher(
1019 test_embedder()->web_contents(), expected_title); 1018 test_embedder()->web_contents(), expected_title);
1020 // Renavigate the guest to |kHTMLForGuest|. 1019 // Renavigate the guest to |kHTMLForGuest|.
1021 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( 1020 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
1022 test_embedder()->web_contents()->GetRenderViewHost()); 1021 test_embedder()->web_contents()->GetRenderViewHost());
1023 ExecuteSyncJSFunction(rvh, ASCIIToUTF16( 1022 ExecuteSyncJSFunction(rvh, StringPrintf("SetSrc('%s');", kHTMLForGuest));
1024 StringPrintf("SetSrc('%s');", kHTMLForGuest)));
1025 1023
1026 string16 actual_title = title_watcher.WaitAndGetTitle(); 1024 string16 actual_title = title_watcher.WaitAndGetTitle();
1027 EXPECT_EQ(expected_title, actual_title); 1025 EXPECT_EQ(expected_title, actual_title);
1028 } 1026 }
1029 1027
1030 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadCommit) { 1028 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadCommit) {
1031 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; 1029 const char* kEmbedderURL = "files/browser_plugin_embedder.html";
1032 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, ""); 1030 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, "");
1033 1031
1034 const string16 expected_title = ASCIIToUTF16( 1032 const string16 expected_title = ASCIIToUTF16(
1035 StringPrintf("loadCommit:%s", kHTMLForGuest)); 1033 StringPrintf("loadCommit:%s", kHTMLForGuest));
1036 content::TitleWatcher title_watcher( 1034 content::TitleWatcher title_watcher(
1037 test_embedder()->web_contents(), expected_title); 1035 test_embedder()->web_contents(), expected_title);
1038 // Renavigate the guest to |kHTMLForGuest|. 1036 // Renavigate the guest to |kHTMLForGuest|.
1039 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( 1037 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
1040 test_embedder()->web_contents()->GetRenderViewHost()); 1038 test_embedder()->web_contents()->GetRenderViewHost());
1041 ExecuteSyncJSFunction(rvh, ASCIIToUTF16( 1039 ExecuteSyncJSFunction(rvh, StringPrintf("SetSrc('%s');", kHTMLForGuest));
1042 StringPrintf("SetSrc('%s');", kHTMLForGuest)));
1043 1040
1044 string16 actual_title = title_watcher.WaitAndGetTitle(); 1041 string16 actual_title = title_watcher.WaitAndGetTitle();
1045 EXPECT_EQ(expected_title, actual_title); 1042 EXPECT_EQ(expected_title, actual_title);
1046 scoped_ptr<base::Value> is_top_level(rvh->ExecuteJavascriptAndGetValue( 1043 scoped_ptr<base::Value> is_top_level(rvh->ExecuteJavascriptAndGetValue(
1047 string16(), ASCIIToUTF16("commitIsTopLevel"))); 1044 string16(), ASCIIToUTF16("commitIsTopLevel")));
1048 bool top_level_bool = false; 1045 bool top_level_bool = false;
1049 EXPECT_TRUE(is_top_level->GetAsBoolean(&top_level_bool)); 1046 EXPECT_TRUE(is_top_level->GetAsBoolean(&top_level_bool));
1050 EXPECT_EQ(true, top_level_bool); 1047 EXPECT_EQ(true, top_level_bool);
1051 } 1048 }
1052 1049
(...skipping 12 matching lines...) Expand all
1065 // the new guest will inherit the visibility state of the old guest. 1062 // the new guest will inherit the visibility state of the old guest.
1066 // 1063 //
1067 // Very flaky on Linux, Linux CrOS, somewhat flaky on XP, slightly on 1064 // Very flaky on Linux, Linux CrOS, somewhat flaky on XP, slightly on
1068 // Mac; http://crbug.com/162809. 1065 // Mac; http://crbug.com/162809.
1069 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, DISABLED_VisibilityPreservation) { 1066 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, DISABLED_VisibilityPreservation) {
1070 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; 1067 const char* kEmbedderURL = "files/browser_plugin_embedder.html";
1071 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, ""); 1068 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, "");
1072 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( 1069 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
1073 test_embedder()->web_contents()->GetRenderViewHost()); 1070 test_embedder()->web_contents()->GetRenderViewHost());
1074 // Hide the BrowserPlugin. 1071 // Hide the BrowserPlugin.
1075 ExecuteSyncJSFunction(rvh, ASCIIToUTF16( 1072 ExecuteSyncJSFunction(
1076 "document.getElementById('plugin').style.visibility = 'hidden';")); 1073 rvh, "document.getElementById('plugin').style.visibility = 'hidden';");
1077 test_guest()->WaitUntilHidden(); 1074 test_guest()->WaitUntilHidden();
1078 // Kill the current guest. 1075 // Kill the current guest.
1079 ExecuteSyncJSFunction(rvh, ASCIIToUTF16( 1076 ExecuteSyncJSFunction(rvh, "document.getElementById('plugin').terminate();");
1080 "document.getElementById('plugin').terminate();"));
1081 test_guest()->WaitForExit(); 1077 test_guest()->WaitForExit();
1082 // Get a new guest. 1078 // Get a new guest.
1083 ExecuteSyncJSFunction(rvh, ASCIIToUTF16( 1079 ExecuteSyncJSFunction(rvh, "document.getElementById('plugin').reload();");
1084 "document.getElementById('plugin').reload();"));
1085 test_guest()->WaitForLoadStop(); 1080 test_guest()->WaitForLoadStop();
1086 // Verify that the guest is told to hide. 1081 // Verify that the guest is told to hide.
1087 test_guest()->WaitUntilHidden(); 1082 test_guest()->WaitUntilHidden();
1088 } 1083 }
1089 1084
1090 // This test verifies that if a browser plugin is focused before navigation then 1085 // This test verifies that if a browser plugin is focused before navigation then
1091 // the guest starts off focused. 1086 // the guest starts off focused.
1092 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, FocusBeforeNavigation) { 1087 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, FocusBeforeNavigation) {
1093 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; 1088 const char* kEmbedderURL = "files/browser_plugin_embedder.html";
1094 const std::string embedder_code = 1089 const std::string embedder_code =
(...skipping 16 matching lines...) Expand all
1111 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, FocusPreservation) { 1106 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, FocusPreservation) {
1112 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; 1107 const char* kEmbedderURL = "files/browser_plugin_embedder.html";
1113 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, ""); 1108 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, "");
1114 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( 1109 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
1115 test_embedder()->web_contents()->GetRenderViewHost()); 1110 test_embedder()->web_contents()->GetRenderViewHost());
1116 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( 1111 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>(
1117 test_guest()->web_contents()->GetRenderViewHost()); 1112 test_guest()->web_contents()->GetRenderViewHost());
1118 { 1113 {
1119 // Focus the BrowserPlugin. This will have the effect of also focusing the 1114 // Focus the BrowserPlugin. This will have the effect of also focusing the
1120 // current guest. 1115 // current guest.
1121 ExecuteSyncJSFunction( 1116 ExecuteSyncJSFunction(rvh, "document.getElementById('plugin').focus();");
1122 rvh, ASCIIToUTF16("document.getElementById('plugin').focus();"));
1123 // Verify that key presses go to the guest. 1117 // Verify that key presses go to the guest.
1124 SimulateSpaceKeyPress(test_embedder()->web_contents()); 1118 SimulateSpaceKeyPress(test_embedder()->web_contents());
1125 test_guest()->WaitForInput(); 1119 test_guest()->WaitForInput();
1126 // Verify that the guest is focused. 1120 // Verify that the guest is focused.
1127 scoped_ptr<base::Value> value( 1121 scoped_ptr<base::Value> value(
1128 guest_rvh->ExecuteJavascriptAndGetValue(string16(), 1122 guest_rvh->ExecuteJavascriptAndGetValue(string16(),
1129 ASCIIToUTF16("document.hasFocus()"))); 1123 ASCIIToUTF16("document.hasFocus()")));
1130 bool result = false; 1124 bool result = false;
1131 ASSERT_TRUE(value->GetAsBoolean(&result)); 1125 ASSERT_TRUE(value->GetAsBoolean(&result));
1132 EXPECT_TRUE(result); 1126 EXPECT_TRUE(result);
1133 } 1127 }
1134 1128
1135 // Kill the current guest. 1129 // Kill the current guest.
1136 ExecuteSyncJSFunction(rvh, ASCIIToUTF16( 1130 ExecuteSyncJSFunction(rvh, "document.getElementById('plugin').terminate();");
1137 "document.getElementById('plugin').terminate();"));
1138 test_guest()->WaitForExit(); 1131 test_guest()->WaitForExit();
1139 1132
1140 { 1133 {
1141 // Get a new guest. 1134 // Get a new guest.
1142 ExecuteSyncJSFunction(rvh, ASCIIToUTF16( 1135 ExecuteSyncJSFunction(rvh, "document.getElementById('plugin').reload();");
1143 "document.getElementById('plugin').reload();"));
1144 test_guest()->WaitForLoadStop(); 1136 test_guest()->WaitForLoadStop();
1145 // Verify that the guest is focused. 1137 // Verify that the guest is focused.
1146 scoped_ptr<base::Value> value( 1138 scoped_ptr<base::Value> value(
1147 guest_rvh->ExecuteJavascriptAndGetValue(string16(), 1139 guest_rvh->ExecuteJavascriptAndGetValue(string16(),
1148 ASCIIToUTF16("document.hasFocus()"))); 1140 ASCIIToUTF16("document.hasFocus()")));
1149 bool result = false; 1141 bool result = false;
1150 ASSERT_TRUE(value->GetAsBoolean(&result)); 1142 ASSERT_TRUE(value->GetAsBoolean(&result));
1151 EXPECT_TRUE(result); 1143 EXPECT_TRUE(result);
1152 } 1144 }
1153 } 1145 }
1154 1146
1155 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, FocusTracksEmbedder) { 1147 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, FocusTracksEmbedder) {
1156 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; 1148 const char* kEmbedderURL = "files/browser_plugin_embedder.html";
1157 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, ""); 1149 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, "");
1158 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( 1150 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
1159 test_embedder()->web_contents()->GetRenderViewHost()); 1151 test_embedder()->web_contents()->GetRenderViewHost());
1160 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( 1152 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>(
1161 test_guest()->web_contents()->GetRenderViewHost()); 1153 test_guest()->web_contents()->GetRenderViewHost());
1162 { 1154 {
1163 // Focus the BrowserPlugin. This will have the effect of also focusing the 1155 // Focus the BrowserPlugin. This will have the effect of also focusing the
1164 // current guest. 1156 // current guest.
1165 ExecuteSyncJSFunction( 1157 ExecuteSyncJSFunction(rvh, "document.getElementById('plugin').focus();");
1166 rvh, ASCIIToUTF16("document.getElementById('plugin').focus();"));
1167 // Verify that key presses go to the guest. 1158 // Verify that key presses go to the guest.
1168 SimulateSpaceKeyPress(test_embedder()->web_contents()); 1159 SimulateSpaceKeyPress(test_embedder()->web_contents());
1169 test_guest()->WaitForInput(); 1160 test_guest()->WaitForInput();
1170 // Verify that the guest is focused. 1161 // Verify that the guest is focused.
1171 scoped_ptr<base::Value> value( 1162 scoped_ptr<base::Value> value(
1172 guest_rvh->ExecuteJavascriptAndGetValue(string16(), 1163 guest_rvh->ExecuteJavascriptAndGetValue(string16(),
1173 ASCIIToUTF16("document.hasFocus()"))); 1164 ASCIIToUTF16("document.hasFocus()")));
1174 bool result = false; 1165 bool result = false;
1175 ASSERT_TRUE(value->GetAsBoolean(&result)); 1166 ASSERT_TRUE(value->GetAsBoolean(&result));
1176 EXPECT_TRUE(result); 1167 EXPECT_TRUE(result);
(...skipping 25 matching lines...) Expand all
1202 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; 1193 const char* kEmbedderURL = "files/browser_plugin_embedder.html";
1203 StartBrowserPluginTest( 1194 StartBrowserPluginTest(
1204 kEmbedderURL, kHTMLForGuestWithSize, true, ""); 1195 kEmbedderURL, kHTMLForGuestWithSize, true, "");
1205 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( 1196 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
1206 test_embedder()->web_contents()->GetRenderViewHost()); 1197 test_embedder()->web_contents()->GetRenderViewHost());
1207 1198
1208 { 1199 {
1209 const string16 expected_title = ASCIIToUTF16("AutoSize(300, 400)"); 1200 const string16 expected_title = ASCIIToUTF16("AutoSize(300, 400)");
1210 content::TitleWatcher title_watcher(test_embedder()->web_contents(), 1201 content::TitleWatcher title_watcher(test_embedder()->web_contents(),
1211 expected_title); 1202 expected_title);
1212 ExecuteSyncJSFunction(rvh, ASCIIToUTF16( 1203 ExecuteSyncJSFunction(
1204 rvh,
1213 "document.getElementById('plugin').minWidth = 300;" 1205 "document.getElementById('plugin').minWidth = 300;"
1214 "document.getElementById('plugin').minHeight = 200;" 1206 "document.getElementById('plugin').minHeight = 200;"
1215 "document.getElementById('plugin').maxWidth = 600;" 1207 "document.getElementById('plugin').maxWidth = 600;"
1216 "document.getElementById('plugin').maxHeight = 400;" 1208 "document.getElementById('plugin').maxHeight = 400;"
1217 "document.getElementById('plugin').autoSize = true;")); 1209 "document.getElementById('plugin').autoSize = true;");
1218 string16 actual_title = title_watcher.WaitAndGetTitle(); 1210 string16 actual_title = title_watcher.WaitAndGetTitle();
1219 EXPECT_EQ(expected_title, actual_title); 1211 EXPECT_EQ(expected_title, actual_title);
1220 } 1212 }
1221 { 1213 {
1222 // Change the minWidth and verify that it causes relayout. 1214 // Change the minWidth and verify that it causes relayout.
1223 const string16 expected_title = ASCIIToUTF16("AutoSize(350, 400)"); 1215 const string16 expected_title = ASCIIToUTF16("AutoSize(350, 400)");
1224 content::TitleWatcher title_watcher(test_embedder()->web_contents(), 1216 content::TitleWatcher title_watcher(test_embedder()->web_contents(),
1225 expected_title); 1217 expected_title);
1226 ExecuteSyncJSFunction(rvh, ASCIIToUTF16( 1218 ExecuteSyncJSFunction(
1227 "document.getElementById('plugin').minWidth = 350;")); 1219 rvh, "document.getElementById('plugin').minWidth = 350;");
1228 string16 actual_title = title_watcher.WaitAndGetTitle(); 1220 string16 actual_title = title_watcher.WaitAndGetTitle();
1229 EXPECT_EQ(expected_title, actual_title); 1221 EXPECT_EQ(expected_title, actual_title);
1230 } 1222 }
1231 { 1223 {
1232 // Turn off autoSize and verify that the guest resizes to fit the container. 1224 // Turn off autoSize and verify that the guest resizes to fit the container.
1233 ExecuteSyncJSFunction(rvh, ASCIIToUTF16( 1225 ExecuteSyncJSFunction(
1234 "document.getElementById('plugin').autoSize = false;")); 1226 rvh, "document.getElementById('plugin').autoSize = false;");
1235 test_guest()->WaitForViewSize(gfx::Size(640, 480)); 1227 test_guest()->WaitForViewSize(gfx::Size(640, 480));
1236 } 1228 }
1237 } 1229 }
1238 1230
1239 // Test for regression http://crbug.com/162961. 1231 // Test for regression http://crbug.com/162961.
1240 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, GetRenderViewHostAtPositionTest) { 1232 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, GetRenderViewHostAtPositionTest) {
1241 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; 1233 const char kEmbedderURL[] = "files/browser_plugin_embedder.html";
1242 const std::string embedder_code = StringPrintf("SetSize(%d, %d);", 100, 100); 1234 const std::string embedder_code = StringPrintf("SetSize(%d, %d);", 100, 100);
1243 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuestWithSize, true, 1235 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuestWithSize, true,
1244 embedder_code); 1236 embedder_code);
1245 // Check for render view host at position (150, 150) that is outside the 1237 // Check for render view host at position (150, 150) that is outside the
1246 // bounds of our guest, so this would respond with the render view host of the 1238 // bounds of our guest, so this would respond with the render view host of the
1247 // embedder. 1239 // embedder.
1248 test_embedder()->WaitForRenderViewHostAtPosition(150, 150); 1240 test_embedder()->WaitForRenderViewHostAtPosition(150, 150);
1249 ASSERT_EQ(test_embedder()->web_contents()->GetRenderViewHost(), 1241 ASSERT_EQ(test_embedder()->web_contents()->GetRenderViewHost(),
1250 test_embedder()->last_rvh_at_position_response()); 1242 test_embedder()->last_rvh_at_position_response());
1251 } 1243 }
1252 1244
1253 } // namespace content 1245 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/bookmarklet_browsertest.cc ('k') | content/browser/database_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698