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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "chrome/browser/chrome_notification_types.h" | 6 #include "chrome/browser/chrome_notification_types.h" |
7 #include "chrome/browser/extensions/extension_apitest.h" | 7 #include "chrome/browser/extensions/extension_apitest.h" |
8 #include "chrome/browser/extensions/extension_host.h" | 8 #include "chrome/browser/extensions/extension_host.h" |
9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
10 #include "chrome/browser/extensions/extension_system.h" | 10 #include "chrome/browser/extensions/extension_system.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" | 12 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" |
13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/browser/ui/browser_commands.h" | 14 #include "chrome/browser/ui/browser_commands.h" |
15 #include "chrome/browser/ui/browser_finder.h" | 15 #include "chrome/browser/ui/browser_finder.h" |
16 #include "chrome/browser/ui/browser_list.h" | 16 #include "chrome/browser/ui/browser_list.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/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
20 #include "chrome/common/extensions/extension_file_util.h" | 20 #include "chrome/common/extensions/extension_file_util.h" |
21 #include "chrome/test/base/test_switches.h" | 21 #include "chrome/test/base/test_switches.h" |
22 #include "chrome/test/base/ui_test_utils.h" | 22 #include "chrome/test/base/ui_test_utils.h" |
23 #include "content/public/browser/navigation_entry.h" | 23 #include "content/public/browser/navigation_entry.h" |
24 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
25 #include "content/public/browser/render_process_host.h" | 25 #include "content/public/browser/render_process_host.h" |
26 #include "content/public/browser/render_view_host.h" | 26 #include "content/public/browser/render_view_host.h" |
| 27 #include "content/public/browser/site_instance.h" |
27 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
28 #include "content/public/test/browser_test_utils.h" | 29 #include "content/public/test/browser_test_utils.h" |
29 #include "content/public/test/test_navigation_observer.h" | 30 #include "content/public/test/test_navigation_observer.h" |
30 #include "extensions/browser/process_map.h" | 31 #include "extensions/browser/process_map.h" |
31 #include "extensions/common/extension.h" | 32 #include "extensions/common/extension.h" |
32 #include "extensions/common/switches.h" | 33 #include "extensions/common/switches.h" |
33 #include "net/dns/mock_host_resolver.h" | 34 #include "net/dns/mock_host_resolver.h" |
34 #include "net/test/embedded_test_server/embedded_test_server.h" | 35 #include "net/test/embedded_test_server/embedded_test_server.h" |
35 #include "sync/api/string_ordinal.h" | 36 #include "sync/api/string_ordinal.h" |
36 | 37 |
37 using content::NavigationController; | 38 using content::NavigationController; |
38 using content::RenderViewHost; | 39 using content::RenderViewHost; |
| 40 using content::SiteInstance; |
39 using content::WebContents; | 41 using content::WebContents; |
40 using extensions::Extension; | 42 using extensions::Extension; |
41 | 43 |
42 class AppApiTest : public ExtensionApiTest { | 44 class AppApiTest : public ExtensionApiTest { |
43 protected: | 45 protected: |
44 // Gets the base URL for files for a specific test, making sure that it uses | 46 // Gets the base URL for files for a specific test, making sure that it uses |
45 // "localhost" as the hostname, since that is what the extent is declared | 47 // "localhost" as the hostname, since that is what the extent is declared |
46 // as in the test apps manifests. | 48 // as in the test apps manifests. |
47 GURL GetTestBaseURL(std::string test_directory) { | 49 GURL GetTestBaseURL(std::string test_directory) { |
48 GURL::Replacements replace_host; | 50 GURL::Replacements replace_host; |
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
825 &browser()->tab_strip_model()->GetActiveWebContents()-> | 827 &browser()->tab_strip_model()->GetActiveWebContents()-> |
826 GetController())); | 828 GetController())); |
827 chrome::Reload(browser(), CURRENT_TAB); | 829 chrome::Reload(browser(), CURRENT_TAB); |
828 observer.Wait(); | 830 observer.Wait(); |
829 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 831 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
830 contents, | 832 contents, |
831 "window.domAutomationController.send(chrome.app.isInstalled)", | 833 "window.domAutomationController.send(chrome.app.isInstalled)", |
832 &is_installed)); | 834 &is_installed)); |
833 ASSERT_TRUE(is_installed); | 835 ASSERT_TRUE(is_installed); |
834 } | 836 } |
| 837 |
| 838 // Test that a cross-process navigation away from a hosted app stays in the same |
| 839 // BrowsingInstance, so that postMessage calls to the app's other windows still |
| 840 // work. |
| 841 IN_PROC_BROWSER_TEST_F(AppApiTest, SameBrowsingInstanceAfterSwap) { |
| 842 extensions::ProcessMap* process_map = extensions::ExtensionSystem::Get( |
| 843 browser()->profile())->extension_service()->process_map(); |
| 844 |
| 845 host_resolver()->AddRule("*", "127.0.0.1"); |
| 846 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 847 |
| 848 GURL base_url = GetTestBaseURL("app_process"); |
| 849 |
| 850 // Load app and start URL (in the app). |
| 851 const Extension* app = |
| 852 LoadExtension(test_data_dir_.AppendASCII("app_process")); |
| 853 ASSERT_TRUE(app); |
| 854 |
| 855 ui_test_utils::NavigateToURL(browser(), |
| 856 base_url.Resolve("path1/iframe.html")); |
| 857 content::SiteInstance* app_instance = |
| 858 browser()->tab_strip_model()->GetWebContentsAt(0)->GetSiteInstance(); |
| 859 EXPECT_TRUE(process_map->Contains(app_instance->GetProcess()->GetID())); |
| 860 |
| 861 // Popup window should be in the app's process. |
| 862 const BrowserList* active_browser_list = |
| 863 BrowserList::GetInstance(chrome::GetActiveDesktop()); |
| 864 EXPECT_EQ(2U, active_browser_list->size()); |
| 865 content::WebContents* popup_contents = |
| 866 active_browser_list->get(1)->tab_strip_model()->GetActiveWebContents(); |
| 867 content::WaitForLoadStop(popup_contents); |
| 868 |
| 869 SiteInstance* popup_instance = popup_contents->GetSiteInstance(); |
| 870 EXPECT_EQ(app_instance, popup_instance); |
| 871 |
| 872 // Navigate the popup to another process outside the app. |
| 873 GURL non_app_url(base_url.Resolve("path3/empty.html")); |
| 874 ui_test_utils::NavigateToURL(active_browser_list->get(1), non_app_url); |
| 875 SiteInstance* new_instance = popup_contents->GetSiteInstance(); |
| 876 EXPECT_NE(app_instance, new_instance); |
| 877 |
| 878 // It should still be in the same BrowsingInstance, allowing postMessage to |
| 879 // work. |
| 880 EXPECT_TRUE(app_instance->IsRelatedSiteInstance(new_instance)); |
| 881 } |
OLD | NEW |