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 "chrome/browser/extensions/extension_apitest.h" | 5 #include "chrome/browser/extensions/extension_apitest.h" |
6 #include "chrome/browser/extensions/extension_host.h" | 6 #include "chrome/browser/extensions/extension_host.h" |
7 #include "chrome/browser/extensions/extension_service.h" | 7 #include "chrome/browser/extensions/extension_service.h" |
| 8 #include "chrome/browser/extensions/extension_system.h" |
8 #include "chrome/browser/extensions/process_map.h" | 9 #include "chrome/browser/extensions/process_map.h" |
9 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" | 11 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" |
11 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/browser_commands.h" | 13 #include "chrome/browser/ui/browser_commands.h" |
13 #include "chrome/browser/ui/browser_finder.h" | 14 #include "chrome/browser/ui/browser_finder.h" |
14 #include "chrome/browser/ui/browser_list.h" | 15 #include "chrome/browser/ui/browser_list.h" |
15 #include "chrome/browser/ui/browser_tabstrip.h" | 16 #include "chrome/browser/ui/browser_tabstrip.h" |
16 #include "chrome/browser/ui/browser_window.h" | 17 #include "chrome/browser/ui/browser_window.h" |
17 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 18 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 switches::kDisablePopupBlocking); | 57 switches::kDisablePopupBlocking); |
57 CommandLine::ForCurrentProcess()->AppendSwitch( | 58 CommandLine::ForCurrentProcess()->AppendSwitch( |
58 switches::kAllowHTTPBackgroundPage); | 59 switches::kAllowHTTPBackgroundPage); |
59 } | 60 } |
60 | 61 |
61 // Helper function to test that independent tabs of the named app are loaded | 62 // Helper function to test that independent tabs of the named app are loaded |
62 // into separate processes. | 63 // into separate processes. |
63 void TestAppInstancesHelper(std::string app_name) { | 64 void TestAppInstancesHelper(std::string app_name) { |
64 LOG(INFO) << "Start of test."; | 65 LOG(INFO) << "Start of test."; |
65 | 66 |
66 extensions::ProcessMap* process_map = | 67 extensions::ProcessMap* process_map = extensions::ExtensionSystem::Get( |
67 browser()->profile()->GetExtensionService()->process_map(); | 68 browser()->profile())->extension_service()->process_map(); |
68 | 69 |
69 host_resolver()->AddRule("*", "127.0.0.1"); | 70 host_resolver()->AddRule("*", "127.0.0.1"); |
70 ASSERT_TRUE(test_server()->Start()); | 71 ASSERT_TRUE(test_server()->Start()); |
71 | 72 |
72 ASSERT_TRUE(LoadExtension( | 73 ASSERT_TRUE(LoadExtension( |
73 test_data_dir_.AppendASCII(app_name))); | 74 test_data_dir_.AppendASCII(app_name))); |
74 | 75 |
75 // Open two tabs in the app, one outside it. | 76 // Open two tabs in the app, one outside it. |
76 GURL base_url = GetTestBaseURL(app_name); | 77 GURL base_url = GetTestBaseURL(app_name); |
77 | 78 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 CommandLine::ForCurrentProcess()->AppendSwitch( | 128 CommandLine::ForCurrentProcess()->AppendSwitch( |
128 switches::kAllowHTTPBackgroundPage); | 129 switches::kAllowHTTPBackgroundPage); |
129 } | 130 } |
130 }; | 131 }; |
131 | 132 |
132 // Tests that hosted apps with the background permission get a process-per-app | 133 // Tests that hosted apps with the background permission get a process-per-app |
133 // model, since all pages need to be able to script the background page. | 134 // model, since all pages need to be able to script the background page. |
134 IN_PROC_BROWSER_TEST_F(AppApiTest, AppProcess) { | 135 IN_PROC_BROWSER_TEST_F(AppApiTest, AppProcess) { |
135 LOG(INFO) << "Start of test."; | 136 LOG(INFO) << "Start of test."; |
136 | 137 |
137 extensions::ProcessMap* process_map = | 138 extensions::ProcessMap* process_map = extensions::ExtensionSystem::Get( |
138 browser()->profile()->GetExtensionService()->process_map(); | 139 browser()->profile())->extension_service()->process_map(); |
139 | 140 |
140 host_resolver()->AddRule("*", "127.0.0.1"); | 141 host_resolver()->AddRule("*", "127.0.0.1"); |
141 ASSERT_TRUE(test_server()->Start()); | 142 ASSERT_TRUE(test_server()->Start()); |
142 | 143 |
143 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process"))); | 144 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process"))); |
144 | 145 |
145 LOG(INFO) << "Loaded extension."; | 146 LOG(INFO) << "Loaded extension."; |
146 | 147 |
147 // Open two tabs in the app, one outside it. | 148 // Open two tabs in the app, one outside it. |
148 GURL base_url = GetTestBaseURL("app_process"); | 149 GURL base_url = GetTestBaseURL("app_process"); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 // Test that hosted apps with the background permission but that set | 243 // Test that hosted apps with the background permission but that set |
243 // allow_js_access to false also use a process per app instance model. | 244 // allow_js_access to false also use a process per app instance model. |
244 // Separate instances should be in separate processes. | 245 // Separate instances should be in separate processes. |
245 IN_PROC_BROWSER_TEST_F(AppApiTest, AppProcessBackgroundInstances) { | 246 IN_PROC_BROWSER_TEST_F(AppApiTest, AppProcessBackgroundInstances) { |
246 TestAppInstancesHelper("app_process_background_instances"); | 247 TestAppInstancesHelper("app_process_background_instances"); |
247 } | 248 } |
248 | 249 |
249 // Tests that bookmark apps do not use the app process model and are treated | 250 // Tests that bookmark apps do not use the app process model and are treated |
250 // like normal web pages instead. http://crbug.com/104636. | 251 // like normal web pages instead. http://crbug.com/104636. |
251 IN_PROC_BROWSER_TEST_F(AppApiTest, BookmarkAppGetsNormalProcess) { | 252 IN_PROC_BROWSER_TEST_F(AppApiTest, BookmarkAppGetsNormalProcess) { |
252 ExtensionService* service = browser()->profile()->GetExtensionService(); | 253 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 254 browser()->profile())->extension_service(); |
253 extensions::ProcessMap* process_map = service->process_map(); | 255 extensions::ProcessMap* process_map = service->process_map(); |
254 | 256 |
255 host_resolver()->AddRule("*", "127.0.0.1"); | 257 host_resolver()->AddRule("*", "127.0.0.1"); |
256 ASSERT_TRUE(test_server()->Start()); | 258 ASSERT_TRUE(test_server()->Start()); |
257 GURL base_url = GetTestBaseURL("app_process"); | 259 GURL base_url = GetTestBaseURL("app_process"); |
258 | 260 |
259 // Load an app as a bookmark app. | 261 // Load an app as a bookmark app. |
260 std::string error; | 262 std::string error; |
261 scoped_refptr<const Extension> extension(extension_file_util::LoadExtension( | 263 scoped_refptr<const Extension> extension(extension_file_util::LoadExtension( |
262 test_data_dir_.AppendASCII("app_process"), | 264 test_data_dir_.AppendASCII("app_process"), |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 // Ensure that reloading a URL after installing or uninstalling it as an app | 363 // Ensure that reloading a URL after installing or uninstalling it as an app |
362 // correctly swaps the process. (http://crbug.com/80621) | 364 // correctly swaps the process. (http://crbug.com/80621) |
363 // | 365 // |
364 // The test times out under AddressSanitizer, see http://crbug.com/103371 | 366 // The test times out under AddressSanitizer, see http://crbug.com/103371 |
365 #if defined(ADDRESS_SANITIZER) | 367 #if defined(ADDRESS_SANITIZER) |
366 #define MAYBE_ReloadIntoAppProcess DISABLED_ReloadIntoAppProcess | 368 #define MAYBE_ReloadIntoAppProcess DISABLED_ReloadIntoAppProcess |
367 #else | 369 #else |
368 #define MAYBE_ReloadIntoAppProcess ReloadIntoAppProcess | 370 #define MAYBE_ReloadIntoAppProcess ReloadIntoAppProcess |
369 #endif | 371 #endif |
370 IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_ReloadIntoAppProcess) { | 372 IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_ReloadIntoAppProcess) { |
371 extensions::ProcessMap* process_map = | 373 extensions::ProcessMap* process_map = extensions::ExtensionSystem::Get( |
372 browser()->profile()->GetExtensionService()->process_map(); | 374 browser()->profile())->extension_service()->process_map(); |
373 | 375 |
374 host_resolver()->AddRule("*", "127.0.0.1"); | 376 host_resolver()->AddRule("*", "127.0.0.1"); |
375 ASSERT_TRUE(test_server()->Start()); | 377 ASSERT_TRUE(test_server()->Start()); |
376 | 378 |
377 // The app under test acts on URLs whose host is "localhost", | 379 // The app under test acts on URLs whose host is "localhost", |
378 // so the URLs we navigate to must have host "localhost". | 380 // so the URLs we navigate to must have host "localhost". |
379 GURL base_url = GetTestBaseURL("app_process"); | 381 GURL base_url = GetTestBaseURL("app_process"); |
380 | 382 |
381 // Load an app URL before loading the app. | 383 // Load an app URL before loading the app. |
382 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); | 384 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 EXPECT_FALSE(process_map->Contains( | 446 EXPECT_FALSE(process_map->Contains( |
445 contents->GetRenderProcessHost()->GetID())); | 447 contents->GetRenderProcessHost()->GetID())); |
446 } | 448 } |
447 | 449 |
448 // Tests that if we have a non-app process (path3/container.html) that has an | 450 // Tests that if we have a non-app process (path3/container.html) that has an |
449 // iframe with a URL in the app's extent (path1/iframe.html), then opening a | 451 // iframe with a URL in the app's extent (path1/iframe.html), then opening a |
450 // link from that iframe to a new window to a URL in the app's extent (path1/ | 452 // link from that iframe to a new window to a URL in the app's extent (path1/ |
451 // empty.html) results in the new window being in an app process. See | 453 // empty.html) results in the new window being in an app process. See |
452 // http://crbug.com/89272 for more details. | 454 // http://crbug.com/89272 for more details. |
453 IN_PROC_BROWSER_TEST_F(AppApiTest, OpenAppFromIframe) { | 455 IN_PROC_BROWSER_TEST_F(AppApiTest, OpenAppFromIframe) { |
454 extensions::ProcessMap* process_map = | 456 extensions::ProcessMap* process_map = extensions::ExtensionSystem::Get( |
455 browser()->profile()->GetExtensionService()->process_map(); | 457 browser()->profile())->extension_service()->process_map(); |
456 | 458 |
457 host_resolver()->AddRule("*", "127.0.0.1"); | 459 host_resolver()->AddRule("*", "127.0.0.1"); |
458 ASSERT_TRUE(test_server()->Start()); | 460 ASSERT_TRUE(test_server()->Start()); |
459 | 461 |
460 GURL base_url = GetTestBaseURL("app_process"); | 462 GURL base_url = GetTestBaseURL("app_process"); |
461 | 463 |
462 // Load app and start URL (not in the app). | 464 // Load app and start URL (not in the app). |
463 const Extension* app = | 465 const Extension* app = |
464 LoadExtension(test_data_dir_.AppendASCII("app_process")); | 466 LoadExtension(test_data_dir_.AppendASCII("app_process")); |
465 ASSERT_TRUE(app); | 467 ASSERT_TRUE(app); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 } | 557 } |
556 | 558 |
557 // Tests that if we have an app process (path1/container.html) with a non-app | 559 // Tests that if we have an app process (path1/container.html) with a non-app |
558 // iframe (path3/iframe.html), then opening a link from that iframe to a new | 560 // iframe (path3/iframe.html), then opening a link from that iframe to a new |
559 // window to a same-origin non-app URL (path3/empty.html) should keep the window | 561 // window to a same-origin non-app URL (path3/empty.html) should keep the window |
560 // in the app process. | 562 // in the app process. |
561 // This is in contrast to OpenAppFromIframe, since here the popup will not be | 563 // This is in contrast to OpenAppFromIframe, since here the popup will not be |
562 // missing special permissions and should be scriptable from the iframe. | 564 // missing special permissions and should be scriptable from the iframe. |
563 // See http://crbug.com/92669 for more details. | 565 // See http://crbug.com/92669 for more details. |
564 IN_PROC_BROWSER_TEST_F(AppApiTest, OpenWebPopupFromWebIframe) { | 566 IN_PROC_BROWSER_TEST_F(AppApiTest, OpenWebPopupFromWebIframe) { |
565 extensions::ProcessMap* process_map = | 567 extensions::ProcessMap* process_map = extensions::ExtensionSystem::Get( |
566 browser()->profile()->GetExtensionService()->process_map(); | 568 browser()->profile())->extension_service()->process_map(); |
567 | 569 |
568 host_resolver()->AddRule("*", "127.0.0.1"); | 570 host_resolver()->AddRule("*", "127.0.0.1"); |
569 ASSERT_TRUE(test_server()->Start()); | 571 ASSERT_TRUE(test_server()->Start()); |
570 | 572 |
571 GURL base_url = GetTestBaseURL("app_process"); | 573 GURL base_url = GetTestBaseURL("app_process"); |
572 | 574 |
573 // Load app and start URL (in the app). | 575 // Load app and start URL (in the app). |
574 const Extension* app = | 576 const Extension* app = |
575 LoadExtension(test_data_dir_.AppendASCII("app_process")); | 577 LoadExtension(test_data_dir_.AppendASCII("app_process")); |
576 ASSERT_TRUE(app); | 578 ASSERT_TRUE(app); |
(...skipping 16 matching lines...) Expand all Loading... |
593 EXPECT_EQ(process, popup_host->GetProcess()); | 595 EXPECT_EQ(process, popup_host->GetProcess()); |
594 } | 596 } |
595 | 597 |
596 // http://crbug.com/118502 | 598 // http://crbug.com/118502 |
597 #if defined(OS_MACOSX) || defined(OS_LINUX) | 599 #if defined(OS_MACOSX) || defined(OS_LINUX) |
598 #define MAYBE_ReloadAppAfterCrash DISABLED_ReloadAppAfterCrash | 600 #define MAYBE_ReloadAppAfterCrash DISABLED_ReloadAppAfterCrash |
599 #else | 601 #else |
600 #define MAYBE_ReloadAppAfterCrash ReloadAppAfterCrash | 602 #define MAYBE_ReloadAppAfterCrash ReloadAppAfterCrash |
601 #endif | 603 #endif |
602 IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_ReloadAppAfterCrash) { | 604 IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_ReloadAppAfterCrash) { |
603 extensions::ProcessMap* process_map = | 605 extensions::ProcessMap* process_map = extensions::ExtensionSystem::Get( |
604 browser()->profile()->GetExtensionService()->process_map(); | 606 browser()->profile())->extension_service()->process_map(); |
605 | 607 |
606 host_resolver()->AddRule("*", "127.0.0.1"); | 608 host_resolver()->AddRule("*", "127.0.0.1"); |
607 ASSERT_TRUE(test_server()->Start()); | 609 ASSERT_TRUE(test_server()->Start()); |
608 | 610 |
609 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process"))); | 611 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process"))); |
610 | 612 |
611 GURL base_url = GetTestBaseURL("app_process"); | 613 GURL base_url = GetTestBaseURL("app_process"); |
612 | 614 |
613 // Load the app, chrome.app.isInstalled should be true. | 615 // Load the app, chrome.app.isInstalled should be true. |
614 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); | 616 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); |
(...skipping 14 matching lines...) Expand all Loading... |
629 content::Source<NavigationController>( | 631 content::Source<NavigationController>( |
630 &chrome::GetActiveWebContents(browser())->GetController())); | 632 &chrome::GetActiveWebContents(browser())->GetController())); |
631 chrome::Reload(browser(), CURRENT_TAB); | 633 chrome::Reload(browser(), CURRENT_TAB); |
632 observer.Wait(); | 634 observer.Wait(); |
633 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( | 635 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
634 contents->GetRenderViewHost(), L"", | 636 contents->GetRenderViewHost(), L"", |
635 L"window.domAutomationController.send(chrome.app.isInstalled)", | 637 L"window.domAutomationController.send(chrome.app.isInstalled)", |
636 &is_installed)); | 638 &is_installed)); |
637 ASSERT_TRUE(is_installed); | 639 ASSERT_TRUE(is_installed); |
638 } | 640 } |
OLD | NEW |