OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "extensions/browser/process_manager.h" | 5 #include "extensions/browser/process_manager.h" |
6 | 6 |
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_browsertest.h" | 8 #include "chrome/browser/extensions/extension_browsertest.h" |
9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
| 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
10 #include "chrome/test/base/in_process_browser_test.h" | 11 #include "chrome/test/base/in_process_browser_test.h" |
| 12 #include "chrome/test/base/ui_test_utils.h" |
11 #include "content/public/browser/notification_service.h" | 13 #include "content/public/browser/notification_service.h" |
| 14 #include "content/public/browser/web_contents.h" |
12 #include "content/public/test/test_utils.h" | 15 #include "content/public/test/test_utils.h" |
13 #include "extensions/browser/extension_system.h" | 16 #include "extensions/browser/extension_system.h" |
| 17 #include "net/dns/mock_host_resolver.h" |
| 18 #include "net/test/embedded_test_server/embedded_test_server.h" |
14 | 19 |
15 namespace extensions { | 20 namespace extensions { |
16 | 21 |
17 // Exists as a browser test because ExtensionHosts are hard to create without | 22 // Exists as a browser test because ExtensionHosts are hard to create without |
18 // a real browser. | 23 // a real browser. |
19 typedef ExtensionBrowserTest ProcessManagerBrowserTest; | 24 typedef ExtensionBrowserTest ProcessManagerBrowserTest; |
20 | 25 |
21 // Test that basic extension loading creates the appropriate ExtensionHosts | 26 // Test that basic extension loading creates the appropriate ExtensionHosts |
22 // and background pages. | 27 // and background pages. |
23 IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest, | 28 IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest, |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 // We now have a view, but still no background hosts. | 100 // We now have a view, but still no background hosts. |
96 EXPECT_EQ(0u, pm->background_hosts().size()); | 101 EXPECT_EQ(0u, pm->background_hosts().size()); |
97 EXPECT_EQ(1u, pm->GetAllViews().size()); | 102 EXPECT_EQ(1u, pm->GetAllViews().size()); |
98 EXPECT_FALSE(pm->GetBackgroundHostForExtension(popup->id())); | 103 EXPECT_FALSE(pm->GetBackgroundHostForExtension(popup->id())); |
99 EXPECT_EQ(1u, pm->GetRenderViewHostsForExtension(popup->id()).size()); | 104 EXPECT_EQ(1u, pm->GetRenderViewHostsForExtension(popup->id()).size()); |
100 EXPECT_TRUE(pm->GetSiteInstanceForURL(popup->url())); | 105 EXPECT_TRUE(pm->GetSiteInstanceForURL(popup->url())); |
101 EXPECT_FALSE(pm->IsBackgroundHostClosing(popup->id())); | 106 EXPECT_FALSE(pm->IsBackgroundHostClosing(popup->id())); |
102 EXPECT_EQ(0, pm->GetLazyKeepaliveCount(popup.get())); | 107 EXPECT_EQ(0, pm->GetLazyKeepaliveCount(popup.get())); |
103 } | 108 } |
104 | 109 |
| 110 // Content loaded from http://hlogonemlfkgpejgnedahbkiabcdhnnn should not |
| 111 // interact with an installed extension with that ID. Regression test |
| 112 // for bug 357382. |
| 113 IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest, HttpHostMatchingExtensionId) { |
| 114 ProcessManager* pm = ExtensionSystem::Get(profile())->process_manager(); |
| 115 |
| 116 // We start with no background hosts. |
| 117 ASSERT_EQ(0u, pm->background_hosts().size()); |
| 118 ASSERT_EQ(0u, pm->GetAllViews().size()); |
| 119 |
| 120 // Load an extension with a background page. |
| 121 scoped_refptr<const Extension> extension = |
| 122 LoadExtension(test_data_dir_.AppendASCII("api_test") |
| 123 .AppendASCII("browser_action") |
| 124 .AppendASCII("none")); |
| 125 |
| 126 // Set up a test server running at http://[extension-id] |
| 127 ASSERT_TRUE(extension.get()); |
| 128 const std::string aliased_host = extension->id(); |
| 129 host_resolver()->AddRule(aliased_host, "127.0.0.1"); |
| 130 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 131 GURL url = |
| 132 embedded_test_server()->GetURL("/extensions/test_file_with_body.html"); |
| 133 GURL::Replacements replace_host; |
| 134 replace_host.SetHostStr(aliased_host); |
| 135 url = url.ReplaceComponents(replace_host); |
| 136 |
| 137 // Load a page from the test host in a new tab. |
| 138 ui_test_utils::NavigateToURLWithDisposition( |
| 139 browser(), |
| 140 url, |
| 141 NEW_FOREGROUND_TAB, |
| 142 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 143 |
| 144 // Sanity check that there's no bleeding between the extension and the tab. |
| 145 content::WebContents* tab_web_contents = |
| 146 browser()->tab_strip_model()->GetActiveWebContents(); |
| 147 EXPECT_EQ(url, tab_web_contents->GetVisibleURL()); |
| 148 EXPECT_TRUE(NULL == pm->GetExtensionForRenderViewHost( |
| 149 tab_web_contents->GetRenderViewHost())) |
| 150 << "Non-extension content must not have an associated extension"; |
| 151 ASSERT_EQ(1u, pm->GetRenderViewHostsForExtension(extension->id()).size()); |
| 152 content::WebContents* extension_web_contents = |
| 153 content::WebContents::FromRenderViewHost( |
| 154 *pm->GetRenderViewHostsForExtension(extension->id()).begin()); |
| 155 EXPECT_TRUE(extension_web_contents->GetSiteInstance() != |
| 156 tab_web_contents->GetSiteInstance()); |
| 157 EXPECT_TRUE(pm->GetSiteInstanceForURL(extension->url()) != |
| 158 tab_web_contents->GetSiteInstance()); |
| 159 EXPECT_TRUE(pm->GetBackgroundHostForExtension(extension->id())); |
| 160 } |
| 161 |
105 } // namespace extensions | 162 } // namespace extensions |
OLD | NEW |