blob: 58a92d8dfa7c28b2fe114b77082703460aa3ca2e [file] [log] [blame]
[email protected]aa84a7e2012-03-15 21:29:061// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]c145edad2009-11-18 02:14:272// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]218aa6a12011-09-13 17:38:385#include "base/bind.h"
[email protected]ee611372011-11-29 05:41:176#include "base/bind_helpers.h"
avi6846aef2015-12-26 01:09:387#include "base/macros.h"
Christian Dullweber10d62c12019-08-19 12:08:198#include "base/path_service.h"
Lei Zhangfe5b86932019-02-01 17:26:599#include "base/strings/stringprintf.h"
Christian Dullweber10d62c12019-08-19 12:08:1910#include "base/test/scoped_feature_list.h"
11#include "chrome/browser/content_settings/cookie_settings_factory.h"
[email protected]8ecad5e2010-12-02 21:18:3312#include "chrome/browser/profiles/profile.h"
[email protected]7b5dc002010-11-16 23:08:1013#include "chrome/browser/ui/browser.h"
[email protected]59253a652012-11-20 00:17:2614#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]30fde822011-10-28 09:49:0515#include "chrome/common/pref_names.h"
[email protected]af44e7fb2011-07-29 18:32:3216#include "chrome/test/base/in_process_browser_test.h"
17#include "chrome/test/base/ui_test_utils.h"
Christian Dullweber10d62c12019-08-19 12:08:1918#include "components/content_settings/core/browser/cookie_settings.h"
19#include "components/content_settings/core/common/features.h"
droger8ff2b7e2015-06-26 16:30:0220#include "components/content_settings/core/common/pref_names.h"
Christian Dullweber4a8afe22019-09-19 16:57:3221#include "components/network_session_configurator/common/network_switches.h"
brettwb1fc1b82016-02-02 00:19:0822#include "components/prefs/pref_service.h"
Christian Dullweber10d62c12019-08-19 12:08:1923#include "content/public/common/content_paths.h"
[email protected]88509ab2012-08-27 15:04:1424#include "content/public/test/browser_test_utils.h"
Mike Westdd5cc632018-09-07 17:44:2325#include "content/public/test/test_navigation_observer.h"
[email protected]f2cb3cf2013-03-21 01:40:5326#include "net/dns/mock_host_resolver.h"
svaldeze2745872015-11-04 23:30:2027#include "net/test/embedded_test_server/embedded_test_server.h"
[email protected]c145edad2009-11-18 02:14:2728
[email protected]631bb742011-11-02 11:29:3929using content::BrowserThread;
30
[email protected]9eaa18e2010-06-29 20:51:0131namespace {
32
Christian Dullweber4a8afe22019-09-19 16:57:3233// "ServiceWorker" is not handled correctly by content settings with secondary
34// pattern yet.
Christian Dullweber10d62c12019-08-19 12:08:1935const std::vector<std::string> kStorageTypes{
Christian Dullweber4a8afe22019-09-19 16:57:3236 "Cookie", "LocalStorage", "FileSystem", "SessionStorage",
37 "IndexedDb", "WebSql", "CacheStorage",
Christian Dullweber10d62c12019-08-19 12:08:1938};
39
[email protected]9eaa18e2010-06-29 20:51:0140class CookiePolicyBrowserTest : public InProcessBrowserTest {
41 protected:
Christian Dullweber4a8afe22019-09-19 16:57:3242 CookiePolicyBrowserTest()
43 : https_server_(net::EmbeddedTestServer::TYPE_HTTPS) {}
[email protected]c145edad2009-11-18 02:14:2744
jam1a5b5582017-05-01 16:50:1045 void SetUpOnMainThread() override {
46 host_resolver()->AddRule("*", "127.0.0.1");
Christian Dullweber10d62c12019-08-19 12:08:1947 base::FilePath path;
48 base::PathService::Get(content::DIR_TEST_DATA, &path);
Christian Dullweber4a8afe22019-09-19 16:57:3249 https_server_.ServeFilesFromDirectory(path);
50 https_server_.AddDefaultHandlers(GetChromeTestDataDir());
51 ASSERT_TRUE(https_server_.Start());
52 }
53
54 void SetUpCommandLine(base::CommandLine* command_line) override {
55 // HTTPS server only serves a valid cert for localhost, so this is needed
56 // to load pages from other hosts without an error.
57 command_line->AppendSwitch(switches::kIgnoreCertificateErrors);
Mike Westdd5cc632018-09-07 17:44:2358 }
59
60 void SetBlockThirdPartyCookies(bool value) {
61 browser()->profile()->GetPrefs()->SetBoolean(prefs::kBlockThirdPartyCookies,
62 value);
63 }
64
65 void NavigateToPageWithFrame(const std::string& host) {
Christian Dullweber4a8afe22019-09-19 16:57:3266 GURL main_url(https_server_.GetURL(host, "/iframe.html"));
Mike Westdd5cc632018-09-07 17:44:2367 ui_test_utils::NavigateToURL(browser(), main_url);
68 }
69
70 void NavigateFrameTo(const std::string& host, const std::string& path) {
Christian Dullweber4a8afe22019-09-19 16:57:3271 GURL page = https_server_.GetURL(host, path);
Mike Westdd5cc632018-09-07 17:44:2372 content::WebContents* web_contents =
73 browser()->tab_strip_model()->GetActiveWebContents();
74 EXPECT_TRUE(NavigateIframeToURL(web_contents, "test", page));
75 }
76
77 void ExpectFrameContent(const std::string& expected) {
Mike Westdd5cc632018-09-07 17:44:2378 std::string content;
79 ASSERT_TRUE(ExecuteScriptAndExtractString(
Christian Dullweber10d62c12019-08-19 12:08:1980 GetFrame(),
Mike Westdd5cc632018-09-07 17:44:2381 "window.domAutomationController.send(document.body.textContent)",
82 &content));
83 EXPECT_EQ(expected, content);
84 }
85
86 void NavigateNestedFrameTo(const std::string& host, const std::string& path) {
Christian Dullweber4a8afe22019-09-19 16:57:3287 GURL url(https_server_.GetURL(host, path));
Mike Westdd5cc632018-09-07 17:44:2388 content::WebContents* web_contents =
89 browser()->tab_strip_model()->GetActiveWebContents();
Mike Westdd5cc632018-09-07 17:44:2390 content::TestNavigationObserver load_observer(web_contents);
91 ASSERT_TRUE(ExecuteScript(
Christian Dullweber10d62c12019-08-19 12:08:1992 GetFrame(),
Mike Westdd5cc632018-09-07 17:44:2393 base::StringPrintf("document.body.querySelector('iframe').src = '%s';",
94 url.spec().c_str())));
95 load_observer.Wait();
96 }
97
98 void ExpectNestedFrameContent(const std::string& expected) {
Mike Westdd5cc632018-09-07 17:44:2399 std::string content;
100 ASSERT_TRUE(ExecuteScriptAndExtractString(
Christian Dullweber10d62c12019-08-19 12:08:19101 GetNestedFrame(),
Mike Westdd5cc632018-09-07 17:44:23102 "window.domAutomationController.send(document.body.textContent)",
103 &content));
104 EXPECT_EQ(expected, content);
105 }
106
107 void ExpectCookiesOnHost(const std::string& host,
108 const std::string& expected) {
Christian Dullweber4a8afe22019-09-19 16:57:32109 EXPECT_EQ(expected, content::GetCookies(browser()->profile(),
110 https_server_.GetURL(host, "/")));
jam1a5b5582017-05-01 16:50:10111 }
112
Christian Dullweber10d62c12019-08-19 12:08:19113 void SetStorageForFrame(content::RenderFrameHost* frame) {
114 for (const auto& data_type : kStorageTypes) {
115 bool data;
116 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
117 frame, "set" + data_type + "()", &data));
118 EXPECT_TRUE(data) << data_type;
119 }
120 }
121
122 void ExpectStorageForFrame(content::RenderFrameHost* frame, bool expected) {
123 for (const auto& data_type : kStorageTypes) {
124 bool data;
125 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
Christian Dullweber4a8afe22019-09-19 16:57:32126 frame, "has" + data_type + "();", &data));
Christian Dullweber10d62c12019-08-19 12:08:19127 EXPECT_EQ(expected, data) << data_type;
128 }
129 }
130
131 content::RenderFrameHost* GetFrame() {
132 content::WebContents* web_contents =
133 browser()->tab_strip_model()->GetActiveWebContents();
134 return ChildFrameAt(web_contents->GetMainFrame(), 0);
135 }
136
137 content::RenderFrameHost* GetNestedFrame() {
138 return ChildFrameAt(GetFrame(), 0);
139 }
140
Christian Dullweber4a8afe22019-09-19 16:57:32141 protected:
142 net::test_server::EmbeddedTestServer https_server_;
143
[email protected]c145edad2009-11-18 02:14:27144 private:
145 DISALLOW_COPY_AND_ASSIGN(CookiePolicyBrowserTest);
146};
147
Christian Dullweber10d62c12019-08-19 12:08:19148// CookiePolicyBrowserTest with a feature list that enables usage of
149// TopLevelOrigin for CookieSettings. This is only required until this
150// behavior can be enabled by default. https://crbug.com/988398
151class CookiePolicyTopLevelOriginBrowserTest : public CookiePolicyBrowserTest {
152 public:
153 CookiePolicyTopLevelOriginBrowserTest() {
154 enable_cookie_controls_.InitAndEnableFeature(
155 content_settings::kImprovedCookieControls);
156 }
157
158 private:
159 base::test::ScopedFeatureList enable_cookie_controls_;
160};
161
[email protected]c145edad2009-11-18 02:14:27162// Visits a page that sets a first-party cookie.
163IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest, AllowFirstPartyCookies) {
Mike Westdd5cc632018-09-07 17:44:23164 SetBlockThirdPartyCookies(false);
[email protected]c145edad2009-11-18 02:14:27165
Christian Dullweber4a8afe22019-09-19 16:57:32166 GURL url(https_server_.GetURL("/set-cookie?cookie1"));
[email protected]c145edad2009-11-18 02:14:27167
[email protected]1f2469a2012-12-13 21:19:55168 std::string cookie = content::GetCookies(browser()->profile(), url);
[email protected]c145edad2009-11-18 02:14:27169 ASSERT_EQ("", cookie);
170
171 ui_test_utils::NavigateToURL(browser(), url);
172
[email protected]1f2469a2012-12-13 21:19:55173 cookie = content::GetCookies(browser()->profile(), url);
[email protected]c145edad2009-11-18 02:14:27174 EXPECT_EQ("cookie1", cookie);
175}
176
[email protected]c145edad2009-11-18 02:14:27177// Visits a page that is a redirect across domain boundary to a page that sets
178// a first-party cookie.
179IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest,
180 AllowFirstPartyCookiesRedirect) {
Mike Westdd5cc632018-09-07 17:44:23181 SetBlockThirdPartyCookies(true);
[email protected]c145edad2009-11-18 02:14:27182
Christian Dullweber4a8afe22019-09-19 16:57:32183 GURL url(https_server_.GetURL("/server-redirect?"));
184 GURL redirected_url(https_server_.GetURL("/set-cookie?cookie2"));
[email protected]c145edad2009-11-18 02:14:27185
[email protected]95409e12010-08-17 20:07:11186 // Change the host name from 127.0.0.1 to www.example.com so it triggers
[email protected]c145edad2009-11-18 02:14:27187 // third-party cookie blocking if the first party for cookies URL is not
188 // changed when we follow a redirect.
[email protected]95409e12010-08-17 20:07:11189 ASSERT_EQ("127.0.0.1", redirected_url.host());
[email protected]c145edad2009-11-18 02:14:27190 GURL::Replacements replacements;
mgiuca77752c32015-02-05 07:31:18191 replacements.SetHostStr("www.example.com");
[email protected]c145edad2009-11-18 02:14:27192 redirected_url = redirected_url.ReplaceComponents(replacements);
193
[email protected]1f2469a2012-12-13 21:19:55194 std::string cookie =
195 content::GetCookies(browser()->profile(), redirected_url);
[email protected]c145edad2009-11-18 02:14:27196 ASSERT_EQ("", cookie);
197
[email protected]c145edad2009-11-18 02:14:27198 ui_test_utils::NavigateToURL(browser(),
199 GURL(url.spec() + redirected_url.spec()));
200
[email protected]1f2469a2012-12-13 21:19:55201 cookie = content::GetCookies(browser()->profile(), redirected_url);
[email protected]c145edad2009-11-18 02:14:27202 EXPECT_EQ("cookie2", cookie);
203}
[email protected]9eaa18e2010-06-29 20:51:01204
Mike Westdd5cc632018-09-07 17:44:23205// Third-Party Frame Tests
206IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest,
207 ThirdPartyCookiesIFrameAllowSetting) {
208 SetBlockThirdPartyCookies(false);
209
210 NavigateToPageWithFrame("a.com");
211
212 ExpectCookiesOnHost("b.com", "");
213
214 // Navigate iframe to a cross-site, cookie-setting endpoint, and verify that
215 // the cookie is set:
216 NavigateFrameTo("b.com", "/set-cookie?thirdparty");
217 ExpectCookiesOnHost("b.com", "thirdparty");
218
219 // Navigate iframe to a cross-site frame with a frame, and navigate _that_
220 // frame to a cross-site, cookie-setting endpoint, and verify that the cookie
221 // is set:
222 NavigateFrameTo("b.com", "/iframe.html");
223 NavigateNestedFrameTo("b.com", "/set-cookie?thirdparty");
224 ExpectCookiesOnHost("b.com", "thirdparty");
225
226 // Navigate iframe to a cross-site frame with a frame, and navigate _that_
227 // frame to a cross-site, cookie-setting endpoint, and verify that the cookie
228 // is set:
229 NavigateFrameTo("c.com", "/iframe.html");
230 NavigateNestedFrameTo("b.com", "/set-cookie?thirdparty");
231 ExpectCookiesOnHost("b.com", "thirdparty");
232}
233
234IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest,
235 ThirdPartyCookiesIFrameBlockSetting) {
236 SetBlockThirdPartyCookies(true);
237
238 NavigateToPageWithFrame("a.com");
239
240 // Navigate iframe to a cross-site, cookie-setting endpoint, and verify that
241 // the cookie is not set:
242 NavigateFrameTo("b.com", "/set-cookie?thirdparty");
243 ExpectCookiesOnHost("b.com", "");
244
245 // Navigate iframe to a cross-site frame with a frame, and navigate _that_
246 // frame to a cross-site, cookie-setting endpoint, and verify that the cookie
247 // is not set:
248 NavigateFrameTo("b.com", "/iframe.html");
249 NavigateNestedFrameTo("b.com", "/set-cookie?thirdparty");
250 ExpectCookiesOnHost("b.com", "");
251
252 // Navigate iframe to a cross-site frame with a frame, and navigate _that_
253 // frame to a cross-site, cookie-setting endpoint, and verify that the cookie
254 // is not set:
255 NavigateFrameTo("c.com", "/iframe.html");
256 NavigateNestedFrameTo("b.com", "/set-cookie?thirdparty");
257 ExpectCookiesOnHost("b.com", "");
258}
259
260IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest,
261 ThirdPartyCookiesIFrameAllowReading) {
262 SetBlockThirdPartyCookies(false);
263
264 // Set a cookie on `b.com`.
Christian Dullweber4a8afe22019-09-19 16:57:32265 content::SetCookie(browser()->profile(), https_server_.GetURL("b.com", "/"),
Mike Westdd5cc632018-09-07 17:44:23266 "thirdparty");
267 ExpectCookiesOnHost("b.com", "thirdparty");
268
269 NavigateToPageWithFrame("a.com");
270
271 // Navigate iframe to a cross-site, cookie-reading endpoint, and verify that
272 // the cookie is sent:
273 NavigateFrameTo("b.com", "/echoheader?cookie");
274 ExpectFrameContent("thirdparty");
275
276 // Navigate iframe to a cross-site frame with a frame, and navigate _that_
277 // frame to a cross-site page that echos the cookie header, and verify that
278 // the cookie is sent:
279 NavigateFrameTo("b.com", "/iframe.html");
280 NavigateNestedFrameTo("b.com", "/echoheader?cookie");
281 ExpectNestedFrameContent("thirdparty");
282
283 // Navigate iframe to a cross-site frame with a frame, and navigate _that_
284 // frame to a distinct cross-site page that echos the cookie header, and
285 // verify that the cookie is not sent:
286 NavigateFrameTo("c.com", "/iframe.html");
287 NavigateNestedFrameTo("b.com", "/echoheader?cookie");
288 ExpectNestedFrameContent("thirdparty");
289}
290
291IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest,
292 ThirdPartyCookiesIFrameBlockReading) {
293 SetBlockThirdPartyCookies(true);
294
295 // Set a cookie on `b.com`.
Christian Dullweber4a8afe22019-09-19 16:57:32296 content::SetCookie(browser()->profile(), https_server_.GetURL("b.com", "/"),
Mike Westdd5cc632018-09-07 17:44:23297 "thirdparty");
298 ExpectCookiesOnHost("b.com", "thirdparty");
299
300 NavigateToPageWithFrame("a.com");
301
302 // Navigate iframe to a cross-site, cookie-reading endpoint, and verify that
303 // the cookie is not sent:
304 NavigateFrameTo("b.com", "/echoheader?cookie");
305 ExpectFrameContent("None");
306
307 // Navigate iframe to a cross-site frame with a frame, and navigate _that_
308 // frame to a cross-site page that echos the cookie header, and verify that
309 // the cookie is not sent:
310 NavigateFrameTo("b.com", "/iframe.html");
311 NavigateNestedFrameTo("b.com", "/echoheader?cookie");
312 ExpectNestedFrameContent("None");
313
314 // Navigate iframe to a cross-site frame with a frame, and navigate _that_
315 // frame to a distinct cross-site page that echos the cookie header, and
316 // verify that the cookie is not sent:
317 NavigateFrameTo("c.com", "/iframe.html");
318 NavigateNestedFrameTo("b.com", "/echoheader?cookie");
319 ExpectNestedFrameContent("None");
320}
321
Christian Dullweber10d62c12019-08-19 12:08:19322IN_PROC_BROWSER_TEST_F(CookiePolicyTopLevelOriginBrowserTest,
323 ThirdPartyCookiesIFrameExceptions) {
324 SetBlockThirdPartyCookies(true);
325
326 // Set a cookie on `b.com`.
Christian Dullweber4a8afe22019-09-19 16:57:32327 content::SetCookie(browser()->profile(), https_server_.GetURL("b.com", "/"),
Christian Dullweber10d62c12019-08-19 12:08:19328 "thirdparty");
329 ExpectCookiesOnHost("b.com", "thirdparty");
330
331 // Allow all requests to b.com to have cookies.
332 auto cookie_settings =
333 CookieSettingsFactory::GetForProfile(browser()->profile());
Christian Dullweber4a8afe22019-09-19 16:57:32334 GURL url = https_server_.GetURL("b.com", "/");
Christian Dullweber10d62c12019-08-19 12:08:19335 cookie_settings->SetCookieSetting(url, ContentSetting::CONTENT_SETTING_ALLOW);
336
337 NavigateToPageWithFrame("a.com");
338
339 // Navigate iframe to a cross-site, cookie-reading endpoint, and verify that
340 // the cookie is sent:
341 NavigateFrameTo("b.com", "/echoheader?cookie");
342 ExpectFrameContent("thirdparty");
343
344 // Navigate iframe to a cross-site frame with a frame, and navigate _that_
345 // frame to a cross-site page that echos the cookie header, and verify that
346 // the cookie is sent:
347 NavigateFrameTo("b.com", "/iframe.html");
348 NavigateNestedFrameTo("b.com", "/echoheader?cookie");
349 ExpectNestedFrameContent("thirdparty");
350
351 // Navigate iframe to a cross-site frame with a frame, and navigate _that_
352 // frame to a distinct cross-site page that echos the cookie header, and
353 // verify that the cookie is sent:
354 NavigateFrameTo("c.com", "/iframe.html");
355 NavigateNestedFrameTo("b.com", "/echoheader?cookie");
356 ExpectNestedFrameContent("thirdparty");
357}
358
359IN_PROC_BROWSER_TEST_F(CookiePolicyTopLevelOriginBrowserTest,
360 ThirdPartyCookiesIFrameThirdPartyExceptions) {
361 SetBlockThirdPartyCookies(true);
362
363 // Set a cookie on `b.com`.
Christian Dullweber4a8afe22019-09-19 16:57:32364 content::SetCookie(browser()->profile(), https_server_.GetURL("b.com", "/"),
Christian Dullweber10d62c12019-08-19 12:08:19365 "thirdparty");
366 ExpectCookiesOnHost("b.com", "thirdparty");
367
368 // Allow all requests on the top frame domain a.com to have cookies.
369 auto cookie_settings =
370 CookieSettingsFactory::GetForProfile(browser()->profile());
Christian Dullweber4a8afe22019-09-19 16:57:32371 GURL url = https_server_.GetURL("a.com", "/");
Christian Dullweber10d62c12019-08-19 12:08:19372 cookie_settings->SetThirdPartyCookieSetting(
373 url, ContentSetting::CONTENT_SETTING_ALLOW);
374
375 NavigateToPageWithFrame("a.com");
376
377 // Navigate iframe to a cross-site, cookie-reading endpoint, and verify that
378 // the cookie is sent:
379 NavigateFrameTo("b.com", "/echoheader?cookie");
380 ExpectFrameContent("thirdparty");
381
382 // Navigate iframe to a cross-site frame with a frame, and navigate _that_
383 // frame to a cross-site page that echos the cookie header, and verify that
384 // the cookie is sent:
385 NavigateFrameTo("b.com", "/iframe.html");
386 NavigateNestedFrameTo("b.com", "/echoheader?cookie");
387 ExpectNestedFrameContent("thirdparty");
388
389 // Navigate iframe to a cross-site frame with a frame, and navigate _that_
390 // frame to a distinct cross-site page that echos the cookie header, and
391 // verify that the cookie is sent:
392 NavigateFrameTo("c.com", "/iframe.html");
393 NavigateNestedFrameTo("b.com", "/echoheader?cookie");
394 ExpectNestedFrameContent("thirdparty");
395}
396
397IN_PROC_BROWSER_TEST_F(CookiePolicyTopLevelOriginBrowserTest,
398 ThirdPartyIFrameStorage) {
399 NavigateToPageWithFrame("a.com");
400 NavigateFrameTo("b.com", "/browsing_data/site_data.html");
401 ExpectStorageForFrame(GetFrame(), false);
402 SetStorageForFrame(GetFrame());
403 ExpectStorageForFrame(GetFrame(), true);
404
405 SetBlockThirdPartyCookies(true);
406
407 NavigateToPageWithFrame("a.com");
408 NavigateFrameTo("b.com", "/browsing_data/site_data.html");
409 ExpectStorageForFrame(GetFrame(), false);
410
411 // Allow all requests to b.com to access storage.
412 auto cookie_settings =
413 CookieSettingsFactory::GetForProfile(browser()->profile());
Christian Dullweber4a8afe22019-09-19 16:57:32414 GURL a_url = https_server_.GetURL("a.com", "/");
415 GURL b_url = https_server_.GetURL("b.com", "/");
Christian Dullweber10d62c12019-08-19 12:08:19416 cookie_settings->SetCookieSetting(b_url,
417 ContentSetting::CONTENT_SETTING_ALLOW);
418
419 NavigateToPageWithFrame("a.com");
420 NavigateFrameTo("b.com", "/browsing_data/site_data.html");
421 ExpectStorageForFrame(GetFrame(), true);
422
423 // Remove ALLOW setting.
424 cookie_settings->ResetCookieSetting(b_url);
425
426 NavigateToPageWithFrame("a.com");
427 NavigateFrameTo("b.com", "/browsing_data/site_data.html");
428 ExpectStorageForFrame(GetFrame(), false);
429
430 // Allow all third-parties on a.com to access storage.
431 cookie_settings->SetThirdPartyCookieSetting(
432 a_url, ContentSetting::CONTENT_SETTING_ALLOW);
433
434 NavigateToPageWithFrame("a.com");
435 NavigateFrameTo("b.com", "/browsing_data/site_data.html");
436 ExpectStorageForFrame(GetFrame(), true);
437}
438
439IN_PROC_BROWSER_TEST_F(CookiePolicyTopLevelOriginBrowserTest,
440 NestedThirdPartyIFrameStorage) {
441 NavigateToPageWithFrame("a.com");
442 NavigateFrameTo("b.com", "/iframe.html");
443 NavigateNestedFrameTo("c.com", "/browsing_data/site_data.html");
444
445 ExpectStorageForFrame(GetNestedFrame(), false);
446 SetStorageForFrame(GetNestedFrame());
447 ExpectStorageForFrame(GetNestedFrame(), true);
448
449 SetBlockThirdPartyCookies(true);
450
451 NavigateToPageWithFrame("a.com");
452 NavigateFrameTo("b.com", "/iframe.html");
453 NavigateNestedFrameTo("c.com", "/browsing_data/site_data.html");
454 ExpectStorageForFrame(GetNestedFrame(), false);
455
456 // Allow all requests to b.com to access storage.
457 auto cookie_settings =
458 CookieSettingsFactory::GetForProfile(browser()->profile());
Christian Dullweber4a8afe22019-09-19 16:57:32459 GURL a_url = https_server_.GetURL("a.com", "/");
460 GURL c_url = https_server_.GetURL("c.com", "/");
Christian Dullweber10d62c12019-08-19 12:08:19461 cookie_settings->SetCookieSetting(c_url,
462 ContentSetting::CONTENT_SETTING_ALLOW);
463
464 NavigateToPageWithFrame("a.com");
465 NavigateFrameTo("b.com", "/iframe.html");
466 NavigateNestedFrameTo("c.com", "/browsing_data/site_data.html");
467 ExpectStorageForFrame(GetNestedFrame(), true);
468
469 // Remove ALLOW setting.
470 cookie_settings->ResetCookieSetting(c_url);
471
472 NavigateToPageWithFrame("a.com");
473 NavigateFrameTo("b.com", "/iframe.html");
474 NavigateNestedFrameTo("c.com", "/browsing_data/site_data.html");
475 ExpectStorageForFrame(GetNestedFrame(), false);
476
477 // Allow all third-parties on a.com to access storage.
478 cookie_settings->SetThirdPartyCookieSetting(
479 a_url, ContentSetting::CONTENT_SETTING_ALLOW);
480
481 NavigateToPageWithFrame("a.com");
482 NavigateFrameTo("b.com", "/iframe.html");
483 NavigateNestedFrameTo("c.com", "/browsing_data/site_data.html");
484 ExpectStorageForFrame(GetNestedFrame(), true);
485}
486
Christian Dullweber10d62c12019-08-19 12:08:19487IN_PROC_BROWSER_TEST_F(CookiePolicyTopLevelOriginBrowserTest,
Christian Dullweber7f17aecf2019-08-19 16:36:14488 NestedFirstPartyIFrameStorage) {
Christian Dullweber10d62c12019-08-19 12:08:19489 NavigateToPageWithFrame("a.com");
490 NavigateFrameTo("b.com", "/iframe.html");
491 NavigateNestedFrameTo("a.com", "/browsing_data/site_data.html");
492
493 ExpectStorageForFrame(GetNestedFrame(), false);
494 SetStorageForFrame(GetNestedFrame());
495 ExpectStorageForFrame(GetNestedFrame(), true);
496
497 SetBlockThirdPartyCookies(true);
498
499 NavigateToPageWithFrame("a.com");
500 NavigateFrameTo("b.com", "/iframe.html");
501 NavigateNestedFrameTo("a.com", "/browsing_data/site_data.html");
502 ExpectStorageForFrame(GetNestedFrame(), false);
503
504 // Allow all requests to b.com to access storage.
505 auto cookie_settings =
506 CookieSettingsFactory::GetForProfile(browser()->profile());
Christian Dullweber4a8afe22019-09-19 16:57:32507 GURL a_url = https_server_.GetURL("a.com", "/");
Christian Dullweber10d62c12019-08-19 12:08:19508 cookie_settings->SetCookieSetting(a_url,
509 ContentSetting::CONTENT_SETTING_ALLOW);
510
511 NavigateToPageWithFrame("a.com");
512 NavigateFrameTo("b.com", "/iframe.html");
513 NavigateNestedFrameTo("a.com", "/browsing_data/site_data.html");
514 ExpectStorageForFrame(GetNestedFrame(), true);
515
516 // Remove ALLOW setting.
517 cookie_settings->ResetCookieSetting(a_url);
518
519 NavigateToPageWithFrame("a.com");
520 NavigateFrameTo("b.com", "/iframe.html");
521 NavigateNestedFrameTo("a.com", "/browsing_data/site_data.html");
522 ExpectStorageForFrame(GetNestedFrame(), false);
523
524 // Allow all third-parties on a.com to access storage.
525 cookie_settings->SetThirdPartyCookieSetting(
526 a_url, ContentSetting::CONTENT_SETTING_ALLOW);
527
528 NavigateToPageWithFrame("a.com");
529 NavigateFrameTo("b.com", "/iframe.html");
530 NavigateNestedFrameTo("a.com", "/browsing_data/site_data.html");
531 ExpectStorageForFrame(GetNestedFrame(), true);
532}
533
[email protected]9eaa18e2010-06-29 20:51:01534} // namespace