| 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/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" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 // separation as you would expect. | 76 // separation as you would expect. |
| 77 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, CookieIsolation) { | 77 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, CookieIsolation) { |
| 78 host_resolver()->AddRule("*", "127.0.0.1"); | 78 host_resolver()->AddRule("*", "127.0.0.1"); |
| 79 ASSERT_TRUE(test_server()->Start()); | 79 ASSERT_TRUE(test_server()->Start()); |
| 80 | 80 |
| 81 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1"))); | 81 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1"))); |
| 82 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app2"))); | 82 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app2"))); |
| 83 | 83 |
| 84 // The app under test acts on URLs whose host is "localhost", | 84 // The app under test acts on URLs whose host is "localhost", |
| 85 // so the URLs we navigate to must have host "localhost". | 85 // so the URLs we navigate to must have host "localhost". |
| 86 GURL base_url = test_server()->GetURL( | 86 GURL base_url = test_server()->GetURL("files/extensions/isolated_apps/"); |
| 87 "files/extensions/isolated_apps/"); | |
| 88 GURL::Replacements replace_host; | 87 GURL::Replacements replace_host; |
| 89 std::string host_str("localhost"); // Must stay in scope with replace_host. | 88 std::string host_str("localhost"); // Must stay in scope with replace_host. |
| 90 replace_host.SetHostStr(host_str); | 89 replace_host.SetHostStr(host_str); |
| 91 base_url = base_url.ReplaceComponents(replace_host); | 90 base_url = base_url.ReplaceComponents(replace_host); |
| 92 | 91 |
| 93 ui_test_utils::NavigateToURLWithDisposition( | 92 ui_test_utils::NavigateToURLWithDisposition( |
| 94 browser(), base_url.Resolve("app1/main.html"), | 93 browser(), base_url.Resolve("app1/main.html"), |
| 95 CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 94 CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 96 ui_test_utils::NavigateToURLWithDisposition( | 95 ui_test_utils::NavigateToURLWithDisposition( |
| 97 browser(), base_url.Resolve("app2/main.html"), | 96 browser(), base_url.Resolve("app2/main.html"), |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 | 174 |
| 176 } | 175 } |
| 177 | 176 |
| 178 // Ensure that cookies are not isolated if the isolated apps are not installed. | 177 // Ensure that cookies are not isolated if the isolated apps are not installed. |
| 179 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, NoCookieIsolationWithoutApp) { | 178 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, NoCookieIsolationWithoutApp) { |
| 180 host_resolver()->AddRule("*", "127.0.0.1"); | 179 host_resolver()->AddRule("*", "127.0.0.1"); |
| 181 ASSERT_TRUE(test_server()->Start()); | 180 ASSERT_TRUE(test_server()->Start()); |
| 182 | 181 |
| 183 // The app under test acts on URLs whose host is "localhost", | 182 // The app under test acts on URLs whose host is "localhost", |
| 184 // so the URLs we navigate to must have host "localhost". | 183 // so the URLs we navigate to must have host "localhost". |
| 185 GURL base_url = test_server()->GetURL( | 184 GURL base_url = test_server()->GetURL("files/extensions/isolated_apps/"); |
| 186 "files/extensions/isolated_apps/"); | |
| 187 GURL::Replacements replace_host; | 185 GURL::Replacements replace_host; |
| 188 std::string host_str("localhost"); // Must stay in scope with replace_host. | 186 std::string host_str("localhost"); // Must stay in scope with replace_host. |
| 189 replace_host.SetHostStr(host_str); | 187 replace_host.SetHostStr(host_str); |
| 190 base_url = base_url.ReplaceComponents(replace_host); | 188 base_url = base_url.ReplaceComponents(replace_host); |
| 191 | 189 |
| 192 ui_test_utils::NavigateToURLWithDisposition( | 190 ui_test_utils::NavigateToURLWithDisposition( |
| 193 browser(), base_url.Resolve("app1/main.html"), | 191 browser(), base_url.Resolve("app1/main.html"), |
| 194 CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 192 CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 195 ui_test_utils::NavigateToURLWithDisposition( | 193 ui_test_utils::NavigateToURLWithDisposition( |
| 196 browser(), base_url.Resolve("app2/main.html"), | 194 browser(), base_url.Resolve("app2/main.html"), |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 app1_rvh, L"", kRetrieveLocalStorage.c_str(), &result)); | 233 app1_rvh, L"", kRetrieveLocalStorage.c_str(), &result)); |
| 236 EXPECT_EQ("ls_normal", result); | 234 EXPECT_EQ("ls_normal", result); |
| 237 ASSERT_TRUE(ExecuteJavaScriptAndExtractString( | 235 ASSERT_TRUE(ExecuteJavaScriptAndExtractString( |
| 238 app2_rvh, L"", kRetrieveLocalStorage.c_str(), &result)); | 236 app2_rvh, L"", kRetrieveLocalStorage.c_str(), &result)); |
| 239 EXPECT_EQ("ls_normal", result); | 237 EXPECT_EQ("ls_normal", result); |
| 240 ASSERT_TRUE(ExecuteJavaScriptAndExtractString( | 238 ASSERT_TRUE(ExecuteJavaScriptAndExtractString( |
| 241 non_app_rvh, L"", kRetrieveLocalStorage.c_str(), &result)); | 239 non_app_rvh, L"", kRetrieveLocalStorage.c_str(), &result)); |
| 242 EXPECT_EQ("ls_normal", result); | 240 EXPECT_EQ("ls_normal", result); |
| 243 } | 241 } |
| 244 | 242 |
| 243 // Tests that subresource and media requests use the app's cookie store. |
| 244 // See http://crbug.com/141172. |
| 245 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, SubresourceCookieIsolation) { |
| 246 host_resolver()->AddRule("*", "127.0.0.1"); |
| 247 ASSERT_TRUE(test_server()->Start()); |
| 248 |
| 249 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1"))); |
| 250 |
| 251 // The app under test acts on URLs whose host is "localhost", |
| 252 // so the URLs we navigate to must have host "localhost". |
| 253 GURL root_url = test_server()->GetURL(""); |
| 254 GURL base_url = test_server()->GetURL("files/extensions/isolated_apps/"); |
| 255 GURL::Replacements replace_host; |
| 256 std::string host_str("localhost"); // Must stay in scope with replace_host. |
| 257 replace_host.SetHostStr(host_str); |
| 258 root_url = root_url.ReplaceComponents(replace_host); |
| 259 base_url = base_url.ReplaceComponents(replace_host); |
| 260 |
| 261 // First set cookies inside and outside the app. |
| 262 ui_test_utils::NavigateToURLWithDisposition( |
| 263 browser(), root_url.Resolve("set-cookie?nonApp=1"), |
| 264 CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 265 WebContents* tab0 = chrome::GetWebContentsAt(browser(), 0); |
| 266 ASSERT_FALSE(GetInstalledApp(tab0)); |
| 267 ui_test_utils::NavigateToURLWithDisposition( |
| 268 browser(), base_url.Resolve("app1/main.html"), |
| 269 NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 270 WebContents* tab1 = chrome::GetWebContentsAt(browser(), 1); |
| 271 ASSERT_TRUE(GetInstalledApp(tab1)); |
| 272 |
| 273 // Check that each tab sees its own cookie. |
| 274 EXPECT_TRUE(HasCookie(tab0, "nonApp=1")); |
| 275 EXPECT_FALSE(HasCookie(tab0, "app1=3")); |
| 276 EXPECT_FALSE(HasCookie(tab1, "nonApp=1")); |
| 277 EXPECT_TRUE(HasCookie(tab1, "app1=3")); |
| 278 |
| 279 // Now visit an app page that loads subresources located outside the app. |
| 280 // For both images and video tags, it loads two URLs: |
| 281 // - One will set nonApp{Media,Image}=1 cookies if nonApp=1 is set. |
| 282 // - One will set app1{Media,Image}=1 cookies if app1=3 is set. |
| 283 // We expect only the app's cookies to be present. |
| 284 // We must wait for the onload event, to allow the subresources to finish. |
| 285 content::WindowedNotificationObserver observer( |
| 286 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 287 content::Source<WebContents>(chrome::GetActiveWebContents(browser()))); |
| 288 ui_test_utils::NavigateToURLWithDisposition( |
| 289 browser(), base_url.Resolve("app1/app_subresources.html"), |
| 290 CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 291 observer.Wait(); |
| 292 EXPECT_FALSE(HasCookie(tab1, "nonAppMedia=1")); |
| 293 EXPECT_TRUE(HasCookie(tab1, "app1Media=1")); |
| 294 EXPECT_FALSE(HasCookie(tab1, "nonAppImage=1")); |
| 295 EXPECT_TRUE(HasCookie(tab1, "app1Image=1")); |
| 296 |
| 297 // Also create a non-app tab to ensure no new cookies were set in that jar. |
| 298 ui_test_utils::NavigateToURLWithDisposition( |
| 299 browser(), root_url, |
| 300 NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 301 WebContents* tab2 = chrome::GetWebContentsAt(browser(), 2); |
| 302 EXPECT_FALSE(HasCookie(tab2, "nonAppMedia=1")); |
| 303 EXPECT_FALSE(HasCookie(tab2, "app1Media=1")); |
| 304 EXPECT_FALSE(HasCookie(tab2, "nonAppImage=1")); |
| 305 EXPECT_FALSE(HasCookie(tab2, "app1Image=1")); |
| 306 } |
| 307 |
| 245 // Tests that isolated apps processes do not render top-level non-app pages. | 308 // Tests that isolated apps processes do not render top-level non-app pages. |
| 246 // This is true even in the case of the OAuth workaround for hosted apps, | 309 // This is true even in the case of the OAuth workaround for hosted apps, |
| 247 // where non-app popups may be kept in the hosted app process. | 310 // where non-app popups may be kept in the hosted app process. |
| 248 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, IsolatedAppProcessModel) { | 311 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, IsolatedAppProcessModel) { |
| 249 host_resolver()->AddRule("*", "127.0.0.1"); | 312 host_resolver()->AddRule("*", "127.0.0.1"); |
| 250 ASSERT_TRUE(test_server()->Start()); | 313 ASSERT_TRUE(test_server()->Start()); |
| 251 | 314 |
| 252 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1"))); | 315 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1"))); |
| 253 | 316 |
| 254 // The app under test acts on URLs whose host is "localhost", | 317 // The app under test acts on URLs whose host is "localhost", |
| 255 // so the URLs we navigate to must have host "localhost". | 318 // so the URLs we navigate to must have host "localhost". |
| 256 GURL base_url = test_server()->GetURL( | 319 GURL base_url = test_server()->GetURL("files/extensions/isolated_apps/"); |
| 257 "files/extensions/isolated_apps/"); | |
| 258 GURL::Replacements replace_host; | 320 GURL::Replacements replace_host; |
| 259 std::string host_str("localhost"); // Must stay in scope with replace_host. | 321 std::string host_str("localhost"); // Must stay in scope with replace_host. |
| 260 replace_host.SetHostStr(host_str); | 322 replace_host.SetHostStr(host_str); |
| 261 base_url = base_url.ReplaceComponents(replace_host); | 323 base_url = base_url.ReplaceComponents(replace_host); |
| 262 | 324 |
| 263 // Create three tabs in the isolated app in different ways. | 325 // Create three tabs in the isolated app in different ways. |
| 264 ui_test_utils::NavigateToURLWithDisposition( | 326 ui_test_utils::NavigateToURLWithDisposition( |
| 265 browser(), base_url.Resolve("app1/main.html"), | 327 browser(), base_url.Resolve("app1/main.html"), |
| 266 CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 328 CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 267 ui_test_utils::NavigateToURLWithDisposition( | 329 ui_test_utils::NavigateToURLWithDisposition( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 | 361 |
| 300 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, SessionStorage) { | 362 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, SessionStorage) { |
| 301 host_resolver()->AddRule("*", "127.0.0.1"); | 363 host_resolver()->AddRule("*", "127.0.0.1"); |
| 302 ASSERT_TRUE(test_server()->Start()); | 364 ASSERT_TRUE(test_server()->Start()); |
| 303 | 365 |
| 304 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1"))); | 366 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1"))); |
| 305 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app2"))); | 367 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app2"))); |
| 306 | 368 |
| 307 // The app under test acts on URLs whose host is "localhost", | 369 // The app under test acts on URLs whose host is "localhost", |
| 308 // so the URLs we navigate to must have host "localhost". | 370 // so the URLs we navigate to must have host "localhost". |
| 309 GURL base_url = test_server()->GetURL( | 371 GURL base_url = test_server()->GetURL("files/extensions/isolated_apps/"); |
| 310 "files/extensions/isolated_apps/"); | |
| 311 GURL::Replacements replace_host; | 372 GURL::Replacements replace_host; |
| 312 std::string host_str("localhost"); // Must stay in scope with replace_host. | 373 std::string host_str("localhost"); // Must stay in scope with replace_host. |
| 313 replace_host.SetHostStr(host_str); | 374 replace_host.SetHostStr(host_str); |
| 314 base_url = base_url.ReplaceComponents(replace_host); | 375 base_url = base_url.ReplaceComponents(replace_host); |
| 315 | 376 |
| 316 // Enter some state into sessionStorage three times on the same origin, but | 377 // Enter some state into sessionStorage three times on the same origin, but |
| 317 // for three URLs that correspond to app1, app2, and a non-isolated site. | 378 // for three URLs that correspond to app1, app2, and a non-isolated site. |
| 318 ui_test_utils::NavigateToURLWithDisposition( | 379 ui_test_utils::NavigateToURLWithDisposition( |
| 319 browser(), base_url.Resolve("app1/main.html"), | 380 browser(), base_url.Resolve("app1/main.html"), |
| 320 CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 381 CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 EXPECT_EQ("ss_app2", result); | 423 EXPECT_EQ("ss_app2", result); |
| 363 | 424 |
| 364 ui_test_utils::NavigateToURLWithDisposition( | 425 ui_test_utils::NavigateToURLWithDisposition( |
| 365 browser(), base_url.Resolve("non_app/main.html"), | 426 browser(), base_url.Resolve("non_app/main.html"), |
| 366 CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 427 CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 367 ASSERT_TRUE(ExecuteJavaScriptAndExtractString( | 428 ASSERT_TRUE(ExecuteJavaScriptAndExtractString( |
| 368 chrome::GetWebContentsAt(browser(), 0)->GetRenderViewHost(), | 429 chrome::GetWebContentsAt(browser(), 0)->GetRenderViewHost(), |
| 369 L"", kRetrieveSessionStorage.c_str(), &result)); | 430 L"", kRetrieveSessionStorage.c_str(), &result)); |
| 370 EXPECT_EQ("ss_normal", result); | 431 EXPECT_EQ("ss_normal", result); |
| 371 } | 432 } |
| OLD | NEW |