Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(149)

Side by Side Diff: chrome/browser/extensions/isolated_app_browsertest.cc

Issue 10702029: Move tab functions off Browser into browser_tabstrip and browser_tabrestore. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/utf_string_conversions.h" 5 #include "base/utf_string_conversions.h"
6 #include "chrome/browser/automation/automation_util.h" 6 #include "chrome/browser/automation/automation_util.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/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ui/browser.h" 11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_commands.h" 12 #include "chrome/browser/ui/browser_commands.h"
13 #include "chrome/browser/ui/browser_tabstrip.h"
13 #include "chrome/browser/ui/tab_contents/tab_contents.h" 14 #include "chrome/browser/ui/tab_contents/tab_contents.h"
14 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
15 #include "chrome/common/url_constants.h" 16 #include "chrome/common/url_constants.h"
16 #include "chrome/test/base/ui_test_utils.h" 17 #include "chrome/test/base/ui_test_utils.h"
17 #include "content/public/browser/render_process_host.h" 18 #include "content/public/browser/render_process_host.h"
18 #include "content/public/browser/render_view_host.h" 19 #include "content/public/browser/render_view_host.h"
19 #include "content/public/browser/site_instance.h" 20 #include "content/public/browser/site_instance.h"
20 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
21 #include "net/base/mock_host_resolver.h" 22 #include "net/base/mock_host_resolver.h"
22 23
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 ui_test_utils::NavigateToURLWithDisposition( 82 ui_test_utils::NavigateToURLWithDisposition(
82 browser(), base_url.Resolve("app2/main.html"), 83 browser(), base_url.Resolve("app2/main.html"),
83 NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 84 NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
84 ui_test_utils::NavigateToURLWithDisposition( 85 ui_test_utils::NavigateToURLWithDisposition(
85 browser(), base_url.Resolve("non_app/main.html"), 86 browser(), base_url.Resolve("non_app/main.html"),
86 NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 87 NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
87 88
88 ASSERT_EQ(3, browser()->tab_count()); 89 ASSERT_EQ(3, browser()->tab_count());
89 90
90 // Ensure first two tabs have installed apps. 91 // Ensure first two tabs have installed apps.
91 WebContents* tab1 = browser()->GetWebContentsAt(0); 92 WebContents* tab1 = chrome::GetWebContentsAt(browser(), 0);
92 WebContents* tab2 = browser()->GetWebContentsAt(1); 93 WebContents* tab2 = chrome::GetWebContentsAt(browser(), 1);
93 WebContents* tab3 = browser()->GetWebContentsAt(2); 94 WebContents* tab3 = chrome::GetWebContentsAt(browser(), 2);
94 ASSERT_TRUE(GetInstalledApp(tab1)); 95 ASSERT_TRUE(GetInstalledApp(tab1));
95 ASSERT_TRUE(GetInstalledApp(tab2)); 96 ASSERT_TRUE(GetInstalledApp(tab2));
96 ASSERT_TRUE(!GetInstalledApp(tab3)); 97 ASSERT_TRUE(!GetInstalledApp(tab3));
97 98
98 // Check that each tab sees its own cookie. 99 // Check that each tab sees its own cookie.
99 EXPECT_TRUE(HasCookie(tab1, "app1=3")); 100 EXPECT_TRUE(HasCookie(tab1, "app1=3"));
100 EXPECT_TRUE(HasCookie(tab2, "app2=4")); 101 EXPECT_TRUE(HasCookie(tab2, "app2=4"));
101 EXPECT_TRUE(HasCookie(tab3, "normalPage=5")); 102 EXPECT_TRUE(HasCookie(tab3, "normalPage=5"));
102 103
103 // Check that app1 tab cannot see the other cookies. 104 // Check that app1 tab cannot see the other cookies.
(...skipping 13 matching lines...) Expand all
117 // process, even if they aren't in the app manifest.) 118 // process, even if they aren't in the app manifest.)
118 EXPECT_TRUE(HasCookie(tab1, "nonAppFrame=6")); 119 EXPECT_TRUE(HasCookie(tab1, "nonAppFrame=6"));
119 EXPECT_FALSE(HasCookie(tab3, "nonAppFrame")); 120 EXPECT_FALSE(HasCookie(tab3, "nonAppFrame"));
120 121
121 // Check that isolation persists even if the tab crashes and is reloaded. 122 // Check that isolation persists even if the tab crashes and is reloaded.
122 chrome::SelectNumberedTab(browser(), 1); 123 chrome::SelectNumberedTab(browser(), 1);
123 ui_test_utils::CrashTab(tab1); 124 ui_test_utils::CrashTab(tab1);
124 ui_test_utils::WindowedNotificationObserver observer( 125 ui_test_utils::WindowedNotificationObserver observer(
125 content::NOTIFICATION_LOAD_STOP, 126 content::NOTIFICATION_LOAD_STOP,
126 content::Source<NavigationController>( 127 content::Source<NavigationController>(
127 &browser()->GetActiveWebContents()->GetController())); 128 &chrome::GetActiveWebContents(browser())->GetController()));
128 chrome::Reload(browser(), CURRENT_TAB); 129 chrome::Reload(browser(), CURRENT_TAB);
129 observer.Wait(); 130 observer.Wait();
130 EXPECT_TRUE(HasCookie(tab1, "app1=3")); 131 EXPECT_TRUE(HasCookie(tab1, "app1=3"));
131 EXPECT_FALSE(HasCookie(tab1, "app2")); 132 EXPECT_FALSE(HasCookie(tab1, "app2"));
132 EXPECT_FALSE(HasCookie(tab1, "normalPage")); 133 EXPECT_FALSE(HasCookie(tab1, "normalPage"));
133 } 134 }
134 135
135 // Ensure that cookies are not isolated if the isolated apps are not installed. 136 // Ensure that cookies are not isolated if the isolated apps are not installed.
136 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, NoCookieIsolationWithoutApp) { 137 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, NoCookieIsolationWithoutApp) {
137 host_resolver()->AddRule("*", "127.0.0.1"); 138 host_resolver()->AddRule("*", "127.0.0.1");
(...skipping 14 matching lines...) Expand all
152 ui_test_utils::NavigateToURLWithDisposition( 153 ui_test_utils::NavigateToURLWithDisposition(
153 browser(), base_url.Resolve("app2/main.html"), 154 browser(), base_url.Resolve("app2/main.html"),
154 NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 155 NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
155 ui_test_utils::NavigateToURLWithDisposition( 156 ui_test_utils::NavigateToURLWithDisposition(
156 browser(), base_url.Resolve("non_app/main.html"), 157 browser(), base_url.Resolve("non_app/main.html"),
157 NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 158 NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
158 159
159 ASSERT_EQ(3, browser()->tab_count()); 160 ASSERT_EQ(3, browser()->tab_count());
160 161
161 // Check that tabs see each others' cookies. 162 // Check that tabs see each others' cookies.
162 EXPECT_TRUE(HasCookie(browser()->GetWebContentsAt(0), "app2=4")); 163 EXPECT_TRUE(HasCookie(chrome::GetWebContentsAt(browser(), 0), "app2=4"));
163 EXPECT_TRUE(HasCookie(browser()->GetWebContentsAt(0), "normalPage=5")); 164 EXPECT_TRUE(HasCookie(chrome::GetWebContentsAt(browser(), 0), "normalPage=5")) ;
164 EXPECT_TRUE(HasCookie(browser()->GetWebContentsAt(0), "nonAppFrame=6")); 165 EXPECT_TRUE(HasCookie(chrome::GetWebContentsAt(browser(), 0), "nonAppFrame=6") );
165 EXPECT_TRUE(HasCookie(browser()->GetWebContentsAt(1), "app1=3")); 166 EXPECT_TRUE(HasCookie(chrome::GetWebContentsAt(browser(), 1), "app1=3"));
166 EXPECT_TRUE(HasCookie(browser()->GetWebContentsAt(1), "normalPage=5")); 167 EXPECT_TRUE(HasCookie(chrome::GetWebContentsAt(browser(), 1), "normalPage=5")) ;
167 EXPECT_TRUE(HasCookie(browser()->GetWebContentsAt(1), "nonAppFrame=6")); 168 EXPECT_TRUE(HasCookie(chrome::GetWebContentsAt(browser(), 1), "nonAppFrame=6") );
168 EXPECT_TRUE(HasCookie(browser()->GetWebContentsAt(2), "app1=3")); 169 EXPECT_TRUE(HasCookie(chrome::GetWebContentsAt(browser(), 2), "app1=3"));
169 EXPECT_TRUE(HasCookie(browser()->GetWebContentsAt(2), "app2=4")); 170 EXPECT_TRUE(HasCookie(chrome::GetWebContentsAt(browser(), 2), "app2=4"));
170 EXPECT_TRUE(HasCookie(browser()->GetWebContentsAt(2), "nonAppFrame=6")); 171 EXPECT_TRUE(HasCookie(chrome::GetWebContentsAt(browser(), 2), "nonAppFrame=6") );
171 } 172 }
172 173
173 // Tests that isolated apps processes do not render top-level non-app pages. 174 // Tests that isolated apps processes do not render top-level non-app pages.
174 // This is true even in the case of the OAuth workaround for hosted apps, 175 // This is true even in the case of the OAuth workaround for hosted apps,
175 // where non-app popups may be kept in the hosted app process. 176 // where non-app popups may be kept in the hosted app process.
176 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, IsolatedAppProcessModel) { 177 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, IsolatedAppProcessModel) {
177 host_resolver()->AddRule("*", "127.0.0.1"); 178 host_resolver()->AddRule("*", "127.0.0.1");
178 ASSERT_TRUE(test_server()->Start()); 179 ASSERT_TRUE(test_server()->Start());
179 180
180 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1"))); 181 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1")));
181 182
182 // The app under test acts on URLs whose host is "localhost", 183 // The app under test acts on URLs whose host is "localhost",
183 // so the URLs we navigate to must have host "localhost". 184 // so the URLs we navigate to must have host "localhost".
184 GURL base_url = test_server()->GetURL( 185 GURL base_url = test_server()->GetURL(
185 "files/extensions/isolated_apps/"); 186 "files/extensions/isolated_apps/");
186 GURL::Replacements replace_host; 187 GURL::Replacements replace_host;
187 std::string host_str("localhost"); // Must stay in scope with replace_host. 188 std::string host_str("localhost"); // Must stay in scope with replace_host.
188 replace_host.SetHostStr(host_str); 189 replace_host.SetHostStr(host_str);
189 base_url = base_url.ReplaceComponents(replace_host); 190 base_url = base_url.ReplaceComponents(replace_host);
190 191
191 // Create three tabs in the isolated app in different ways. 192 // Create three tabs in the isolated app in different ways.
192 ui_test_utils::NavigateToURLWithDisposition( 193 ui_test_utils::NavigateToURLWithDisposition(
193 browser(), base_url.Resolve("app1/main.html"), 194 browser(), base_url.Resolve("app1/main.html"),
194 CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 195 CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
195 ui_test_utils::NavigateToURLWithDisposition( 196 ui_test_utils::NavigateToURLWithDisposition(
196 browser(), base_url.Resolve("app1/main.html"), 197 browser(), base_url.Resolve("app1/main.html"),
197 NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 198 NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
198 // For the third tab, use window.open to keep it in process with an opener. 199 // For the third tab, use window.open to keep it in process with an opener.
199 OpenWindow(browser()->GetWebContentsAt(0), 200 OpenWindow(chrome::GetWebContentsAt(browser(), 0),
200 base_url.Resolve("app1/main.html"), true, NULL); 201 base_url.Resolve("app1/main.html"), true, NULL);
201 202
202 // In a fourth tab, use window.open to a non-app URL. It should open in a 203 // In a fourth tab, use window.open to a non-app URL. It should open in a
203 // separate process, even though this would trigger the OAuth workaround 204 // separate process, even though this would trigger the OAuth workaround
204 // for hosted apps (from http://crbug.com/59285). 205 // for hosted apps (from http://crbug.com/59285).
205 OpenWindow(browser()->GetWebContentsAt(0), 206 OpenWindow(chrome::GetWebContentsAt(browser(), 0),
206 base_url.Resolve("non_app/main.html"), false, NULL); 207 base_url.Resolve("non_app/main.html"), false, NULL);
207 208
208 // We should now have four tabs, the first and third sharing a process. 209 // We should now have four tabs, the first and third sharing a process.
209 // The second one is an independent instance in a separate process. 210 // The second one is an independent instance in a separate process.
210 ASSERT_EQ(4, browser()->tab_count()); 211 ASSERT_EQ(4, browser()->tab_count());
211 int process_id_0 = 212 int process_id_0 =
212 browser()->GetWebContentsAt(0)->GetRenderProcessHost()->GetID(); 213 chrome::GetWebContentsAt(browser(), 0)->GetRenderProcessHost()->GetID();
213 int process_id_1 = 214 int process_id_1 =
214 browser()->GetWebContentsAt(1)->GetRenderProcessHost()->GetID(); 215 chrome::GetWebContentsAt(browser(), 1)->GetRenderProcessHost()->GetID();
215 EXPECT_NE(process_id_0, process_id_1); 216 EXPECT_NE(process_id_0, process_id_1);
216 EXPECT_EQ(process_id_0, 217 EXPECT_EQ(process_id_0,
217 browser()->GetWebContentsAt(2)->GetRenderProcessHost()->GetID()); 218 chrome::GetWebContentsAt(browser(), 2)->GetRenderProcessHost()->GetI D());
218 EXPECT_NE(process_id_0, 219 EXPECT_NE(process_id_0,
219 browser()->GetWebContentsAt(3)->GetRenderProcessHost()->GetID()); 220 chrome::GetWebContentsAt(browser(), 3)->GetRenderProcessHost()->GetI D());
220 221
221 // Navigating the second tab out of the app should cause a process swap. 222 // Navigating the second tab out of the app should cause a process swap.
222 const GURL& non_app_url(base_url.Resolve("non_app/main.html")); 223 const GURL& non_app_url(base_url.Resolve("non_app/main.html"));
223 NavigateInRenderer(browser()->GetWebContentsAt(1), non_app_url); 224 NavigateInRenderer(chrome::GetWebContentsAt(browser(), 1), non_app_url);
224 EXPECT_NE(process_id_1, 225 EXPECT_NE(process_id_1,
225 browser()->GetWebContentsAt(1)->GetRenderProcessHost()->GetID()); 226 chrome::GetWebContentsAt(browser(), 1)->GetRenderProcessHost()->GetI D());
226 } 227 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698