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>(new EmptyHttpResponse); |
| 857 |
| 858 return scoped_ptr<net::test_server::HttpResponse>(NULL); |
| 859 } |
| 860 |
| 861 // Handles |request| by serving a redirect response. |
| 862 scoped_ptr<net::test_server::HttpResponse> RedirectResponseHandler( |
| 863 const std::string& path, |
| 864 const GURL& redirect_target, |
| 865 const net::test_server::HttpRequest& request) { |
| 866 if (!StartsWithASCII(path, request.relative_url, true)) |
| 867 return scoped_ptr<net::test_server::HttpResponse>(NULL); |
| 868 |
| 869 scoped_ptr<net::test_server::HttpResponseImpl> http_response( |
| 870 new net::test_server::HttpResponseImpl); |
| 871 http_response->set_code(net::test_server::MOVED); |
| 872 http_response->AddCustomHeader("Location", redirect_target.spec()); |
| 873 return http_response.PassAs<net::test_server::HttpResponse>(); |
| 874 } |
| 875 |
| 876 } // namespace |
| 877 |
839 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadAbort) { | 878 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadAbort) { |
840 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; | 879 const char kEmbedderURL[] = "/browser_plugin_embedder.html"; |
841 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, std::string()); | 880 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, std::string()); |
842 | 881 |
843 { | 882 { |
844 // Navigate the guest to "close-socket". | 883 // Navigate the guest to "close-socket". |
| 884 const char kEmptyResponsePath[] = "/close-socket"; |
| 885 embedded_test_server()->RegisterRequestHandler( |
| 886 base::Bind(&EmptyResponseHandler, kEmptyResponsePath)); |
845 const string16 expected_title = ASCIIToUTF16("ERR_EMPTY_RESPONSE"); | 887 const string16 expected_title = ASCIIToUTF16("ERR_EMPTY_RESPONSE"); |
846 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | 888 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
847 expected_title); | 889 expected_title); |
848 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 890 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
849 test_embedder()->web_contents()->GetRenderViewHost()); | 891 test_embedder()->web_contents()->GetRenderViewHost()); |
850 GURL test_url = test_server()->GetURL("close-socket"); | 892 GURL test_url = embedded_test_server()->GetURL(kEmptyResponsePath); |
851 ExecuteSyncJSFunction( | 893 ExecuteSyncJSFunction( |
852 rvh, base::StringPrintf("SetSrc('%s');", test_url.spec().c_str())); | 894 rvh, base::StringPrintf("SetSrc('%s');", test_url.spec().c_str())); |
853 string16 actual_title = title_watcher.WaitAndGetTitle(); | 895 string16 actual_title = title_watcher.WaitAndGetTitle(); |
854 EXPECT_EQ(expected_title, actual_title); | 896 EXPECT_EQ(expected_title, actual_title); |
855 } | 897 } |
856 | 898 |
857 { | 899 { |
858 // Navigate the guest to an illegal chrome:// URL. | 900 // Navigate the guest to an illegal chrome:// URL. |
859 GURL test_url("chrome://newtab"); | 901 GURL test_url("chrome://newtab"); |
860 ChildProcessSecurityPolicyImpl* policy = | 902 ChildProcessSecurityPolicyImpl* policy = |
(...skipping 22 matching lines...) Expand all Loading... |
883 test_embedder()->web_contents()->GetRenderViewHost()); | 925 test_embedder()->web_contents()->GetRenderViewHost()); |
884 GURL test_url("file://foo"); | 926 GURL test_url("file://foo"); |
885 ExecuteSyncJSFunction( | 927 ExecuteSyncJSFunction( |
886 rvh, base::StringPrintf("SetSrc('%s');", test_url.spec().c_str())); | 928 rvh, base::StringPrintf("SetSrc('%s');", test_url.spec().c_str())); |
887 string16 actual_title = title_watcher.WaitAndGetTitle(); | 929 string16 actual_title = title_watcher.WaitAndGetTitle(); |
888 EXPECT_EQ(expected_title, actual_title); | 930 EXPECT_EQ(expected_title, actual_title); |
889 } | 931 } |
890 } | 932 } |
891 | 933 |
892 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadRedirect) { | 934 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadRedirect) { |
893 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; | 935 const char kEmbedderURL[] = "/browser_plugin_embedder.html"; |
894 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, std::string()); | 936 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, std::string()); |
895 | 937 |
896 const string16 expected_title = ASCIIToUTF16("redirected"); | 938 const string16 expected_title = ASCIIToUTF16("redirected"); |
897 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | 939 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
898 expected_title); | 940 expected_title); |
899 | 941 |
900 // Navigate with a redirect and wait until the title changes. | 942 // Navigate with a redirect and wait until the title changes. |
901 GURL redirect_url(test_server()->GetURL( | 943 const char kRedirectResponsePath[] = "/server-redirect"; |
902 "server-redirect?files/title1.html")); | 944 embedded_test_server()->RegisterRequestHandler( |
| 945 base::Bind(&RedirectResponseHandler, |
| 946 kRedirectResponsePath, |
| 947 embedded_test_server()->GetURL("/title1.html"))); |
| 948 GURL redirect_url(embedded_test_server()->GetURL(kRedirectResponsePath)); |
903 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 949 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
904 test_embedder()->web_contents()->GetRenderViewHost()); | 950 test_embedder()->web_contents()->GetRenderViewHost()); |
905 ExecuteSyncJSFunction( | 951 ExecuteSyncJSFunction( |
906 rvh, base::StringPrintf("SetSrc('%s');", redirect_url.spec().c_str())); | 952 rvh, base::StringPrintf("SetSrc('%s');", redirect_url.spec().c_str())); |
907 | 953 |
908 string16 actual_title = title_watcher.WaitAndGetTitle(); | 954 string16 actual_title = title_watcher.WaitAndGetTitle(); |
909 EXPECT_EQ(expected_title, actual_title); | 955 EXPECT_EQ(expected_title, actual_title); |
910 | 956 |
911 // Verify that we heard a loadRedirect during the navigation. | 957 // Verify that we heard a loadRedirect during the navigation. |
912 scoped_ptr<base::Value> value = | 958 scoped_ptr<base::Value> value = |
913 content::ExecuteScriptAndGetValue(rvh, "redirectOldUrl"); | 959 content::ExecuteScriptAndGetValue(rvh, "redirectOldUrl"); |
914 std::string result; | 960 std::string result; |
915 EXPECT_TRUE(value->GetAsString(&result)); | 961 EXPECT_TRUE(value->GetAsString(&result)); |
916 EXPECT_EQ(redirect_url.spec().c_str(), result); | 962 EXPECT_EQ(redirect_url.spec().c_str(), result); |
917 | 963 |
918 value = content::ExecuteScriptAndGetValue(rvh, "redirectNewUrl"); | 964 value = content::ExecuteScriptAndGetValue(rvh, "redirectNewUrl"); |
919 EXPECT_TRUE(value->GetAsString(&result)); | 965 EXPECT_TRUE(value->GetAsString(&result)); |
920 EXPECT_EQ(test_server()->GetURL("files/title1.html").spec().c_str(), result); | 966 EXPECT_EQ(embedded_test_server()->GetURL("/title1.html").spec().c_str(), |
| 967 result); |
921 } | 968 } |
922 | 969 |
923 // Always failing in the win7_aura try bot. See http://crbug.com/181107. | 970 // Always failing in the win7_aura try bot. See http://crbug.com/181107. |
924 #if defined(OS_WIN) && defined(USE_AURA) | 971 #if defined(OS_WIN) && defined(USE_AURA) |
925 #define MAYBE_AcceptDragEvents DISABLED_AcceptDragEvents | 972 #define MAYBE_AcceptDragEvents DISABLED_AcceptDragEvents |
926 #else | 973 #else |
927 #define MAYBE_AcceptDragEvents AcceptDragEvents | 974 #define MAYBE_AcceptDragEvents AcceptDragEvents |
928 #endif | 975 #endif |
929 | 976 |
930 // Tests that a drag-n-drop over the browser plugin in the embedder happens | 977 // Tests that a drag-n-drop over the browser plugin in the embedder happens |
931 // correctly. | 978 // correctly. |
932 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, MAYBE_AcceptDragEvents) { | 979 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, MAYBE_AcceptDragEvents) { |
933 const char kEmbedderURL[] = "files/browser_plugin_dragging.html"; | 980 const char kEmbedderURL[] = "/browser_plugin_dragging.html"; |
934 StartBrowserPluginTest( | 981 StartBrowserPluginTest( |
935 kEmbedderURL, kHTMLForGuestAcceptDrag, true, std::string()); | 982 kEmbedderURL, kHTMLForGuestAcceptDrag, true, std::string()); |
936 | 983 |
937 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 984 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
938 test_embedder()->web_contents()->GetRenderViewHost()); | 985 test_embedder()->web_contents()->GetRenderViewHost()); |
939 | 986 |
940 // Get a location in the embedder outside of the plugin. | 987 // Get a location in the embedder outside of the plugin. |
941 base::ListValue *start, *end; | 988 base::ListValue *start, *end; |
942 scoped_ptr<base::Value> value = | 989 scoped_ptr<base::Value> value = |
943 content::ExecuteScriptAndGetValue(rvh, "dragLocation()"); | 990 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 | 1026 // 2. The guest receives and replies to the message using the event object's |
980 // source object: event.source.postMessage('foobar', '*') | 1027 // source object: event.source.postMessage('foobar', '*') |
981 // 3. The embedder receives the message and uses the event's source | 1028 // 3. The embedder receives the message and uses the event's source |
982 // object to do one final reply: 'stop' | 1029 // object to do one final reply: 'stop' |
983 // 4. The guest receives the final 'stop' message. | 1030 // 4. The guest receives the final 'stop' message. |
984 // 5. The guest acks the 'stop' message with a 'stop_ack' message. | 1031 // 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' | 1032 // 6. The embedder changes its title to 'main guest' when it sees the 'stop_ack' |
986 // message. | 1033 // message. |
987 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, PostMessage) { | 1034 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, PostMessage) { |
988 const char* kTesting = "testing123"; | 1035 const char* kTesting = "testing123"; |
989 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 1036 const char* kEmbedderURL = "/browser_plugin_embedder.html"; |
990 const char* kGuestURL = "files/browser_plugin_post_message_guest.html"; | 1037 const char* kGuestURL = "/browser_plugin_post_message_guest.html"; |
991 StartBrowserPluginTest(kEmbedderURL, kGuestURL, false, std::string()); | 1038 StartBrowserPluginTest(kEmbedderURL, kGuestURL, false, std::string()); |
992 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 1039 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
993 test_embedder()->web_contents()->GetRenderViewHost()); | 1040 test_embedder()->web_contents()->GetRenderViewHost()); |
994 { | 1041 { |
995 const string16 expected_title = ASCIIToUTF16("main guest"); | 1042 const string16 expected_title = ASCIIToUTF16("main guest"); |
996 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | 1043 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
997 expected_title); | 1044 expected_title); |
998 | 1045 |
999 // By the time we get here 'contentWindow' should be ready because the | 1046 // By the time we get here 'contentWindow' should be ready because the |
1000 // guest has completed loading. | 1047 // guest has completed loading. |
1001 ExecuteSyncJSFunction( | 1048 ExecuteSyncJSFunction( |
1002 rvh, base::StringPrintf("PostMessage('%s, false');", kTesting)); | 1049 rvh, base::StringPrintf("PostMessage('%s, false');", kTesting)); |
1003 | 1050 |
1004 // The title will be updated to "main guest" at the last stage of the | 1051 // The title will be updated to "main guest" at the last stage of the |
1005 // process described above. | 1052 // process described above. |
1006 string16 actual_title = title_watcher.WaitAndGetTitle(); | 1053 string16 actual_title = title_watcher.WaitAndGetTitle(); |
1007 EXPECT_EQ(expected_title, actual_title); | 1054 EXPECT_EQ(expected_title, actual_title); |
1008 } | 1055 } |
1009 } | 1056 } |
1010 | 1057 |
1011 // This is the same as BrowserPluginHostTest.PostMessage but also | 1058 // This is the same as BrowserPluginHostTest.PostMessage but also |
1012 // posts a message to an iframe. | 1059 // posts a message to an iframe. |
1013 // TODO(fsamuel): This test should replace the previous test once postMessage | 1060 // TODO(fsamuel): This test should replace the previous test once postMessage |
1014 // iframe targeting is fixed (see http://crbug.com/153701). | 1061 // iframe targeting is fixed (see http://crbug.com/153701). |
1015 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, DISABLED_PostMessageToIFrame) { | 1062 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, DISABLED_PostMessageToIFrame) { |
1016 const char* kTesting = "testing123"; | 1063 const char* kTesting = "testing123"; |
1017 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 1064 const char* kEmbedderURL = "/browser_plugin_embedder.html"; |
1018 const char* kGuestURL = "files/browser_plugin_post_message_guest.html"; | 1065 const char* kGuestURL = "/browser_plugin_post_message_guest.html"; |
1019 StartBrowserPluginTest(kEmbedderURL, kGuestURL, false, std::string()); | 1066 StartBrowserPluginTest(kEmbedderURL, kGuestURL, false, std::string()); |
1020 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 1067 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
1021 test_embedder()->web_contents()->GetRenderViewHost()); | 1068 test_embedder()->web_contents()->GetRenderViewHost()); |
1022 { | 1069 { |
1023 const string16 expected_title = ASCIIToUTF16("main guest"); | 1070 const string16 expected_title = ASCIIToUTF16("main guest"); |
1024 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | 1071 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
1025 expected_title); | 1072 expected_title); |
1026 | 1073 |
1027 ExecuteSyncJSFunction( | 1074 ExecuteSyncJSFunction( |
1028 rvh, base::StringPrintf("PostMessage('%s, false');", kTesting)); | 1075 rvh, base::StringPrintf("PostMessage('%s, false');", kTesting)); |
1029 | 1076 |
1030 // The title will be updated to "main guest" at the last stage of the | 1077 // The title will be updated to "main guest" at the last stage of the |
1031 // process described above. | 1078 // process described above. |
1032 string16 actual_title = title_watcher.WaitAndGetTitle(); | 1079 string16 actual_title = title_watcher.WaitAndGetTitle(); |
1033 EXPECT_EQ(expected_title, actual_title); | 1080 EXPECT_EQ(expected_title, actual_title); |
1034 } | 1081 } |
1035 { | 1082 { |
1036 content::TitleWatcher ready_watcher(test_embedder()->web_contents(), | 1083 content::TitleWatcher ready_watcher(test_embedder()->web_contents(), |
1037 ASCIIToUTF16("ready")); | 1084 ASCIIToUTF16("ready")); |
1038 | 1085 |
1039 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( | 1086 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( |
1040 test_guest()->web_contents()->GetRenderViewHost()); | 1087 test_guest()->web_contents()->GetRenderViewHost()); |
1041 GURL test_url = test_server()->GetURL( | 1088 GURL test_url = embedded_test_server()->GetURL( |
1042 "files/browser_plugin_post_message_guest.html"); | 1089 "/browser_plugin_post_message_guest.html"); |
1043 ExecuteSyncJSFunction( | 1090 ExecuteSyncJSFunction( |
1044 guest_rvh, | 1091 guest_rvh, |
1045 base::StringPrintf( | 1092 base::StringPrintf( |
1046 "CreateChildFrame('%s');", test_url.spec().c_str())); | 1093 "CreateChildFrame('%s');", test_url.spec().c_str())); |
1047 | 1094 |
1048 string16 actual_title = ready_watcher.WaitAndGetTitle(); | 1095 string16 actual_title = ready_watcher.WaitAndGetTitle(); |
1049 EXPECT_EQ(ASCIIToUTF16("ready"), actual_title); | 1096 EXPECT_EQ(ASCIIToUTF16("ready"), actual_title); |
1050 | 1097 |
1051 content::TitleWatcher iframe_watcher(test_embedder()->web_contents(), | 1098 content::TitleWatcher iframe_watcher(test_embedder()->web_contents(), |
1052 ASCIIToUTF16("iframe")); | 1099 ASCIIToUTF16("iframe")); |
1053 ExecuteSyncJSFunction( | 1100 ExecuteSyncJSFunction( |
1054 rvh, base::StringPrintf("PostMessage('%s', true);", kTesting)); | 1101 rvh, base::StringPrintf("PostMessage('%s', true);", kTesting)); |
1055 | 1102 |
1056 // The title will be updated to "iframe" at the last stage of the | 1103 // The title will be updated to "iframe" at the last stage of the |
1057 // process described above. | 1104 // process described above. |
1058 actual_title = iframe_watcher.WaitAndGetTitle(); | 1105 actual_title = iframe_watcher.WaitAndGetTitle(); |
1059 EXPECT_EQ(ASCIIToUTF16("iframe"), actual_title); | 1106 EXPECT_EQ(ASCIIToUTF16("iframe"), actual_title); |
1060 } | 1107 } |
1061 } | 1108 } |
1062 | 1109 |
1063 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadStop) { | 1110 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadStop) { |
1064 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 1111 const char* kEmbedderURL = "/browser_plugin_embedder.html"; |
1065 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, std::string()); | 1112 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, std::string()); |
1066 | 1113 |
1067 const string16 expected_title = ASCIIToUTF16("loadStop"); | 1114 const string16 expected_title = ASCIIToUTF16("loadStop"); |
1068 content::TitleWatcher title_watcher( | 1115 content::TitleWatcher title_watcher( |
1069 test_embedder()->web_contents(), expected_title); | 1116 test_embedder()->web_contents(), expected_title); |
1070 // Renavigate the guest to |kHTMLForGuest|. | 1117 // Renavigate the guest to |kHTMLForGuest|. |
1071 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 1118 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
1072 test_embedder()->web_contents()->GetRenderViewHost()); | 1119 test_embedder()->web_contents()->GetRenderViewHost()); |
1073 ExecuteSyncJSFunction(rvh, | 1120 ExecuteSyncJSFunction(rvh, |
1074 base::StringPrintf("SetSrc('%s');", kHTMLForGuest)); | 1121 base::StringPrintf("SetSrc('%s');", kHTMLForGuest)); |
1075 | 1122 |
1076 string16 actual_title = title_watcher.WaitAndGetTitle(); | 1123 string16 actual_title = title_watcher.WaitAndGetTitle(); |
1077 EXPECT_EQ(expected_title, actual_title); | 1124 EXPECT_EQ(expected_title, actual_title); |
1078 } | 1125 } |
1079 | 1126 |
1080 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadCommit) { | 1127 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadCommit) { |
1081 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 1128 const char* kEmbedderURL = "/browser_plugin_embedder.html"; |
1082 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, std::string()); | 1129 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, std::string()); |
1083 | 1130 |
1084 const string16 expected_title = ASCIIToUTF16( | 1131 const string16 expected_title = ASCIIToUTF16( |
1085 base::StringPrintf("loadCommit:%s", kHTMLForGuest)); | 1132 base::StringPrintf("loadCommit:%s", kHTMLForGuest)); |
1086 content::TitleWatcher title_watcher( | 1133 content::TitleWatcher title_watcher( |
1087 test_embedder()->web_contents(), expected_title); | 1134 test_embedder()->web_contents(), expected_title); |
1088 // Renavigate the guest to |kHTMLForGuest|. | 1135 // Renavigate the guest to |kHTMLForGuest|. |
1089 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 1136 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
1090 test_embedder()->web_contents()->GetRenderViewHost()); | 1137 test_embedder()->web_contents()->GetRenderViewHost()); |
1091 ExecuteSyncJSFunction(rvh, | 1138 ExecuteSyncJSFunction(rvh, |
1092 base::StringPrintf("SetSrc('%s');", kHTMLForGuest)); | 1139 base::StringPrintf("SetSrc('%s');", kHTMLForGuest)); |
1093 | 1140 |
1094 string16 actual_title = title_watcher.WaitAndGetTitle(); | 1141 string16 actual_title = title_watcher.WaitAndGetTitle(); |
1095 EXPECT_EQ(expected_title, actual_title); | 1142 EXPECT_EQ(expected_title, actual_title); |
1096 scoped_ptr<base::Value> is_top_level = | 1143 scoped_ptr<base::Value> is_top_level = |
1097 content::ExecuteScriptAndGetValue(rvh, "commitIsTopLevel"); | 1144 content::ExecuteScriptAndGetValue(rvh, "commitIsTopLevel"); |
1098 bool top_level_bool = false; | 1145 bool top_level_bool = false; |
1099 EXPECT_TRUE(is_top_level->GetAsBoolean(&top_level_bool)); | 1146 EXPECT_TRUE(is_top_level->GetAsBoolean(&top_level_bool)); |
1100 EXPECT_EQ(true, top_level_bool); | 1147 EXPECT_EQ(true, top_level_bool); |
1101 } | 1148 } |
1102 | 1149 |
1103 // This test verifies that if a browser plugin is hidden before navigation, | 1150 // This test verifies that if a browser plugin is hidden before navigation, |
1104 // the guest starts off hidden. | 1151 // the guest starts off hidden. |
1105 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, HiddenBeforeNavigation) { | 1152 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, HiddenBeforeNavigation) { |
1106 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 1153 const char* kEmbedderURL = "/browser_plugin_embedder.html"; |
1107 const std::string embedder_code = | 1154 const std::string embedder_code = |
1108 "document.getElementById('plugin').style.visibility = 'hidden'"; | 1155 "document.getElementById('plugin').style.visibility = 'hidden'"; |
1109 StartBrowserPluginTest( | 1156 StartBrowserPluginTest( |
1110 kEmbedderURL, kHTMLForGuest, true, embedder_code); | 1157 kEmbedderURL, kHTMLForGuest, true, embedder_code); |
1111 EXPECT_FALSE(test_guest()->visible()); | 1158 EXPECT_FALSE(test_guest()->visible()); |
1112 } | 1159 } |
1113 | 1160 |
1114 // This test verifies that if we lose the guest, and get a new one, | 1161 // 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. | 1162 // the new guest will inherit the visibility state of the old guest. |
1116 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, VisibilityPreservation) { | 1163 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, VisibilityPreservation) { |
1117 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 1164 const char* kEmbedderURL = "/browser_plugin_embedder.html"; |
1118 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); | 1165 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); |
1119 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 1166 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
1120 test_embedder()->web_contents()->GetRenderViewHost()); | 1167 test_embedder()->web_contents()->GetRenderViewHost()); |
1121 // Hide the BrowserPlugin. | 1168 // Hide the BrowserPlugin. |
1122 ExecuteSyncJSFunction( | 1169 ExecuteSyncJSFunction( |
1123 rvh, "document.getElementById('plugin').style.visibility = 'hidden';"); | 1170 rvh, "document.getElementById('plugin').style.visibility = 'hidden';"); |
1124 test_guest()->WaitUntilHidden(); | 1171 test_guest()->WaitUntilHidden(); |
1125 // Kill the current guest. | 1172 // Kill the current guest. |
1126 ExecuteSyncJSFunction(rvh, "document.getElementById('plugin').terminate();"); | 1173 ExecuteSyncJSFunction(rvh, "document.getElementById('plugin').terminate();"); |
1127 test_guest()->WaitForExit(); | 1174 test_guest()->WaitForExit(); |
1128 // Get a new guest. | 1175 // Get a new guest. |
1129 ExecuteSyncJSFunction(rvh, "document.getElementById('plugin').reload();"); | 1176 ExecuteSyncJSFunction(rvh, "document.getElementById('plugin').reload();"); |
1130 test_guest()->WaitForLoadStop(); | 1177 test_guest()->WaitForLoadStop(); |
1131 // Verify that the guest is told to hide. | 1178 // Verify that the guest is told to hide. |
1132 test_guest()->WaitUntilHidden(); | 1179 test_guest()->WaitUntilHidden(); |
1133 } | 1180 } |
1134 | 1181 |
1135 // This test verifies that if a browser plugin is focused before navigation then | 1182 // This test verifies that if a browser plugin is focused before navigation then |
1136 // the guest starts off focused. | 1183 // the guest starts off focused. |
1137 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, FocusBeforeNavigation) { | 1184 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, FocusBeforeNavigation) { |
1138 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 1185 const char* kEmbedderURL = "/browser_plugin_embedder.html"; |
1139 const std::string embedder_code = | 1186 const std::string embedder_code = |
1140 "document.getElementById('plugin').focus();"; | 1187 "document.getElementById('plugin').focus();"; |
1141 StartBrowserPluginTest( | 1188 StartBrowserPluginTest( |
1142 kEmbedderURL, kHTMLForGuest, true, embedder_code); | 1189 kEmbedderURL, kHTMLForGuest, true, embedder_code); |
1143 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( | 1190 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( |
1144 test_guest()->web_contents()->GetRenderViewHost()); | 1191 test_guest()->web_contents()->GetRenderViewHost()); |
1145 // Verify that the guest is focused. | 1192 // Verify that the guest is focused. |
1146 scoped_ptr<base::Value> value = | 1193 scoped_ptr<base::Value> value = |
1147 content::ExecuteScriptAndGetValue(guest_rvh, "document.hasFocus()"); | 1194 content::ExecuteScriptAndGetValue(guest_rvh, "document.hasFocus()"); |
1148 bool result = false; | 1195 bool result = false; |
1149 ASSERT_TRUE(value->GetAsBoolean(&result)); | 1196 ASSERT_TRUE(value->GetAsBoolean(&result)); |
1150 EXPECT_TRUE(result); | 1197 EXPECT_TRUE(result); |
1151 } | 1198 } |
1152 | 1199 |
1153 // This test verifies that if we lose the guest, and get a new one, | 1200 // 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. | 1201 // the new guest will inherit the focus state of the old guest. |
1155 // crbug.com/170249 | 1202 // crbug.com/170249 |
1156 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, DISABLED_FocusPreservation) { | 1203 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, DISABLED_FocusPreservation) { |
1157 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 1204 const char* kEmbedderURL = "/browser_plugin_embedder.html"; |
1158 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); | 1205 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); |
1159 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 1206 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
1160 test_embedder()->web_contents()->GetRenderViewHost()); | 1207 test_embedder()->web_contents()->GetRenderViewHost()); |
1161 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( | 1208 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( |
1162 test_guest()->web_contents()->GetRenderViewHost()); | 1209 test_guest()->web_contents()->GetRenderViewHost()); |
1163 { | 1210 { |
1164 // Focus the BrowserPlugin. This will have the effect of also focusing the | 1211 // Focus the BrowserPlugin. This will have the effect of also focusing the |
1165 // current guest. | 1212 // current guest. |
1166 ExecuteSyncJSFunction(rvh, "document.getElementById('plugin').focus();"); | 1213 ExecuteSyncJSFunction(rvh, "document.getElementById('plugin').focus();"); |
1167 // Verify that key presses go to the guest. | 1214 // Verify that key presses go to the guest. |
(...skipping 18 matching lines...) Expand all Loading... |
1186 // Verify that the guest is focused. | 1233 // Verify that the guest is focused. |
1187 scoped_ptr<base::Value> value = | 1234 scoped_ptr<base::Value> value = |
1188 content::ExecuteScriptAndGetValue(guest_rvh, "document.hasFocus()"); | 1235 content::ExecuteScriptAndGetValue(guest_rvh, "document.hasFocus()"); |
1189 bool result = false; | 1236 bool result = false; |
1190 ASSERT_TRUE(value->GetAsBoolean(&result)); | 1237 ASSERT_TRUE(value->GetAsBoolean(&result)); |
1191 EXPECT_TRUE(result); | 1238 EXPECT_TRUE(result); |
1192 } | 1239 } |
1193 } | 1240 } |
1194 | 1241 |
1195 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, FocusTracksEmbedder) { | 1242 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, FocusTracksEmbedder) { |
1196 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 1243 const char* kEmbedderURL = "/browser_plugin_embedder.html"; |
1197 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); | 1244 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); |
1198 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 1245 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
1199 test_embedder()->web_contents()->GetRenderViewHost()); | 1246 test_embedder()->web_contents()->GetRenderViewHost()); |
1200 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( | 1247 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( |
1201 test_guest()->web_contents()->GetRenderViewHost()); | 1248 test_guest()->web_contents()->GetRenderViewHost()); |
1202 { | 1249 { |
1203 // Focus the BrowserPlugin. This will have the effect of also focusing the | 1250 // Focus the BrowserPlugin. This will have the effect of also focusing the |
1204 // current guest. | 1251 // current guest. |
1205 ExecuteSyncJSFunction(rvh, "document.getElementById('plugin').focus();"); | 1252 ExecuteSyncJSFunction(rvh, "document.getElementById('plugin').focus();"); |
1206 // Verify that key presses go to the guest. | 1253 // Verify that key presses go to the guest. |
1207 SimulateSpaceKeyPress(test_embedder()->web_contents()); | 1254 SimulateSpaceKeyPress(test_embedder()->web_contents()); |
1208 test_guest()->WaitForInput(); | 1255 test_guest()->WaitForInput(); |
1209 // Verify that the guest is focused. | 1256 // Verify that the guest is focused. |
1210 scoped_ptr<base::Value> value = | 1257 scoped_ptr<base::Value> value = |
1211 content::ExecuteScriptAndGetValue(guest_rvh, "document.hasFocus()"); | 1258 content::ExecuteScriptAndGetValue(guest_rvh, "document.hasFocus()"); |
1212 bool result = false; | 1259 bool result = false; |
1213 ASSERT_TRUE(value->GetAsBoolean(&result)); | 1260 ASSERT_TRUE(value->GetAsBoolean(&result)); |
1214 EXPECT_TRUE(result); | 1261 EXPECT_TRUE(result); |
1215 } | 1262 } |
1216 // Blur the embedder. | 1263 // Blur the embedder. |
1217 test_embedder()->web_contents()->GetRenderViewHost()->Blur(); | 1264 test_embedder()->web_contents()->GetRenderViewHost()->Blur(); |
1218 test_guest()->WaitForBlur(); | 1265 test_guest()->WaitForBlur(); |
1219 } | 1266 } |
1220 | 1267 |
1221 // This test verifies that if a browser plugin is in autosize mode before | 1268 // This test verifies that if a browser plugin is in autosize mode before |
1222 // navigation then the guest starts auto-sized. | 1269 // navigation then the guest starts auto-sized. |
1223 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, AutoSizeBeforeNavigation) { | 1270 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, AutoSizeBeforeNavigation) { |
1224 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 1271 const char* kEmbedderURL = "/browser_plugin_embedder.html"; |
1225 const std::string embedder_code = | 1272 const std::string embedder_code = |
1226 "document.getElementById('plugin').minwidth = 300;" | 1273 "document.getElementById('plugin').minwidth = 300;" |
1227 "document.getElementById('plugin').minheight = 200;" | 1274 "document.getElementById('plugin').minheight = 200;" |
1228 "document.getElementById('plugin').maxwidth = 600;" | 1275 "document.getElementById('plugin').maxwidth = 600;" |
1229 "document.getElementById('plugin').maxheight = 400;" | 1276 "document.getElementById('plugin').maxheight = 400;" |
1230 "document.getElementById('plugin').autosize = true;"; | 1277 "document.getElementById('plugin').autosize = true;"; |
1231 StartBrowserPluginTest( | 1278 StartBrowserPluginTest( |
1232 kEmbedderURL, kHTMLForGuestWithSize, true, embedder_code); | 1279 kEmbedderURL, kHTMLForGuestWithSize, true, embedder_code); |
1233 // Verify that the guest has been auto-sized. | 1280 // Verify that the guest has been auto-sized. |
1234 test_guest()->WaitForViewSize(gfx::Size(300, 400)); | 1281 test_guest()->WaitForViewSize(gfx::Size(300, 400)); |
1235 } | 1282 } |
1236 | 1283 |
1237 // This test verifies that enabling autosize resizes the guest and triggers | 1284 // This test verifies that enabling autosize resizes the guest and triggers |
1238 // a 'sizechanged' event. | 1285 // a 'sizechanged' event. |
1239 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, AutoSizeAfterNavigation) { | 1286 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, AutoSizeAfterNavigation) { |
1240 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 1287 const char* kEmbedderURL = "/browser_plugin_embedder.html"; |
1241 StartBrowserPluginTest( | 1288 StartBrowserPluginTest( |
1242 kEmbedderURL, kHTMLForGuestWithSize, true, std::string()); | 1289 kEmbedderURL, kHTMLForGuestWithSize, true, std::string()); |
1243 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 1290 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
1244 test_embedder()->web_contents()->GetRenderViewHost()); | 1291 test_embedder()->web_contents()->GetRenderViewHost()); |
1245 | 1292 |
1246 { | 1293 { |
1247 const string16 expected_title = ASCIIToUTF16("AutoSize(300, 400)"); | 1294 const string16 expected_title = ASCIIToUTF16("AutoSize(300, 400)"); |
1248 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | 1295 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
1249 expected_title); | 1296 expected_title); |
1250 ExecuteSyncJSFunction( | 1297 ExecuteSyncJSFunction( |
(...skipping 19 matching lines...) Expand all Loading... |
1270 { | 1317 { |
1271 // Turn off autoSize and verify that the guest resizes to fit the container. | 1318 // Turn off autoSize and verify that the guest resizes to fit the container. |
1272 ExecuteSyncJSFunction( | 1319 ExecuteSyncJSFunction( |
1273 rvh, "document.getElementById('plugin').autosize = null;"); | 1320 rvh, "document.getElementById('plugin').autosize = null;"); |
1274 test_guest()->WaitForViewSize(gfx::Size(640, 480)); | 1321 test_guest()->WaitForViewSize(gfx::Size(640, 480)); |
1275 } | 1322 } |
1276 } | 1323 } |
1277 | 1324 |
1278 // Test for regression http://crbug.com/162961. | 1325 // Test for regression http://crbug.com/162961. |
1279 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, GetRenderViewHostAtPositionTest) { | 1326 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, GetRenderViewHostAtPositionTest) { |
1280 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; | 1327 const char kEmbedderURL[] = "/browser_plugin_embedder.html"; |
1281 const std::string embedder_code = | 1328 const std::string embedder_code = |
1282 base::StringPrintf("SetSize(%d, %d);", 100, 100); | 1329 base::StringPrintf("SetSize(%d, %d);", 100, 100); |
1283 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuestWithSize, true, | 1330 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuestWithSize, true, |
1284 embedder_code); | 1331 embedder_code); |
1285 // Check for render view host at position (150, 150) that is outside the | 1332 // 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 | 1333 // bounds of our guest, so this would respond with the render view host of the |
1287 // embedder. | 1334 // embedder. |
1288 test_embedder()->WaitForRenderViewHostAtPosition(150, 150); | 1335 test_embedder()->WaitForRenderViewHostAtPosition(150, 150); |
1289 ASSERT_EQ(test_embedder()->web_contents()->GetRenderViewHost(), | 1336 ASSERT_EQ(test_embedder()->web_contents()->GetRenderViewHost(), |
1290 test_embedder()->last_rvh_at_position_response()); | 1337 test_embedder()->last_rvh_at_position_response()); |
1291 } | 1338 } |
1292 | 1339 |
1293 // Flaky on Win Aura Tests (1) bot. See http://crbug.com/233087. | 1340 // Flaky on Win Aura Tests (1) bot. See http://crbug.com/233087. |
1294 #if defined(OS_WIN) && defined(USE_AURA) | 1341 #if defined(OS_WIN) && defined(USE_AURA) |
1295 #define MAYBE_ChangeWindowName DISABLED_ChangeWindowName | 1342 #define MAYBE_ChangeWindowName DISABLED_ChangeWindowName |
1296 #else | 1343 #else |
1297 #define MAYBE_ChangeWindowName ChangeWindowName | 1344 #define MAYBE_ChangeWindowName ChangeWindowName |
1298 #endif | 1345 #endif |
1299 | 1346 |
1300 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, MAYBE_ChangeWindowName) { | 1347 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, MAYBE_ChangeWindowName) { |
1301 const char kEmbedderURL[] = "files/browser_plugin_naming_embedder.html"; | 1348 const char kEmbedderURL[] = "/browser_plugin_naming_embedder.html"; |
1302 const char* kGuestURL = "files/browser_plugin_naming_guest.html"; | 1349 const char* kGuestURL = "/browser_plugin_naming_guest.html"; |
1303 StartBrowserPluginTest(kEmbedderURL, kGuestURL, false, std::string()); | 1350 StartBrowserPluginTest(kEmbedderURL, kGuestURL, false, std::string()); |
1304 | 1351 |
1305 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 1352 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
1306 test_embedder()->web_contents()->GetRenderViewHost()); | 1353 test_embedder()->web_contents()->GetRenderViewHost()); |
1307 // Verify that the plugin's name is properly initialized. | 1354 // Verify that the plugin's name is properly initialized. |
1308 { | 1355 { |
1309 scoped_ptr<base::Value> value = content::ExecuteScriptAndGetValue( | 1356 scoped_ptr<base::Value> value = content::ExecuteScriptAndGetValue( |
1310 rvh, "document.getElementById('plugin').name"); | 1357 rvh, "document.getElementById('plugin').name"); |
1311 std::string result; | 1358 std::string result; |
1312 EXPECT_TRUE(value->GetAsString(&result)); | 1359 EXPECT_TRUE(value->GetAsString(&result)); |
(...skipping 25 matching lines...) Expand all Loading... |
1338 "document.getElementById('plugin').name = 'foobar';"); | 1385 "document.getElementById('plugin').name = 'foobar';"); |
1339 string16 actual_title = title_watcher.WaitAndGetTitle(); | 1386 string16 actual_title = title_watcher.WaitAndGetTitle(); |
1340 EXPECT_EQ(expected_title, actual_title); | 1387 EXPECT_EQ(expected_title, actual_title); |
1341 | 1388 |
1342 } | 1389 } |
1343 } | 1390 } |
1344 | 1391 |
1345 // This test verifies that all autosize attributes can be removed | 1392 // This test verifies that all autosize attributes can be removed |
1346 // without crashing the plugin, or throwing errors. | 1393 // without crashing the plugin, or throwing errors. |
1347 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, RemoveAutosizeAttributes) { | 1394 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, RemoveAutosizeAttributes) { |
1348 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 1395 const char* kEmbedderURL = "/browser_plugin_embedder.html"; |
1349 const std::string embedder_code = | 1396 const std::string embedder_code = |
1350 "document.getElementById('plugin').minwidth = 300;" | 1397 "document.getElementById('plugin').minwidth = 300;" |
1351 "document.getElementById('plugin').minheight = 200;" | 1398 "document.getElementById('plugin').minheight = 200;" |
1352 "document.getElementById('plugin').maxwidth = 600;" | 1399 "document.getElementById('plugin').maxwidth = 600;" |
1353 "document.getElementById('plugin').maxheight = 400;" | 1400 "document.getElementById('plugin').maxheight = 400;" |
1354 "document.getElementById('plugin').name = 'name';" | 1401 "document.getElementById('plugin').name = 'name';" |
1355 "document.getElementById('plugin').src = 'foo';" | 1402 "document.getElementById('plugin').src = 'foo';" |
1356 "document.getElementById('plugin').autosize = '';"; | 1403 "document.getElementById('plugin').autosize = '';"; |
1357 StartBrowserPluginTest( | 1404 StartBrowserPluginTest( |
1358 kEmbedderURL, kHTMLForGuestWithSize, true, embedder_code); | 1405 kEmbedderURL, kHTMLForGuestWithSize, true, embedder_code); |
1359 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 1406 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
1360 test_embedder()->web_contents()->GetRenderViewHost()); | 1407 test_embedder()->web_contents()->GetRenderViewHost()); |
1361 RemoveAttributes(rvh, "maxheight, maxwidth, minheight, minwidth, autosize"); | 1408 RemoveAttributes(rvh, "maxheight, maxwidth, minheight, minwidth, autosize"); |
1362 | 1409 |
1363 // Verify that the guest resizes to fit the container (and hasn't crashed). | 1410 // Verify that the guest resizes to fit the container (and hasn't crashed). |
1364 test_guest()->WaitForViewSize(gfx::Size(640, 480)); | 1411 test_guest()->WaitForViewSize(gfx::Size(640, 480)); |
1365 EXPECT_TRUE(IsAttributeNull(rvh, "maxheight")); | 1412 EXPECT_TRUE(IsAttributeNull(rvh, "maxheight")); |
1366 EXPECT_TRUE(IsAttributeNull(rvh, "maxwidth")); | 1413 EXPECT_TRUE(IsAttributeNull(rvh, "maxwidth")); |
1367 EXPECT_TRUE(IsAttributeNull(rvh, "minheight")); | 1414 EXPECT_TRUE(IsAttributeNull(rvh, "minheight")); |
1368 EXPECT_TRUE(IsAttributeNull(rvh, "minwidth")); | 1415 EXPECT_TRUE(IsAttributeNull(rvh, "minwidth")); |
1369 EXPECT_TRUE(IsAttributeNull(rvh, "autosize")); | 1416 EXPECT_TRUE(IsAttributeNull(rvh, "autosize")); |
1370 } | 1417 } |
1371 | 1418 |
1372 // This test verifies that autosize works when some of the parameters are unset. | 1419 // This test verifies that autosize works when some of the parameters are unset. |
1373 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, PartialAutosizeAttributes) { | 1420 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, PartialAutosizeAttributes) { |
1374 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 1421 const char* kEmbedderURL = "/browser_plugin_embedder.html"; |
1375 const std::string embedder_code = | 1422 const std::string embedder_code = |
1376 "document.getElementById('plugin').minwidth = 300;" | 1423 "document.getElementById('plugin').minwidth = 300;" |
1377 "document.getElementById('plugin').minheight = 200;" | 1424 "document.getElementById('plugin').minheight = 200;" |
1378 "document.getElementById('plugin').maxwidth = 700;" | 1425 "document.getElementById('plugin').maxwidth = 700;" |
1379 "document.getElementById('plugin').maxheight = 600;" | 1426 "document.getElementById('plugin').maxheight = 600;" |
1380 "document.getElementById('plugin').autosize = '';"; | 1427 "document.getElementById('plugin').autosize = '';"; |
1381 StartBrowserPluginTest( | 1428 StartBrowserPluginTest( |
1382 kEmbedderURL, kHTMLForGuestWithSize, true, embedder_code); | 1429 kEmbedderURL, kHTMLForGuestWithSize, true, embedder_code); |
1383 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 1430 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
1384 test_embedder()->web_contents()->GetRenderViewHost()); | 1431 test_embedder()->web_contents()->GetRenderViewHost()); |
(...skipping 24 matching lines...) Expand all Loading... |
1409 const string16 expected_title = ASCIIToUTF16("AutoSize(640, 480)"); | 1456 const string16 expected_title = ASCIIToUTF16("AutoSize(640, 480)"); |
1410 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | 1457 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
1411 expected_title); | 1458 expected_title); |
1412 RemoveAttributes(rvh, "maxwidth"); | 1459 RemoveAttributes(rvh, "maxwidth"); |
1413 string16 actual_title = title_watcher.WaitAndGetTitle(); | 1460 string16 actual_title = title_watcher.WaitAndGetTitle(); |
1414 EXPECT_EQ(expected_title, actual_title); | 1461 EXPECT_EQ(expected_title, actual_title); |
1415 } | 1462 } |
1416 } | 1463 } |
1417 | 1464 |
1418 } // namespace content | 1465 } // namespace content |
OLD | NEW |