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/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/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "content/public/browser/notification_types.h" | 22 #include "content/public/browser/notification_types.h" |
23 #include "content/public/browser/render_view_host_observer.h" | 23 #include "content/public/browser/render_view_host_observer.h" |
24 #include "content/public/browser/render_widget_host_view.h" | 24 #include "content/public/browser/render_widget_host_view.h" |
25 #include "content/public/common/content_switches.h" | 25 #include "content/public/common/content_switches.h" |
26 #include "content/public/test/browser_test_utils.h" | 26 #include "content/public/test/browser_test_utils.h" |
27 #include "content/public/test/test_utils.h" | 27 #include "content/public/test/test_utils.h" |
28 #include "content/shell/shell.h" | 28 #include "content/shell/shell.h" |
29 #include "content/test/content_browser_test.h" | 29 #include "content/test/content_browser_test.h" |
30 #include "content/test/content_browser_test_utils.h" | 30 #include "content/test/content_browser_test_utils.h" |
31 #include "net/base/net_util.h" | 31 #include "net/base/net_util.h" |
| 32 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 33 #include "net/test/embedded_test_server/http_response.h" |
| 34 #include "net/test/embedded_test_server/http_request.h" |
32 #include "net/test/spawned_test_server/spawned_test_server.h" | 35 #include "net/test/spawned_test_server/spawned_test_server.h" |
33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
34 #include "webkit/glue/webdropdata.h" | 37 #include "webkit/glue/webdropdata.h" |
35 | 38 |
36 using WebKit::WebInputEvent; | 39 using WebKit::WebInputEvent; |
37 using WebKit::WebMouseEvent; | 40 using WebKit::WebMouseEvent; |
38 using content::BrowserPluginEmbedder; | 41 using content::BrowserPluginEmbedder; |
39 using content::BrowserPluginGuest; | 42 using content::BrowserPluginGuest; |
40 using content::BrowserPluginHostFactory; | 43 using content::BrowserPluginHostFactory; |
41 using content::WebContentsImpl; | 44 using content::WebContentsImpl; |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 | 305 |
303 // This helper method does the following: | 306 // This helper method does the following: |
304 // 1. Start the test server and navigate the shell to |embedder_url|. | 307 // 1. Start the test server and navigate the shell to |embedder_url|. |
305 // 2. Execute custom pre-navigation |embedder_code| if provided. | 308 // 2. Execute custom pre-navigation |embedder_code| if provided. |
306 // 3. Navigate the guest to the |guest_url|. | 309 // 3. Navigate the guest to the |guest_url|. |
307 // 4. Verify that the guest has been created and has completed loading. | 310 // 4. Verify that the guest has been created and has completed loading. |
308 void StartBrowserPluginTest(const std::string& embedder_url, | 311 void StartBrowserPluginTest(const std::string& embedder_url, |
309 const std::string& guest_url, | 312 const std::string& guest_url, |
310 bool is_guest_data_url, | 313 bool is_guest_data_url, |
311 const std::string& embedder_code) { | 314 const std::string& embedder_code) { |
312 ASSERT_TRUE(test_server()->Start()); | 315 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
313 GURL test_url(test_server()->GetURL(embedder_url)); | 316 GURL test_url(embedded_test_server()->GetURL(embedder_url)); |
314 NavigateToURL(shell(), test_url); | 317 NavigateToURL(shell(), test_url); |
315 | 318 |
316 WebContentsImpl* embedder_web_contents = static_cast<WebContentsImpl*>( | 319 WebContentsImpl* embedder_web_contents = static_cast<WebContentsImpl*>( |
317 shell()->web_contents()); | 320 shell()->web_contents()); |
318 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 321 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
319 embedder_web_contents->GetRenderViewHost()); | 322 embedder_web_contents->GetRenderViewHost()); |
320 // Focus the embedder. | 323 // Focus the embedder. |
321 rvh->Focus(); | 324 rvh->Focus(); |
322 | 325 |
323 // Allow the test to do some operations on the embedder before we perform | 326 // Allow the test to do some operations on the embedder before we perform |
324 // the first navigation of the guest. | 327 // the first navigation of the guest. |
325 if (!embedder_code.empty()) | 328 if (!embedder_code.empty()) |
326 ExecuteSyncJSFunction(rvh, embedder_code); | 329 ExecuteSyncJSFunction(rvh, embedder_code); |
327 | 330 |
328 if (!is_guest_data_url) { | 331 if (!is_guest_data_url) { |
329 test_url = test_server()->GetURL(guest_url); | 332 test_url = embedded_test_server()->GetURL(guest_url); |
330 ExecuteSyncJSFunction( | 333 ExecuteSyncJSFunction( |
331 rvh, base::StringPrintf("SetSrc('%s');", test_url.spec().c_str())); | 334 rvh, base::StringPrintf("SetSrc('%s');", test_url.spec().c_str())); |
332 } else { | 335 } else { |
333 ExecuteSyncJSFunction( | 336 ExecuteSyncJSFunction( |
334 rvh, base::StringPrintf("SetSrc('%s');", guest_url.c_str())); | 337 rvh, base::StringPrintf("SetSrc('%s');", guest_url.c_str())); |
335 } | 338 } |
336 | 339 |
337 // Wait to make sure embedder is created/attached to WebContents. | 340 // Wait to make sure embedder is created/attached to WebContents. |
338 TestBrowserPluginHostFactory::GetInstance()->WaitForGuestManagerCreation(); | 341 TestBrowserPluginHostFactory::GetInstance()->WaitForGuestManagerCreation(); |
339 | 342 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 #define MAYBE_GuestUnresponsive DISABLED_GuestUnresponsive | 384 #define MAYBE_GuestUnresponsive DISABLED_GuestUnresponsive |
382 #else | 385 #else |
383 #define MAYBE_GuestUnresponsive GuestUnresponsive | 386 #define MAYBE_GuestUnresponsive GuestUnresponsive |
384 #endif | 387 #endif |
385 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, | 388 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, |
386 MAYBE_GuestUnresponsive) { | 389 MAYBE_GuestUnresponsive) { |
387 // Override the hang timeout for guest to be very small. | 390 // Override the hang timeout for guest to be very small. |
388 content::BrowserPluginGuest::set_factory_for_testing( | 391 content::BrowserPluginGuest::set_factory_for_testing( |
389 TestShortHangTimeoutGuestFactory::GetInstance()); | 392 TestShortHangTimeoutGuestFactory::GetInstance()); |
390 const char kEmbedderURL[] = | 393 const char kEmbedderURL[] = |
391 "files/browser_plugin_embedder_guest_unresponsive.html"; | 394 "/browser_plugin_embedder_guest_unresponsive.html"; |
392 StartBrowserPluginTest( | 395 StartBrowserPluginTest( |
393 kEmbedderURL, kHTMLForGuestBusyLoop, true, std::string()); | 396 kEmbedderURL, kHTMLForGuestBusyLoop, true, std::string()); |
394 // Wait until the busy loop starts. | 397 // Wait until the busy loop starts. |
395 { | 398 { |
396 const string16 expected_title = ASCIIToUTF16("start"); | 399 const string16 expected_title = ASCIIToUTF16("start"); |
397 content::TitleWatcher title_watcher(test_guest()->web_contents(), | 400 content::TitleWatcher title_watcher(test_guest()->web_contents(), |
398 expected_title); | 401 expected_title); |
399 // Hang the guest for a length of time. | 402 // Hang the guest for a length of time. |
400 int spin_time = 10 * TestTimeouts::tiny_timeout().InMilliseconds(); | 403 int spin_time = 10 * TestTimeouts::tiny_timeout().InMilliseconds(); |
401 ExecuteSyncJSFunction( | 404 ExecuteSyncJSFunction( |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 // This test ensures that if guest isn't there and we resize the guest (from | 440 // This test ensures that if guest isn't there and we resize the guest (from |
438 // js), it remembers the size correctly. | 441 // js), it remembers the size correctly. |
439 // | 442 // |
440 // Initially we load an embedder with a guest without a src attribute (which has | 443 // Initially we load an embedder with a guest without a src attribute (which has |
441 // dimension 640x480), resize it to 100x200, and then we set the source to a | 444 // dimension 640x480), resize it to 100x200, and then we set the source to a |
442 // sample guest. In the end we verify that the correct size has been set. | 445 // sample guest. In the end we verify that the correct size has been set. |
443 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, NavigateAfterResize) { | 446 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, NavigateAfterResize) { |
444 const gfx::Size nxt_size = gfx::Size(100, 200); | 447 const gfx::Size nxt_size = gfx::Size(100, 200); |
445 const std::string embedder_code = base::StringPrintf( | 448 const std::string embedder_code = base::StringPrintf( |
446 "SetSize(%d, %d);", nxt_size.width(), nxt_size.height()); | 449 "SetSize(%d, %d);", nxt_size.width(), nxt_size.height()); |
447 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; | 450 const char kEmbedderURL[] = "/browser_plugin_embedder.html"; |
448 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, embedder_code); | 451 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, embedder_code); |
449 | 452 |
450 // Wait for the guest to receive a damage buffer of size 100x200. | 453 // Wait for the guest to receive a damage buffer of size 100x200. |
451 // This means the guest will be painted properly at that size. | 454 // This means the guest will be painted properly at that size. |
452 test_guest()->WaitForDamageBufferWithSize(nxt_size); | 455 test_guest()->WaitForDamageBufferWithSize(nxt_size); |
453 } | 456 } |
454 | 457 |
455 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, AdvanceFocus) { | 458 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, AdvanceFocus) { |
456 const char kEmbedderURL[] = "files/browser_plugin_focus.html"; | 459 const char kEmbedderURL[] = "/browser_plugin_focus.html"; |
457 const char* kGuestURL = "files/browser_plugin_focus_child.html"; | 460 const char* kGuestURL = "/browser_plugin_focus_child.html"; |
458 StartBrowserPluginTest(kEmbedderURL, kGuestURL, false, std::string()); | 461 StartBrowserPluginTest(kEmbedderURL, kGuestURL, false, std::string()); |
459 | 462 |
460 SimulateMouseClick(test_embedder()->web_contents(), 0, | 463 SimulateMouseClick(test_embedder()->web_contents(), 0, |
461 WebKit::WebMouseEvent::ButtonLeft); | 464 WebKit::WebMouseEvent::ButtonLeft); |
462 BrowserPluginHostTest::SimulateTabKeyPress(test_embedder()->web_contents()); | 465 BrowserPluginHostTest::SimulateTabKeyPress(test_embedder()->web_contents()); |
463 // Wait until we focus into the guest. | 466 // Wait until we focus into the guest. |
464 test_guest()->WaitForFocus(); | 467 test_guest()->WaitForFocus(); |
465 | 468 |
466 // TODO(fsamuel): A third Tab key press should not be necessary. | 469 // TODO(fsamuel): A third Tab key press should not be necessary. |
467 // The browser plugin will take keyboard focus but it will not | 470 // The browser plugin will take keyboard focus but it will not |
(...skipping 10 matching lines...) Expand all Loading... |
478 // a RenderViewHost swap in the web_contents. We verify that the embedder in the | 481 // a RenderViewHost swap in the web_contents. We verify that the embedder in the |
479 // web_contents gets cleared properly. | 482 // web_contents gets cleared properly. |
480 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, EmbedderChangedAfterSwap) { | 483 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, EmbedderChangedAfterSwap) { |
481 net::SpawnedTestServer https_server( | 484 net::SpawnedTestServer https_server( |
482 net::SpawnedTestServer::TYPE_HTTPS, | 485 net::SpawnedTestServer::TYPE_HTTPS, |
483 net::SpawnedTestServer::kLocalhost, | 486 net::SpawnedTestServer::kLocalhost, |
484 base::FilePath(FILE_PATH_LITERAL("content/test/data"))); | 487 base::FilePath(FILE_PATH_LITERAL("content/test/data"))); |
485 ASSERT_TRUE(https_server.Start()); | 488 ASSERT_TRUE(https_server.Start()); |
486 | 489 |
487 // 1. Load an embedder page with one guest in it. | 490 // 1. Load an embedder page with one guest in it. |
488 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; | 491 const char kEmbedderURL[] = "/browser_plugin_embedder.html"; |
489 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); | 492 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); |
490 | 493 |
491 // 2. Navigate to a URL in https, so we trigger a RenderViewHost swap. | 494 // 2. Navigate to a URL in https, so we trigger a RenderViewHost swap. |
492 GURL test_https_url(https_server.GetURL( | 495 GURL test_https_url(https_server.GetURL( |
493 "files/browser_plugin_title_change.html")); | 496 "files/browser_plugin_title_change.html")); |
494 content::WindowedNotificationObserver swap_observer( | 497 content::WindowedNotificationObserver swap_observer( |
495 content::NOTIFICATION_WEB_CONTENTS_SWAPPED, | 498 content::NOTIFICATION_WEB_CONTENTS_SWAPPED, |
496 content::Source<WebContents>(test_embedder()->web_contents())); | 499 content::Source<WebContents>(test_embedder()->web_contents())); |
497 NavigateToURL(shell(), test_https_url); | 500 NavigateToURL(shell(), test_https_url); |
498 swap_observer.Wait(); | 501 swap_observer.Wait(); |
499 | 502 |
500 TestBrowserPluginEmbedder* test_embedder_after_swap = | 503 TestBrowserPluginEmbedder* test_embedder_after_swap = |
501 static_cast<TestBrowserPluginEmbedder*>( | 504 static_cast<TestBrowserPluginEmbedder*>( |
502 static_cast<WebContentsImpl*>(shell()->web_contents())-> | 505 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
503 GetBrowserPluginEmbedder()); | 506 GetBrowserPluginEmbedder()); |
504 // Verify we have a no embedder in web_contents (since the new page doesn't | 507 // Verify we have a no embedder in web_contents (since the new page doesn't |
505 // have any browser plugin). | 508 // have any browser plugin). |
506 ASSERT_TRUE(!test_embedder_after_swap); | 509 ASSERT_TRUE(!test_embedder_after_swap); |
507 ASSERT_NE(test_embedder(), test_embedder_after_swap); | 510 ASSERT_NE(test_embedder(), test_embedder_after_swap); |
508 } | 511 } |
509 | 512 |
510 // This test opens two pages in http and there is no RenderViewHost swap, | 513 // This test opens two pages in http and there is no RenderViewHost swap, |
511 // therefore the embedder created on first page navigation stays the same in | 514 // therefore the embedder created on first page navigation stays the same in |
512 // web_contents. | 515 // web_contents. |
513 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, EmbedderSameAfterNav) { | 516 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, EmbedderSameAfterNav) { |
514 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; | 517 const char kEmbedderURL[] = "/browser_plugin_embedder.html"; |
515 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); | 518 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); |
516 WebContentsImpl* embedder_web_contents = test_embedder()->web_contents(); | 519 WebContentsImpl* embedder_web_contents = test_embedder()->web_contents(); |
517 | 520 |
518 // Navigate to another page in same host and port, so RenderViewHost swap | 521 // Navigate to another page in same host and port, so RenderViewHost swap |
519 // does not happen and existing embedder doesn't change in web_contents. | 522 // does not happen and existing embedder doesn't change in web_contents. |
520 GURL test_url_new(test_server()->GetURL( | 523 GURL test_url_new(embedded_test_server()->GetURL( |
521 "files/browser_plugin_title_change.html")); | 524 "/browser_plugin_title_change.html")); |
522 const string16 expected_title = ASCIIToUTF16("done"); | 525 const string16 expected_title = ASCIIToUTF16("done"); |
523 content::TitleWatcher title_watcher(shell()->web_contents(), expected_title); | 526 content::TitleWatcher title_watcher(shell()->web_contents(), expected_title); |
524 NavigateToURL(shell(), test_url_new); | 527 NavigateToURL(shell(), test_url_new); |
525 LOG(INFO) << "Start waiting for title"; | 528 LOG(INFO) << "Start waiting for title"; |
526 string16 actual_title = title_watcher.WaitAndGetTitle(); | 529 string16 actual_title = title_watcher.WaitAndGetTitle(); |
527 EXPECT_EQ(expected_title, actual_title); | 530 EXPECT_EQ(expected_title, actual_title); |
528 LOG(INFO) << "Done navigating to second page"; | 531 LOG(INFO) << "Done navigating to second page"; |
529 | 532 |
530 TestBrowserPluginEmbedder* test_embedder_after_nav = | 533 TestBrowserPluginEmbedder* test_embedder_after_nav = |
531 static_cast<TestBrowserPluginEmbedder*>( | 534 static_cast<TestBrowserPluginEmbedder*>( |
532 embedder_web_contents->GetBrowserPluginEmbedder()); | 535 embedder_web_contents->GetBrowserPluginEmbedder()); |
533 // Embedder must not change in web_contents. | 536 // Embedder must not change in web_contents. |
534 ASSERT_EQ(test_embedder_after_nav, test_embedder()); | 537 ASSERT_EQ(test_embedder_after_nav, test_embedder()); |
535 } | 538 } |
536 | 539 |
537 // This test verifies that hiding the embedder also hides the guest. | 540 // This test verifies that hiding the embedder also hides the guest. |
538 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, BrowserPluginVisibilityChanged) { | 541 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, BrowserPluginVisibilityChanged) { |
539 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; | 542 const char kEmbedderURL[] = "/browser_plugin_embedder.html"; |
540 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); | 543 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); |
541 | 544 |
542 // Hide the Browser Plugin. | 545 // Hide the Browser Plugin. |
543 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 546 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
544 test_embedder()->web_contents()->GetRenderViewHost()); | 547 test_embedder()->web_contents()->GetRenderViewHost()); |
545 ExecuteSyncJSFunction( | 548 ExecuteSyncJSFunction( |
546 rvh, "document.getElementById('plugin').style.visibility = 'hidden'"); | 549 rvh, "document.getElementById('plugin').style.visibility = 'hidden'"); |
547 | 550 |
548 // Make sure that the guest is hidden. | 551 // Make sure that the guest is hidden. |
549 test_guest()->WaitUntilHidden(); | 552 test_guest()->WaitUntilHidden(); |
550 } | 553 } |
551 | 554 |
552 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, EmbedderVisibilityChanged) { | 555 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, EmbedderVisibilityChanged) { |
553 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; | 556 const char kEmbedderURL[] = "/browser_plugin_embedder.html"; |
554 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); | 557 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); |
555 | 558 |
556 // Hide the embedder. | 559 // Hide the embedder. |
557 test_embedder()->web_contents()->WasHidden(); | 560 test_embedder()->web_contents()->WasHidden(); |
558 | 561 |
559 // Make sure that hiding the embedder also hides the guest. | 562 // Make sure that hiding the embedder also hides the guest. |
560 test_guest()->WaitUntilHidden(); | 563 test_guest()->WaitUntilHidden(); |
561 } | 564 } |
562 | 565 |
563 // This test verifies that calling the reload method reloads the guest. | 566 // This test verifies that calling the reload method reloads the guest. |
564 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, ReloadGuest) { | 567 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, ReloadGuest) { |
565 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; | 568 const char kEmbedderURL[] = "/browser_plugin_embedder.html"; |
566 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); | 569 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); |
567 | 570 |
568 test_guest()->ResetUpdateRectCount(); | 571 test_guest()->ResetUpdateRectCount(); |
569 | 572 |
570 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 573 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
571 test_embedder()->web_contents()->GetRenderViewHost()); | 574 test_embedder()->web_contents()->GetRenderViewHost()); |
572 ExecuteSyncJSFunction(rvh, "document.getElementById('plugin').reload()"); | 575 ExecuteSyncJSFunction(rvh, "document.getElementById('plugin').reload()"); |
573 test_guest()->WaitForReload(); | 576 test_guest()->WaitForReload(); |
574 } | 577 } |
575 | 578 |
576 // This test verifies that calling the stop method forwards the stop request | 579 // This test verifies that calling the stop method forwards the stop request |
577 // to the guest's WebContents. | 580 // to the guest's WebContents. |
578 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, StopGuest) { | 581 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, StopGuest) { |
579 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; | 582 const char kEmbedderURL[] = "/browser_plugin_embedder.html"; |
580 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); | 583 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); |
581 | 584 |
582 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 585 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
583 test_embedder()->web_contents()->GetRenderViewHost()); | 586 test_embedder()->web_contents()->GetRenderViewHost()); |
584 ExecuteSyncJSFunction(rvh, "document.getElementById('plugin').stop()"); | 587 ExecuteSyncJSFunction(rvh, "document.getElementById('plugin').stop()"); |
585 test_guest()->WaitForStop(); | 588 test_guest()->WaitForStop(); |
586 } | 589 } |
587 | 590 |
588 // Verifies that installing/uninstalling touch-event handlers in the guest | 591 // Verifies that installing/uninstalling touch-event handlers in the guest |
589 // plugin correctly updates the touch-event handling state in the embedder. | 592 // plugin correctly updates the touch-event handling state in the embedder. |
590 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, AcceptTouchEvents) { | 593 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, AcceptTouchEvents) { |
591 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; | 594 const char kEmbedderURL[] = "/browser_plugin_embedder.html"; |
592 StartBrowserPluginTest( | 595 StartBrowserPluginTest( |
593 kEmbedderURL, kHTMLForGuestTouchHandler, true, std::string()); | 596 kEmbedderURL, kHTMLForGuestTouchHandler, true, std::string()); |
594 | 597 |
595 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 598 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
596 test_embedder()->web_contents()->GetRenderViewHost()); | 599 test_embedder()->web_contents()->GetRenderViewHost()); |
597 // The embedder should not have any touch event handlers at this point. | 600 // The embedder should not have any touch event handlers at this point. |
598 EXPECT_FALSE(rvh->has_touch_handler()); | 601 EXPECT_FALSE(rvh->has_touch_handler()); |
599 | 602 |
600 // Install the touch handler in the guest. This should cause the embedder to | 603 // Install the touch handler in the guest. This should cause the embedder to |
601 // start listening for touch events too. | 604 // start listening for touch events too. |
602 RenderViewHostMessageObserver observer(rvh, | 605 RenderViewHostMessageObserver observer(rvh, |
603 ViewHostMsg_HasTouchEventHandlers::ID); | 606 ViewHostMsg_HasTouchEventHandlers::ID); |
604 ExecuteSyncJSFunction(test_guest()->web_contents()->GetRenderViewHost(), | 607 ExecuteSyncJSFunction(test_guest()->web_contents()->GetRenderViewHost(), |
605 "InstallTouchHandler();"); | 608 "InstallTouchHandler();"); |
606 observer.WaitUntilMessageReceived(); | 609 observer.WaitUntilMessageReceived(); |
607 EXPECT_TRUE(rvh->has_touch_handler()); | 610 EXPECT_TRUE(rvh->has_touch_handler()); |
608 | 611 |
609 // Uninstalling the touch-handler in guest should cause the embedder to stop | 612 // Uninstalling the touch-handler in guest should cause the embedder to stop |
610 // listening for touch events. | 613 // listening for touch events. |
611 observer.ResetState(); | 614 observer.ResetState(); |
612 ExecuteSyncJSFunction(test_guest()->web_contents()->GetRenderViewHost(), | 615 ExecuteSyncJSFunction(test_guest()->web_contents()->GetRenderViewHost(), |
613 "UninstallTouchHandler();"); | 616 "UninstallTouchHandler();"); |
614 observer.WaitUntilMessageReceived(); | 617 observer.WaitUntilMessageReceived(); |
615 EXPECT_FALSE(rvh->has_touch_handler()); | 618 EXPECT_FALSE(rvh->has_touch_handler()); |
616 } | 619 } |
617 | 620 |
618 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, Renavigate) { | 621 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, Renavigate) { |
619 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; | 622 const char kEmbedderURL[] = "/browser_plugin_embedder.html"; |
620 StartBrowserPluginTest( | 623 StartBrowserPluginTest( |
621 kEmbedderURL, GetHTMLForGuestWithTitle("P1"), true, std::string()); | 624 kEmbedderURL, GetHTMLForGuestWithTitle("P1"), true, std::string()); |
622 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 625 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
623 test_embedder()->web_contents()->GetRenderViewHost()); | 626 test_embedder()->web_contents()->GetRenderViewHost()); |
624 | 627 |
625 // Navigate to P2 and verify that the navigation occurred. | 628 // Navigate to P2 and verify that the navigation occurred. |
626 { | 629 { |
627 const string16 expected_title = ASCIIToUTF16("P2"); | 630 const string16 expected_title = ASCIIToUTF16("P2"); |
628 content::TitleWatcher title_watcher(test_guest()->web_contents(), | 631 content::TitleWatcher title_watcher(test_guest()->web_contents(), |
629 expected_title); | 632 expected_title); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 content::ExecuteScriptAndGetValue(rvh, "CanGoBack()"); | 708 content::ExecuteScriptAndGetValue(rvh, "CanGoBack()"); |
706 bool result = true; | 709 bool result = true; |
707 ASSERT_TRUE(value->GetAsBoolean(&result)); | 710 ASSERT_TRUE(value->GetAsBoolean(&result)); |
708 EXPECT_FALSE(result); | 711 EXPECT_FALSE(result); |
709 } | 712 } |
710 } | 713 } |
711 | 714 |
712 // This tests verifies that reloading the embedder does not crash the browser | 715 // This tests verifies that reloading the embedder does not crash the browser |
713 // and that the guest is reset. | 716 // and that the guest is reset. |
714 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, ReloadEmbedder) { | 717 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, ReloadEmbedder) { |
715 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; | 718 const char kEmbedderURL[] = "/browser_plugin_embedder.html"; |
716 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); | 719 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); |
717 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 720 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
718 test_embedder()->web_contents()->GetRenderViewHost()); | 721 test_embedder()->web_contents()->GetRenderViewHost()); |
719 | 722 |
720 // Change the title of the page to 'modified' so that we know that | 723 // Change the title of the page to 'modified' so that we know that |
721 // the page has successfully reloaded when it goes back to 'embedder' | 724 // the page has successfully reloaded when it goes back to 'embedder' |
722 // in the next step. | 725 // in the next step. |
723 { | 726 { |
724 const string16 expected_title = ASCIIToUTF16("modified"); | 727 const string16 expected_title = ASCIIToUTF16("modified"); |
725 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | 728 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
(...skipping 30 matching lines...) Expand all Loading... |
756 static_cast<TestBrowserPluginGuest*>( | 759 static_cast<TestBrowserPluginGuest*>( |
757 test_guest_web_contents->GetBrowserPluginGuest()); | 760 test_guest_web_contents->GetBrowserPluginGuest()); |
758 ASSERT_TRUE(new_test_guest != NULL); | 761 ASSERT_TRUE(new_test_guest != NULL); |
759 | 762 |
760 // Wait for the guest to send an UpdateRectMsg, meaning it is ready. | 763 // Wait for the guest to send an UpdateRectMsg, meaning it is ready. |
761 new_test_guest->WaitForUpdateRectMsg(); | 764 new_test_guest->WaitForUpdateRectMsg(); |
762 } | 765 } |
763 } | 766 } |
764 | 767 |
765 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, TerminateGuest) { | 768 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, TerminateGuest) { |
766 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; | 769 const char kEmbedderURL[] = "/browser_plugin_embedder.html"; |
767 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); | 770 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); |
768 | 771 |
769 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 772 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
770 test_embedder()->web_contents()->GetRenderViewHost()); | 773 test_embedder()->web_contents()->GetRenderViewHost()); |
771 ExecuteSyncJSFunction(rvh, "document.getElementById('plugin').terminate()"); | 774 ExecuteSyncJSFunction(rvh, "document.getElementById('plugin').terminate()"); |
772 | 775 |
773 // Expect the guest to crash. | 776 // Expect the guest to crash. |
774 test_guest()->WaitForExit(); | 777 test_guest()->WaitForExit(); |
775 } | 778 } |
776 | 779 |
777 // This test verifies that the guest is responsive after crashing and going back | 780 // This test verifies that the guest is responsive after crashing and going back |
778 // to a previous navigation entry. | 781 // to a previous navigation entry. |
779 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, BackAfterTerminateGuest) { | 782 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, BackAfterTerminateGuest) { |
780 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 783 const char* kEmbedderURL = "/browser_plugin_embedder.html"; |
781 StartBrowserPluginTest( | 784 StartBrowserPluginTest( |
782 kEmbedderURL, GetHTMLForGuestWithTitle("P1"), true, std::string()); | 785 kEmbedderURL, GetHTMLForGuestWithTitle("P1"), true, std::string()); |
783 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 786 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
784 test_embedder()->web_contents()->GetRenderViewHost()); | 787 test_embedder()->web_contents()->GetRenderViewHost()); |
785 | 788 |
786 // Navigate to P2 and verify that the navigation occurred. | 789 // Navigate to P2 and verify that the navigation occurred. |
787 { | 790 { |
788 const string16 expected_title = ASCIIToUTF16("P2"); | 791 const string16 expected_title = ASCIIToUTF16("P2"); |
789 content::TitleWatcher title_watcher(test_guest()->web_contents(), | 792 content::TitleWatcher title_watcher(test_guest()->web_contents(), |
790 expected_title); | 793 expected_title); |
(...skipping 22 matching lines...) Expand all Loading... |
813 string16 actual_title = title_watcher.WaitAndGetTitle(); | 816 string16 actual_title = title_watcher.WaitAndGetTitle(); |
814 EXPECT_EQ(expected_title, actual_title); | 817 EXPECT_EQ(expected_title, actual_title); |
815 } | 818 } |
816 // Send an input event and verify that the guest receives the input. | 819 // Send an input event and verify that the guest receives the input. |
817 SimulateMouseClick(test_embedder()->web_contents(), 0, | 820 SimulateMouseClick(test_embedder()->web_contents(), 0, |
818 WebKit::WebMouseEvent::ButtonLeft); | 821 WebKit::WebMouseEvent::ButtonLeft); |
819 test_guest()->WaitForInput(); | 822 test_guest()->WaitForInput(); |
820 } | 823 } |
821 | 824 |
822 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadStart) { | 825 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadStart) { |
823 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; | 826 const char kEmbedderURL[] = "/browser_plugin_embedder.html"; |
824 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, std::string()); | 827 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, std::string()); |
825 | 828 |
826 const string16 expected_title = ASCIIToUTF16(kHTMLForGuest); | 829 const string16 expected_title = ASCIIToUTF16(kHTMLForGuest); |
827 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | 830 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
828 expected_title); | 831 expected_title); |
829 // Renavigate the guest to |kHTMLForGuest|. | 832 // Renavigate the guest to |kHTMLForGuest|. |
830 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 833 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
831 test_embedder()->web_contents()->GetRenderViewHost()); | 834 test_embedder()->web_contents()->GetRenderViewHost()); |
832 ExecuteSyncJSFunction(rvh, | 835 ExecuteSyncJSFunction(rvh, |
833 base::StringPrintf("SetSrc('%s');", kHTMLForGuest)); | 836 base::StringPrintf("SetSrc('%s');", kHTMLForGuest)); |
834 | 837 |
835 string16 actual_title = title_watcher.WaitAndGetTitle(); | 838 string16 actual_title = title_watcher.WaitAndGetTitle(); |
836 EXPECT_EQ(expected_title, actual_title); | 839 EXPECT_EQ(expected_title, actual_title); |
837 } | 840 } |
838 | 841 |
| 842 namespace { |
| 843 |
| 844 class EmptyHttpResponse : public net::test_server::HttpResponse { |
| 845 public: |
| 846 virtual std::string ToResponseString() const OVERRIDE { |
| 847 return std::string(); |
| 848 } |
| 849 }; |
| 850 |
| 851 // Handles |request| by serving an empty response. |
| 852 scoped_ptr<net::test_server::HttpResponse> EmptyResponseHandler( |
| 853 const std::string& path, |
| 854 const net::test_server::HttpRequest& request) { |
| 855 if (StartsWithASCII(path, request.relative_url, true)) { |
| 856 return scoped_ptr<net::test_server::HttpResponse>( |
| 857 new EmptyHttpResponse); |
| 858 } |
| 859 |
| 860 return scoped_ptr<net::test_server::HttpResponse>(NULL); |
| 861 } |
| 862 |
| 863 // Handles |request| by serving a redirect response. |
| 864 scoped_ptr<net::test_server::HttpResponse> RedirectResponseHandler( |
| 865 const std::string& path, |
| 866 const GURL& redirect_target, |
| 867 const net::test_server::HttpRequest& request) { |
| 868 if (!StartsWithASCII(path, request.relative_url, true)) |
| 869 return scoped_ptr<net::test_server::HttpResponse>(NULL); |
| 870 |
| 871 scoped_ptr<net::test_server::BasicHttpResponse> http_response( |
| 872 new net::test_server::BasicHttpResponse); |
| 873 http_response->set_code(net::test_server::MOVED); |
| 874 http_response->AddCustomHeader("Location", redirect_target.spec()); |
| 875 return http_response.PassAs<net::test_server::HttpResponse>(); |
| 876 } |
| 877 |
| 878 } // namespace |
| 879 |
839 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadAbort) { | 880 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadAbort) { |
840 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; | 881 const char kEmbedderURL[] = "/browser_plugin_embedder.html"; |
841 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, std::string()); | 882 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, std::string()); |
842 | 883 |
843 { | 884 { |
844 // Navigate the guest to "close-socket". | 885 // Navigate the guest to "close-socket". |
| 886 const char kEmptyResponsePath[] = "/close-socket"; |
| 887 embedded_test_server()->RegisterRequestHandler( |
| 888 base::Bind(&EmptyResponseHandler, kEmptyResponsePath)); |
845 const string16 expected_title = ASCIIToUTF16("ERR_EMPTY_RESPONSE"); | 889 const string16 expected_title = ASCIIToUTF16("ERR_EMPTY_RESPONSE"); |
846 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | 890 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
847 expected_title); | 891 expected_title); |
848 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 892 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
849 test_embedder()->web_contents()->GetRenderViewHost()); | 893 test_embedder()->web_contents()->GetRenderViewHost()); |
850 GURL test_url = test_server()->GetURL("close-socket"); | 894 GURL test_url = embedded_test_server()->GetURL(kEmptyResponsePath); |
851 ExecuteSyncJSFunction( | 895 ExecuteSyncJSFunction( |
852 rvh, base::StringPrintf("SetSrc('%s');", test_url.spec().c_str())); | 896 rvh, base::StringPrintf("SetSrc('%s');", test_url.spec().c_str())); |
853 string16 actual_title = title_watcher.WaitAndGetTitle(); | 897 string16 actual_title = title_watcher.WaitAndGetTitle(); |
854 EXPECT_EQ(expected_title, actual_title); | 898 EXPECT_EQ(expected_title, actual_title); |
855 } | 899 } |
856 | 900 |
857 { | 901 { |
858 // Navigate the guest to an illegal chrome:// URL. | 902 // Navigate the guest to an illegal chrome:// URL. |
859 GURL test_url("chrome://newtab"); | 903 GURL test_url("chrome://newtab"); |
860 ChildProcessSecurityPolicyImpl* policy = | 904 ChildProcessSecurityPolicyImpl* policy = |
(...skipping 22 matching lines...) Expand all Loading... |
883 test_embedder()->web_contents()->GetRenderViewHost()); | 927 test_embedder()->web_contents()->GetRenderViewHost()); |
884 GURL test_url("file://foo"); | 928 GURL test_url("file://foo"); |
885 ExecuteSyncJSFunction( | 929 ExecuteSyncJSFunction( |
886 rvh, base::StringPrintf("SetSrc('%s');", test_url.spec().c_str())); | 930 rvh, base::StringPrintf("SetSrc('%s');", test_url.spec().c_str())); |
887 string16 actual_title = title_watcher.WaitAndGetTitle(); | 931 string16 actual_title = title_watcher.WaitAndGetTitle(); |
888 EXPECT_EQ(expected_title, actual_title); | 932 EXPECT_EQ(expected_title, actual_title); |
889 } | 933 } |
890 } | 934 } |
891 | 935 |
892 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadRedirect) { | 936 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadRedirect) { |
893 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; | 937 const char kEmbedderURL[] = "/browser_plugin_embedder.html"; |
894 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, std::string()); | 938 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, std::string()); |
895 | 939 |
896 const string16 expected_title = ASCIIToUTF16("redirected"); | 940 const string16 expected_title = ASCIIToUTF16("redirected"); |
897 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | 941 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
898 expected_title); | 942 expected_title); |
899 | 943 |
900 // Navigate with a redirect and wait until the title changes. | 944 // Navigate with a redirect and wait until the title changes. |
901 GURL redirect_url(test_server()->GetURL( | 945 const char kRedirectResponsePath[] = "/server-redirect"; |
902 "server-redirect?files/title1.html")); | 946 embedded_test_server()->RegisterRequestHandler( |
| 947 base::Bind(&RedirectResponseHandler, |
| 948 kRedirectResponsePath, |
| 949 embedded_test_server()->GetURL("/title1.html"))); |
| 950 GURL redirect_url(embedded_test_server()->GetURL(kRedirectResponsePath)); |
903 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 951 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
904 test_embedder()->web_contents()->GetRenderViewHost()); | 952 test_embedder()->web_contents()->GetRenderViewHost()); |
905 ExecuteSyncJSFunction( | 953 ExecuteSyncJSFunction( |
906 rvh, base::StringPrintf("SetSrc('%s');", redirect_url.spec().c_str())); | 954 rvh, base::StringPrintf("SetSrc('%s');", redirect_url.spec().c_str())); |
907 | 955 |
908 string16 actual_title = title_watcher.WaitAndGetTitle(); | 956 string16 actual_title = title_watcher.WaitAndGetTitle(); |
909 EXPECT_EQ(expected_title, actual_title); | 957 EXPECT_EQ(expected_title, actual_title); |
910 | 958 |
911 // Verify that we heard a loadRedirect during the navigation. | 959 // Verify that we heard a loadRedirect during the navigation. |
912 scoped_ptr<base::Value> value = | 960 scoped_ptr<base::Value> value = |
913 content::ExecuteScriptAndGetValue(rvh, "redirectOldUrl"); | 961 content::ExecuteScriptAndGetValue(rvh, "redirectOldUrl"); |
914 std::string result; | 962 std::string result; |
915 EXPECT_TRUE(value->GetAsString(&result)); | 963 EXPECT_TRUE(value->GetAsString(&result)); |
916 EXPECT_EQ(redirect_url.spec().c_str(), result); | 964 EXPECT_EQ(redirect_url.spec().c_str(), result); |
917 | 965 |
918 value = content::ExecuteScriptAndGetValue(rvh, "redirectNewUrl"); | 966 value = content::ExecuteScriptAndGetValue(rvh, "redirectNewUrl"); |
919 EXPECT_TRUE(value->GetAsString(&result)); | 967 EXPECT_TRUE(value->GetAsString(&result)); |
920 EXPECT_EQ(test_server()->GetURL("files/title1.html").spec().c_str(), result); | 968 EXPECT_EQ(embedded_test_server()->GetURL("/title1.html").spec().c_str(), |
| 969 result); |
921 } | 970 } |
922 | 971 |
923 // Always failing in the win7_aura try bot. See http://crbug.com/181107. | 972 // Always failing in the win7_aura try bot. See http://crbug.com/181107. |
924 #if defined(OS_WIN) && defined(USE_AURA) | 973 #if defined(OS_WIN) && defined(USE_AURA) |
925 #define MAYBE_AcceptDragEvents DISABLED_AcceptDragEvents | 974 #define MAYBE_AcceptDragEvents DISABLED_AcceptDragEvents |
926 #else | 975 #else |
927 #define MAYBE_AcceptDragEvents AcceptDragEvents | 976 #define MAYBE_AcceptDragEvents AcceptDragEvents |
928 #endif | 977 #endif |
929 | 978 |
930 // Tests that a drag-n-drop over the browser plugin in the embedder happens | 979 // Tests that a drag-n-drop over the browser plugin in the embedder happens |
931 // correctly. | 980 // correctly. |
932 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, MAYBE_AcceptDragEvents) { | 981 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, MAYBE_AcceptDragEvents) { |
933 const char kEmbedderURL[] = "files/browser_plugin_dragging.html"; | 982 const char kEmbedderURL[] = "/browser_plugin_dragging.html"; |
934 StartBrowserPluginTest( | 983 StartBrowserPluginTest( |
935 kEmbedderURL, kHTMLForGuestAcceptDrag, true, std::string()); | 984 kEmbedderURL, kHTMLForGuestAcceptDrag, true, std::string()); |
936 | 985 |
937 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 986 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
938 test_embedder()->web_contents()->GetRenderViewHost()); | 987 test_embedder()->web_contents()->GetRenderViewHost()); |
939 | 988 |
940 // Get a location in the embedder outside of the plugin. | 989 // Get a location in the embedder outside of the plugin. |
941 base::ListValue *start, *end; | 990 base::ListValue *start, *end; |
942 scoped_ptr<base::Value> value = | 991 scoped_ptr<base::Value> value = |
943 content::ExecuteScriptAndGetValue(rvh, "dragLocation()"); | 992 content::ExecuteScriptAndGetValue(rvh, "dragLocation()"); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
979 // 2. The guest receives and replies to the message using the event object's | 1028 // 2. The guest receives and replies to the message using the event object's |
980 // source object: event.source.postMessage('foobar', '*') | 1029 // source object: event.source.postMessage('foobar', '*') |
981 // 3. The embedder receives the message and uses the event's source | 1030 // 3. The embedder receives the message and uses the event's source |
982 // object to do one final reply: 'stop' | 1031 // object to do one final reply: 'stop' |
983 // 4. The guest receives the final 'stop' message. | 1032 // 4. The guest receives the final 'stop' message. |
984 // 5. The guest acks the 'stop' message with a 'stop_ack' message. | 1033 // 5. The guest acks the 'stop' message with a 'stop_ack' message. |
985 // 6. The embedder changes its title to 'main guest' when it sees the 'stop_ack' | 1034 // 6. The embedder changes its title to 'main guest' when it sees the 'stop_ack' |
986 // message. | 1035 // message. |
987 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, PostMessage) { | 1036 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, PostMessage) { |
988 const char* kTesting = "testing123"; | 1037 const char* kTesting = "testing123"; |
989 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 1038 const char* kEmbedderURL = "/browser_plugin_embedder.html"; |
990 const char* kGuestURL = "files/browser_plugin_post_message_guest.html"; | 1039 const char* kGuestURL = "/browser_plugin_post_message_guest.html"; |
991 StartBrowserPluginTest(kEmbedderURL, kGuestURL, false, std::string()); | 1040 StartBrowserPluginTest(kEmbedderURL, kGuestURL, false, std::string()); |
992 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 1041 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
993 test_embedder()->web_contents()->GetRenderViewHost()); | 1042 test_embedder()->web_contents()->GetRenderViewHost()); |
994 { | 1043 { |
995 const string16 expected_title = ASCIIToUTF16("main guest"); | 1044 const string16 expected_title = ASCIIToUTF16("main guest"); |
996 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | 1045 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
997 expected_title); | 1046 expected_title); |
998 | 1047 |
999 // By the time we get here 'contentWindow' should be ready because the | 1048 // By the time we get here 'contentWindow' should be ready because the |
1000 // guest has completed loading. | 1049 // guest has completed loading. |
1001 ExecuteSyncJSFunction( | 1050 ExecuteSyncJSFunction( |
1002 rvh, base::StringPrintf("PostMessage('%s, false');", kTesting)); | 1051 rvh, base::StringPrintf("PostMessage('%s, false');", kTesting)); |
1003 | 1052 |
1004 // The title will be updated to "main guest" at the last stage of the | 1053 // The title will be updated to "main guest" at the last stage of the |
1005 // process described above. | 1054 // process described above. |
1006 string16 actual_title = title_watcher.WaitAndGetTitle(); | 1055 string16 actual_title = title_watcher.WaitAndGetTitle(); |
1007 EXPECT_EQ(expected_title, actual_title); | 1056 EXPECT_EQ(expected_title, actual_title); |
1008 } | 1057 } |
1009 } | 1058 } |
1010 | 1059 |
1011 // This is the same as BrowserPluginHostTest.PostMessage but also | 1060 // This is the same as BrowserPluginHostTest.PostMessage but also |
1012 // posts a message to an iframe. | 1061 // posts a message to an iframe. |
1013 // TODO(fsamuel): This test should replace the previous test once postMessage | 1062 // TODO(fsamuel): This test should replace the previous test once postMessage |
1014 // iframe targeting is fixed (see http://crbug.com/153701). | 1063 // iframe targeting is fixed (see http://crbug.com/153701). |
1015 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, DISABLED_PostMessageToIFrame) { | 1064 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, DISABLED_PostMessageToIFrame) { |
1016 const char* kTesting = "testing123"; | 1065 const char* kTesting = "testing123"; |
1017 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 1066 const char* kEmbedderURL = "/browser_plugin_embedder.html"; |
1018 const char* kGuestURL = "files/browser_plugin_post_message_guest.html"; | 1067 const char* kGuestURL = "/browser_plugin_post_message_guest.html"; |
1019 StartBrowserPluginTest(kEmbedderURL, kGuestURL, false, std::string()); | 1068 StartBrowserPluginTest(kEmbedderURL, kGuestURL, false, std::string()); |
1020 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 1069 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
1021 test_embedder()->web_contents()->GetRenderViewHost()); | 1070 test_embedder()->web_contents()->GetRenderViewHost()); |
1022 { | 1071 { |
1023 const string16 expected_title = ASCIIToUTF16("main guest"); | 1072 const string16 expected_title = ASCIIToUTF16("main guest"); |
1024 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | 1073 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
1025 expected_title); | 1074 expected_title); |
1026 | 1075 |
1027 ExecuteSyncJSFunction( | 1076 ExecuteSyncJSFunction( |
1028 rvh, base::StringPrintf("PostMessage('%s, false');", kTesting)); | 1077 rvh, base::StringPrintf("PostMessage('%s, false');", kTesting)); |
1029 | 1078 |
1030 // The title will be updated to "main guest" at the last stage of the | 1079 // The title will be updated to "main guest" at the last stage of the |
1031 // process described above. | 1080 // process described above. |
1032 string16 actual_title = title_watcher.WaitAndGetTitle(); | 1081 string16 actual_title = title_watcher.WaitAndGetTitle(); |
1033 EXPECT_EQ(expected_title, actual_title); | 1082 EXPECT_EQ(expected_title, actual_title); |
1034 } | 1083 } |
1035 { | 1084 { |
1036 content::TitleWatcher ready_watcher(test_embedder()->web_contents(), | 1085 content::TitleWatcher ready_watcher(test_embedder()->web_contents(), |
1037 ASCIIToUTF16("ready")); | 1086 ASCIIToUTF16("ready")); |
1038 | 1087 |
1039 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( | 1088 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( |
1040 test_guest()->web_contents()->GetRenderViewHost()); | 1089 test_guest()->web_contents()->GetRenderViewHost()); |
1041 GURL test_url = test_server()->GetURL( | 1090 GURL test_url = embedded_test_server()->GetURL( |
1042 "files/browser_plugin_post_message_guest.html"); | 1091 "/browser_plugin_post_message_guest.html"); |
1043 ExecuteSyncJSFunction( | 1092 ExecuteSyncJSFunction( |
1044 guest_rvh, | 1093 guest_rvh, |
1045 base::StringPrintf( | 1094 base::StringPrintf( |
1046 "CreateChildFrame('%s');", test_url.spec().c_str())); | 1095 "CreateChildFrame('%s');", test_url.spec().c_str())); |
1047 | 1096 |
1048 string16 actual_title = ready_watcher.WaitAndGetTitle(); | 1097 string16 actual_title = ready_watcher.WaitAndGetTitle(); |
1049 EXPECT_EQ(ASCIIToUTF16("ready"), actual_title); | 1098 EXPECT_EQ(ASCIIToUTF16("ready"), actual_title); |
1050 | 1099 |
1051 content::TitleWatcher iframe_watcher(test_embedder()->web_contents(), | 1100 content::TitleWatcher iframe_watcher(test_embedder()->web_contents(), |
1052 ASCIIToUTF16("iframe")); | 1101 ASCIIToUTF16("iframe")); |
1053 ExecuteSyncJSFunction( | 1102 ExecuteSyncJSFunction( |
1054 rvh, base::StringPrintf("PostMessage('%s', true);", kTesting)); | 1103 rvh, base::StringPrintf("PostMessage('%s', true);", kTesting)); |
1055 | 1104 |
1056 // The title will be updated to "iframe" at the last stage of the | 1105 // The title will be updated to "iframe" at the last stage of the |
1057 // process described above. | 1106 // process described above. |
1058 actual_title = iframe_watcher.WaitAndGetTitle(); | 1107 actual_title = iframe_watcher.WaitAndGetTitle(); |
1059 EXPECT_EQ(ASCIIToUTF16("iframe"), actual_title); | 1108 EXPECT_EQ(ASCIIToUTF16("iframe"), actual_title); |
1060 } | 1109 } |
1061 } | 1110 } |
1062 | 1111 |
1063 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadStop) { | 1112 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadStop) { |
1064 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 1113 const char* kEmbedderURL = "/browser_plugin_embedder.html"; |
1065 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, std::string()); | 1114 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, std::string()); |
1066 | 1115 |
1067 const string16 expected_title = ASCIIToUTF16("loadStop"); | 1116 const string16 expected_title = ASCIIToUTF16("loadStop"); |
1068 content::TitleWatcher title_watcher( | 1117 content::TitleWatcher title_watcher( |
1069 test_embedder()->web_contents(), expected_title); | 1118 test_embedder()->web_contents(), expected_title); |
1070 // Renavigate the guest to |kHTMLForGuest|. | 1119 // Renavigate the guest to |kHTMLForGuest|. |
1071 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 1120 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
1072 test_embedder()->web_contents()->GetRenderViewHost()); | 1121 test_embedder()->web_contents()->GetRenderViewHost()); |
1073 ExecuteSyncJSFunction(rvh, | 1122 ExecuteSyncJSFunction(rvh, |
1074 base::StringPrintf("SetSrc('%s');", kHTMLForGuest)); | 1123 base::StringPrintf("SetSrc('%s');", kHTMLForGuest)); |
1075 | 1124 |
1076 string16 actual_title = title_watcher.WaitAndGetTitle(); | 1125 string16 actual_title = title_watcher.WaitAndGetTitle(); |
1077 EXPECT_EQ(expected_title, actual_title); | 1126 EXPECT_EQ(expected_title, actual_title); |
1078 } | 1127 } |
1079 | 1128 |
1080 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadCommit) { | 1129 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadCommit) { |
1081 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 1130 const char* kEmbedderURL = "/browser_plugin_embedder.html"; |
1082 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, std::string()); | 1131 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, std::string()); |
1083 | 1132 |
1084 const string16 expected_title = ASCIIToUTF16( | 1133 const string16 expected_title = ASCIIToUTF16( |
1085 base::StringPrintf("loadCommit:%s", kHTMLForGuest)); | 1134 base::StringPrintf("loadCommit:%s", kHTMLForGuest)); |
1086 content::TitleWatcher title_watcher( | 1135 content::TitleWatcher title_watcher( |
1087 test_embedder()->web_contents(), expected_title); | 1136 test_embedder()->web_contents(), expected_title); |
1088 // Renavigate the guest to |kHTMLForGuest|. | 1137 // Renavigate the guest to |kHTMLForGuest|. |
1089 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 1138 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
1090 test_embedder()->web_contents()->GetRenderViewHost()); | 1139 test_embedder()->web_contents()->GetRenderViewHost()); |
1091 ExecuteSyncJSFunction(rvh, | 1140 ExecuteSyncJSFunction(rvh, |
1092 base::StringPrintf("SetSrc('%s');", kHTMLForGuest)); | 1141 base::StringPrintf("SetSrc('%s');", kHTMLForGuest)); |
1093 | 1142 |
1094 string16 actual_title = title_watcher.WaitAndGetTitle(); | 1143 string16 actual_title = title_watcher.WaitAndGetTitle(); |
1095 EXPECT_EQ(expected_title, actual_title); | 1144 EXPECT_EQ(expected_title, actual_title); |
1096 scoped_ptr<base::Value> is_top_level = | 1145 scoped_ptr<base::Value> is_top_level = |
1097 content::ExecuteScriptAndGetValue(rvh, "commitIsTopLevel"); | 1146 content::ExecuteScriptAndGetValue(rvh, "commitIsTopLevel"); |
1098 bool top_level_bool = false; | 1147 bool top_level_bool = false; |
1099 EXPECT_TRUE(is_top_level->GetAsBoolean(&top_level_bool)); | 1148 EXPECT_TRUE(is_top_level->GetAsBoolean(&top_level_bool)); |
1100 EXPECT_EQ(true, top_level_bool); | 1149 EXPECT_EQ(true, top_level_bool); |
1101 } | 1150 } |
1102 | 1151 |
1103 // This test verifies that if a browser plugin is hidden before navigation, | 1152 // This test verifies that if a browser plugin is hidden before navigation, |
1104 // the guest starts off hidden. | 1153 // the guest starts off hidden. |
1105 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, HiddenBeforeNavigation) { | 1154 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, HiddenBeforeNavigation) { |
1106 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 1155 const char* kEmbedderURL = "/browser_plugin_embedder.html"; |
1107 const std::string embedder_code = | 1156 const std::string embedder_code = |
1108 "document.getElementById('plugin').style.visibility = 'hidden'"; | 1157 "document.getElementById('plugin').style.visibility = 'hidden'"; |
1109 StartBrowserPluginTest( | 1158 StartBrowserPluginTest( |
1110 kEmbedderURL, kHTMLForGuest, true, embedder_code); | 1159 kEmbedderURL, kHTMLForGuest, true, embedder_code); |
1111 EXPECT_FALSE(test_guest()->visible()); | 1160 EXPECT_FALSE(test_guest()->visible()); |
1112 } | 1161 } |
1113 | 1162 |
1114 // This test verifies that if we lose the guest, and get a new one, | 1163 // This test verifies that if we lose the guest, and get a new one, |
1115 // the new guest will inherit the visibility state of the old guest. | 1164 // the new guest will inherit the visibility state of the old guest. |
1116 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, VisibilityPreservation) { | 1165 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, VisibilityPreservation) { |
1117 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 1166 const char* kEmbedderURL = "/browser_plugin_embedder.html"; |
1118 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); | 1167 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); |
1119 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 1168 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
1120 test_embedder()->web_contents()->GetRenderViewHost()); | 1169 test_embedder()->web_contents()->GetRenderViewHost()); |
1121 // Hide the BrowserPlugin. | 1170 // Hide the BrowserPlugin. |
1122 ExecuteSyncJSFunction( | 1171 ExecuteSyncJSFunction( |
1123 rvh, "document.getElementById('plugin').style.visibility = 'hidden';"); | 1172 rvh, "document.getElementById('plugin').style.visibility = 'hidden';"); |
1124 test_guest()->WaitUntilHidden(); | 1173 test_guest()->WaitUntilHidden(); |
1125 // Kill the current guest. | 1174 // Kill the current guest. |
1126 ExecuteSyncJSFunction(rvh, "document.getElementById('plugin').terminate();"); | 1175 ExecuteSyncJSFunction(rvh, "document.getElementById('plugin').terminate();"); |
1127 test_guest()->WaitForExit(); | 1176 test_guest()->WaitForExit(); |
1128 // Get a new guest. | 1177 // Get a new guest. |
1129 ExecuteSyncJSFunction(rvh, "document.getElementById('plugin').reload();"); | 1178 ExecuteSyncJSFunction(rvh, "document.getElementById('plugin').reload();"); |
1130 test_guest()->WaitForLoadStop(); | 1179 test_guest()->WaitForLoadStop(); |
1131 // Verify that the guest is told to hide. | 1180 // Verify that the guest is told to hide. |
1132 test_guest()->WaitUntilHidden(); | 1181 test_guest()->WaitUntilHidden(); |
1133 } | 1182 } |
1134 | 1183 |
1135 // This test verifies that if a browser plugin is focused before navigation then | 1184 // This test verifies that if a browser plugin is focused before navigation then |
1136 // the guest starts off focused. | 1185 // the guest starts off focused. |
1137 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, FocusBeforeNavigation) { | 1186 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, FocusBeforeNavigation) { |
1138 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 1187 const char* kEmbedderURL = "/browser_plugin_embedder.html"; |
1139 const std::string embedder_code = | 1188 const std::string embedder_code = |
1140 "document.getElementById('plugin').focus();"; | 1189 "document.getElementById('plugin').focus();"; |
1141 StartBrowserPluginTest( | 1190 StartBrowserPluginTest( |
1142 kEmbedderURL, kHTMLForGuest, true, embedder_code); | 1191 kEmbedderURL, kHTMLForGuest, true, embedder_code); |
1143 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( | 1192 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( |
1144 test_guest()->web_contents()->GetRenderViewHost()); | 1193 test_guest()->web_contents()->GetRenderViewHost()); |
1145 // Verify that the guest is focused. | 1194 // Verify that the guest is focused. |
1146 scoped_ptr<base::Value> value = | 1195 scoped_ptr<base::Value> value = |
1147 content::ExecuteScriptAndGetValue(guest_rvh, "document.hasFocus()"); | 1196 content::ExecuteScriptAndGetValue(guest_rvh, "document.hasFocus()"); |
1148 bool result = false; | 1197 bool result = false; |
1149 ASSERT_TRUE(value->GetAsBoolean(&result)); | 1198 ASSERT_TRUE(value->GetAsBoolean(&result)); |
1150 EXPECT_TRUE(result); | 1199 EXPECT_TRUE(result); |
1151 } | 1200 } |
1152 | 1201 |
1153 // This test verifies that if we lose the guest, and get a new one, | 1202 // This test verifies that if we lose the guest, and get a new one, |
1154 // the new guest will inherit the focus state of the old guest. | 1203 // the new guest will inherit the focus state of the old guest. |
1155 // crbug.com/170249 | 1204 // crbug.com/170249 |
1156 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, DISABLED_FocusPreservation) { | 1205 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, DISABLED_FocusPreservation) { |
1157 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 1206 const char* kEmbedderURL = "/browser_plugin_embedder.html"; |
1158 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); | 1207 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); |
1159 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 1208 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
1160 test_embedder()->web_contents()->GetRenderViewHost()); | 1209 test_embedder()->web_contents()->GetRenderViewHost()); |
1161 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( | 1210 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( |
1162 test_guest()->web_contents()->GetRenderViewHost()); | 1211 test_guest()->web_contents()->GetRenderViewHost()); |
1163 { | 1212 { |
1164 // Focus the BrowserPlugin. This will have the effect of also focusing the | 1213 // Focus the BrowserPlugin. This will have the effect of also focusing the |
1165 // current guest. | 1214 // current guest. |
1166 ExecuteSyncJSFunction(rvh, "document.getElementById('plugin').focus();"); | 1215 ExecuteSyncJSFunction(rvh, "document.getElementById('plugin').focus();"); |
1167 // Verify that key presses go to the guest. | 1216 // Verify that key presses go to the guest. |
(...skipping 18 matching lines...) Expand all Loading... |
1186 // Verify that the guest is focused. | 1235 // Verify that the guest is focused. |
1187 scoped_ptr<base::Value> value = | 1236 scoped_ptr<base::Value> value = |
1188 content::ExecuteScriptAndGetValue(guest_rvh, "document.hasFocus()"); | 1237 content::ExecuteScriptAndGetValue(guest_rvh, "document.hasFocus()"); |
1189 bool result = false; | 1238 bool result = false; |
1190 ASSERT_TRUE(value->GetAsBoolean(&result)); | 1239 ASSERT_TRUE(value->GetAsBoolean(&result)); |
1191 EXPECT_TRUE(result); | 1240 EXPECT_TRUE(result); |
1192 } | 1241 } |
1193 } | 1242 } |
1194 | 1243 |
1195 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, FocusTracksEmbedder) { | 1244 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, FocusTracksEmbedder) { |
1196 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 1245 const char* kEmbedderURL = "/browser_plugin_embedder.html"; |
1197 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); | 1246 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); |
1198 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 1247 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
1199 test_embedder()->web_contents()->GetRenderViewHost()); | 1248 test_embedder()->web_contents()->GetRenderViewHost()); |
1200 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( | 1249 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( |
1201 test_guest()->web_contents()->GetRenderViewHost()); | 1250 test_guest()->web_contents()->GetRenderViewHost()); |
1202 { | 1251 { |
1203 // Focus the BrowserPlugin. This will have the effect of also focusing the | 1252 // Focus the BrowserPlugin. This will have the effect of also focusing the |
1204 // current guest. | 1253 // current guest. |
1205 ExecuteSyncJSFunction(rvh, "document.getElementById('plugin').focus();"); | 1254 ExecuteSyncJSFunction(rvh, "document.getElementById('plugin').focus();"); |
1206 // Verify that key presses go to the guest. | 1255 // Verify that key presses go to the guest. |
1207 SimulateSpaceKeyPress(test_embedder()->web_contents()); | 1256 SimulateSpaceKeyPress(test_embedder()->web_contents()); |
1208 test_guest()->WaitForInput(); | 1257 test_guest()->WaitForInput(); |
1209 // Verify that the guest is focused. | 1258 // Verify that the guest is focused. |
1210 scoped_ptr<base::Value> value = | 1259 scoped_ptr<base::Value> value = |
1211 content::ExecuteScriptAndGetValue(guest_rvh, "document.hasFocus()"); | 1260 content::ExecuteScriptAndGetValue(guest_rvh, "document.hasFocus()"); |
1212 bool result = false; | 1261 bool result = false; |
1213 ASSERT_TRUE(value->GetAsBoolean(&result)); | 1262 ASSERT_TRUE(value->GetAsBoolean(&result)); |
1214 EXPECT_TRUE(result); | 1263 EXPECT_TRUE(result); |
1215 } | 1264 } |
1216 // Blur the embedder. | 1265 // Blur the embedder. |
1217 test_embedder()->web_contents()->GetRenderViewHost()->Blur(); | 1266 test_embedder()->web_contents()->GetRenderViewHost()->Blur(); |
1218 test_guest()->WaitForBlur(); | 1267 test_guest()->WaitForBlur(); |
1219 } | 1268 } |
1220 | 1269 |
1221 // This test verifies that if a browser plugin is in autosize mode before | 1270 // This test verifies that if a browser plugin is in autosize mode before |
1222 // navigation then the guest starts auto-sized. | 1271 // navigation then the guest starts auto-sized. |
1223 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, AutoSizeBeforeNavigation) { | 1272 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, AutoSizeBeforeNavigation) { |
1224 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 1273 const char* kEmbedderURL = "/browser_plugin_embedder.html"; |
1225 const std::string embedder_code = | 1274 const std::string embedder_code = |
1226 "document.getElementById('plugin').minwidth = 300;" | 1275 "document.getElementById('plugin').minwidth = 300;" |
1227 "document.getElementById('plugin').minheight = 200;" | 1276 "document.getElementById('plugin').minheight = 200;" |
1228 "document.getElementById('plugin').maxwidth = 600;" | 1277 "document.getElementById('plugin').maxwidth = 600;" |
1229 "document.getElementById('plugin').maxheight = 400;" | 1278 "document.getElementById('plugin').maxheight = 400;" |
1230 "document.getElementById('plugin').autosize = true;"; | 1279 "document.getElementById('plugin').autosize = true;"; |
1231 StartBrowserPluginTest( | 1280 StartBrowserPluginTest( |
1232 kEmbedderURL, kHTMLForGuestWithSize, true, embedder_code); | 1281 kEmbedderURL, kHTMLForGuestWithSize, true, embedder_code); |
1233 // Verify that the guest has been auto-sized. | 1282 // Verify that the guest has been auto-sized. |
1234 test_guest()->WaitForViewSize(gfx::Size(300, 400)); | 1283 test_guest()->WaitForViewSize(gfx::Size(300, 400)); |
1235 } | 1284 } |
1236 | 1285 |
1237 // This test verifies that enabling autosize resizes the guest and triggers | 1286 // This test verifies that enabling autosize resizes the guest and triggers |
1238 // a 'sizechanged' event. | 1287 // a 'sizechanged' event. |
1239 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, AutoSizeAfterNavigation) { | 1288 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, AutoSizeAfterNavigation) { |
1240 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 1289 const char* kEmbedderURL = "/browser_plugin_embedder.html"; |
1241 StartBrowserPluginTest( | 1290 StartBrowserPluginTest( |
1242 kEmbedderURL, kHTMLForGuestWithSize, true, std::string()); | 1291 kEmbedderURL, kHTMLForGuestWithSize, true, std::string()); |
1243 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 1292 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
1244 test_embedder()->web_contents()->GetRenderViewHost()); | 1293 test_embedder()->web_contents()->GetRenderViewHost()); |
1245 | 1294 |
1246 { | 1295 { |
1247 const string16 expected_title = ASCIIToUTF16("AutoSize(300, 400)"); | 1296 const string16 expected_title = ASCIIToUTF16("AutoSize(300, 400)"); |
1248 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | 1297 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
1249 expected_title); | 1298 expected_title); |
1250 ExecuteSyncJSFunction( | 1299 ExecuteSyncJSFunction( |
(...skipping 19 matching lines...) Expand all Loading... |
1270 { | 1319 { |
1271 // Turn off autoSize and verify that the guest resizes to fit the container. | 1320 // Turn off autoSize and verify that the guest resizes to fit the container. |
1272 ExecuteSyncJSFunction( | 1321 ExecuteSyncJSFunction( |
1273 rvh, "document.getElementById('plugin').autosize = null;"); | 1322 rvh, "document.getElementById('plugin').autosize = null;"); |
1274 test_guest()->WaitForViewSize(gfx::Size(640, 480)); | 1323 test_guest()->WaitForViewSize(gfx::Size(640, 480)); |
1275 } | 1324 } |
1276 } | 1325 } |
1277 | 1326 |
1278 // Test for regression http://crbug.com/162961. | 1327 // Test for regression http://crbug.com/162961. |
1279 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, GetRenderViewHostAtPositionTest) { | 1328 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, GetRenderViewHostAtPositionTest) { |
1280 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; | 1329 const char kEmbedderURL[] = "/browser_plugin_embedder.html"; |
1281 const std::string embedder_code = | 1330 const std::string embedder_code = |
1282 base::StringPrintf("SetSize(%d, %d);", 100, 100); | 1331 base::StringPrintf("SetSize(%d, %d);", 100, 100); |
1283 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuestWithSize, true, | 1332 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuestWithSize, true, |
1284 embedder_code); | 1333 embedder_code); |
1285 // Check for render view host at position (150, 150) that is outside the | 1334 // Check for render view host at position (150, 150) that is outside the |
1286 // bounds of our guest, so this would respond with the render view host of the | 1335 // bounds of our guest, so this would respond with the render view host of the |
1287 // embedder. | 1336 // embedder. |
1288 test_embedder()->WaitForRenderViewHostAtPosition(150, 150); | 1337 test_embedder()->WaitForRenderViewHostAtPosition(150, 150); |
1289 ASSERT_EQ(test_embedder()->web_contents()->GetRenderViewHost(), | 1338 ASSERT_EQ(test_embedder()->web_contents()->GetRenderViewHost(), |
1290 test_embedder()->last_rvh_at_position_response()); | 1339 test_embedder()->last_rvh_at_position_response()); |
1291 } | 1340 } |
1292 | 1341 |
1293 // Flaky on Win Aura Tests (1) bot. See http://crbug.com/233087. | 1342 // Flaky on Win Aura Tests (1) bot. See http://crbug.com/233087. |
1294 #if defined(OS_WIN) && defined(USE_AURA) | 1343 #if defined(OS_WIN) && defined(USE_AURA) |
1295 #define MAYBE_ChangeWindowName DISABLED_ChangeWindowName | 1344 #define MAYBE_ChangeWindowName DISABLED_ChangeWindowName |
1296 #else | 1345 #else |
1297 #define MAYBE_ChangeWindowName ChangeWindowName | 1346 #define MAYBE_ChangeWindowName ChangeWindowName |
1298 #endif | 1347 #endif |
1299 | 1348 |
1300 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, MAYBE_ChangeWindowName) { | 1349 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, MAYBE_ChangeWindowName) { |
1301 const char kEmbedderURL[] = "files/browser_plugin_naming_embedder.html"; | 1350 const char kEmbedderURL[] = "/browser_plugin_naming_embedder.html"; |
1302 const char* kGuestURL = "files/browser_plugin_naming_guest.html"; | 1351 const char* kGuestURL = "/browser_plugin_naming_guest.html"; |
1303 StartBrowserPluginTest(kEmbedderURL, kGuestURL, false, std::string()); | 1352 StartBrowserPluginTest(kEmbedderURL, kGuestURL, false, std::string()); |
1304 | 1353 |
1305 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 1354 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
1306 test_embedder()->web_contents()->GetRenderViewHost()); | 1355 test_embedder()->web_contents()->GetRenderViewHost()); |
1307 // Verify that the plugin's name is properly initialized. | 1356 // Verify that the plugin's name is properly initialized. |
1308 { | 1357 { |
1309 scoped_ptr<base::Value> value = content::ExecuteScriptAndGetValue( | 1358 scoped_ptr<base::Value> value = content::ExecuteScriptAndGetValue( |
1310 rvh, "document.getElementById('plugin').name"); | 1359 rvh, "document.getElementById('plugin').name"); |
1311 std::string result; | 1360 std::string result; |
1312 EXPECT_TRUE(value->GetAsString(&result)); | 1361 EXPECT_TRUE(value->GetAsString(&result)); |
(...skipping 25 matching lines...) Expand all Loading... |
1338 "document.getElementById('plugin').name = 'foobar';"); | 1387 "document.getElementById('plugin').name = 'foobar';"); |
1339 string16 actual_title = title_watcher.WaitAndGetTitle(); | 1388 string16 actual_title = title_watcher.WaitAndGetTitle(); |
1340 EXPECT_EQ(expected_title, actual_title); | 1389 EXPECT_EQ(expected_title, actual_title); |
1341 | 1390 |
1342 } | 1391 } |
1343 } | 1392 } |
1344 | 1393 |
1345 // This test verifies that all autosize attributes can be removed | 1394 // This test verifies that all autosize attributes can be removed |
1346 // without crashing the plugin, or throwing errors. | 1395 // without crashing the plugin, or throwing errors. |
1347 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, RemoveAutosizeAttributes) { | 1396 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, RemoveAutosizeAttributes) { |
1348 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 1397 const char* kEmbedderURL = "/browser_plugin_embedder.html"; |
1349 const std::string embedder_code = | 1398 const std::string embedder_code = |
1350 "document.getElementById('plugin').minwidth = 300;" | 1399 "document.getElementById('plugin').minwidth = 300;" |
1351 "document.getElementById('plugin').minheight = 200;" | 1400 "document.getElementById('plugin').minheight = 200;" |
1352 "document.getElementById('plugin').maxwidth = 600;" | 1401 "document.getElementById('plugin').maxwidth = 600;" |
1353 "document.getElementById('plugin').maxheight = 400;" | 1402 "document.getElementById('plugin').maxheight = 400;" |
1354 "document.getElementById('plugin').name = 'name';" | 1403 "document.getElementById('plugin').name = 'name';" |
1355 "document.getElementById('plugin').src = 'foo';" | 1404 "document.getElementById('plugin').src = 'foo';" |
1356 "document.getElementById('plugin').autosize = '';"; | 1405 "document.getElementById('plugin').autosize = '';"; |
1357 StartBrowserPluginTest( | 1406 StartBrowserPluginTest( |
1358 kEmbedderURL, kHTMLForGuestWithSize, true, embedder_code); | 1407 kEmbedderURL, kHTMLForGuestWithSize, true, embedder_code); |
1359 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 1408 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
1360 test_embedder()->web_contents()->GetRenderViewHost()); | 1409 test_embedder()->web_contents()->GetRenderViewHost()); |
1361 RemoveAttributes(rvh, "maxheight, maxwidth, minheight, minwidth, autosize"); | 1410 RemoveAttributes(rvh, "maxheight, maxwidth, minheight, minwidth, autosize"); |
1362 | 1411 |
1363 // Verify that the guest resizes to fit the container (and hasn't crashed). | 1412 // Verify that the guest resizes to fit the container (and hasn't crashed). |
1364 test_guest()->WaitForViewSize(gfx::Size(640, 480)); | 1413 test_guest()->WaitForViewSize(gfx::Size(640, 480)); |
1365 EXPECT_TRUE(IsAttributeNull(rvh, "maxheight")); | 1414 EXPECT_TRUE(IsAttributeNull(rvh, "maxheight")); |
1366 EXPECT_TRUE(IsAttributeNull(rvh, "maxwidth")); | 1415 EXPECT_TRUE(IsAttributeNull(rvh, "maxwidth")); |
1367 EXPECT_TRUE(IsAttributeNull(rvh, "minheight")); | 1416 EXPECT_TRUE(IsAttributeNull(rvh, "minheight")); |
1368 EXPECT_TRUE(IsAttributeNull(rvh, "minwidth")); | 1417 EXPECT_TRUE(IsAttributeNull(rvh, "minwidth")); |
1369 EXPECT_TRUE(IsAttributeNull(rvh, "autosize")); | 1418 EXPECT_TRUE(IsAttributeNull(rvh, "autosize")); |
1370 } | 1419 } |
1371 | 1420 |
1372 // This test verifies that autosize works when some of the parameters are unset. | 1421 // This test verifies that autosize works when some of the parameters are unset. |
1373 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, PartialAutosizeAttributes) { | 1422 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, PartialAutosizeAttributes) { |
1374 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 1423 const char* kEmbedderURL = "/browser_plugin_embedder.html"; |
1375 const std::string embedder_code = | 1424 const std::string embedder_code = |
1376 "document.getElementById('plugin').minwidth = 300;" | 1425 "document.getElementById('plugin').minwidth = 300;" |
1377 "document.getElementById('plugin').minheight = 200;" | 1426 "document.getElementById('plugin').minheight = 200;" |
1378 "document.getElementById('plugin').maxwidth = 700;" | 1427 "document.getElementById('plugin').maxwidth = 700;" |
1379 "document.getElementById('plugin').maxheight = 600;" | 1428 "document.getElementById('plugin').maxheight = 600;" |
1380 "document.getElementById('plugin').autosize = '';"; | 1429 "document.getElementById('plugin').autosize = '';"; |
1381 StartBrowserPluginTest( | 1430 StartBrowserPluginTest( |
1382 kEmbedderURL, kHTMLForGuestWithSize, true, embedder_code); | 1431 kEmbedderURL, kHTMLForGuestWithSize, true, embedder_code); |
1383 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 1432 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
1384 test_embedder()->web_contents()->GetRenderViewHost()); | 1433 test_embedder()->web_contents()->GetRenderViewHost()); |
(...skipping 24 matching lines...) Expand all Loading... |
1409 const string16 expected_title = ASCIIToUTF16("AutoSize(640, 480)"); | 1458 const string16 expected_title = ASCIIToUTF16("AutoSize(640, 480)"); |
1410 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | 1459 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
1411 expected_title); | 1460 expected_title); |
1412 RemoveAttributes(rvh, "maxwidth"); | 1461 RemoveAttributes(rvh, "maxwidth"); |
1413 string16 actual_title = title_watcher.WaitAndGetTitle(); | 1462 string16 actual_title = title_watcher.WaitAndGetTitle(); |
1414 EXPECT_EQ(expected_title, actual_title); | 1463 EXPECT_EQ(expected_title, actual_title); |
1415 } | 1464 } |
1416 } | 1465 } |
1417 | 1466 |
1418 } // namespace content | 1467 } // namespace content |
OLD | NEW |