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

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

Issue 10600009: Support partitioning of storage contexts based on render_id. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix comments 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
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/tab_contents/tab_contents.h" 13 #include "chrome/browser/ui/tab_contents/tab_contents.h"
14 #include "chrome/common/chrome_switches.h" 14 #include "chrome/common/chrome_switches.h"
15 #include "chrome/common/url_constants.h" 15 #include "chrome/common/url_constants.h"
16 #include "chrome/test/base/ui_test_utils.h" 16 #include "chrome/test/base/ui_test_utils.h"
17 #include "content/public/browser/render_process_host.h" 17 #include "content/public/browser/render_process_host.h"
18 #include "content/public/browser/render_view_host.h" 18 #include "content/public/browser/render_view_host.h"
19 #include "content/public/browser/site_instance.h" 19 #include "content/public/browser/site_instance.h"
20 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
21 #include "net/base/mock_host_resolver.h" 21 #include "net/base/mock_host_resolver.h"
22 22
23 using content::NavigationController; 23 using content::NavigationController;
24 using content::WebContents; 24 using content::WebContents;
25 using content::RenderViewHost;
26 using ui_test_utils::ExecuteJavaScript;
27 using ui_test_utils::ExecuteJavaScriptAndExtractString;
25 28
26 namespace { 29 namespace {
27 30
28 class IsolatedAppTest : public ExtensionBrowserTest { 31 class IsolatedAppTest : public ExtensionBrowserTest {
29 public: 32 public:
30 // Returns whether the given tab's current URL has the given cookie. 33 // Returns whether the given tab's current URL has the given cookie.
31 bool WARN_UNUSED_RESULT HasCookie(WebContents* contents, std::string cookie) { 34 bool WARN_UNUSED_RESULT HasCookie(WebContents* contents, std::string cookie) {
32 int value_size; 35 int value_size;
33 std::string actual_cookie; 36 std::string actual_cookie;
34 automation_util::GetCookies(contents->GetURL(), contents, &value_size, 37 automation_util::GetCookies(contents->GetURL(), contents, &value_size,
(...skipping 17 matching lines...) Expand all
52 virtual void SetUpCommandLine(CommandLine* command_line) { 55 virtual void SetUpCommandLine(CommandLine* command_line) {
53 ExtensionBrowserTest::SetUpCommandLine(command_line); 56 ExtensionBrowserTest::SetUpCommandLine(command_line);
54 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); 57 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
55 } 58 }
56 }; 59 };
57 60
58 } // namespace 61 } // namespace
59 62
60 // Tests that cookies set within an isolated app are not visible to normal 63 // Tests that cookies set within an isolated app are not visible to normal
61 // pages or other apps. 64 // pages or other apps.
65 //
66 // TODO(ajwong): Also test what happens if an app spans multiple sites in its
67 // extent. These origins should also be isolated, but still have origin-based
68 // separation as you would expect.
69 //
70 // TODO(ajwong): How do we test sessionStorage? Install app and watch
71 // sessionStorage get wiped away during reload?
Charlie Reis 2012/07/02 23:21:23 Normally session storage exists for the lifetime o
awong 2012/07/09 20:37:43 I've amended the comment. FYI, session storage is
62 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, CookieIsolation) { 72 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, CookieIsolation) {
63 host_resolver()->AddRule("*", "127.0.0.1"); 73 host_resolver()->AddRule("*", "127.0.0.1");
64 ASSERT_TRUE(test_server()->Start()); 74 ASSERT_TRUE(test_server()->Start());
65 75
66 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1"))); 76 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1")));
67 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app2"))); 77 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app2")));
68 78
69 // The app under test acts on URLs whose host is "localhost", 79 // The app under test acts on URLs whose host is "localhost",
70 // so the URLs we navigate to must have host "localhost". 80 // so the URLs we navigate to must have host "localhost".
71 GURL base_url = test_server()->GetURL( 81 GURL base_url = test_server()->GetURL(
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 EXPECT_FALSE(HasCookie(tab3, "app1")); 122 EXPECT_FALSE(HasCookie(tab3, "app1"));
113 EXPECT_FALSE(HasCookie(tab3, "app2")); 123 EXPECT_FALSE(HasCookie(tab3, "app2"));
114 124
115 // Check that the non_app iframe cookie is associated with app1 and not the 125 // Check that the non_app iframe cookie is associated with app1 and not the
116 // normal tab. (For now, iframes are always rendered in their parent 126 // normal tab. (For now, iframes are always rendered in their parent
117 // process, even if they aren't in the app manifest.) 127 // process, even if they aren't in the app manifest.)
118 EXPECT_TRUE(HasCookie(tab1, "nonAppFrame=6")); 128 EXPECT_TRUE(HasCookie(tab1, "nonAppFrame=6"));
119 EXPECT_FALSE(HasCookie(tab3, "nonAppFrame")); 129 EXPECT_FALSE(HasCookie(tab3, "nonAppFrame"));
120 130
121 // Check that isolation persists even if the tab crashes and is reloaded. 131 // Check that isolation persists even if the tab crashes and is reloaded.
122 chrome::SelectNumberedTab(browser(), 1); 132 chrome::SelectNumberedTab(browser(), 0);
123 ui_test_utils::CrashTab(tab1); 133 ui_test_utils::CrashTab(tab1);
124 ui_test_utils::WindowedNotificationObserver observer( 134 ui_test_utils::WindowedNotificationObserver observer(
125 content::NOTIFICATION_LOAD_STOP, 135 content::NOTIFICATION_LOAD_STOP,
126 content::Source<NavigationController>( 136 content::Source<NavigationController>(
127 &browser()->GetActiveWebContents()->GetController())); 137 &browser()->GetActiveWebContents()->GetController()));
128 chrome::Reload(browser(), CURRENT_TAB); 138 chrome::Reload(browser(), CURRENT_TAB);
129 observer.Wait(); 139 observer.Wait();
130 EXPECT_TRUE(HasCookie(tab1, "app1=3")); 140 EXPECT_TRUE(HasCookie(tab1, "app1=3"));
131 EXPECT_FALSE(HasCookie(tab1, "app2")); 141 EXPECT_FALSE(HasCookie(tab1, "app2"));
132 EXPECT_FALSE(HasCookie(tab1, "normalPage")); 142 EXPECT_FALSE(HasCookie(tab1, "normalPage"));
143
144 // Check that tabs see cannot each others localStorage even though they are
Charlie Reis 2012/07/02 23:21:23 nit: other's
awong 2012/07/09 20:37:43 Done.
145 // in the same origin.
146 RenderViewHost* app1_rvh = tab1->GetRenderViewHost();
147 RenderViewHost* app2_rvh = tab2->GetRenderViewHost();
148 RenderViewHost* non_app_rvh = tab3->GetRenderViewHost();
149 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(
150 app1_rvh, L"", L"window.localStorage.setItem('testdata', 'ls_app1');"));
151 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(
152 app2_rvh, L"", L"window.localStorage.setItem('testdata', 'ls_app2');"));
153 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(
154 non_app_rvh, L"",
155 L"window.localStorage.setItem('testdata', 'ls_normal');"));
156
157 std::string result;
158 ASSERT_TRUE(ExecuteJavaScriptAndExtractString(
159 app1_rvh, L"", L"window.localStorage.getItem('testdata');", &result));
160 EXPECT_EQ("ls_app1", result);
161 ASSERT_TRUE(ExecuteJavaScriptAndExtractString(
162 app2_rvh, L"", L"window.localStorage.getItem('testdata');", &result));
163 EXPECT_EQ("ls_app2", result);
164 ASSERT_TRUE(ExecuteJavaScriptAndExtractString(
165 non_app_rvh, L"", L"window.localStorage.getItem('testdata');", &result));
166 EXPECT_EQ("ls_normal", result);
133 } 167 }
134 168
135 // Ensure that cookies are not isolated if the isolated apps are not installed. 169 // Ensure that cookies are not isolated if the isolated apps are not installed.
136 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, NoCookieIsolationWithoutApp) { 170 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, NoCookieIsolationWithoutApp) {
137 host_resolver()->AddRule("*", "127.0.0.1"); 171 host_resolver()->AddRule("*", "127.0.0.1");
138 ASSERT_TRUE(test_server()->Start()); 172 ASSERT_TRUE(test_server()->Start());
139 173
140 // The app under test acts on URLs whose host is "localhost", 174 // The app under test acts on URLs whose host is "localhost",
141 // so the URLs we navigate to must have host "localhost". 175 // so the URLs we navigate to must have host "localhost".
142 GURL base_url = test_server()->GetURL( 176 GURL base_url = test_server()->GetURL(
(...skipping 18 matching lines...) Expand all
161 // Check that tabs see each others' cookies. 195 // Check that tabs see each others' cookies.
162 EXPECT_TRUE(HasCookie(browser()->GetWebContentsAt(0), "app2=4")); 196 EXPECT_TRUE(HasCookie(browser()->GetWebContentsAt(0), "app2=4"));
163 EXPECT_TRUE(HasCookie(browser()->GetWebContentsAt(0), "normalPage=5")); 197 EXPECT_TRUE(HasCookie(browser()->GetWebContentsAt(0), "normalPage=5"));
164 EXPECT_TRUE(HasCookie(browser()->GetWebContentsAt(0), "nonAppFrame=6")); 198 EXPECT_TRUE(HasCookie(browser()->GetWebContentsAt(0), "nonAppFrame=6"));
165 EXPECT_TRUE(HasCookie(browser()->GetWebContentsAt(1), "app1=3")); 199 EXPECT_TRUE(HasCookie(browser()->GetWebContentsAt(1), "app1=3"));
166 EXPECT_TRUE(HasCookie(browser()->GetWebContentsAt(1), "normalPage=5")); 200 EXPECT_TRUE(HasCookie(browser()->GetWebContentsAt(1), "normalPage=5"));
167 EXPECT_TRUE(HasCookie(browser()->GetWebContentsAt(1), "nonAppFrame=6")); 201 EXPECT_TRUE(HasCookie(browser()->GetWebContentsAt(1), "nonAppFrame=6"));
168 EXPECT_TRUE(HasCookie(browser()->GetWebContentsAt(2), "app1=3")); 202 EXPECT_TRUE(HasCookie(browser()->GetWebContentsAt(2), "app1=3"));
169 EXPECT_TRUE(HasCookie(browser()->GetWebContentsAt(2), "app2=4")); 203 EXPECT_TRUE(HasCookie(browser()->GetWebContentsAt(2), "app2=4"));
170 EXPECT_TRUE(HasCookie(browser()->GetWebContentsAt(2), "nonAppFrame=6")); 204 EXPECT_TRUE(HasCookie(browser()->GetWebContentsAt(2), "nonAppFrame=6"));
205
206 // Check that all tabs share the same localStorage if they have the same
207 // origin.
208 RenderViewHost* app1_rvh =
209 browser()->GetWebContentsAt(0)->GetRenderViewHost();
210 RenderViewHost* app2_rvh =
211 browser()->GetWebContentsAt(1)->GetRenderViewHost();
212 RenderViewHost* non_app_rvh =
213 browser()->GetWebContentsAt(2)->GetRenderViewHost();
214 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(
215 app1_rvh, L"", L"window.localStorage.setItem('testdata', 'ls_app1');"));
216 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(
217 app2_rvh, L"", L"window.localStorage.setItem('testdata', 'ls_app2');"));
218 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(
219 non_app_rvh, L"",
220 L"window.localStorage.setItem('testdata', 'ls_normal');"));
221
222 std::string result;
223 ASSERT_TRUE(ExecuteJavaScriptAndExtractString(
224 app1_rvh, L"", L"window.localStorage.getItem('testdata');", &result));
225 EXPECT_EQ("ls_normal", result);
226 ASSERT_TRUE(ExecuteJavaScriptAndExtractString(
227 app2_rvh, L"", L"window.localStorage.getItem('testdata');", &result));
228 EXPECT_EQ("ls_normal", result);
229 ASSERT_TRUE(ExecuteJavaScriptAndExtractString(
230 non_app_rvh, L"", L"window.localStorage.getItem('testdata');", &result));
231 EXPECT_EQ("ls_normal", result);
171 } 232 }
172 233
173 // Tests that isolated apps processes do not render top-level non-app pages. 234 // 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, 235 // 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. 236 // where non-app popups may be kept in the hosted app process.
176 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, IsolatedAppProcessModel) { 237 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, IsolatedAppProcessModel) {
177 host_resolver()->AddRule("*", "127.0.0.1"); 238 host_resolver()->AddRule("*", "127.0.0.1");
178 ASSERT_TRUE(test_server()->Start()); 239 ASSERT_TRUE(test_server()->Start());
179 240
180 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1"))); 241 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1")));
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 browser()->GetWebContentsAt(2)->GetRenderProcessHost()->GetID()); 278 browser()->GetWebContentsAt(2)->GetRenderProcessHost()->GetID());
218 EXPECT_NE(process_id_0, 279 EXPECT_NE(process_id_0,
219 browser()->GetWebContentsAt(3)->GetRenderProcessHost()->GetID()); 280 browser()->GetWebContentsAt(3)->GetRenderProcessHost()->GetID());
220 281
221 // Navigating the second tab out of the app should cause a process swap. 282 // 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")); 283 const GURL& non_app_url(base_url.Resolve("non_app/main.html"));
223 NavigateInRenderer(browser()->GetWebContentsAt(1), non_app_url); 284 NavigateInRenderer(browser()->GetWebContentsAt(1), non_app_url);
224 EXPECT_NE(process_id_1, 285 EXPECT_NE(process_id_1,
225 browser()->GetWebContentsAt(1)->GetRenderProcessHost()->GetID()); 286 browser()->GetWebContentsAt(1)->GetRenderProcessHost()->GetID());
226 } 287 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698