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

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

Issue 6201005: Initial support for partitioning cookies for isolated apps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 11 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
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/utf_string_conversions.h"
6 #include "chrome/browser/extensions/extension_apitest.h"
7 #include "chrome/browser/extensions/extension_host.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/renderer_host/render_view_host.h"
10 #include "chrome/browser/tab_contents/tab_contents.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/common/chrome_switches.h"
13 #include "chrome/test/ui_test_utils.h"
14 #include "net/base/mock_host_resolver.h"
15
16 class IsolatedAppApiTest : public ExtensionApiTest {
17 };
18
19 // Returns whether the given tab has a cookie with the given name=value pair.
20 static void QueryCookie(TabContents* contents, std::string cookie,
21 bool* result) {
22 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
Paweł Hajdan Jr. 2011/01/12 19:24:12 Do we really need to execute JS to get cookie valu
Charlie Reis 2011/01/19 19:10:26 Thanks-- that's nicer. I had to adapt it a bit fo
23 contents->render_view_host(), L"",
24 L"var index = document.cookie.indexOf('" + UTF8ToWide(cookie) + L"');"
25 L"window.domAutomationController.send(index != -1);",
26 result));
27 }
28
29 // Tests that cookies set within an isolated app are not visible to normal
30 // pages or other apps.
31 IN_PROC_BROWSER_TEST_F(IsolatedAppApiTest, CookieIsolation) {
32 CommandLine::ForCurrentProcess()->AppendSwitch(
33 switches::kDisablePopupBlocking);
34 CommandLine::ForCurrentProcess()->AppendSwitch(
35 switches::kEnableExperimentalAppManifests);
36
37 host_resolver()->AddRule("*", "127.0.0.1");
38 ASSERT_TRUE(test_server()->Start());
39
40 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1")));
41 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app2")));
42
43 // The app under test acts on URLs whose host is "localhost",
44 // so the URLs we navigate to must have host "localhost".
45 GURL base_url = test_server()->GetURL(
46 "files/extensions/api_test/isolated_apps/");
47 GURL::Replacements replace_host;
48 std::string host_str("localhost"); // must stay in scope with replace_host
49 replace_host.SetHostStr(host_str);
50 base_url = base_url.ReplaceComponents(replace_host);
51
52 browser()->NewTab();
53 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("app1/main.html"));
54 browser()->NewTab();
55 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("app2/main.html"));
56 browser()->NewTab();
57 ui_test_utils::NavigateToURL(browser(),
58 base_url.Resolve("non_app/main.html"));
59
60 // Check that each tab sees its own cookie.
61 bool result = false;
62 QueryCookie(browser()->GetTabContentsAt(1), "app1=3", &result);
63 ASSERT_TRUE(result);
64 QueryCookie(browser()->GetTabContentsAt(2), "app2=4", &result);
65 ASSERT_TRUE(result);
66 QueryCookie(browser()->GetTabContentsAt(3), "normalPage=5", &result);
67 ASSERT_TRUE(result);
68
69 // Check that app1 tab cannot see the other cookies.
70 // TODO(creis): Isolate apps from each other.
71 QueryCookie(browser()->GetTabContentsAt(1), "app2", &result);
72 ASSERT_FALSE(result);
73 QueryCookie(browser()->GetTabContentsAt(1), "normalPage", &result);
74 ASSERT_FALSE(result);
75
76 // Check that app2 tab cannot see the other cookies.
77 // TODO(creis): Isolate apps from each other.
78 QueryCookie(browser()->GetTabContentsAt(2), "app1", &result);
79 ASSERT_FALSE(result);
80 QueryCookie(browser()->GetTabContentsAt(2), "normalPage", &result);
81 ASSERT_FALSE(result);
82
83 // Check that normal tab cannot see the other cookies.
84 QueryCookie(browser()->GetTabContentsAt(3), "app1", &result);
85 ASSERT_FALSE(result);
86 QueryCookie(browser()->GetTabContentsAt(3), "app2", &result);
87 ASSERT_FALSE(result);
88 }
89
90 // Without the --enable-experimental-app-manifests flag, all the tabs
91 // should see each others' cookies.
92 IN_PROC_BROWSER_TEST_F(IsolatedAppApiTest, CookieIsolationRequiresFlag) {
93 CommandLine::ForCurrentProcess()->AppendSwitch(
94 switches::kDisablePopupBlocking);
95
96 host_resolver()->AddRule("*", "127.0.0.1");
97 ASSERT_TRUE(test_server()->Start());
98
99 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1")));
100 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app2")));
101
102 // The app under test acts on URLs whose host is "localhost",
103 // so the URLs we navigate to must have host "localhost".
104 GURL base_url = test_server()->GetURL(
105 "files/extensions/api_test/isolated_apps/");
106 GURL::Replacements replace_host;
107 std::string host_str("localhost"); // must stay in scope with replace_host
108 replace_host.SetHostStr(host_str);
109 base_url = base_url.ReplaceComponents(replace_host);
110
111 browser()->NewTab();
112 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("app1/main.html"));
113 browser()->NewTab();
114 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("app2/main.html"));
115 browser()->NewTab();
116 ui_test_utils::NavigateToURL(browser(),
117 base_url.Resolve("non_app/main.html"));
118
119 // Check that tabs see each others' cookies.
120 bool result = false;
121 QueryCookie(browser()->GetTabContentsAt(1), "app2=4", &result);
122 ASSERT_TRUE(result);
123 QueryCookie(browser()->GetTabContentsAt(1), "normalPage=5", &result);
124 ASSERT_TRUE(result);
125 QueryCookie(browser()->GetTabContentsAt(2), "app1=3", &result);
126 ASSERT_TRUE(result);
127 QueryCookie(browser()->GetTabContentsAt(2), "normalPage=5", &result);
128 ASSERT_TRUE(result);
129 QueryCookie(browser()->GetTabContentsAt(3), "app1=3", &result);
130 ASSERT_TRUE(result);
131 QueryCookie(browser()->GetTabContentsAt(3), "app2=4", &result);
132 ASSERT_TRUE(result);
133 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service.cc ('k') | chrome/browser/net/chrome_url_request_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698