Commit 612ba1ba authored by Ayu Ishii's avatar Ayu Ishii Committed by Commit Bot

CookieStore: Remove matchType

This change removes matchType option from CookieStoreGetOptions.
This decision has been discussed here [1], and will
be revisited after launch to re-evaluate if the option
is good to have or if we should do a full cleanup of
the option.

[1] https://github.com/WICG/cookie-store/issues/128

Bug: 1124497
Change-Id: I845c6e872aa25d138114ccf0b0a74332adeb650d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2402132
Commit-Queue: Ayu Ishii <ayui@chromium.org>
Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#805855}
parent 8a47b09d
...@@ -12,8 +12,6 @@ blink_modules_sources("cookie_store") { ...@@ -12,8 +12,6 @@ blink_modules_sources("cookie_store") {
"cookie_store.h", "cookie_store.h",
"cookie_store_manager.cc", "cookie_store_manager.cc",
"cookie_store_manager.h", "cookie_store_manager.h",
"cookie_store_metrics.cc",
"cookie_store_metrics.h",
"extendable_cookie_change_event.cc", "extendable_cookie_change_event.cc",
"extendable_cookie_change_event.h", "extendable_cookie_change_event.h",
"global_cookie_store.cc", "global_cookie_store.cc",
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#include "third_party/blink/renderer/core/dom/dom_exception.h" #include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h" #include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/modules/cookie_store/cookie_change_event.h" #include "third_party/blink/renderer/modules/cookie_store/cookie_change_event.h"
#include "third_party/blink/renderer/modules/cookie_store/cookie_store_metrics.h"
#include "third_party/blink/renderer/modules/event_modules.h" #include "third_party/blink/renderer/modules/event_modules.h"
#include "third_party/blink/renderer/modules/event_target_modules.h" #include "third_party/blink/renderer/modules/event_target_modules.h"
#include "third_party/blink/renderer/modules/service_worker/service_worker_global_scope.h" #include "third_party/blink/renderer/modules/service_worker/service_worker_global_scope.h"
...@@ -44,13 +43,8 @@ network::mojom::blink::CookieManagerGetOptionsPtr ToBackendOptions( ...@@ -44,13 +43,8 @@ network::mojom::blink::CookieManagerGetOptionsPtr ToBackendOptions(
ExceptionState& exception_state) { ExceptionState& exception_state) {
auto backend_options = network::mojom::blink::CookieManagerGetOptions::New(); auto backend_options = network::mojom::blink::CookieManagerGetOptions::New();
if (options->hasMatchType() && options->matchType() == "starts-with") { // TODO(crbug.com/1124499): Cleanup matchType after evaluation.
backend_options->match_type = backend_options->match_type = network::mojom::blink::CookieMatchType::EQUALS;
network::mojom::blink::CookieMatchType::STARTS_WITH;
} else {
backend_options->match_type =
network::mojom::blink::CookieMatchType::EQUALS;
}
if (options->hasName()) { if (options->hasName()) {
backend_options->name = options->name(); backend_options->name = options->name();
...@@ -260,7 +254,6 @@ ScriptPromise CookieStore::getAll(ScriptState* script_state, ...@@ -260,7 +254,6 @@ ScriptPromise CookieStore::getAll(ScriptState* script_state,
ExceptionState& exception_state) { ExceptionState& exception_state) {
UseCounter::Count(CurrentExecutionContext(script_state->GetIsolate()), UseCounter::Count(CurrentExecutionContext(script_state->GetIsolate()),
WebFeature::kCookieStoreAPI); WebFeature::kCookieStoreAPI);
RecordMatchType(*options);
return DoRead(script_state, options, &CookieStore::GetAllForUrlToGetAllResult, return DoRead(script_state, options, &CookieStore::GetAllForUrlToGetAllResult,
exception_state); exception_state);
...@@ -279,7 +272,6 @@ ScriptPromise CookieStore::get(ScriptState* script_state, ...@@ -279,7 +272,6 @@ ScriptPromise CookieStore::get(ScriptState* script_state,
ExceptionState& exception_state) { ExceptionState& exception_state) {
UseCounter::Count(CurrentExecutionContext(script_state->GetIsolate()), UseCounter::Count(CurrentExecutionContext(script_state->GetIsolate()),
WebFeature::kCookieStoreAPI); WebFeature::kCookieStoreAPI);
RecordMatchType(*options);
return DoRead(script_state, options, &CookieStore::GetAllForUrlToGetResult, return DoRead(script_state, options, &CookieStore::GetAllForUrlToGetResult,
exception_state); exception_state);
......
...@@ -4,15 +4,7 @@ ...@@ -4,15 +4,7 @@
// https://github.com/WICG/async-cookies-api/blob/gh-pages/explainer.md // https://github.com/WICG/async-cookies-api/blob/gh-pages/explainer.md
enum CookieMatchType {
"equals",
"starts-with"
};
dictionary CookieStoreGetOptions { dictionary CookieStoreGetOptions {
USVString name; USVString name;
USVString url; USVString url;
// TODO(ayui): Add default value "equals" back once we are done measuring
// usage.
CookieMatchType matchType;
}; };
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#include "third_party/blink/renderer/core/dom/dom_exception.h" #include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h" #include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/modules/cookie_store/cookie_change_event.h" #include "third_party/blink/renderer/modules/cookie_store/cookie_change_event.h"
#include "third_party/blink/renderer/modules/cookie_store/cookie_store_metrics.h"
#include "third_party/blink/renderer/modules/service_worker/service_worker_global_scope.h" #include "third_party/blink/renderer/modules/service_worker/service_worker_global_scope.h"
#include "third_party/blink/renderer/modules/service_worker/service_worker_registration.h" #include "third_party/blink/renderer/modules/service_worker/service_worker_registration.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h" #include "third_party/blink/renderer/platform/bindings/exception_state.h"
...@@ -51,14 +50,9 @@ mojom::blink::CookieChangeSubscriptionPtr ToBackendSubscription( ...@@ -51,14 +50,9 @@ mojom::blink::CookieChangeSubscriptionPtr ToBackendSubscription(
backend_subscription->url = default_cookie_url; backend_subscription->url = default_cookie_url;
} }
if (subscription->hasMatchType() && // TODO(crbug.com/1124499): Cleanup matchType after re-evaluation.
subscription->matchType() == "starts-with") { backend_subscription->match_type =
backend_subscription->match_type = network::mojom::blink::CookieMatchType::EQUALS;
network::mojom::blink::CookieMatchType::STARTS_WITH;
} else {
backend_subscription->match_type =
network::mojom::blink::CookieMatchType::EQUALS;
}
if (subscription->hasName()) { if (subscription->hasName()) {
backend_subscription->name = subscription->name(); backend_subscription->name = subscription->name();
...@@ -78,20 +72,8 @@ CookieStoreGetOptions* ToCookieChangeSubscription( ...@@ -78,20 +72,8 @@ CookieStoreGetOptions* ToCookieChangeSubscription(
CookieStoreGetOptions* subscription = CookieStoreGetOptions::Create(); CookieStoreGetOptions* subscription = CookieStoreGetOptions::Create();
subscription->setUrl(backend_subscription.url); subscription->setUrl(backend_subscription.url);
if (backend_subscription.match_type != if (!backend_subscription.name.IsEmpty())
network::mojom::blink::CookieMatchType::STARTS_WITH ||
!backend_subscription.name.IsEmpty()) {
subscription->setName(backend_subscription.name); subscription->setName(backend_subscription.name);
}
switch (backend_subscription.match_type) {
case network::mojom::blink::CookieMatchType::STARTS_WITH:
subscription->setMatchType(WTF::String("starts-with"));
break;
case network::mojom::blink::CookieMatchType::EQUALS:
subscription->setMatchType(WTF::String("equals"));
break;
}
return subscription; return subscription;
} }
...@@ -121,7 +103,6 @@ ScriptPromise CookieStoreManager::subscribe( ...@@ -121,7 +103,6 @@ ScriptPromise CookieStoreManager::subscribe(
Vector<mojom::blink::CookieChangeSubscriptionPtr> backend_subscriptions; Vector<mojom::blink::CookieChangeSubscriptionPtr> backend_subscriptions;
backend_subscriptions.ReserveInitialCapacity(subscriptions.size()); backend_subscriptions.ReserveInitialCapacity(subscriptions.size());
for (const CookieStoreGetOptions* subscription : subscriptions) { for (const CookieStoreGetOptions* subscription : subscriptions) {
RecordMatchType(*subscription);
mojom::blink::CookieChangeSubscriptionPtr backend_subscription = mojom::blink::CookieChangeSubscriptionPtr backend_subscription =
ToBackendSubscription(default_cookie_url_, subscription, ToBackendSubscription(default_cookie_url_, subscription,
exception_state); exception_state);
...@@ -147,7 +128,6 @@ ScriptPromise CookieStoreManager::unsubscribe( ...@@ -147,7 +128,6 @@ ScriptPromise CookieStoreManager::unsubscribe(
Vector<mojom::blink::CookieChangeSubscriptionPtr> backend_subscriptions; Vector<mojom::blink::CookieChangeSubscriptionPtr> backend_subscriptions;
backend_subscriptions.ReserveInitialCapacity(subscriptions.size()); backend_subscriptions.ReserveInitialCapacity(subscriptions.size());
for (const CookieStoreGetOptions* subscription : subscriptions) { for (const CookieStoreGetOptions* subscription : subscriptions) {
RecordMatchType(*subscription);
mojom::blink::CookieChangeSubscriptionPtr backend_subscription = mojom::blink::CookieChangeSubscriptionPtr backend_subscription =
ToBackendSubscription(default_cookie_url_, subscription, ToBackendSubscription(default_cookie_url_, subscription,
exception_state); exception_state);
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/modules/cookie_store/cookie_store_metrics.h"
#include "base/metrics/histogram_macros.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_cookie_store_get_options.h"
namespace blink {
// This enum describes the MatchType value specified by the user.
enum class MatchTypeOption {
// Do not change the meaning or ordering of these values because they are
// being recorded in a UMA metric.
kUnspecified = 0,
kEquals = 1,
kStartsWith = 2,
kMaxValue = kStartsWith,
};
void RecordMatchType(const CookieStoreGetOptions& options) {
MatchTypeOption uma_match_type;
// TODO(crbug.com/1092328): Switch by V8CookieMatchType::Enum.
if (!options.hasMatchType()) {
uma_match_type = MatchTypeOption::kUnspecified;
} else if (options.matchType() == "equals") {
uma_match_type = MatchTypeOption::kEquals;
} else if (options.matchType() == "starts-with") {
uma_match_type = MatchTypeOption::kStartsWith;
} else {
NOTREACHED();
// In case of an invalid value, we assume it's "equals" for the consistency
// of UMA.
uma_match_type = MatchTypeOption::kEquals;
}
UMA_HISTOGRAM_ENUMERATION("Blink.CookieStore.MatchType", uma_match_type);
}
} // namespace blink
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_COOKIE_STORE_COOKIE_STORE_METRICS_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_COOKIE_STORE_COOKIE_STORE_METRICS_H_
namespace blink {
class CookieStoreGetOptions;
// Record explicitly set MatchType option with UMA.
void RecordMatchType(const CookieStoreGetOptions& options);
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_COOKIE_STORE_COOKIE_STORE_METRICS_H_
...@@ -39,9 +39,7 @@ promise_test(async testCase => { ...@@ -39,9 +39,7 @@ promise_test(async testCase => {
} }
{ {
const subscriptions = [ const subscriptions = [{ name: 'cookie-name1', url: `${scope}/path1` }];
{ name: 'cookie-name1', matchType: 'equals', url: `${scope}/path1` },
];
await registration.cookies.subscribe(subscriptions); await registration.cookies.subscribe(subscriptions);
testCase.add_cleanup(() => { testCase.add_cleanup(() => {
// For non-ServiceWorker environments, registration.unregister() cleans up // For non-ServiceWorker environments, registration.unregister() cleans up
...@@ -54,7 +52,7 @@ promise_test(async testCase => { ...@@ -54,7 +52,7 @@ promise_test(async testCase => {
{ {
const subscriptions = [ const subscriptions = [
{ }, // Test the default values for subscription properties. { }, // Test the default values for subscription properties.
{ name: 'cookie-prefix', matchType: 'starts-with' }, { name: 'cookie-prefix' },
]; ];
await registration.cookies.subscribe(subscriptions); await registration.cookies.subscribe(subscriptions);
testCase.add_cleanup(() => { testCase.add_cleanup(() => {
...@@ -72,11 +70,8 @@ promise_test(async testCase => { ...@@ -72,11 +70,8 @@ promise_test(async testCase => {
subscriptions.sort((a, b) => CompareStrings(`${a.name}`, `${b.name}`)); subscriptions.sort((a, b) => CompareStrings(`${a.name}`, `${b.name}`));
assert_equals(subscriptions[0].name, 'cookie-name1'); assert_equals(subscriptions[0].name, 'cookie-name1');
assert_equals('equals', subscriptions[0].matchType);
assert_equals(subscriptions[1].name, 'cookie-prefix'); assert_equals(subscriptions[1].name, 'cookie-prefix');
assert_equals('starts-with', subscriptions[1].matchType);
assert_false('name' in subscriptions[2]); assert_false('name' in subscriptions[2]);
assert_equals('starts-with', subscriptions[2].matchType);
}, 'getSubscriptions returns a subscription passed to subscribe'); }, 'getSubscriptions returns a subscription passed to subscribe');
...@@ -30,9 +30,7 @@ promise_test(async testCase => { ...@@ -30,9 +30,7 @@ promise_test(async testCase => {
} }
{ {
const subscriptions = [ const subscriptions = [{ name: 'cookie-name', url: `${scope}/path` }];
{ name: 'cookie-name', matchType: 'equals', url: `${scope}/path` }
];
await registration.cookies.subscribe(subscriptions); await registration.cookies.subscribe(subscriptions);
testCase.add_cleanup(() => { testCase.add_cleanup(() => {
// For non-ServiceWorker environments, registration.unregister() cleans up // For non-ServiceWorker environments, registration.unregister() cleans up
...@@ -47,7 +45,6 @@ promise_test(async testCase => { ...@@ -47,7 +45,6 @@ promise_test(async testCase => {
assert_equals(subscriptions.length, 1); assert_equals(subscriptions.length, 1);
assert_equals(subscriptions[0].name, 'cookie-name'); assert_equals(subscriptions[0].name, 'cookie-name');
assert_equals(subscriptions[0].matchType, 'equals');
assert_equals(subscriptions[0].url, assert_equals(subscriptions[0].url,
(new URL(`${scope}/path`, self.location.href)).href); (new URL(`${scope}/path`, self.location.href)).href);
}, 'getSubscriptions returns a subscription passed to subscribe'); }, 'getSubscriptions returns a subscription passed to subscribe');
...@@ -32,11 +32,14 @@ promise_test(async testCase => { ...@@ -32,11 +32,14 @@ promise_test(async testCase => {
await cookieStore.delete('cookie-name-2'); await cookieStore.delete('cookie-name-2');
}); });
const cookies = await cookieStore.getAll('cookie-name'); const cookies = await cookieStore.getAll({});
assert_equals(cookies.length, 1); cookies.sort((a, b) => a.name.localeCompare(b.name));
assert_equals(cookies.length, 2);
assert_equals(cookies[0].name, 'cookie-name'); assert_equals(cookies[0].name, 'cookie-name');
assert_equals(cookies[0].value, 'cookie-value'); assert_equals(cookies[0].value, 'cookie-value');
}, 'cookieStore.getAll with positional name'); assert_equals(cookies[1].name, 'cookie-name-2');
assert_equals(cookies[1].value, 'cookie-value-2');
}, 'cookieStore.getAll with empty options');
promise_test(async testCase => { promise_test(async testCase => {
await cookieStore.set('cookie-name', 'cookie-value'); await cookieStore.set('cookie-name', 'cookie-value');
...@@ -48,11 +51,11 @@ promise_test(async testCase => { ...@@ -48,11 +51,11 @@ promise_test(async testCase => {
await cookieStore.delete('cookie-name-2'); await cookieStore.delete('cookie-name-2');
}); });
const cookies = await cookieStore.getAll({ name: 'cookie-name' }); const cookies = await cookieStore.getAll('cookie-name');
assert_equals(cookies.length, 1); assert_equals(cookies.length, 1);
assert_equals(cookies[0].name, 'cookie-name'); assert_equals(cookies[0].name, 'cookie-name');
assert_equals(cookies[0].value, 'cookie-value'); assert_equals(cookies[0].value, 'cookie-value');
}, 'cookieStore.getAll with name in options'); }, 'cookieStore.getAll with positional name');
promise_test(async testCase => { promise_test(async testCase => {
await cookieStore.set('cookie-name', 'cookie-value'); await cookieStore.set('cookie-name', 'cookie-value');
...@@ -64,46 +67,11 @@ promise_test(async testCase => { ...@@ -64,46 +67,11 @@ promise_test(async testCase => {
await cookieStore.delete('cookie-name-2'); await cookieStore.delete('cookie-name-2');
}); });
const cookies = await cookieStore.getAll('cookie-name', const cookies = await cookieStore.getAll({ name: 'cookie-name' });
{ name: 'wrong-cookie-name' });
assert_equals(cookies.length, 1);
assert_equals(cookies[0].name, 'cookie-name');
assert_equals(cookies[0].value, 'cookie-value');
}, 'cookieStore.getAll with name in both positional arguments and options');
promise_test(async testCase => {
await cookieStore.set('cookie-name', 'cookie-value');
testCase.add_cleanup(async () => {
await cookieStore.delete('cookie-name');
});
const cookies = await cookieStore.getAll({ name: 'cookie-name',
matchType: 'equals' });
assert_equals(cookies.length, 1); assert_equals(cookies.length, 1);
assert_equals(cookies[0].name, 'cookie-name'); assert_equals(cookies[0].name, 'cookie-name');
assert_equals(cookies[0].value, 'cookie-value'); assert_equals(cookies[0].value, 'cookie-value');
}, 'cookieStore.getAll with name in options');
const no_cookies = await cookieStore.getAll(
'cookie-na', { matchType: 'equals' });
assert_equals(no_cookies.length, 0);
}, 'cookieStore.getAll with matchType explicitly set to equals');
promise_test(async testCase => {
await cookieStore.set('cookie-name', 'cookie-value');
testCase.add_cleanup(async () => {
await cookieStore.delete('cookie-name');
});
await cookieStore.set('cookie-name-2', 'cookie-value-2');
testCase.add_cleanup(async () => {
await cookieStore.delete('cookie-name-2');
});
const cookies = await cookieStore.getAll({ name: 'cookie-name-',
matchType: 'starts-with' });
assert_equals(cookies.length, 1);
assert_equals(cookies[0].name, 'cookie-name-2');
assert_equals(cookies[0].value, 'cookie-value-2');
}, 'cookieStore.getAll with matchType set to starts-with');
promise_test(async testCase => { promise_test(async testCase => {
await cookieStore.set('cookie-name', 'cookie-value'); await cookieStore.set('cookie-name', 'cookie-value');
...@@ -115,33 +83,12 @@ promise_test(async testCase => { ...@@ -115,33 +83,12 @@ promise_test(async testCase => {
await cookieStore.delete('cookie-name-2'); await cookieStore.delete('cookie-name-2');
}); });
await promise_rejects_js(testCase, TypeError, cookieStore.getAll( const cookies = await cookieStore.getAll('cookie-name',
{ name: 'cookie-name', matchType: 'invalid' })); { name: 'wrong-cookie-name' });
}, 'cookieStore.getAll with invalid matchType');
promise_test(async testCase => {
await cookieStore.set('cookie-name', 'cookie-value');
testCase.add_cleanup(async () => {
await cookieStore.delete('cookie-name');
});
const cookies = await cookieStore.getAll({ matchType: 'equals' });
assert_equals(cookies.length, 1);
assert_equals(cookies[0].name, 'cookie-name');
assert_equals(cookies[0].value, 'cookie-value');
}, 'cookieStore.getAll with matchType set to equals and missing name');
promise_test(async testCase => {
await cookieStore.set('cookie-name', 'cookie-value');
testCase.add_cleanup(async () => {
await cookieStore.delete('cookie-name');
});
const cookies = await cookieStore.getAll({ matchType: 'starts-with' });
assert_equals(cookies.length, 1); assert_equals(cookies.length, 1);
assert_equals(cookies[0].name, 'cookie-name'); assert_equals(cookies[0].name, 'cookie-name');
assert_equals(cookies[0].value, 'cookie-value'); assert_equals(cookies[0].value, 'cookie-value');
}, 'cookieStore.getAll with matchType set to starts-with and missing name'); }, 'cookieStore.getAll with name in both positional arguments and options');
promise_test(async testCase => { promise_test(async testCase => {
await cookieStore.set('cookie-name', 'cookie-value'); await cookieStore.set('cookie-name', 'cookie-value');
......
...@@ -35,49 +35,25 @@ promise_test(async testCase => { ...@@ -35,49 +35,25 @@ promise_test(async testCase => {
await cookieStore.delete('cookie-name'); await cookieStore.delete('cookie-name');
}); });
const cookie = await cookieStore.get('cookie-name'); const cookie = await cookieStore.get({});
assert_equals(cookie.name, 'cookie-name'); assert_equals(cookie.name, 'cookie-name');
assert_equals(cookie.value, 'cookie-value'); assert_equals(cookie.value, 'cookie-value');
}, 'cookieStore.get with positional name'); }, 'cookieStore.get with empty options');
promise_test(async testCase => {
await cookieStore.set('cookie-name', 'cookie-value');
testCase.add_cleanup(async () => {
await cookieStore.delete('cookie-name');
});
const cookie = await cookieStore.get({ name: 'cookie-name' });
assert_equals(cookie.name, 'cookie-name');
assert_equals(cookie.value, 'cookie-value');
}, 'cookieStore.get with name in options');
promise_test(async testCase => { promise_test(async testCase => {
await cookieStore.set('cookie-name', 'cookie-value'); await cookieStore.set('cookie-name-1', 'cookie-value-1');
testCase.add_cleanup(async () => { testCase.add_cleanup(async () => {
await cookieStore.delete('cookie-name'); await cookieStore.delete('cookie-name-1');
}); });
await cookieStore.set('cookie-name-2', 'cookie-value-2');
const cookie = await cookieStore.get('cookie-name',
{ name: 'wrong-cookie-name' });
assert_equals(cookie.name, 'cookie-name');
assert_equals(cookie.value, 'cookie-value');
}, 'cookieStore.get with name in both positional arguments and options');
promise_test(async testCase => {
await cookieStore.set('cookie-name', 'cookie-value');
testCase.add_cleanup(async () => { testCase.add_cleanup(async () => {
await cookieStore.delete('cookie-name'); await cookieStore.delete('cookie-name-2');
}); });
const cookie = await cookieStore.get( const cookie = await cookieStore.get({});
'cookie-name', { matchType: 'equals' }); assert_equals(cookie.name, 'cookie-name-1');
assert_equals(cookie.name, 'cookie-name'); assert_equals(cookie.value, 'cookie-value-1');
assert_equals(cookie.value, 'cookie-value'); },'cookieStore.get with empty options and multiple matches');
const no_cookie = await cookieStore.get({ name: 'cookie-na',
matchType: 'equals' });
assert_equals(no_cookie, null);
}, 'cookieStore.get with matchType explicitly set to equals');
promise_test(async testCase => { promise_test(async testCase => {
await cookieStore.set('cookie-name', 'cookie-value'); await cookieStore.set('cookie-name', 'cookie-value');
...@@ -85,21 +61,10 @@ promise_test(async testCase => { ...@@ -85,21 +61,10 @@ promise_test(async testCase => {
await cookieStore.delete('cookie-name'); await cookieStore.delete('cookie-name');
}); });
const cookie = await cookieStore.get({ name: 'cookie-na', const cookie = await cookieStore.get('cookie-name');
matchType: 'starts-with' });
assert_equals(cookie.name, 'cookie-name'); assert_equals(cookie.name, 'cookie-name');
assert_equals(cookie.value, 'cookie-value'); assert_equals(cookie.value, 'cookie-value');
}, 'cookieStore.get with matchType set to starts-with'); }, 'cookieStore.get with positional name');
promise_test(async testCase => {
await cookieStore.set('cookie-name', 'cookie-value');
testCase.add_cleanup(async () => {
await cookieStore.delete('cookie-name');
});
await promise_rejects_js(testCase, TypeError, cookieStore.get(
{ name: 'cookie-name', matchType: 'invalid' }));
}, 'cookieStore.get with invalid matchType');
promise_test(async testCase => { promise_test(async testCase => {
await cookieStore.set('cookie-name', 'cookie-value'); await cookieStore.set('cookie-name', 'cookie-value');
...@@ -107,10 +72,10 @@ promise_test(async testCase => { ...@@ -107,10 +72,10 @@ promise_test(async testCase => {
await cookieStore.delete('cookie-name'); await cookieStore.delete('cookie-name');
}); });
const cookie = await cookieStore.get({ matchType: 'equals' }); const cookie = await cookieStore.get({ name: 'cookie-name' });
assert_equals(cookie.name, 'cookie-name'); assert_equals(cookie.name, 'cookie-name');
assert_equals(cookie.value, 'cookie-value'); assert_equals(cookie.value, 'cookie-value');
}, 'cookieStore.get with matchType set to equals and missing name'); }, 'cookieStore.get with name in options');
promise_test(async testCase => { promise_test(async testCase => {
await cookieStore.set('cookie-name', 'cookie-value'); await cookieStore.set('cookie-name', 'cookie-value');
...@@ -118,10 +83,11 @@ promise_test(async testCase => { ...@@ -118,10 +83,11 @@ promise_test(async testCase => {
await cookieStore.delete('cookie-name'); await cookieStore.delete('cookie-name');
}); });
const cookie = await cookieStore.get({ matchType: 'starts-with' }); const cookie = await cookieStore.get('cookie-name',
{ name: 'wrong-cookie-name' });
assert_equals(cookie.name, 'cookie-name'); assert_equals(cookie.name, 'cookie-name');
assert_equals(cookie.value, 'cookie-value'); assert_equals(cookie.value, 'cookie-value');
}, 'cookieStore.get with matchType set to starts-with and missing name'); }, 'cookieStore.get with name in both positional arguments and options');
promise_test(async testCase => { promise_test(async testCase => {
await cookieStore.set('cookie-name', 'cookie-value'); await cookieStore.set('cookie-name', 'cookie-value');
......
...@@ -25,9 +25,7 @@ promise_test(async testCase => { ...@@ -25,9 +25,7 @@ promise_test(async testCase => {
} }
{ {
const subscriptions = [ const subscriptions = [{ name: 'cookie-name' }];
{ name: 'cookie-name', matchType: 'equals' }
];
await self.registration.cookies.subscribe(subscriptions); await self.registration.cookies.subscribe(subscriptions);
testCase.add_cleanup(() => registration.cookies.unsubscribe(subscriptions)); testCase.add_cleanup(() => registration.cookies.unsubscribe(subscriptions));
} }
...@@ -36,7 +34,6 @@ promise_test(async testCase => { ...@@ -36,7 +34,6 @@ promise_test(async testCase => {
assert_equals(subscriptions.length, 1); assert_equals(subscriptions.length, 1);
assert_equals(subscriptions[0].name, 'cookie-name'); assert_equals(subscriptions[0].name, 'cookie-name');
assert_equals(subscriptions[0].matchType, 'equals');
assert_equals(subscriptions[0].url, registration.scope); assert_equals(subscriptions[0].url, registration.scope);
}, 'cookieStore.subscribe without url in option'); }, 'cookieStore.subscribe without url in option');
...@@ -62,7 +59,7 @@ promise_test(async testCase => { ...@@ -62,7 +59,7 @@ promise_test(async testCase => {
await promise_rejects_js(testCase, TypeError, await promise_rejects_js(testCase, TypeError,
registration.cookies.subscribe( registration.cookies.subscribe(
{ name: 'cookie-name', matchType: 'equals', url: '/wrong/path' })); { name: 'cookie-name', url: '/wrong/path' }));
}, 'cookieStore.subscribe with invalid url path in option'); }, 'cookieStore.subscribe with invalid url path in option');
promise_test(async testCase => { promise_test(async testCase => {
...@@ -86,9 +83,7 @@ promise_test(async testCase => { ...@@ -86,9 +83,7 @@ promise_test(async testCase => {
} }
{ {
const subscriptions = [ const subscriptions = [{ name: 'cookie-name' }];
{ name: 'cookie-name', matchType: 'equals' }
];
// Call subscribe for same subscription multiple times to verify that it is // Call subscribe for same subscription multiple times to verify that it is
// idempotent. // idempotent.
await self.registration.cookies.subscribe(subscriptions); await self.registration.cookies.subscribe(subscriptions);
...@@ -101,7 +96,6 @@ promise_test(async testCase => { ...@@ -101,7 +96,6 @@ promise_test(async testCase => {
assert_equals(subscriptions.length, 1); assert_equals(subscriptions.length, 1);
assert_equals(subscriptions[0].name, 'cookie-name'); assert_equals(subscriptions[0].name, 'cookie-name');
assert_equals(subscriptions[0].matchType, 'equals');
assert_equals(subscriptions[0].url, registration.scope); assert_equals(subscriptions[0].url, registration.scope);
}, 'cookieStore.subscribe is idempotent'); }, 'cookieStore.subscribe is idempotent');
...@@ -127,8 +121,8 @@ promise_test(async testCase => { ...@@ -127,8 +121,8 @@ promise_test(async testCase => {
{ {
const subscriptions = [ const subscriptions = [
{ name: 'cookie-name1', matchType: 'equals' }, { name: 'cookie-name1' },
{ name: 'cookie-name2', matchType: 'equals' } { name: 'cookie-name2' },
]; ];
await self.registration.cookies.subscribe(subscriptions); await self.registration.cookies.subscribe(subscriptions);
testCase.add_cleanup(() => registration.cookies.unsubscribe(subscriptions)); testCase.add_cleanup(() => registration.cookies.unsubscribe(subscriptions));
...@@ -144,6 +138,5 @@ promise_test(async testCase => { ...@@ -144,6 +138,5 @@ promise_test(async testCase => {
assert_equals(subscriptions.length, 1); assert_equals(subscriptions.length, 1);
assert_equals(subscriptions[0].name, 'cookie-name2'); assert_equals(subscriptions[0].name, 'cookie-name2');
assert_equals(subscriptions[0].matchType, 'equals');
assert_equals(subscriptions[0].url, registration.scope); assert_equals(subscriptions[0].url, registration.scope);
}, 'CookieStore.unsubscribe is idempotent'); }, 'CookieStore.unsubscribe is idempotent');
...@@ -16,7 +16,7 @@ promise_test(async t => { ...@@ -16,7 +16,7 @@ promise_test(async t => {
t.add_cleanup(() => registration.unregister()); t.add_cleanup(() => registration.unregister());
await wait_for_state(t, registration.installing, 'activated'); await wait_for_state(t, registration.installing, 'activated');
await registration.cookies.subscribe( await registration.cookies.subscribe(
[{ name: 'cookie-name', matchType: 'equals' }]); [{ name: 'cookie-name' }]);
const original_subscriptions = await registration.cookies.getSubscriptions(); const original_subscriptions = await registration.cookies.getSubscriptions();
assert_equals(original_subscriptions.length, 1, assert_equals(original_subscriptions.length, 1,
'subscription count before unregistration'); 'subscription count before unregistration');
...@@ -39,7 +39,7 @@ promise_test(async t => { ...@@ -39,7 +39,7 @@ promise_test(async t => {
t.add_cleanup(() => registration.unregister()); t.add_cleanup(() => registration.unregister());
await wait_for_state(t, registration.installing, 'activated'); await wait_for_state(t, registration.installing, 'activated');
await registration.cookies.subscribe( await registration.cookies.subscribe(
[{ name: 'cookie-name', matchType: 'equals' }]); [{ name: 'cookie-name' }]);
const original_subscriptions = await registration.cookies.getSubscriptions(); const original_subscriptions = await registration.cookies.getSubscriptions();
assert_equals(original_subscriptions.length, 1, assert_equals(original_subscriptions.length, 1,
'subscription count before update'); 'subscription count before update');
......
...@@ -20,9 +20,7 @@ const kCookieChangeReceivedPromise = new Promise((resolve) => { ...@@ -20,9 +20,7 @@ const kCookieChangeReceivedPromise = new Promise((resolve) => {
promise_test(async testCase => { promise_test(async testCase => {
await kServiceWorkerActivatedPromise; await kServiceWorkerActivatedPromise;
const subscriptions = [ const subscriptions = [{ name: 'cookie-name', url: `${kScope}/path` }];
{ name: 'cookie-name', matchType: 'equals', url: `${kScope}/path` },
];
await registration.cookies.subscribe(subscriptions); await registration.cookies.subscribe(subscriptions);
testCase.add_cleanup(() => registration.cookies.unsubscribe(subscriptions)); testCase.add_cleanup(() => registration.cookies.unsubscribe(subscriptions));
......
...@@ -34,16 +34,14 @@ promise_test(async testCase => { ...@@ -34,16 +34,14 @@ promise_test(async testCase => {
await kServiceWorkerActivatedPromise; await kServiceWorkerActivatedPromise;
{ {
const subscriptions = [ const subscriptions = [{ name: 'cookie-name1', url: `${kScope}/path1` }];
{ name: 'cookie-name1', matchType: 'equals', url: `${kScope}/path1` },
];
await registration.cookies.subscribe(subscriptions); await registration.cookies.subscribe(subscriptions);
testCase.add_cleanup(() => registration.cookies.unsubscribe(subscriptions)); testCase.add_cleanup(() => registration.cookies.unsubscribe(subscriptions));
} }
{ {
const subscriptions = [ const subscriptions = [
{ }, // Test the default values for subscription properties. { }, // Test the default values for subscription properties.
{ name: 'cookie-prefix', matchType: 'starts-with' }, { name: 'cookie-name2' },
]; ];
await registration.cookies.subscribe(subscriptions); await registration.cookies.subscribe(subscriptions);
testCase.add_cleanup(() => registration.cookies.unsubscribe(subscriptions)); testCase.add_cleanup(() => registration.cookies.unsubscribe(subscriptions));
......
...@@ -35,8 +35,8 @@ promise_test(async testCase => { ...@@ -35,8 +35,8 @@ promise_test(async testCase => {
await kServiceWorkerActivatedPromise; await kServiceWorkerActivatedPromise;
const subscriptions = [ const subscriptions = [
{ name: 'coo', matchType: 'starts-with' }, { name: 'cookie-name' },
{ name: 'cookie', matchType: 'starts-with' }, { url: `${kScope}/path` }
]; ];
await registration.cookies.subscribe(subscriptions); await registration.cookies.subscribe(subscriptions);
testCase.add_cleanup(() => registration.cookies.unsubscribe(subscriptions)); testCase.add_cleanup(() => registration.cookies.unsubscribe(subscriptions));
......
...@@ -18,9 +18,7 @@ const kCookieChangeReceivedPromise = new Promise(resolve => { ...@@ -18,9 +18,7 @@ const kCookieChangeReceivedPromise = new Promise(resolve => {
promise_test(async testCase => { promise_test(async testCase => {
await kServiceWorkerActivatedPromise; await kServiceWorkerActivatedPromise;
const subscriptions = [ const subscriptions = [{ name: 'cookie-name', url: `${kScope}/path` }];
{ name: 'cookie-name', matchType: 'equals', url: `${kScope}/path` },
];
await registration.cookies.subscribe(subscriptions); await registration.cookies.subscribe(subscriptions);
testCase.add_cleanup(() => registration.cookies.unsubscribe(subscriptions)); testCase.add_cleanup(() => registration.cookies.unsubscribe(subscriptions));
......
...@@ -18,9 +18,7 @@ const kCookieChangeReceivedPromise = new Promise(resolve => { ...@@ -18,9 +18,7 @@ const kCookieChangeReceivedPromise = new Promise(resolve => {
promise_test(async testCase => { promise_test(async testCase => {
await kServiceWorkerActivatedPromise; await kServiceWorkerActivatedPromise;
const subscriptions = [ const subscriptions = [{ name: 'cookie-name', url: `${kScope}/path` }];
{ name: 'cookie-name', matchType: 'equals', url: `${kScope}/path` }
];
await registration.cookies.subscribe(subscriptions); await registration.cookies.subscribe(subscriptions);
testCase.add_cleanup(() => registration.cookies.unsubscribe(subscriptions)); testCase.add_cleanup(() => registration.cookies.unsubscribe(subscriptions));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment