| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/command_line.h" | |
| 6 #include "base/memory/singleton.h" | 5 #include "base/memory/singleton.h" |
| 7 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
| 8 #include "base/strings/string_split.h" | 7 #include "base/strings/string_split.h" |
| 9 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
| 12 #include "content/browser/browser_plugin/browser_plugin_embedder.h" | 11 #include "content/browser/browser_plugin/browser_plugin_embedder.h" |
| 13 #include "content/browser/browser_plugin/browser_plugin_guest.h" | 12 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
| 14 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" | 13 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" |
| 15 #include "content/browser/browser_plugin/test_browser_plugin_guest.h" | 14 #include "content/browser/browser_plugin/test_browser_plugin_guest.h" |
| 16 #include "content/browser/browser_plugin/test_browser_plugin_guest_delegate.h" | 15 #include "content/browser/browser_plugin/test_browser_plugin_guest_delegate.h" |
| 17 #include "content/browser/browser_plugin/test_guest_manager.h" | 16 #include "content/browser/browser_plugin/test_guest_manager.h" |
| 18 #include "content/browser/child_process_security_policy_impl.h" | 17 #include "content/browser/child_process_security_policy_impl.h" |
| 19 #include "content/browser/frame_host/render_frame_host_impl.h" | |
| 20 #include "content/browser/frame_host/render_widget_host_view_guest.h" | |
| 21 #include "content/browser/renderer_host/render_view_host_impl.h" | 18 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 22 #include "content/browser/web_contents/web_contents_impl.h" | 19 #include "content/browser/web_contents/web_contents_impl.h" |
| 23 #include "content/common/browser_plugin/browser_plugin_messages.h" | 20 #include "content/common/browser_plugin/browser_plugin_messages.h" |
| 24 #include "content/common/view_messages.h" | 21 #include "content/common/view_messages.h" |
| 25 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
| 26 #include "content/public/browser/notification_types.h" | 23 #include "content/public/browser/notification_types.h" |
| 27 #include "content/public/browser/render_frame_host.h" | 24 #include "content/public/browser/render_frame_host.h" |
| 28 #include "content/public/browser/render_widget_host_view.h" | 25 #include "content/public/browser/render_widget_host_view.h" |
| 29 #include "content/public/browser/web_contents_observer.h" | 26 #include "content/public/browser/web_contents_observer.h" |
| 30 #include "content/public/common/content_switches.h" | |
| 31 #include "content/public/common/drop_data.h" | 27 #include "content/public/common/drop_data.h" |
| 32 #include "content/public/common/url_constants.h" | 28 #include "content/public/common/url_constants.h" |
| 33 #include "content/public/test/browser_test_utils.h" | 29 #include "content/public/test/browser_test_utils.h" |
| 34 #include "content/public/test/content_browser_test.h" | 30 #include "content/public/test/content_browser_test.h" |
| 35 #include "content/public/test/content_browser_test_utils.h" | 31 #include "content/public/test/content_browser_test_utils.h" |
| 36 #include "content/public/test/test_utils.h" | 32 #include "content/public/test/test_utils.h" |
| 37 #include "content/shell/browser/shell.h" | 33 #include "content/shell/browser/shell.h" |
| 38 #include "content/shell/browser/shell_browser_context.h" | 34 #include "content/shell/browser/shell_browser_context.h" |
| 39 #include "net/base/net_util.h" | 35 #include "net/base/net_util.h" |
| 40 #include "net/test/embedded_test_server/embedded_test_server.h" | 36 #include "net/test/embedded_test_server/embedded_test_server.h" |
| (...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 | 623 |
| 628 // Attempt a navigation to chrome-guest://abc123, which is a valid URL. But it | 624 // Attempt a navigation to chrome-guest://abc123, which is a valid URL. But it |
| 629 // should be blocked because the scheme isn't web-safe or a pseudo-scheme. | 625 // should be blocked because the scheme isn't web-safe or a pseudo-scheme. |
| 630 ExecuteSyncJSFunction( | 626 ExecuteSyncJSFunction( |
| 631 test_embedder()->web_contents()->GetMainFrame(), | 627 test_embedder()->web_contents()->GetMainFrame(), |
| 632 base::StringPrintf("SetSrc('%s://abc123');", kGuestScheme)); | 628 base::StringPrintf("SetSrc('%s://abc123');", kGuestScheme)); |
| 633 EXPECT_TRUE(delegate->load_aborted()); | 629 EXPECT_TRUE(delegate->load_aborted()); |
| 634 EXPECT_TRUE(delegate->load_aborted_url().is_valid()); | 630 EXPECT_TRUE(delegate->load_aborted_url().is_valid()); |
| 635 } | 631 } |
| 636 | 632 |
| 637 // Tests involving the threaded compositor. | |
| 638 class BrowserPluginThreadedCompositorTest : public BrowserPluginHostTest { | |
| 639 public: | |
| 640 BrowserPluginThreadedCompositorTest() {} | |
| 641 virtual ~BrowserPluginThreadedCompositorTest() {} | |
| 642 | |
| 643 protected: | |
| 644 virtual void SetUpCommandLine(CommandLine* cmd) OVERRIDE { | |
| 645 BrowserPluginHostTest::SetUpCommandLine(cmd); | |
| 646 cmd->AppendSwitch(switches::kEnableThreadedCompositing); | |
| 647 } | |
| 648 }; | |
| 649 | |
| 650 class BrowserPluginThreadedCompositorPixelTest | |
| 651 : public BrowserPluginThreadedCompositorTest { | |
| 652 protected: | |
| 653 virtual void SetUp() OVERRIDE { | |
| 654 EnablePixelOutput(); | |
| 655 BrowserPluginThreadedCompositorTest::SetUp(); | |
| 656 } | |
| 657 }; | |
| 658 | |
| 659 static void CompareSkBitmaps(const SkBitmap& expected_bitmap, | |
| 660 const SkBitmap& bitmap) { | |
| 661 EXPECT_EQ(expected_bitmap.width(), bitmap.width()); | |
| 662 if (expected_bitmap.width() != bitmap.width()) | |
| 663 return; | |
| 664 EXPECT_EQ(expected_bitmap.height(), bitmap.height()); | |
| 665 if (expected_bitmap.height() != bitmap.height()) | |
| 666 return; | |
| 667 EXPECT_EQ(expected_bitmap.config(), bitmap.config()); | |
| 668 if (expected_bitmap.config() != bitmap.config()) | |
| 669 return; | |
| 670 | |
| 671 SkAutoLockPixels expected_bitmap_lock(expected_bitmap); | |
| 672 SkAutoLockPixels bitmap_lock(bitmap); | |
| 673 int fails = 0; | |
| 674 const int kAllowableError = 2; | |
| 675 for (int i = 0; i < bitmap.width() && fails < 10; ++i) { | |
| 676 for (int j = 0; j < bitmap.height() && fails < 10; ++j) { | |
| 677 SkColor expected_color = expected_bitmap.getColor(i, j); | |
| 678 SkColor color = bitmap.getColor(i, j); | |
| 679 int expected_alpha = SkColorGetA(expected_color); | |
| 680 int alpha = SkColorGetA(color); | |
| 681 int expected_red = SkColorGetR(expected_color); | |
| 682 int red = SkColorGetR(color); | |
| 683 int expected_green = SkColorGetG(expected_color); | |
| 684 int green = SkColorGetG(color); | |
| 685 int expected_blue = SkColorGetB(expected_color); | |
| 686 int blue = SkColorGetB(color); | |
| 687 EXPECT_NEAR(expected_alpha, alpha, kAllowableError) | |
| 688 << "expected_color: " << std::hex << expected_color | |
| 689 << " color: " << color | |
| 690 << " Failed at " << std::dec << i << ", " << j | |
| 691 << " Failure " << ++fails; | |
| 692 EXPECT_NEAR(expected_red, red, kAllowableError) | |
| 693 << "expected_color: " << std::hex << expected_color | |
| 694 << " color: " << color | |
| 695 << " Failed at " << std::dec << i << ", " << j | |
| 696 << " Failure " << ++fails; | |
| 697 EXPECT_NEAR(expected_green, green, kAllowableError) | |
| 698 << "expected_color: " << std::hex << expected_color | |
| 699 << " color: " << color | |
| 700 << " Failed at " << std::dec << i << ", " << j | |
| 701 << " Failure " << ++fails; | |
| 702 EXPECT_NEAR(expected_blue, blue, kAllowableError) | |
| 703 << "expected_color: " << std::hex << expected_color | |
| 704 << " color: " << color | |
| 705 << " Failed at " << std::dec << i << ", " << j | |
| 706 << " Failure " << ++fails; | |
| 707 } | |
| 708 } | |
| 709 EXPECT_LT(fails, 10); | |
| 710 } | |
| 711 | |
| 712 static void CompareSkBitmapAndRun(const base::Closure& callback, | |
| 713 const SkBitmap& expected_bitmap, | |
| 714 bool *result, | |
| 715 bool succeed, | |
| 716 const SkBitmap& bitmap) { | |
| 717 *result = succeed; | |
| 718 if (succeed) | |
| 719 CompareSkBitmaps(expected_bitmap, bitmap); | |
| 720 callback.Run(); | |
| 721 } | |
| 722 | |
| 723 // Mac: http://crbug.com/171744 | |
| 724 // Aura/Ubercomp: http://crbug.com//327035 | |
| 725 #if defined(OS_MACOSX) || defined(USE_AURA) | |
| 726 #define MAYBE_GetBackingStore DISABLED_GetBackingStore | |
| 727 #else | |
| 728 #define MAYBE_GetBackingStore GetBackingStore | |
| 729 #endif | |
| 730 IN_PROC_BROWSER_TEST_F(BrowserPluginThreadedCompositorPixelTest, | |
| 731 MAYBE_GetBackingStore) { | |
| 732 const char kEmbedderURL[] = "/browser_plugin_embedder.html"; | |
| 733 const char kHTMLForGuest[] = | |
| 734 "data:text/html,<html><style>body { background-color: red; }</style>" | |
| 735 "<body></body></html>"; | |
| 736 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, | |
| 737 std::string("SetSize(50, 60);")); | |
| 738 | |
| 739 WebContentsImpl* guest_contents = test_guest()->web_contents(); | |
| 740 RenderWidgetHostImpl* guest_widget_host = | |
| 741 RenderWidgetHostImpl::From(guest_contents->GetRenderViewHost()); | |
| 742 | |
| 743 SkBitmap expected_bitmap; | |
| 744 expected_bitmap.setConfig(SkBitmap::kARGB_8888_Config, 50, 60); | |
| 745 expected_bitmap.allocPixels(); | |
| 746 expected_bitmap.eraseARGB(255, 255, 0, 0); // #f00 | |
| 747 bool result = false; | |
| 748 while (!result) { | |
| 749 base::RunLoop loop; | |
| 750 guest_widget_host->CopyFromBackingStore( | |
| 751 gfx::Rect(), | |
| 752 guest_widget_host->GetView()->GetViewBounds().size(), | |
| 753 base::Bind(&CompareSkBitmapAndRun, | |
| 754 loop.QuitClosure(), | |
| 755 expected_bitmap, | |
| 756 &result), | |
| 757 SkBitmap::kARGB_8888_Config); | |
| 758 loop.Run(); | |
| 759 } | |
| 760 } | |
| 761 | |
| 762 // This test exercises the following scenario: | 633 // This test exercises the following scenario: |
| 763 // 1. An <input> in guest has focus. | 634 // 1. An <input> in guest has focus. |
| 764 // 2. User takes focus to embedder by clicking e.g. an <input> in embedder. | 635 // 2. User takes focus to embedder by clicking e.g. an <input> in embedder. |
| 765 // 3. User brings back the focus directly to the <input> in #1. | 636 // 3. User brings back the focus directly to the <input> in #1. |
| 766 // | 637 // |
| 767 // Now we need to make sure TextInputTypeChange fires properly for the guest's | 638 // Now we need to make sure TextInputTypeChange fires properly for the guest's |
| 768 // view (RenderWidgetHostViewGuest) upon step #3. This test ensures that, | 639 // view (RenderWidgetHostViewGuest) upon step #3. This test ensures that, |
| 769 // otherwise IME doesn't work after step #3. | 640 // otherwise IME doesn't work after step #3. |
| 770 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, FocusRestored) { | 641 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, FocusRestored) { |
| 771 const char kEmbedderURL[] = "/browser_plugin_embedder.html"; | 642 const char kEmbedderURL[] = "/browser_plugin_embedder.html"; |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 912 scoped_ptr<base::Value> value = | 783 scoped_ptr<base::Value> value = |
| 913 content::ExecuteScriptAndGetValue( | 784 content::ExecuteScriptAndGetValue( |
| 914 guest_rfh, "document.getElementById('input1').value"); | 785 guest_rfh, "document.getElementById('input1').value"); |
| 915 std::string actual_value; | 786 std::string actual_value; |
| 916 ASSERT_TRUE(value->GetAsString(&actual_value)); | 787 ASSERT_TRUE(value->GetAsString(&actual_value)); |
| 917 EXPECT_EQ(base::UTF16ToUTF8(expected_value), actual_value); | 788 EXPECT_EQ(base::UTF16ToUTF8(expected_value), actual_value); |
| 918 } | 789 } |
| 919 } | 790 } |
| 920 | 791 |
| 921 } // namespace content | 792 } // namespace content |
| OLD | NEW |