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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" | 6 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
7 #include "chrome/browser/extensions/browser_action_test_util.h" | 7 #include "chrome/browser/extensions/browser_action_test_util.h" |
8 #include "chrome/browser/extensions/extension_action.h" | 8 #include "chrome/browser/extensions/extension_action.h" |
9 #include "chrome/browser/extensions/extension_action_icon_factory.h" | 9 #include "chrome/browser/extensions/extension_action_icon_factory.h" |
10 #include "chrome/browser/extensions/extension_action_manager.h" | 10 #include "chrome/browser/extensions/extension_action_manager.h" |
11 #include "chrome/browser/extensions/extension_apitest.h" | 11 #include "chrome/browser/extensions/extension_apitest.h" |
12 #include "chrome/browser/extensions/extension_tab_util.h" | 12 #include "chrome/browser/extensions/extension_tab_util.h" |
13 #include "chrome/browser/extensions/extension_util.h" | 13 #include "chrome/browser/extensions/extension_util.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/browser/ui/browser_commands.h" | 16 #include "chrome/browser/ui/browser_commands.h" |
17 #include "chrome/browser/ui/browser_window.h" | 17 #include "chrome/browser/ui/browser_window.h" |
18 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
19 #include "chrome/common/url_constants.h" | 19 #include "chrome/common/url_constants.h" |
20 #include "chrome/test/base/ui_test_utils.h" | 20 #include "chrome/test/base/ui_test_utils.h" |
21 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
| 22 #include "content/public/browser/render_frame_host.h" |
22 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
23 #include "content/public/test/browser_test_utils.h" | 24 #include "content/public/test/browser_test_utils.h" |
24 #include "extensions/browser/extension_registry.h" | 25 #include "extensions/browser/extension_registry.h" |
25 #include "extensions/browser/extension_system.h" | 26 #include "extensions/browser/extension_system.h" |
26 #include "extensions/browser/notification_types.h" | 27 #include "extensions/browser/notification_types.h" |
27 #include "extensions/browser/process_manager.h" | 28 #include "extensions/browser/process_manager.h" |
28 #include "extensions/browser/test_extension_registry_observer.h" | 29 #include "extensions/browser/test_extension_registry_observer.h" |
29 #include "extensions/common/feature_switch.h" | 30 #include "extensions/common/feature_switch.h" |
30 #include "extensions/test/result_catcher.h" | 31 #include "extensions/test/result_catcher.h" |
31 #include "grit/theme_resources.h" | 32 #include "grit/theme_resources.h" |
| 33 #include "net/dns/mock_host_resolver.h" |
32 #include "net/test/embedded_test_server/embedded_test_server.h" | 34 #include "net/test/embedded_test_server/embedded_test_server.h" |
33 #include "ui/base/resource/resource_bundle.h" | 35 #include "ui/base/resource/resource_bundle.h" |
34 #include "ui/gfx/geometry/rect.h" | 36 #include "ui/gfx/geometry/rect.h" |
35 #include "ui/gfx/geometry/size.h" | 37 #include "ui/gfx/geometry/size.h" |
36 #include "ui/gfx/image/canvas_image_source.h" | 38 #include "ui/gfx/image/canvas_image_source.h" |
37 #include "ui/gfx/image/image_skia.h" | 39 #include "ui/gfx/image/image_skia.h" |
38 #include "ui/gfx/image/image_skia_operations.h" | 40 #include "ui/gfx/image/image_skia_operations.h" |
39 #include "ui/gfx/skia_util.h" | 41 #include "ui/gfx/skia_util.h" |
40 | 42 |
41 using content::WebContents; | 43 using content::WebContents; |
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 | 679 |
678 // Verify that the browser action turned the background color red. | 680 // Verify that the browser action turned the background color red. |
679 const std::string script = | 681 const std::string script = |
680 "window.domAutomationController.send(document.body.style." | 682 "window.domAutomationController.send(document.body.style." |
681 "backgroundColor);"; | 683 "backgroundColor);"; |
682 std::string result; | 684 std::string result; |
683 EXPECT_TRUE(content::ExecuteScriptAndExtractString(tab, script, &result)); | 685 EXPECT_TRUE(content::ExecuteScriptAndExtractString(tab, script, &result)); |
684 EXPECT_EQ(result, "red"); | 686 EXPECT_EQ(result, "red"); |
685 } | 687 } |
686 | 688 |
| 689 // Test that a browser action popup with a web iframe works correctly. This |
| 690 // primarily targets --isolate-extensions and --site-per-process modes, where |
| 691 // the iframe runs in a separate process. See https://crbug.com/546267. |
| 692 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BrowserActionPopupWithIframe) { |
| 693 host_resolver()->AddRule("*", "127.0.0.1"); |
| 694 ASSERT_TRUE(embedded_test_server()->Start()); |
| 695 |
| 696 ASSERT_TRUE(LoadExtension( |
| 697 test_data_dir_.AppendASCII("browser_action/popup_with_iframe"))); |
| 698 BrowserActionTestUtil* actions_bar = GetBrowserActionsBar(); |
| 699 const Extension* extension = GetSingleLoadedExtension(); |
| 700 ASSERT_TRUE(extension) << message_; |
| 701 |
| 702 // Simulate a click on the browser action to open the popup. |
| 703 ASSERT_TRUE(OpenPopup(0)); |
| 704 |
| 705 // Find the RenderFrameHost associated with the iframe in the popup. |
| 706 content::RenderFrameHost* frame_host = nullptr; |
| 707 extensions::ProcessManager* manager = |
| 708 extensions::ProcessManager::Get(browser()->profile()); |
| 709 std::set<content::RenderFrameHost*> frame_hosts = |
| 710 manager->GetRenderFrameHostsForExtension(extension->id()); |
| 711 for (auto host : frame_hosts) { |
| 712 if (host->GetFrameName() == "child_frame") { |
| 713 frame_host = host; |
| 714 break; |
| 715 } |
| 716 } |
| 717 |
| 718 ASSERT_TRUE(frame_host); |
| 719 EXPECT_EQ(extension->GetResourceURL("frame.html"), |
| 720 frame_host->GetLastCommittedURL()); |
| 721 EXPECT_TRUE(frame_host->GetParent()); |
| 722 |
| 723 // Navigate the popup's iframe to a (cross-site) web page, and wait for that |
| 724 // page to send a message, which will ensure that the page has loaded. |
| 725 GURL foo_url(embedded_test_server()->GetURL("foo.com", "/popup_iframe.html")); |
| 726 std::string script = "location.href = '" + foo_url.spec() + "'"; |
| 727 std::string result; |
| 728 EXPECT_TRUE( |
| 729 content::ExecuteScriptAndExtractString(frame_host, script, &result)); |
| 730 EXPECT_EQ("DONE", result); |
| 731 |
| 732 EXPECT_TRUE(actions_bar->HidePopup()); |
| 733 } |
| 734 |
687 } // namespace | 735 } // namespace |
688 } // namespace extensions | 736 } // namespace extensions |
OLD | NEW |