Chromium Code Reviews| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 #include "chrome/browser/extensions/extension_apitest.h" | 9 #include "chrome/browser/extensions/extension_apitest.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/profiles/profile_manager.h" | 12 #include "chrome/browser/profiles/profile_manager.h" |
| 13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 15 #include "chrome/common/chrome_switches.h" | |
| 15 #include "chrome/common/extensions/extension_process_policy.h" | 16 #include "chrome/common/extensions/extension_process_policy.h" |
| 16 #include "chrome/common/url_constants.h" | 17 #include "chrome/common/url_constants.h" |
| 17 #include "chrome/test/base/ui_test_utils.h" | 18 #include "chrome/test/base/ui_test_utils.h" |
| 18 #include "content/public/browser/render_frame_host.h" | 19 #include "content/public/browser/render_frame_host.h" |
| 19 #include "content/public/browser/render_process_host.h" | 20 #include "content/public/browser/render_process_host.h" |
| 20 #include "content/public/browser/render_view_host.h" | 21 #include "content/public/browser/render_view_host.h" |
| 21 #include "content/public/browser/site_instance.h" | 22 #include "content/public/browser/site_instance.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 "content/public/test/test_navigation_observer.h" | 25 #include "content/public/test/test_navigation_observer.h" |
| 25 #include "extensions/browser/extension_host.h" | 26 #include "extensions/browser/extension_host.h" |
| 27 #include "extensions/browser/extension_registry.h" | |
|
lazyboy
2016/10/05 23:20:02
Not needed?
Łukasz Anforowicz
2016/10/05 23:46:59
Oh, right. Not sure how I missed that one :-)
Do
| |
| 26 #include "extensions/browser/process_manager.h" | 28 #include "extensions/browser/process_manager.h" |
| 29 #include "extensions/browser/process_map.h" | |
| 27 #include "extensions/common/switches.h" | 30 #include "extensions/common/switches.h" |
| 28 #include "net/dns/mock_host_resolver.h" | 31 #include "net/dns/mock_host_resolver.h" |
| 29 #include "net/test/embedded_test_server/embedded_test_server.h" | 32 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 30 | 33 |
| 31 using content::NavigationController; | 34 using content::NavigationController; |
| 32 using content::WebContents; | 35 using content::WebContents; |
| 33 | 36 |
| 34 namespace { | 37 namespace { |
| 35 | 38 |
| 36 class ProcessManagementTest : public ExtensionBrowserTest { | 39 class ProcessManagementTest : public ExtensionBrowserTest { |
| 37 private: | 40 private: |
| 38 // This is needed for testing isolated apps, which are still experimental. | 41 // This is needed for testing isolated apps, which are still experimental. |
| 39 void SetUpCommandLine(base::CommandLine* command_line) override { | 42 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 40 ExtensionBrowserTest::SetUpCommandLine(command_line); | 43 ExtensionBrowserTest::SetUpCommandLine(command_line); |
| 41 command_line->AppendSwitch( | 44 command_line->AppendSwitch( |
| 42 extensions::switches::kEnableExperimentalExtensionApis); | 45 extensions::switches::kEnableExperimentalExtensionApis); |
| 43 } | 46 } |
| 44 }; | 47 }; |
| 45 | 48 |
| 49 class ChromeWebStoreProcessTest : public ExtensionBrowserTest { | |
| 50 public: | |
| 51 const GURL& gallery_url() { return gallery_url_; } | |
| 52 | |
| 53 private: | |
| 54 // Overrides location of Chrome Web Store gallery to a test controlled URL. | |
| 55 void SetUpCommandLine(base::CommandLine* command_line) override { | |
| 56 ExtensionBrowserTest::SetUpCommandLine(command_line); | |
| 57 | |
| 58 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 59 gallery_url_ = | |
| 60 embedded_test_server()->GetURL("chrome.webstore.test.com", "/"); | |
| 61 command_line->AppendSwitchASCII(switches::kAppsGalleryURL, | |
| 62 gallery_url_.spec()); | |
| 63 } | |
| 64 | |
| 65 void SetUpOnMainThread() override { | |
| 66 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 67 } | |
| 68 | |
| 69 GURL gallery_url_; | |
| 70 }; | |
| 71 | |
| 46 } // namespace | 72 } // namespace |
| 47 | 73 |
| 48 | 74 |
| 49 // TODO(nasko): crbug.com/173137 | 75 // TODO(nasko): crbug.com/173137 |
| 50 #if defined(OS_WIN) | 76 #if defined(OS_WIN) |
| 51 #define MAYBE_ProcessOverflow DISABLED_ProcessOverflow | 77 #define MAYBE_ProcessOverflow DISABLED_ProcessOverflow |
| 52 #else | 78 #else |
| 53 #define MAYBE_ProcessOverflow ProcessOverflow | 79 #define MAYBE_ProcessOverflow ProcessOverflow |
| 54 #endif | 80 #endif |
| 55 | 81 |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 295 EXPECT_EQ(web_url, web_contents->GetLastCommittedURL()); | 321 EXPECT_EQ(web_url, web_contents->GetLastCommittedURL()); |
| 296 | 322 |
| 297 // Verify that the navigation transferred the contents to another renderer | 323 // Verify that the navigation transferred the contents to another renderer |
| 298 // process. | 324 // process. |
| 299 if (extensions::IsIsolateExtensionsEnabled()) { | 325 if (extensions::IsIsolateExtensionsEnabled()) { |
| 300 content::RenderProcessHost* new_process_host = | 326 content::RenderProcessHost* new_process_host = |
| 301 web_contents->GetMainFrame()->GetProcess(); | 327 web_contents->GetMainFrame()->GetProcess(); |
| 302 EXPECT_NE(old_process_host, new_process_host); | 328 EXPECT_NE(old_process_host, new_process_host); |
| 303 } | 329 } |
| 304 } | 330 } |
| 331 | |
| 332 IN_PROC_BROWSER_TEST_F(ChromeWebStoreProcessTest, | |
| 333 NavigateWebTabToChromeWebStoreViaPost) { | |
| 334 // Navigate a tab to a web page with a form. | |
| 335 GURL web_url = embedded_test_server()->GetURL("foo.com", "/form.html"); | |
| 336 ui_test_utils::NavigateToURL(browser(), web_url); | |
| 337 WebContents* web_contents = | |
| 338 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 339 EXPECT_EQ(web_url, web_contents->GetLastCommittedURL()); | |
| 340 content::RenderProcessHost* old_process_host = | |
| 341 web_contents->GetMainFrame()->GetProcess(); | |
| 342 | |
| 343 // Calculate an URL that is 1) relative to the fake (i.e. test-controlled) | |
| 344 // Chrome Web Store gallery URL and 2) resolves to something that | |
| 345 // embedded_test_server can actually serve (e.g. title1.html test file). | |
| 346 GURL::Replacements replace_path; | |
| 347 replace_path.SetPathStr("/title1.html"); | |
| 348 GURL cws_web_url = gallery_url().ReplaceComponents(replace_path); | |
| 349 | |
| 350 // Note that the |setTimeout| call below is needed to make sure | |
| 351 // ExecuteScriptAndExtractBool returns *after* a scheduled navigation has | |
| 352 // already started. | |
| 353 std::string navigation_starting_script = | |
| 354 "var form = document.getElementById('form');\n" | |
| 355 "form.action = '" + cws_web_url.spec() + "';\n" | |
| 356 "form.submit();\n" | |
| 357 "setTimeout(\n" | |
| 358 " function() { window.domAutomationController.send(true); },\n" | |
| 359 " 0);\n"; | |
| 360 | |
| 361 // Trigger a renderer-initiated POST navigation (via the form) to a Chrome Web | |
| 362 // Store gallery URL (which will commit into a chrome-extension://cws-app-id). | |
| 363 bool ignored_script_result = false; | |
| 364 content::TestNavigationObserver nav_observer(web_contents, 1); | |
| 365 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | |
| 366 web_contents, navigation_starting_script, &ignored_script_result)); | |
| 367 | |
| 368 // Verify that the navigation succeeded. | |
| 369 nav_observer.Wait(); | |
| 370 EXPECT_EQ(cws_web_url, web_contents->GetLastCommittedURL()); | |
| 371 | |
| 372 // Verify that we really have the Chrome Web Store app loaded in the Web | |
| 373 // Contents. | |
| 374 content::RenderProcessHost* new_process_host = | |
| 375 web_contents->GetMainFrame()->GetProcess(); | |
| 376 EXPECT_TRUE(extensions::ProcessMap::Get(profile())->Contains( | |
| 377 extensions::kWebStoreAppId, new_process_host->GetID())); | |
| 378 | |
| 379 // Verify that Chrome Web Store is isolated in a separate renderer process. | |
| 380 if (extensions::IsIsolateExtensionsEnabled()) | |
| 381 EXPECT_NE(old_process_host, new_process_host); | |
| 382 } | |
| OLD | NEW |