| 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 ASSERT_EQ(3, browser()->tab_count()); | 108 ASSERT_EQ(3, browser()->tab_count()); |
| 109 | 109 |
| 110 // Ensure first two tabs have installed apps. | 110 // Ensure first two tabs have installed apps. |
| 111 WebContents* tab1 = chrome::GetWebContentsAt(browser(), 0); | 111 WebContents* tab1 = chrome::GetWebContentsAt(browser(), 0); |
| 112 WebContents* tab2 = chrome::GetWebContentsAt(browser(), 1); | 112 WebContents* tab2 = chrome::GetWebContentsAt(browser(), 1); |
| 113 WebContents* tab3 = chrome::GetWebContentsAt(browser(), 2); | 113 WebContents* tab3 = chrome::GetWebContentsAt(browser(), 2); |
| 114 ASSERT_TRUE(GetInstalledApp(tab1)); | 114 ASSERT_TRUE(GetInstalledApp(tab1)); |
| 115 ASSERT_TRUE(GetInstalledApp(tab2)); | 115 ASSERT_TRUE(GetInstalledApp(tab2)); |
| 116 ASSERT_TRUE(!GetInstalledApp(tab3)); | 116 ASSERT_TRUE(!GetInstalledApp(tab3)); |
| 117 | 117 |
| 118 // Check that tabs see cannot each other's localStorage even though they are |
| 119 // in the same origin. |
| 120 RenderViewHost* app1_rvh = tab1->GetRenderViewHost(); |
| 121 RenderViewHost* app2_rvh = tab2->GetRenderViewHost(); |
| 122 RenderViewHost* non_app_rvh = tab3->GetRenderViewHost(); |
| 123 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( |
| 124 app1_rvh, L"", L"window.localStorage.setItem('testdata', 'ls_app1');")); |
| 125 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( |
| 126 app2_rvh, L"", L"window.localStorage.setItem('testdata', 'ls_app2');")); |
| 127 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( |
| 128 non_app_rvh, L"", |
| 129 L"window.localStorage.setItem('testdata', 'ls_normal');")); |
| 130 |
| 131 ASSERT_TRUE(ExecuteJavaScript( |
| 132 app1_rvh, L"", L"window.localStorage.getItem('testdata');")); |
| 133 |
| 134 const std::wstring& kRetrieveLocalStorage = |
| 135 WrapForJavascriptAndExtract(L"window.localStorage.getItem('testdata')"); |
| 136 std::string result; |
| 137 ASSERT_TRUE(ExecuteJavaScriptAndExtractString( |
| 138 app1_rvh, L"", kRetrieveLocalStorage.c_str(), &result)); |
| 139 EXPECT_EQ("ls_app1", result); |
| 140 ASSERT_TRUE(ExecuteJavaScriptAndExtractString( |
| 141 app2_rvh, L"", kRetrieveLocalStorage.c_str(), &result)); |
| 142 EXPECT_EQ("ls_app2", result); |
| 143 ASSERT_TRUE(ExecuteJavaScriptAndExtractString( |
| 144 non_app_rvh, L"", kRetrieveLocalStorage.c_str(), &result)); |
| 145 EXPECT_EQ("ls_normal", result); |
| 146 |
| 118 // Check that each tab sees its own cookie. | 147 // Check that each tab sees its own cookie. |
| 119 EXPECT_TRUE(HasCookie(tab1, "app1=3")); | 148 EXPECT_TRUE(HasCookie(tab1, "app1=3")); |
| 120 EXPECT_TRUE(HasCookie(tab2, "app2=4")); | 149 EXPECT_TRUE(HasCookie(tab2, "app2=4")); |
| 121 EXPECT_TRUE(HasCookie(tab3, "normalPage=5")); | 150 EXPECT_TRUE(HasCookie(tab3, "normalPage=5")); |
| 122 | 151 |
| 123 // Check that app1 tab cannot see the other cookies. | 152 // Check that app1 tab cannot see the other cookies. |
| 124 EXPECT_FALSE(HasCookie(tab1, "app2")); | 153 EXPECT_FALSE(HasCookie(tab1, "app2")); |
| 125 EXPECT_FALSE(HasCookie(tab1, "normalPage")); | 154 EXPECT_FALSE(HasCookie(tab1, "normalPage")); |
| 126 | 155 |
| 127 // Check that app2 tab cannot see the other cookies. | 156 // Check that app2 tab cannot see the other cookies. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 144 ui_test_utils::WindowedNotificationObserver observer( | 173 ui_test_utils::WindowedNotificationObserver observer( |
| 145 content::NOTIFICATION_LOAD_STOP, | 174 content::NOTIFICATION_LOAD_STOP, |
| 146 content::Source<NavigationController>( | 175 content::Source<NavigationController>( |
| 147 &chrome::GetActiveWebContents(browser())->GetController())); | 176 &chrome::GetActiveWebContents(browser())->GetController())); |
| 148 chrome::Reload(browser(), CURRENT_TAB); | 177 chrome::Reload(browser(), CURRENT_TAB); |
| 149 observer.Wait(); | 178 observer.Wait(); |
| 150 EXPECT_TRUE(HasCookie(tab1, "app1=3")); | 179 EXPECT_TRUE(HasCookie(tab1, "app1=3")); |
| 151 EXPECT_FALSE(HasCookie(tab1, "app2")); | 180 EXPECT_FALSE(HasCookie(tab1, "app2")); |
| 152 EXPECT_FALSE(HasCookie(tab1, "normalPage")); | 181 EXPECT_FALSE(HasCookie(tab1, "normalPage")); |
| 153 | 182 |
| 154 // Check that tabs see cannot each other's localStorage even though they are | |
| 155 // in the same origin. | |
| 156 RenderViewHost* app1_rvh = tab1->GetRenderViewHost(); | |
| 157 RenderViewHost* app2_rvh = tab2->GetRenderViewHost(); | |
| 158 RenderViewHost* non_app_rvh = tab3->GetRenderViewHost(); | |
| 159 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( | |
| 160 app1_rvh, L"", L"window.localStorage.setItem('testdata', 'ls_app1');")); | |
| 161 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( | |
| 162 app2_rvh, L"", L"window.localStorage.setItem('testdata', 'ls_app2');")); | |
| 163 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( | |
| 164 non_app_rvh, L"", | |
| 165 L"window.localStorage.setItem('testdata', 'ls_normal');")); | |
| 166 | |
| 167 ASSERT_TRUE(ExecuteJavaScript( | |
| 168 app1_rvh, L"", L"window.localStorage.getItem('testdata');")); | |
| 169 | |
| 170 const std::wstring& kRetrieveLocalStorage = | |
| 171 WrapForJavascriptAndExtract(L"window.localStorage.getItem('testdata')"); | |
| 172 std::string result; | |
| 173 ASSERT_TRUE(ExecuteJavaScriptAndExtractString( | |
| 174 app1_rvh, L"", kRetrieveLocalStorage.c_str(), &result)); | |
| 175 EXPECT_EQ("ls_app1", result); | |
| 176 ASSERT_TRUE(ExecuteJavaScriptAndExtractString( | |
| 177 app2_rvh, L"", kRetrieveLocalStorage.c_str(), &result)); | |
| 178 EXPECT_EQ("ls_app2", result); | |
| 179 ASSERT_TRUE(ExecuteJavaScriptAndExtractString( | |
| 180 non_app_rvh, L"", kRetrieveLocalStorage.c_str(), &result)); | |
| 181 EXPECT_EQ("ls_normal", result); | |
| 182 } | 183 } |
| 183 | 184 |
| 184 // Ensure that cookies are not isolated if the isolated apps are not installed. | 185 // Ensure that cookies are not isolated if the isolated apps are not installed. |
| 185 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, NoCookieIsolationWithoutApp) { | 186 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, NoCookieIsolationWithoutApp) { |
| 186 host_resolver()->AddRule("*", "127.0.0.1"); | 187 host_resolver()->AddRule("*", "127.0.0.1"); |
| 187 ASSERT_TRUE(test_server()->Start()); | 188 ASSERT_TRUE(test_server()->Start()); |
| 188 | 189 |
| 189 // The app under test acts on URLs whose host is "localhost", | 190 // The app under test acts on URLs whose host is "localhost", |
| 190 // so the URLs we navigate to must have host "localhost". | 191 // so the URLs we navigate to must have host "localhost". |
| 191 GURL base_url = test_server()->GetURL( | 192 GURL base_url = test_server()->GetURL( |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 chrome::GetWebContentsAt(browser(), 2)->GetRenderProcessHost()->GetI
D()); | 296 chrome::GetWebContentsAt(browser(), 2)->GetRenderProcessHost()->GetI
D()); |
| 296 EXPECT_NE(process_id_0, | 297 EXPECT_NE(process_id_0, |
| 297 chrome::GetWebContentsAt(browser(), 3)->GetRenderProcessHost()->GetI
D()); | 298 chrome::GetWebContentsAt(browser(), 3)->GetRenderProcessHost()->GetI
D()); |
| 298 | 299 |
| 299 // Navigating the second tab out of the app should cause a process swap. | 300 // Navigating the second tab out of the app should cause a process swap. |
| 300 const GURL& non_app_url(base_url.Resolve("non_app/main.html")); | 301 const GURL& non_app_url(base_url.Resolve("non_app/main.html")); |
| 301 NavigateInRenderer(chrome::GetWebContentsAt(browser(), 1), non_app_url); | 302 NavigateInRenderer(chrome::GetWebContentsAt(browser(), 1), non_app_url); |
| 302 EXPECT_NE(process_id_1, | 303 EXPECT_NE(process_id_1, |
| 303 chrome::GetWebContentsAt(browser(), 1)->GetRenderProcessHost()->GetI
D()); | 304 chrome::GetWebContentsAt(browser(), 1)->GetRenderProcessHost()->GetI
D()); |
| 304 } | 305 } |
| OLD | NEW |