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

Unified Diff: content/browser/browsing_data/clear_site_data_throttle_unittest.cc

Issue 2933083002: Revert of Align `clear-site-data` syntax with the spec. (Closed)
Patch Set: Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/browsing_data/clear_site_data_throttle_unittest.cc
diff --git a/content/browser/browsing_data/clear_site_data_throttle_unittest.cc b/content/browser/browsing_data/clear_site_data_throttle_unittest.cc
index 20f61749b2bd21d8ec8fea4372c6f0962c251104..7d76da46e1088f5c0f5c16ae69039f3c1a976f3c 100644
--- a/content/browser/browsing_data/clear_site_data_throttle_unittest.cc
+++ b/content/browser/browsing_data/clear_site_data_throttle_unittest.cc
@@ -33,7 +33,8 @@
const char kClearSiteDataHeaderPrefix[] = "Clear-Site-Data: ";
-const char kClearCookiesHeader[] = "Clear-Site-Data: \"cookies\"";
+const char kClearCookiesHeader[] =
+ "Clear-Site-Data: { \"types\": [ \"cookies\" ] }";
void WaitForUIThread() {
base::RunLoop run_loop;
@@ -173,32 +174,36 @@
bool cache;
} test_cases[] = {
// One data type.
- {"\"cookies\"", true, false, false},
- {"\"storage\"", false, true, false},
- {"\"cache\"", false, false, true},
+ {"{ \"types\": [\"cookies\"] }", true, false, false},
+ {"{ \"types\": [\"storage\"] }", false, true, false},
+ {"{ \"types\": [\"cache\"] }", false, false, true},
// Two data types.
- {"\"cookies\", \"storage\"", true, true, false},
- {"\"cookies\", \"cache\"", true, false, true},
- {"\"storage\", \"cache\"", false, true, true},
+ {"{ \"types\": [\"cookies\", \"storage\"] }", true, true, false},
+ {"{ \"types\": [\"cookies\", \"cache\"] }", true, false, true},
+ {"{ \"types\": [\"storage\", \"cache\"] }", false, true, true},
// Three data types.
- {"\"storage\", \"cache\", \"cookies\"", true, true, true},
- {"\"cache\", \"cookies\", \"storage\"", true, true, true},
- {"\"cookies\", \"storage\", \"cache\"", true, true, true},
+ {"{ \"types\": [\"storage\", \"cache\", \"cookies\"] }", true, true,
+ true},
+ {"{ \"types\": [\"cache\", \"cookies\", \"storage\"] }", true, true,
+ true},
+ {"{ \"types\": [\"cookies\", \"storage\", \"cache\"] }", true, true,
+ true},
// Different formatting.
- {"\"cookies\"", true, false, false},
+ {" { \"types\": [\"cookies\" ]}", true, false, false},
// Duplicates.
- {"\"cookies\", \"cookies\"", true, false, false},
-
- // Other JSON-formatted items in the list.
- {"\"storage\", { \"other_params\": {} }", false, true, false},
+ {"{ \"types\": [\"cookies\", \"cookies\"] }", true, false, false},
+
+ // Other entries in the dictionary.
+ {"{ \"types\": [\"storage\"], \"other_params\": {} }", false, true,
+ false},
// Unknown types are ignored, but we still proceed with the deletion for
// those that we recognize.
- {"\"cache\", \"foo\"", false, false, true},
+ {"{ \"types\": [\"cache\", \"foo\"] }", false, false, true},
};
for (const TestCase& test_case : test_cases) {
@@ -247,21 +252,18 @@
const char* header;
const char* console_message;
} test_cases[] = {
- {"", "No recognized types specified.\n"},
- {"\"unclosed", "The header's value does not parse as valid JSON.\n"},
- {"\"passwords\"",
+ {"", "Expected valid JSON.\n"},
+ {"\"unclosed quote", "Expected valid JSON.\n"},
+ {"\"some text\"", "Expected a JSON dictionary with a 'types' field.\n"},
+ {"{ \"field\" : {} }",
+ "Expected a JSON dictionary with a 'types' field.\n"},
+ {"{ \"types\" : [ \"passwords\" ] }",
"Unrecognized type: \"passwords\".\n"
- "No recognized types specified.\n"},
- {"[ \"list\" ]",
- "Unrecognized type: [\"list\"].\n"
- "No recognized types specified.\n"},
- {"[ \"list\" ]",
- "Unrecognized type: [\"list\"].\n"
- "No recognized types specified.\n"},
- {"{ \"cookies\": [ \"a\" ] }",
- "Unrecognized type: {\"cookies\":[\"a\"]}.\n"
- "No recognized types specified.\n"},
- {"\"кукис\", \"сторидж\", \"кэш\"",
+ "No recognized types specified in the 'types' field.\n"},
+ {"{ \"types\" : [ [ \"list in a list\" ] ] }",
+ "Unrecognized type: [\"list in a list\"].\n"
+ "No recognized types specified in the 'types' field.\n"},
+ {"{ \"types\" : [ \"кукис\", \"сторидж\", \"кэш\" ]",
"Must only contain ASCII characters.\n"}};
for (const TestCase& test_case : test_cases) {
@@ -403,11 +405,13 @@
// That includes malformed Clear-Site-Data headers or header values
// that do not lead to deletion.
- {REDIRECT, "Clear-Site-Data: cookies", false},
- {REDIRECT, "Clear-Site-Data: \"unknown type\"", false},
+ {REDIRECT, "Clear-Site-Data: { types: cookies } ", false},
+ {REDIRECT, "Clear-Site-Data: { \"types\": [ \"unknown type\" ] }", false},
// However, redirects are deferred for valid Clear-Site-Data headers.
- {REDIRECT, "Clear-Site-Data: \"cookies\", \"unknown type\"", true},
+ {REDIRECT,
+ "Clear-Site-Data: { \"types\": [ \"cookies\", \"unknown type\" ] }",
+ true},
{REDIRECT,
base::StringPrintf("Content-Type: image/png;\n%s", kClearCookiesHeader),
true},
@@ -415,15 +419,17 @@
base::StringPrintf("%s\nContent-Type: image/png;", kClearCookiesHeader),
true},
- // Multiple instances of the header will be parsed correctly.
+ // We expect at most one instance of the header. Multiple instances
+ // will not be parsed currently. This is not an inherent property of
+ // Clear-Site-Data, just a documentation of the current behavior.
{REDIRECT,
base::StringPrintf("%s\n%s", kClearCookiesHeader, kClearCookiesHeader),
- true},
+ false},
// Final response headers are treated the same way as in the case
// of redirect.
{REDIRECT, "Set-Cookie: abc=123;", false},
- {REDIRECT, "Clear-Site-Data: cookies", false},
+ {REDIRECT, "Clear-Site-Data: { types: cookies } ", false},
{REDIRECT, kClearCookiesHeader, true},
};
@@ -512,38 +518,34 @@
const char* output;
} kTestCases[] = {
// Successful deletion outputs one line.
- {"\"cookies\"", "https://origin1.com/foo",
+ {"{ \"types\": [ \"cookies\" ] }", "https://origin1.com/foo",
"Clear-Site-Data header on 'https://origin1.com/foo': "
"Cleared data types: cookies.\n"},
// Another successful deletion.
- {"\"storage\"", "https://origin2.com/foo",
+ {"{ \"types\": [ \"storage\" ] }", "https://origin2.com/foo",
"Clear-Site-Data header on 'https://origin2.com/foo': "
"Cleared data types: storage.\n"},
// Redirect to the same URL. Unsuccessful deletion outputs two lines.
- {"\"foo\"", "https://origin2.com/foo",
+ {"{ \"foo\": \"bar\" }", "https://origin2.com/foo",
"Clear-Site-Data header on 'https://origin2.com/foo': "
- "Unrecognized type: \"foo\".\n"
- "Clear-Site-Data header on 'https://origin2.com/foo': "
- "No recognized types specified.\n"},
+ "Expected a JSON dictionary with a 'types' field.\n"},
// Redirect to another URL. Another unsuccessful deletion.
{"\"some text\"", "https://origin3.com/bar",
"Clear-Site-Data header on 'https://origin3.com/bar': "
- "Unrecognized type: \"some text\".\n"
- "Clear-Site-Data header on 'https://origin3.com/bar': "
- "No recognized types specified.\n"},
+ "Expected a JSON dictionary with a 'types' field.\n"},
// Yet another on the same URL.
- {"\"passwords\"", "https://origin3.com/bar",
+ {"{ \"types\" : [ \"passwords\" ] }", "https://origin3.com/bar",
"Clear-Site-Data header on 'https://origin3.com/bar': "
"Unrecognized type: \"passwords\".\n"
"Clear-Site-Data header on 'https://origin3.com/bar': "
- "No recognized types specified.\n"},
+ "No recognized types specified in the 'types' field.\n"},
// Successful deletion on the same URL.
- {"\"cache\"", "https://origin3.com/bar",
+ {"{ \"types\": [ \"cache\" ] }", "https://origin3.com/bar",
"Clear-Site-Data header on 'https://origin3.com/bar': "
"Cleared data types: cache.\n"},
@@ -551,7 +553,7 @@
// Successful deletion outputs one line.
{"", "https://origin1.com/foo",
"Clear-Site-Data header on 'https://origin1.com/foo': "
- "No recognized types specified.\n"}};
+ "Expected valid JSON.\n"}};
bool kThrottleTypeIsNavigation[] = {true, false};
« no previous file with comments | « content/browser/browsing_data/clear_site_data_throttle_browsertest.cc ('k') | content/test/data/browsing_data/worker.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698