diff --git a/android_webview/browser/network_service/aw_proxying_restricted_cookie_manager.cc b/android_webview/browser/network_service/aw_proxying_restricted_cookie_manager.cc index 1a8f0801a6bbe..83154d42933af 100644 --- a/android_webview/browser/network_service/aw_proxying_restricted_cookie_manager.cc +++ b/android_webview/browser/network_service/aw_proxying_restricted_cookie_manager.cc @@ -30,11 +30,10 @@ class AwProxyingRestrictedCookieManagerListener aw_restricted_cookie_manager_(aw_restricted_cookie_manager), client_listener_(std::move(client_listener)) {} - void OnCookieChange(const net::CanonicalCookie& cookie, - network::mojom::CookieChangeCause cause) override { + void OnCookieChange(const net::CookieChangeInfo& change) override { if (aw_restricted_cookie_manager_ && aw_restricted_cookie_manager_->AllowCookies(url_, site_for_cookies_)) - client_listener_->OnCookieChange(cookie, cause); + client_listener_->OnCookieChange(change); } private: diff --git a/chrome/browser/chromeos/android_sms/android_sms_pairing_state_tracker_impl.cc b/chrome/browser/chromeos/android_sms/android_sms_pairing_state_tracker_impl.cc index b8d1a4f6de950..e82731981a3e5 100644 --- a/chrome/browser/chromeos/android_sms/android_sms_pairing_state_tracker_impl.cc +++ b/chrome/browser/chromeos/android_sms/android_sms_pairing_state_tracker_impl.cc @@ -75,10 +75,9 @@ void AndroidSmsPairingStateTrackerImpl::OnCookiesRetrieved( } void AndroidSmsPairingStateTrackerImpl::OnCookieChange( - const net::CanonicalCookie& cookie, - network::mojom::CookieChangeCause cause) { - DCHECK_EQ(kMessagesPairStateCookieName, cookie.Name()); - DCHECK(cookie.IsDomainMatch(GetPairingUrl().host())); + const net::CookieChangeInfo& change) { + DCHECK_EQ(kMessagesPairStateCookieName, change.cookie.Name()); + DCHECK(change.cookie.IsDomainMatch(GetPairingUrl().host())); // NOTE: cookie.Value() cannot be trusted in this callback. The cookie may // have expired or been removed and the Value() does not get updated. It's diff --git a/chrome/browser/chromeos/android_sms/android_sms_pairing_state_tracker_impl.h b/chrome/browser/chromeos/android_sms/android_sms_pairing_state_tracker_impl.h index 01dd195c9f1ea..16e19c0c072d7 100644 --- a/chrome/browser/chromeos/android_sms/android_sms_pairing_state_tracker_impl.h +++ b/chrome/browser/chromeos/android_sms/android_sms_pairing_state_tracker_impl.h @@ -36,8 +36,7 @@ class AndroidSmsPairingStateTrackerImpl private: // network::mojom::CookieChangeListener: - void OnCookieChange(const net::CanonicalCookie& cookie, - network::mojom::CookieChangeCause cause) override; + void OnCookieChange(const net::CookieChangeInfo& change) override; // AndroidSmsAppManager::Observer: void OnInstalledAppUrlChanged() override; diff --git a/chrome/browser/extensions/api/cookies/cookies_api.cc b/chrome/browser/extensions/api/cookies/cookies_api.cc index aca854a958e73..e30f454b5b33b 100644 --- a/chrome/browser/extensions/api/cookies/cookies_api.cc +++ b/chrome/browser/extensions/api/cookies/cookies_api.cc @@ -95,9 +95,8 @@ CookiesEventRouter::CookieChangeListener::CookieChangeListener( CookiesEventRouter::CookieChangeListener::~CookieChangeListener() = default; void CookiesEventRouter::CookieChangeListener::OnCookieChange( - const net::CanonicalCookie& canonical_cookie, - network::mojom::CookieChangeCause cause) { - router_->OnCookieChange(otr_, canonical_cookie, cause); + const net::CookieChangeInfo& change) { + router_->OnCookieChange(otr_, change); } CookiesEventRouter::CookiesEventRouter(content::BrowserContext* context) @@ -110,50 +109,48 @@ CookiesEventRouter::~CookiesEventRouter() { BrowserList::RemoveObserver(this); } -void CookiesEventRouter::OnCookieChange( - bool otr, - const net::CanonicalCookie& canonical_cookie, - network::mojom::CookieChangeCause cause) { +void CookiesEventRouter::OnCookieChange(bool otr, + const net::CookieChangeInfo& change) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); std::unique_ptr args(new base::ListValue()); std::unique_ptr dict(new base::DictionaryValue()); dict->SetBoolean(cookies_api_constants::kRemovedKey, - cause != network::mojom::CookieChangeCause::INSERTED); + change.cause != net::CookieChangeCause::INSERTED); Profile* profile = otr ? profile_->GetOffTheRecordProfile() : profile_->GetOriginalProfile(); api::cookies::Cookie cookie = cookies_helpers::CreateCookie( - canonical_cookie, cookies_helpers::GetStoreIdFromProfile(profile)); + change.cookie, cookies_helpers::GetStoreIdFromProfile(profile)); dict->Set(cookies_api_constants::kCookieKey, cookie.ToValue()); // Map the internal cause to an external string. std::string cause_dict_entry; - switch (cause) { + switch (change.cause) { // Report an inserted cookie as an "explicit" change cause. All other causes // only make sense for deletions. - case network::mojom::CookieChangeCause::INSERTED: - case network::mojom::CookieChangeCause::EXPLICIT: + case net::CookieChangeCause::INSERTED: + case net::CookieChangeCause::EXPLICIT: cause_dict_entry = cookies_api_constants::kExplicitChangeCause; break; - case network::mojom::CookieChangeCause::OVERWRITE: + case net::CookieChangeCause::OVERWRITE: cause_dict_entry = cookies_api_constants::kOverwriteChangeCause; break; - case network::mojom::CookieChangeCause::EXPIRED: + case net::CookieChangeCause::EXPIRED: cause_dict_entry = cookies_api_constants::kExpiredChangeCause; break; - case network::mojom::CookieChangeCause::EVICTED: + case net::CookieChangeCause::EVICTED: cause_dict_entry = cookies_api_constants::kEvictedChangeCause; break; - case network::mojom::CookieChangeCause::EXPIRED_OVERWRITE: + case net::CookieChangeCause::EXPIRED_OVERWRITE: cause_dict_entry = cookies_api_constants::kExpiredOverwriteChangeCause; break; - case network::mojom::CookieChangeCause::UNKNOWN_DELETION: + case net::CookieChangeCause::UNKNOWN_DELETION: NOTREACHED(); } dict->SetString(cookies_api_constants::kCauseKey, cause_dict_entry); @@ -162,7 +159,7 @@ void CookiesEventRouter::OnCookieChange( DispatchEvent(profile, events::COOKIES_ON_CHANGED, api::cookies::OnChanged::kEventName, std::move(args), - cookies_helpers::GetURLFromCanonicalCookie(canonical_cookie)); + cookies_helpers::GetURLFromCanonicalCookie(change.cookie)); } void CookiesEventRouter::OnBrowserAdded(Browser* browser) { diff --git a/chrome/browser/extensions/api/cookies/cookies_api.h b/chrome/browser/extensions/api/cookies/cookies_api.h index ac95fc3573668..0761d5333fbcc 100644 --- a/chrome/browser/extensions/api/cookies/cookies_api.h +++ b/chrome/browser/extensions/api/cookies/cookies_api.h @@ -22,6 +22,7 @@ #include "mojo/public/cpp/bindings/receiver.h" #include "mojo/public/cpp/bindings/remote.h" #include "net/cookies/canonical_cookie.h" +#include "net/cookies/cookie_change_dispatcher.h" #include "services/network/public/mojom/cookie_manager.mojom.h" #include "url/gurl.h" @@ -49,8 +50,7 @@ class CookiesEventRouter : public BrowserListObserver { ~CookieChangeListener() override; // network::mojom::CookieChangeListener: - void OnCookieChange(const net::CanonicalCookie& canonical_cookie, - network::mojom::CookieChangeCause cause) override; + void OnCookieChange(const net::CookieChangeInfo& change) override; private: CookiesEventRouter* router_; @@ -65,9 +65,7 @@ class CookiesEventRouter : public BrowserListObserver { Profile* profile); void OnConnectionError( mojo::Receiver* receiver); - void OnCookieChange(bool otr, - const net::CanonicalCookie& canonical_cookie, - network::mojom::CookieChangeCause cause); + void OnCookieChange(bool otr, const net::CookieChangeInfo& change); // This method dispatches events to the extension message service. void DispatchEvent(content::BrowserContext* context, diff --git a/chrome/browser/signin/consistency_cookie_browsertest.cc b/chrome/browser/signin/consistency_cookie_browsertest.cc index f465e02b3fb6c..02919856020c1 100644 --- a/chrome/browser/signin/consistency_cookie_browsertest.cc +++ b/chrome/browser/signin/consistency_cookie_browsertest.cc @@ -67,9 +67,8 @@ class TestConsistencyCookieManager } // CookieChangeListener: - void OnCookieChange(const net::CanonicalCookie& cookie, - network::mojom::CookieChangeCause cause) override { - if (cookie.Name() != kConsistencyCookieName) + void OnCookieChange(const net::CookieChangeInfo& change) override { + if (change.cookie.Name() != kConsistencyCookieName) return; if (!run_loop_quit_closure_.is_null()) std::move(run_loop_quit_closure_).Run(); diff --git a/components/signin/internal/identity_manager/gaia_cookie_manager_service.cc b/components/signin/internal/identity_manager/gaia_cookie_manager_service.cc index 6ea30bc77ddba..29953e4221661 100644 --- a/components/signin/internal/identity_manager/gaia_cookie_manager_service.cc +++ b/components/signin/internal/identity_manager/gaia_cookie_manager_service.cc @@ -32,6 +32,7 @@ #include "net/base/load_flags.h" #include "net/base/net_errors.h" #include "net/cookies/cookie_change_dispatcher.h" +#include "net/cookies/cookie_constants.h" #include "net/http/http_status_code.h" #include "net/traffic_annotation/network_traffic_annotation.h" #include "services/network/public/cpp/resource_request.h" @@ -580,7 +581,9 @@ void GaiaCookieManagerService::ForceOnCookieChangeProcessing() { base::Time(), base::Time(), base::Time(), true /* secure */, false /* httponly */, net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_DEFAULT)); - OnCookieChange(*cookie, network::mojom::CookieChangeCause::UNKNOWN_DELETION); + OnCookieChange( + net::CookieChangeInfo(*cookie, net::CookieAccessSemantics::UNKNOWN, + net::CookieChangeCause::UNKNOWN_DELETION)); } void GaiaCookieManagerService::LogOutAllAccounts(gaia::GaiaSource source) { @@ -658,13 +661,13 @@ void GaiaCookieManagerService::MarkListAccountsStale() { } void GaiaCookieManagerService::OnCookieChange( - const net::CanonicalCookie& cookie, - network::mojom::CookieChangeCause cause) { - DCHECK_EQ(kGaiaCookieName, cookie.Name()); - DCHECK(cookie.IsDomainMatch(GaiaUrls::GetInstance()->google_url().host())); + const net::CookieChangeInfo& change) { + DCHECK_EQ(kGaiaCookieName, change.cookie.Name()); + DCHECK(change.cookie.IsDomainMatch( + GaiaUrls::GetInstance()->google_url().host())); list_accounts_stale_ = true; - if (cause == network::mojom::CookieChangeCause::EXPLICIT) { + if (change.cause == net::CookieChangeCause::EXPLICIT) { DCHECK(net::CookieChangeCauseIsDeletion(net::CookieChangeCause::EXPLICIT)); if (gaia_cookie_deleted_by_user_action_callback_) { gaia_cookie_deleted_by_user_action_callback_.Run(); diff --git a/components/signin/internal/identity_manager/gaia_cookie_manager_service.h b/components/signin/internal/identity_manager/gaia_cookie_manager_service.h index 61df0d3302474..730b18ce2cca1 100644 --- a/components/signin/internal/identity_manager/gaia_cookie_manager_service.h +++ b/components/signin/internal/identity_manager/gaia_cookie_manager_service.h @@ -26,6 +26,7 @@ #include "google_apis/gaia/gaia_auth_util.h" #include "mojo/public/cpp/bindings/receiver.h" #include "net/base/backoff_entry.h" +#include "net/cookies/cookie_change_dispatcher.h" #include "services/network/public/mojom/cookie_manager.mojom.h" class GaiaAuthFetcher; @@ -312,8 +313,7 @@ class GaiaCookieManagerService : public GaiaAuthConsumer, // Overridden from network::mojom::CookieChangeListner. If the cookie relates // to a GAIA APISID cookie, then we call ListAccounts and fire // OnGaiaAccountsInCookieUpdated. - void OnCookieChange(const net::CanonicalCookie& cookie, - network::mojom::CookieChangeCause cause) override; + void OnCookieChange(const net::CookieChangeInfo& change) override; void OnCookieListenerConnectionError(); // Overridden from GaiaAuthConsumer. diff --git a/components/signin/public/identity_manager/identity_manager_unittest.cc b/components/signin/public/identity_manager/identity_manager_unittest.cc index 764368c84d66e..d15f8eb897e29 100644 --- a/components/signin/public/identity_manager/identity_manager_unittest.cc +++ b/components/signin/public/identity_manager/identity_manager_unittest.cc @@ -41,6 +41,8 @@ #include "components/sync_preferences/testing_pref_service_syncable.h" #include "google_apis/gaia/core_account_id.h" #include "google_apis/gaia/google_service_auth_error.h" +#include "net/cookies/cookie_change_dispatcher.h" +#include "net/cookies/cookie_constants.h" #include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h" #include "services/network/test/test_cookie_manager.h" #include "services/network/test/test_url_loader_factory.h" @@ -383,8 +385,9 @@ class IdentityManagerTest : public testing::Test { void SimulateCookieDeletedByUser( network::mojom::CookieChangeListener* listener, const net::CanonicalCookie& cookie) { - listener->OnCookieChange(cookie, - network::mojom::CookieChangeCause::EXPLICIT); + listener->OnCookieChange( + net::CookieChangeInfo(cookie, net::CookieAccessSemantics::UNKNOWN, + net::CookieChangeCause::EXPLICIT)); } void SimulateOAuthMultiloginFinished(GaiaCookieManagerService* manager, @@ -2061,7 +2064,8 @@ TEST_F(IdentityManagerTest, OnNetworkInitialized) { base::Time(), /*secure=*/true, false, net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_DEFAULT); test_cookie_manager_ptr->DispatchCookieChange( - cookie, network::mojom::CookieChangeCause::EXPLICIT); + net::CookieChangeInfo(cookie, net::CookieAccessSemantics::UNKNOWN, + net::CookieChangeCause::EXPLICIT)); run_loop.Run(); } diff --git a/content/browser/cookie_store/cookie_change_subscription.cc b/content/browser/cookie_store/cookie_change_subscription.cc index 4d61fbf4dc4c3..ff5de3f6999d4 100644 --- a/content/browser/cookie_store/cookie_change_subscription.cc +++ b/content/browser/cookie_store/cookie_change_subscription.cc @@ -158,7 +158,8 @@ void CookieChangeSubscription::Serialize( } bool CookieChangeSubscription::ShouldObserveChangeTo( - const net::CanonicalCookie& cookie) const { + const net::CanonicalCookie& cookie, + net::CookieAccessSemantics access_semantics) const { switch (match_type_) { case ::network::mojom::CookieMatchType::EQUALS: if (cookie.Name() != name_) @@ -174,7 +175,8 @@ bool CookieChangeSubscription::ShouldObserveChangeTo( net_options.set_same_site_cookie_context( net::CookieOptions::SameSiteCookieContext::SAME_SITE_STRICT); - return cookie.IncludeForRequestURL(url_, net_options).IsInclude(); + return cookie.IncludeForRequestURL(url_, net_options, access_semantics) + .IsInclude(); } } // namespace content diff --git a/content/browser/cookie_store/cookie_change_subscription.h b/content/browser/cookie_store/cookie_change_subscription.h index c2c4839a26d14..8276cd201447b 100644 --- a/content/browser/cookie_store/cookie_change_subscription.h +++ b/content/browser/cookie_store/cookie_change_subscription.h @@ -98,7 +98,8 @@ class CookieChangeSubscription blink::mojom::CookieChangeSubscription* mojo_subscription) const; // True if the subscription covers a change to the given cookie. - bool ShouldObserveChangeTo(const net::CanonicalCookie& cookie) const; + bool ShouldObserveChangeTo(const net::CanonicalCookie& cookie, + net::CookieAccessSemantics access_semantics) const; private: const GURL url_; diff --git a/content/browser/cookie_store/cookie_store_manager.cc b/content/browser/cookie_store/cookie_store_manager.cc index 2f8a925ece767..63dea53074787 100644 --- a/content/browser/cookie_store/cookie_store_manager.cc +++ b/content/browser/cookie_store/cookie_store_manager.cc @@ -444,16 +444,14 @@ void CookieStoreManager::OnStorageWiped() { subscriptions_by_registration_.clear(); } -void CookieStoreManager::OnCookieChange( - const net::CanonicalCookie& cookie, - ::network::mojom::CookieChangeCause cause) { +void CookieStoreManager::OnCookieChange(const net::CookieChangeInfo& change) { // Waiting for on-disk subscriptions to be loaded ensures that changes are // delivered to all service workers that subscribed to them in previous // browser sessions. Without waiting, workers might miss cookie changes. if (!done_loading_subscriptions_) { subscriptions_loaded_callbacks_.emplace_back( base::BindOnce(&CookieStoreManager::OnCookieChange, - weak_factory_.GetWeakPtr(), cookie, cause)); + weak_factory_.GetWeakPtr(), change)); return; } @@ -464,7 +462,7 @@ void CookieStoreManager::OnCookieChange( // net::CookieMonsterChangeDispatcher::DomainKey. Extract that // implementation into net/cookies.cookie_util.h and call it. std::string url_key = net::registry_controlled_domains::GetDomainAndRegistry( - cookie.Domain(), + change.cookie.Domain(), net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); auto it = subscriptions_by_url_key_.find(url_key); if (it == subscriptions_by_url_key_.end()) @@ -475,7 +473,8 @@ void CookieStoreManager::OnCookieChange( subscriptions.head(); node != subscriptions.end(); node = node->next()) { const CookieChangeSubscription* subscription = node->value(); - if (subscription->ShouldObserveChangeTo(cookie)) { + if (subscription->ShouldObserveChangeTo(change.cookie, + change.access_semantics)) { interested_registration_ids.insert( subscription->service_worker_registration_id()); } @@ -487,8 +486,7 @@ void CookieStoreManager::OnCookieChange( registration_id, base::BindOnce( [](base::WeakPtr manager, - const net::CanonicalCookie& cookie, - ::network::mojom::CookieChangeCause cause, + const net::CookieChangeInfo& change, blink::ServiceWorkerStatusCode find_status, scoped_refptr registration) { if (find_status != blink::ServiceWorkerStatusCode::kOk) @@ -497,17 +495,15 @@ void CookieStoreManager::OnCookieChange( DCHECK(registration); if (!manager) return; - manager->DispatchChangeEvent(std::move(registration), cookie, - cause); + manager->DispatchChangeEvent(std::move(registration), change); }, - weak_factory_.GetWeakPtr(), cookie, cause)); + weak_factory_.GetWeakPtr(), change)); } } void CookieStoreManager::DispatchChangeEvent( scoped_refptr registration, - const net::CanonicalCookie& cookie, - ::network::mojom::CookieChangeCause cause) { + const net::CookieChangeInfo& change) { scoped_refptr active_version = registration->active_version(); if (active_version->running_status() != EmbeddedWorkerStatus::RUNNING) { @@ -515,7 +511,7 @@ void CookieStoreManager::DispatchChangeEvent( ServiceWorkerMetrics::EventType::COOKIE_CHANGE, base::BindOnce(&CookieStoreManager::DidStartWorkerForChangeEvent, weak_factory_.GetWeakPtr(), std::move(registration), - cookie, cause)); + change)); return; } @@ -523,17 +519,16 @@ void CookieStoreManager::DispatchChangeEvent( ServiceWorkerMetrics::EventType::COOKIE_CHANGE, base::DoNothing()); active_version->endpoint()->DispatchCookieChangeEvent( - cookie, cause, active_version->CreateSimpleEventCallback(request_id)); + change, active_version->CreateSimpleEventCallback(request_id)); } void CookieStoreManager::DidStartWorkerForChangeEvent( scoped_refptr registration, - const net::CanonicalCookie& cookie, - ::network::mojom::CookieChangeCause cause, + const net::CookieChangeInfo& change, blink::ServiceWorkerStatusCode start_worker_status) { if (start_worker_status != blink::ServiceWorkerStatusCode::kOk) return; - DispatchChangeEvent(std::move(registration), cookie, cause); + DispatchChangeEvent(std::move(registration), change); } } // namespace content diff --git a/content/browser/cookie_store/cookie_store_manager.h b/content/browser/cookie_store/cookie_store_manager.h index 5d193b0406fd4..12fc6a5d85302 100644 --- a/content/browser/cookie_store/cookie_store_manager.h +++ b/content/browser/cookie_store/cookie_store_manager.h @@ -96,8 +96,7 @@ class CookieStoreManager : public ServiceWorkerContextCoreObserver, void OnStorageWiped() override; // ::network::mojom::CookieChangeListener - void OnCookieChange(const net::CanonicalCookie& cookie, - ::network::mojom::CookieChangeCause cause) override; + void OnCookieChange(const net::CookieChangeInfo& change) override; private: // Updates internal state with the result of loading disk subscription data. @@ -132,20 +131,17 @@ class CookieStoreManager : public ServiceWorkerContextCoreObserver, // // Must only be called after the on-disk subscription data is successfully // loaded. - void DispatchCookieChange(const net::CanonicalCookie& cookie, - ::network::mojom::CookieChangeCause cause); + void DispatchCookieChange(const net::CookieChangeInfo& change); // Sends a cookie change event to one service worker. void DispatchChangeEvent( scoped_refptr registration, - const net::CanonicalCookie& cookie, - ::network::mojom::CookieChangeCause cause); + const net::CookieChangeInfo& change); // Called after a service worker was started so it can get a cookie change. void DidStartWorkerForChangeEvent( scoped_refptr registration, - const net::CanonicalCookie& cookie, - ::network::mojom::CookieChangeCause cause, + const net::CookieChangeInfo& change, blink::ServiceWorkerStatusCode start_worker_status); // Used to efficiently implement OnRegistrationDeleted(). diff --git a/content/browser/cookie_store/cookie_store_manager_unittest.cc b/content/browser/cookie_store/cookie_store_manager_unittest.cc index f0d77c761895e..3c2e0e4acb218 100644 --- a/content/browser/cookie_store/cookie_store_manager_unittest.cc +++ b/content/browser/cookie_store/cookie_store_manager_unittest.cc @@ -9,6 +9,7 @@ #include "base/macros.h" #include "base/memory/scoped_refptr.h" #include "base/test/bind_test_util.h" +#include "base/test/scoped_feature_list.h" #include "content/browser/cookie_store/cookie_store_context.h" #include "content/browser/cookie_store/cookie_store_manager.h" #include "content/browser/service_worker/embedded_worker_test_helper.h" @@ -18,6 +19,8 @@ #include "content/browser/storage_partition_impl.h" #include "content/public/test/browser_task_environment.h" #include "content/public/test/test_browser_context.h" +#include "net/base/features.h" +#include "net/cookies/cookie_constants.h" #include "services/network/public/cpp/features.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/blink/public/mojom/service_worker/service_worker.mojom.h" @@ -80,6 +83,8 @@ const char kExampleScope[] = "https://example.com/a"; const char kExampleWorkerScript[] = "https://example.com/a/script.js"; const char kGoogleScope[] = "https://google.com/a"; const char kGoogleWorkerScript[] = "https://google.com/a/script.js"; +const char kLegacyScope[] = "https://legacy.com/a"; +const char kLegacyWorkerScript[] = "https://legacy.com/a/script.js"; // Mocks a service worker that uses the cookieStore API. class CookieStoreWorkerTestHelper : public EmbeddedWorkerTestHelper { @@ -155,10 +160,9 @@ class CookieStoreWorkerTestHelper : public EmbeddedWorkerTestHelper { } void DispatchCookieChangeEvent( - const net::CanonicalCookie& cookie, - ::network::mojom::CookieChangeCause cause, + const net::CookieChangeInfo& change, DispatchCookieChangeEventCallback callback) override { - worker_helper_->changes_.emplace_back(cookie, cause); + worker_helper_->changes_.emplace_back(change); std::move(callback).Run( blink::mojom::ServiceWorkerEventStatus::COMPLETED); } @@ -196,11 +200,7 @@ class CookieStoreWorkerTestHelper : public EmbeddedWorkerTestHelper { } // The data in the CookieChangeEvents received by the worker. - std::vector< - std::pair>& - changes() { - return changes_; - } + std::vector& changes() { return changes_; } private: // Used to add cookie change subscriptions during OnInstallEvent(). @@ -213,9 +213,7 @@ class CookieStoreWorkerTestHelper : public EmbeddedWorkerTestHelper { base::RunLoop* quit_on_activate_ = nullptr; // Collects the changes reported to OnCookieChangeEvent(). - std::vector< - std::pair> - changes_; + std::vector changes_; }; } // namespace @@ -227,7 +225,13 @@ class CookieStoreManagerTest public testing::WithParamInterface { public: CookieStoreManagerTest() - : task_environment_(BrowserTaskEnvironment::IO_MAINLOOP) {} + : task_environment_(BrowserTaskEnvironment::IO_MAINLOOP) { + // Enable SameSiteByDefaultCookies because the default CookieAccessSemantics + // setting is based on the state of this feature, and we want a consistent + // expected value in the tests for domains without a custom setting. + feature_list_.InitAndEnableFeature( + net::features::kSameSiteByDefaultCookies); + } void SetUp() override { // Use an on-disk service worker storage to test saving and loading. @@ -248,8 +252,10 @@ class CookieStoreManagerTest // called by ResetServiceWorkerContext(). example_service_.reset(); google_service_.reset(); + legacy_service_.reset(); example_service_remote_.reset(); google_service_remote_.reset(); + legacy_service_remote_.reset(); cookie_manager_.reset(); cookie_store_context_ = nullptr; storage_partition_impl_.reset(); @@ -292,6 +298,24 @@ class CookieStoreManagerTest google_service_remote_.BindNewPipeAndPassReceiver()); google_service_ = std::make_unique(google_service_remote_.get()); + + cookie_store_context_->CreateServiceForTesting( + url::Origin::Create(GURL(kLegacyScope)), + legacy_service_remote_.BindNewPipeAndPassReceiver()); + legacy_service_ = + std::make_unique(legacy_service_remote_.get()); + + // Set Legacy cookie access setting for legacy.com to test + // CookieAccessSemantics. + std::vector legacy_settings; + legacy_settings.emplace_back( + ContentSettingsPattern::FromString("[*.]legacy.com"), + ContentSettingsPattern::FromString("*"), + base::Value(ContentSetting::CONTENT_SETTING_ALLOW), std::string(), + false /* incognito */); + cookie_manager_->SetContentSettingsForLegacyCookieAccess( + std::move(legacy_settings)); + cookie_manager_.FlushForTesting(); } int64_t RegisterServiceWorker(const char* scope, const char* script_url) { @@ -323,10 +347,8 @@ class CookieStoreManagerTest bool SetCanonicalCookie(const net::CanonicalCookie& cookie) { base::RunLoop run_loop; bool success = false; - net::CookieOptions options; - options.set_include_httponly(); cookie_manager_->SetCanonicalCookie( - cookie, "https", options, + cookie, "https", net::CookieOptions::MakeAllInclusive(), base::BindLambdaForTesting( [&](net::CanonicalCookie::CookieInclusionStatus service_status) { success = service_status.IsInclude(); @@ -346,7 +368,7 @@ class CookieStoreManagerTest const char* path) { return SetCanonicalCookie(net::CanonicalCookie( name, value, domain, path, base::Time(), base::Time(), base::Time(), - /* secure = */ false, + /* secure = */ true, /* httponly = */ false, net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_DEFAULT)); } @@ -357,6 +379,7 @@ class CookieStoreManagerTest protected: BrowserTaskEnvironment task_environment_; + base::test::ScopedFeatureList feature_list_; base::ScopedTempDir user_data_directory_; std::unique_ptr worker_test_helper_; std::unique_ptr storage_partition_impl_; @@ -364,8 +387,9 @@ class CookieStoreManagerTest mojo::Remote<::network::mojom::CookieManager> cookie_manager_; mojo::Remote example_service_remote_, - google_service_remote_; - std::unique_ptr example_service_, google_service_; + google_service_remote_, legacy_service_remote_; + std::unique_ptr example_service_, google_service_, + legacy_service_; }; const int64_t CookieStoreManagerTest::kInvalidRegistrationId; @@ -758,12 +782,59 @@ TEST_P(CookieStoreManagerTest, OneCookieChange) { task_environment_.RunUntilIdle(); ASSERT_EQ(1u, worker_test_helper_->changes().size()); - EXPECT_EQ("cookie-name", worker_test_helper_->changes()[0].first.Name()); - EXPECT_EQ("cookie-value", worker_test_helper_->changes()[0].first.Value()); - EXPECT_EQ("example.com", worker_test_helper_->changes()[0].first.Domain()); - EXPECT_EQ("/", worker_test_helper_->changes()[0].first.Path()); - EXPECT_EQ(::network::mojom::CookieChangeCause::INSERTED, - worker_test_helper_->changes()[0].second); + EXPECT_EQ("cookie-name", worker_test_helper_->changes()[0].cookie.Name()); + EXPECT_EQ("cookie-value", worker_test_helper_->changes()[0].cookie.Value()); + EXPECT_EQ("example.com", worker_test_helper_->changes()[0].cookie.Domain()); + EXPECT_EQ("/", worker_test_helper_->changes()[0].cookie.Path()); + EXPECT_EQ(net::CookieChangeCause::INSERTED, + worker_test_helper_->changes()[0].cause); + // example.com does not have a custom access semantics setting, so it defaults + // to NONLEGACY, because the FeatureList has SameSiteByDefaultCookies enabled. + EXPECT_EQ(net::CookieAccessSemantics::NONLEGACY, + worker_test_helper_->changes()[0].access_semantics); +} + +// Same as above except this tests that the LEGACY access semantics for +// legacy.com cookies is correctly reflected in the change info. +TEST_P(CookieStoreManagerTest, OneCookieChangeLegacy) { + std::vector batches; + batches.emplace_back(); + + CookieStoreSync::Subscriptions& subscriptions = batches.back(); + subscriptions.emplace_back(blink::mojom::CookieChangeSubscription::New()); + subscriptions.back()->name = ""; + subscriptions.back()->match_type = + ::network::mojom::CookieMatchType::STARTS_WITH; + subscriptions.back()->url = GURL(kLegacyScope); + + worker_test_helper_->SetOnInstallSubscriptions(std::move(batches), + legacy_service_remote_.get()); + int64_t registration_id = + RegisterServiceWorker(kLegacyScope, kLegacyWorkerScript); + ASSERT_NE(registration_id, kInvalidRegistrationId); + + base::Optional all_subscriptions_opt = + legacy_service_->GetSubscriptions(registration_id); + ASSERT_TRUE(all_subscriptions_opt.has_value()); + ASSERT_EQ(1u, all_subscriptions_opt.value().size()); + + if (reset_context_during_test()) + ResetServiceWorkerContext(); + + ASSERT_TRUE( + SetSessionCookie("cookie-name", "cookie-value", "legacy.com", "/")); + task_environment_.RunUntilIdle(); + + ASSERT_EQ(1u, worker_test_helper_->changes().size()); + EXPECT_EQ("cookie-name", worker_test_helper_->changes()[0].cookie.Name()); + EXPECT_EQ("cookie-value", worker_test_helper_->changes()[0].cookie.Value()); + EXPECT_EQ("legacy.com", worker_test_helper_->changes()[0].cookie.Domain()); + EXPECT_EQ("/", worker_test_helper_->changes()[0].cookie.Path()); + EXPECT_EQ(net::CookieChangeCause::INSERTED, + worker_test_helper_->changes()[0].cause); + // legacy.com has a custom Legacy setting. + EXPECT_EQ(net::CookieAccessSemantics::LEGACY, + worker_test_helper_->changes()[0].access_semantics); } TEST_P(CookieStoreManagerTest, CookieChangeNameStartsWith) { @@ -802,12 +873,16 @@ TEST_P(CookieStoreManagerTest, CookieChangeNameStartsWith) { task_environment_.RunUntilIdle(); ASSERT_EQ(1u, worker_test_helper_->changes().size()); - EXPECT_EQ("cookie-name-2", worker_test_helper_->changes()[0].first.Name()); - EXPECT_EQ("cookie-value-2", worker_test_helper_->changes()[0].first.Value()); - EXPECT_EQ("example.com", worker_test_helper_->changes()[0].first.Domain()); - EXPECT_EQ("/", worker_test_helper_->changes()[0].first.Path()); - EXPECT_EQ(::network::mojom::CookieChangeCause::INSERTED, - worker_test_helper_->changes()[0].second); + EXPECT_EQ("cookie-name-2", worker_test_helper_->changes()[0].cookie.Name()); + EXPECT_EQ("cookie-value-2", worker_test_helper_->changes()[0].cookie.Value()); + EXPECT_EQ("example.com", worker_test_helper_->changes()[0].cookie.Domain()); + EXPECT_EQ("/", worker_test_helper_->changes()[0].cookie.Path()); + EXPECT_EQ(net::CookieChangeCause::INSERTED, + worker_test_helper_->changes()[0].cause); + // example.com does not have a custom access semantics setting, so it defaults + // to NONLEGACY, because the FeatureList has SameSiteByDefaultCookies enabled. + EXPECT_EQ(net::CookieAccessSemantics::NONLEGACY, + worker_test_helper_->changes()[0].access_semantics); worker_test_helper_->changes().clear(); ASSERT_TRUE(SetSessionCookie("cookie-name-22", "cookie-value-22", @@ -815,12 +890,83 @@ TEST_P(CookieStoreManagerTest, CookieChangeNameStartsWith) { task_environment_.RunUntilIdle(); ASSERT_EQ(1u, worker_test_helper_->changes().size()); - EXPECT_EQ("cookie-name-22", worker_test_helper_->changes()[0].first.Name()); - EXPECT_EQ("cookie-value-22", worker_test_helper_->changes()[0].first.Value()); - EXPECT_EQ("example.com", worker_test_helper_->changes()[0].first.Domain()); - EXPECT_EQ("/", worker_test_helper_->changes()[0].first.Path()); - EXPECT_EQ(::network::mojom::CookieChangeCause::INSERTED, - worker_test_helper_->changes()[0].second); + EXPECT_EQ("cookie-name-22", worker_test_helper_->changes()[0].cookie.Name()); + EXPECT_EQ("cookie-value-22", + worker_test_helper_->changes()[0].cookie.Value()); + EXPECT_EQ("example.com", worker_test_helper_->changes()[0].cookie.Domain()); + EXPECT_EQ("/", worker_test_helper_->changes()[0].cookie.Path()); + EXPECT_EQ(net::CookieChangeCause::INSERTED, + worker_test_helper_->changes()[0].cause); + // example.com does not have a custom access semantics setting, so it defaults + // to NONLEGACY, because the FeatureList has SameSiteByDefaultCookies enabled. + EXPECT_EQ(net::CookieAccessSemantics::NONLEGACY, + worker_test_helper_->changes()[0].access_semantics); +} + +// Same as above except this tests that the LEGACY access semantics for +// legacy.com cookies is correctly reflected in the change info. +TEST_P(CookieStoreManagerTest, CookieChangeNameStartsWithLegacy) { + std::vector batches; + batches.emplace_back(); + + CookieStoreSync::Subscriptions& subscriptions = batches.back(); + subscriptions.emplace_back(blink::mojom::CookieChangeSubscription::New()); + subscriptions.back()->name = "cookie-name-2"; + subscriptions.back()->match_type = + ::network::mojom::CookieMatchType::STARTS_WITH; + subscriptions.back()->url = GURL(kLegacyScope); + + worker_test_helper_->SetOnInstallSubscriptions(std::move(batches), + legacy_service_remote_.get()); + int64_t registration_id = + RegisterServiceWorker(kLegacyScope, kLegacyWorkerScript); + ASSERT_NE(registration_id, kInvalidRegistrationId); + + base::Optional all_subscriptions_opt = + legacy_service_->GetSubscriptions(registration_id); + ASSERT_TRUE(all_subscriptions_opt.has_value()); + ASSERT_EQ(1u, all_subscriptions_opt.value().size()); + + if (reset_context_during_test()) + ResetServiceWorkerContext(); + + ASSERT_TRUE( + SetSessionCookie("cookie-name-1", "cookie-value-1", "legacy.com", "/")); + task_environment_.RunUntilIdle(); + EXPECT_EQ(0u, worker_test_helper_->changes().size()); + + worker_test_helper_->changes().clear(); + ASSERT_TRUE( + SetSessionCookie("cookie-name-2", "cookie-value-2", "legacy.com", "/")); + task_environment_.RunUntilIdle(); + + ASSERT_EQ(1u, worker_test_helper_->changes().size()); + EXPECT_EQ("cookie-name-2", worker_test_helper_->changes()[0].cookie.Name()); + EXPECT_EQ("cookie-value-2", worker_test_helper_->changes()[0].cookie.Value()); + EXPECT_EQ("legacy.com", worker_test_helper_->changes()[0].cookie.Domain()); + EXPECT_EQ("/", worker_test_helper_->changes()[0].cookie.Path()); + EXPECT_EQ(net::CookieChangeCause::INSERTED, + worker_test_helper_->changes()[0].cause); + // legacy.com has a custom Legacy setting. + EXPECT_EQ(net::CookieAccessSemantics::LEGACY, + worker_test_helper_->changes()[0].access_semantics); + + worker_test_helper_->changes().clear(); + ASSERT_TRUE( + SetSessionCookie("cookie-name-22", "cookie-value-22", "legacy.com", "/")); + task_environment_.RunUntilIdle(); + + ASSERT_EQ(1u, worker_test_helper_->changes().size()); + EXPECT_EQ("cookie-name-22", worker_test_helper_->changes()[0].cookie.Name()); + EXPECT_EQ("cookie-value-22", + worker_test_helper_->changes()[0].cookie.Value()); + EXPECT_EQ("legacy.com", worker_test_helper_->changes()[0].cookie.Domain()); + EXPECT_EQ("/", worker_test_helper_->changes()[0].cookie.Path()); + EXPECT_EQ(net::CookieChangeCause::INSERTED, + worker_test_helper_->changes()[0].cause); + // legacy.com has a custom Legacy setting. + EXPECT_EQ(net::CookieAccessSemantics::LEGACY, + worker_test_helper_->changes()[0].access_semantics); } TEST_P(CookieStoreManagerTest, CookieChangeUrl) { @@ -865,12 +1011,16 @@ TEST_P(CookieStoreManagerTest, CookieChangeUrl) { task_environment_.RunUntilIdle(); ASSERT_EQ(1u, worker_test_helper_->changes().size()); - EXPECT_EQ("cookie-name-3", worker_test_helper_->changes()[0].first.Name()); - EXPECT_EQ("cookie-value-3", worker_test_helper_->changes()[0].first.Value()); - EXPECT_EQ("example.com", worker_test_helper_->changes()[0].first.Domain()); - EXPECT_EQ("/", worker_test_helper_->changes()[0].first.Path()); - EXPECT_EQ(::network::mojom::CookieChangeCause::INSERTED, - worker_test_helper_->changes()[0].second); + EXPECT_EQ("cookie-name-3", worker_test_helper_->changes()[0].cookie.Name()); + EXPECT_EQ("cookie-value-3", worker_test_helper_->changes()[0].cookie.Value()); + EXPECT_EQ("example.com", worker_test_helper_->changes()[0].cookie.Domain()); + EXPECT_EQ("/", worker_test_helper_->changes()[0].cookie.Path()); + EXPECT_EQ(net::CookieChangeCause::INSERTED, + worker_test_helper_->changes()[0].cause); + // example.com does not have a custom access semantics setting, so it defaults + // to NONLEGACY, because the FeatureList has SameSiteByDefaultCookies enabled. + EXPECT_EQ(net::CookieAccessSemantics::NONLEGACY, + worker_test_helper_->changes()[0].access_semantics); worker_test_helper_->changes().clear(); ASSERT_TRUE( @@ -878,12 +1028,87 @@ TEST_P(CookieStoreManagerTest, CookieChangeUrl) { task_environment_.RunUntilIdle(); ASSERT_EQ(1u, worker_test_helper_->changes().size()); - EXPECT_EQ("cookie-name-4", worker_test_helper_->changes()[0].first.Name()); - EXPECT_EQ("cookie-value-4", worker_test_helper_->changes()[0].first.Value()); - EXPECT_EQ("example.com", worker_test_helper_->changes()[0].first.Domain()); - EXPECT_EQ("/a", worker_test_helper_->changes()[0].first.Path()); - EXPECT_EQ(::network::mojom::CookieChangeCause::INSERTED, - worker_test_helper_->changes()[0].second); + EXPECT_EQ("cookie-name-4", worker_test_helper_->changes()[0].cookie.Name()); + EXPECT_EQ("cookie-value-4", worker_test_helper_->changes()[0].cookie.Value()); + EXPECT_EQ("example.com", worker_test_helper_->changes()[0].cookie.Domain()); + EXPECT_EQ("/a", worker_test_helper_->changes()[0].cookie.Path()); + EXPECT_EQ(net::CookieChangeCause::INSERTED, + worker_test_helper_->changes()[0].cause); + // example.com does not have a custom access semantics setting, so it defaults + // to NONLEGACY, because the FeatureList has SameSiteByDefaultCookies enabled. + EXPECT_EQ(net::CookieAccessSemantics::NONLEGACY, + worker_test_helper_->changes()[0].access_semantics); +} + +// Same as above except this tests that the LEGACY access semantics for +// legacy.com cookies is correctly reflected in the change info. +TEST_P(CookieStoreManagerTest, CookieChangeUrlLegacy) { + std::vector batches; + batches.emplace_back(); + + CookieStoreSync::Subscriptions& subscriptions = batches.back(); + subscriptions.emplace_back(blink::mojom::CookieChangeSubscription::New()); + subscriptions.back()->name = ""; + subscriptions.back()->match_type = + ::network::mojom::CookieMatchType::STARTS_WITH; + subscriptions.back()->url = GURL(kLegacyScope); + + worker_test_helper_->SetOnInstallSubscriptions(std::move(batches), + legacy_service_remote_.get()); + int64_t registration_id = + RegisterServiceWorker(kLegacyScope, kLegacyWorkerScript); + ASSERT_NE(registration_id, kInvalidRegistrationId); + + base::Optional all_subscriptions_opt = + legacy_service_->GetSubscriptions(registration_id); + ASSERT_TRUE(all_subscriptions_opt.has_value()); + ASSERT_EQ(1u, all_subscriptions_opt.value().size()); + + if (reset_context_during_test()) + ResetServiceWorkerContext(); + + ASSERT_TRUE( + SetSessionCookie("cookie-name-1", "cookie-value-1", "google.com", "/")); + task_environment_.RunUntilIdle(); + ASSERT_EQ(0u, worker_test_helper_->changes().size()); + + worker_test_helper_->changes().clear(); + ASSERT_TRUE(SetSessionCookie("cookie-name-2", "cookie-value-2", "legacy.com", + "/a/subpath")); + task_environment_.RunUntilIdle(); + EXPECT_EQ(0u, worker_test_helper_->changes().size()); + + worker_test_helper_->changes().clear(); + ASSERT_TRUE( + SetSessionCookie("cookie-name-3", "cookie-value-3", "legacy.com", "/")); + task_environment_.RunUntilIdle(); + + ASSERT_EQ(1u, worker_test_helper_->changes().size()); + EXPECT_EQ("cookie-name-3", worker_test_helper_->changes()[0].cookie.Name()); + EXPECT_EQ("cookie-value-3", worker_test_helper_->changes()[0].cookie.Value()); + EXPECT_EQ("legacy.com", worker_test_helper_->changes()[0].cookie.Domain()); + EXPECT_EQ("/", worker_test_helper_->changes()[0].cookie.Path()); + EXPECT_EQ(net::CookieChangeCause::INSERTED, + worker_test_helper_->changes()[0].cause); + // legacy.com has a custom Legacy setting. + EXPECT_EQ(net::CookieAccessSemantics::LEGACY, + worker_test_helper_->changes()[0].access_semantics); + + worker_test_helper_->changes().clear(); + ASSERT_TRUE( + SetSessionCookie("cookie-name-4", "cookie-value-4", "legacy.com", "/a")); + task_environment_.RunUntilIdle(); + + ASSERT_EQ(1u, worker_test_helper_->changes().size()); + EXPECT_EQ("cookie-name-4", worker_test_helper_->changes()[0].cookie.Name()); + EXPECT_EQ("cookie-value-4", worker_test_helper_->changes()[0].cookie.Value()); + EXPECT_EQ("legacy.com", worker_test_helper_->changes()[0].cookie.Domain()); + EXPECT_EQ("/a", worker_test_helper_->changes()[0].cookie.Path()); + EXPECT_EQ(net::CookieChangeCause::INSERTED, + worker_test_helper_->changes()[0].cause); + // legacy.com has a custom Legacy setting. + EXPECT_EQ(net::CookieAccessSemantics::LEGACY, + worker_test_helper_->changes()[0].access_semantics); } TEST_P(CookieStoreManagerTest, HttpOnlyCookieChange) { @@ -930,12 +1155,73 @@ TEST_P(CookieStoreManagerTest, HttpOnlyCookieChange) { task_environment_.RunUntilIdle(); ASSERT_EQ(1u, worker_test_helper_->changes().size()); - EXPECT_EQ("cookie-name-2", worker_test_helper_->changes()[0].first.Name()); - EXPECT_EQ("cookie-value-2", worker_test_helper_->changes()[0].first.Value()); - EXPECT_EQ("example.com", worker_test_helper_->changes()[0].first.Domain()); - EXPECT_EQ("/", worker_test_helper_->changes()[0].first.Path()); - EXPECT_EQ(::network::mojom::CookieChangeCause::INSERTED, - worker_test_helper_->changes()[0].second); + EXPECT_EQ("cookie-name-2", worker_test_helper_->changes()[0].cookie.Name()); + EXPECT_EQ("cookie-value-2", worker_test_helper_->changes()[0].cookie.Value()); + EXPECT_EQ("example.com", worker_test_helper_->changes()[0].cookie.Domain()); + EXPECT_EQ("/", worker_test_helper_->changes()[0].cookie.Path()); + EXPECT_EQ(net::CookieChangeCause::INSERTED, + worker_test_helper_->changes()[0].cause); + // example.com does not have a custom access semantics setting, so it defaults + // to NONLEGACY, because the FeatureList has SameSiteByDefaultCookies enabled. + EXPECT_EQ(net::CookieAccessSemantics::NONLEGACY, + worker_test_helper_->changes()[0].access_semantics); +} + +// Same as above except this tests that the LEGACY access semantics for +// legacy.com cookies is correctly reflected in the change info. +TEST_P(CookieStoreManagerTest, HttpOnlyCookieChangeLegacy) { + std::vector batches; + batches.emplace_back(); + + CookieStoreSync::Subscriptions& subscriptions = batches.back(); + subscriptions.emplace_back(blink::mojom::CookieChangeSubscription::New()); + subscriptions.back()->name = ""; + subscriptions.back()->match_type = + ::network::mojom::CookieMatchType::STARTS_WITH; + subscriptions.back()->url = GURL(kLegacyScope); + + worker_test_helper_->SetOnInstallSubscriptions(std::move(batches), + legacy_service_remote_.get()); + int64_t registration_id = + RegisterServiceWorker(kLegacyScope, kLegacyWorkerScript); + ASSERT_NE(registration_id, kInvalidRegistrationId); + + base::Optional all_subscriptions_opt = + legacy_service_->GetSubscriptions(registration_id); + ASSERT_TRUE(all_subscriptions_opt.has_value()); + ASSERT_EQ(1u, all_subscriptions_opt.value().size()); + + if (reset_context_during_test()) + ResetServiceWorkerContext(); + + ASSERT_TRUE(SetCanonicalCookie(net::CanonicalCookie( + "cookie-name-1", "cookie-value-1", "legacy.com", "/", base::Time(), + base::Time(), base::Time(), + /* secure = */ false, + /* httponly = */ true, net::CookieSameSite::NO_RESTRICTION, + net::COOKIE_PRIORITY_DEFAULT))); + task_environment_.RunUntilIdle(); + EXPECT_EQ(0u, worker_test_helper_->changes().size()); + + worker_test_helper_->changes().clear(); + ASSERT_TRUE(SetCanonicalCookie(net::CanonicalCookie( + "cookie-name-2", "cookie-value-2", "legacy.com", "/", base::Time(), + base::Time(), base::Time(), + /* secure = */ false, + /* httponly = */ false, net::CookieSameSite::NO_RESTRICTION, + net::COOKIE_PRIORITY_DEFAULT))); + task_environment_.RunUntilIdle(); + + ASSERT_EQ(1u, worker_test_helper_->changes().size()); + EXPECT_EQ("cookie-name-2", worker_test_helper_->changes()[0].cookie.Name()); + EXPECT_EQ("cookie-value-2", worker_test_helper_->changes()[0].cookie.Value()); + EXPECT_EQ("legacy.com", worker_test_helper_->changes()[0].cookie.Domain()); + EXPECT_EQ("/", worker_test_helper_->changes()[0].cookie.Path()); + EXPECT_EQ(net::CookieChangeCause::INSERTED, + worker_test_helper_->changes()[0].cause); + // legacy.com has a custom Legacy setting. + EXPECT_EQ(net::CookieAccessSemantics::LEGACY, + worker_test_helper_->changes()[0].access_semantics); } TEST_P(CookieStoreManagerTest, GetSubscriptionsFromWrongOrigin) { diff --git a/content/browser/service_worker/fake_service_worker.cc b/content/browser/service_worker/fake_service_worker.cc index 39b1d93178dd3..4435e23a694d2 100644 --- a/content/browser/service_worker/fake_service_worker.cc +++ b/content/browser/service_worker/fake_service_worker.cc @@ -109,8 +109,7 @@ void FakeServiceWorker::DispatchBackgroundFetchSuccessEvent( } void FakeServiceWorker::DispatchCookieChangeEvent( - const net::CanonicalCookie& cookie, - ::network::mojom::CookieChangeCause cause, + const net::CookieChangeInfo& change, DispatchCookieChangeEventCallback callback) { std::move(callback).Run(blink::mojom::ServiceWorkerEventStatus::COMPLETED); } diff --git a/content/browser/service_worker/fake_service_worker.h b/content/browser/service_worker/fake_service_worker.h index b6d7ef9ad96bb..93a7f1be76f26 100644 --- a/content/browser/service_worker/fake_service_worker.h +++ b/content/browser/service_worker/fake_service_worker.h @@ -71,8 +71,7 @@ class FakeServiceWorker : public blink::mojom::ServiceWorker { blink::mojom::BackgroundFetchRegistrationPtr registration, DispatchBackgroundFetchSuccessEventCallback callback) override; void DispatchCookieChangeEvent( - const net::CanonicalCookie& cookie, - ::network::mojom::CookieChangeCause cause, + const net::CookieChangeInfo& change, DispatchCookieChangeEventCallback callback) override; void DispatchFetchEventForMainResource( blink::mojom::DispatchFetchEventParamsPtr params, diff --git a/fuchsia/engine/browser/cookie_manager_impl.cc b/fuchsia/engine/browser/cookie_manager_impl.cc index ad875621fc5a1..becb5285249eb 100644 --- a/fuchsia/engine/browser/cookie_manager_impl.cc +++ b/fuchsia/engine/browser/cookie_manager_impl.cc @@ -10,6 +10,7 @@ #include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/receiver.h" #include "net/cookies/canonical_cookie.h" +#include "net/cookies/cookie_change_dispatcher.h" #include "services/network/public/mojom/network_context.mojom.h" #include "url/gurl.h" @@ -17,7 +18,7 @@ namespace { fuchsia::web::Cookie ConvertCanonicalCookie( const net::CanonicalCookie& canonical_cookie, - network::mojom::CookieChangeCause cause) { + net::CookieChangeCause cause) { fuchsia::web::CookieId id; id.set_name(canonical_cookie.Name()); id.set_domain(canonical_cookie.Domain()); @@ -26,15 +27,15 @@ fuchsia::web::Cookie ConvertCanonicalCookie( fuchsia::web::Cookie cookie; cookie.set_id(std::move(id)); switch (cause) { - case network::mojom::CookieChangeCause::INSERTED: + case net::CookieChangeCause::INSERTED: cookie.set_value(canonical_cookie.Value()); break; - case network::mojom::CookieChangeCause::EXPLICIT: - case network::mojom::CookieChangeCause::UNKNOWN_DELETION: - case network::mojom::CookieChangeCause::OVERWRITE: - case network::mojom::CookieChangeCause::EXPIRED: - case network::mojom::CookieChangeCause::EVICTED: - case network::mojom::CookieChangeCause::EXPIRED_OVERWRITE: + case net::CookieChangeCause::EXPLICIT: + case net::CookieChangeCause::UNKNOWN_DELETION: + case net::CookieChangeCause::OVERWRITE: + case net::CookieChangeCause::EXPIRED: + case net::CookieChangeCause::EVICTED: + case net::CookieChangeCause::EXPIRED_OVERWRITE: break; }; @@ -60,8 +61,8 @@ class CookiesIteratorImpl : public fuchsia::web::CookiesIterator, fidl::InterfaceRequest iterator) : CookiesIteratorImpl(std::move(iterator)) { for (const auto& cookie : cookies) { - queued_cookies_[cookie.UniqueKey()] = ConvertCanonicalCookie( - cookie, network::mojom::CookieChangeCause::INSERTED); + queued_cookies_[cookie.UniqueKey()] = + ConvertCanonicalCookie(cookie, net::CookieChangeCause::INSERTED); } } // Same as above except it takes CookieStatusList instead of just CookieList. @@ -72,7 +73,7 @@ class CookiesIteratorImpl : public fuchsia::web::CookiesIterator, for (const auto& cookie_with_status : cookies_with_statuses) { queued_cookies_[cookie_with_status.cookie.UniqueKey()] = ConvertCanonicalCookie(cookie_with_status.cookie, - network::mojom::CookieChangeCause::INSERTED); + net::CookieChangeCause::INSERTED); } } ~CookiesIteratorImpl() final = default; @@ -130,9 +131,9 @@ class CookiesIteratorImpl : public fuchsia::web::CookiesIterator, } // network::mojom::CookieChangeListener implementation: - void OnCookieChange(const net::CanonicalCookie& cookie, - network::mojom::CookieChangeCause cause) final { - queued_cookies_[cookie.UniqueKey()] = ConvertCanonicalCookie(cookie, cause); + void OnCookieChange(const net::CookieChangeInfo& change) final { + queued_cookies_[change.cookie.UniqueKey()] = + ConvertCanonicalCookie(change.cookie, change.cause); MaybeSendQueuedCookies(); } diff --git a/ios/net/cookies/cookie_store_ios.h b/ios/net/cookies/cookie_store_ios.h index 937247850790b..d0b1ebc5a7aec 100644 --- a/ios/net/cookies/cookie_store_ios.h +++ b/ios/net/cookies/cookie_store_ios.h @@ -125,8 +125,7 @@ class CookieStoreIOS : public net::CookieStore, private: using CookieChangeCallbackList = - base::CallbackList; + base::CallbackList; class Subscription : public base::LinkNode, public CookieChangeSubscription { diff --git a/ios/net/cookies/cookie_store_ios.mm b/ios/net/cookies/cookie_store_ios.mm index 97dd12d1845e1..6fa47eab1cc6b 100644 --- a/ios/net/cookies/cookie_store_ios.mm +++ b/ios/net/cookies/cookie_store_ios.mm @@ -605,7 +605,10 @@ void OnlyCookiesWithName(const net::CookieStatusList& cookies, CookieChangeCallbackList* callbacks = hook_map_[key].get(); for (const auto& cookie : cookies) { DCHECK_EQ(name, cookie.Name()); - callbacks->Notify(cookie, cause); + // TODO(crbug.com/978172): Support CookieAccessSemantics values on iOS and + // use it to check IncludeForRequestURL before notifying? + callbacks->Notify(net::CookieChangeInfo( + cookie, net::CookieAccessSemantics::UNKNOWN, cause)); } } diff --git a/ios/net/cookies/cookie_store_ios_test_util.h b/ios/net/cookies/cookie_store_ios_test_util.h index 1febf668e5cfe..2eee97e729652 100644 --- a/ios/net/cookies/cookie_store_ios_test_util.h +++ b/ios/net/cookies/cookie_store_ios_test_util.h @@ -76,8 +76,7 @@ class ScopedTestingCookieStoreIOSClient { void RecordCookieChanges(std::vector* out_cookies, std::vector* out_removes, - const net::CanonicalCookie& cookie, - net::CookieChangeCause cause); + const net::CookieChangeInfo& change); // Sets a cookie. void SetCookie(const std::string& cookie_line, diff --git a/ios/net/cookies/cookie_store_ios_test_util.mm b/ios/net/cookies/cookie_store_ios_test_util.mm index 66312bd91c128..0240b43c638a0 100644 --- a/ios/net/cookies/cookie_store_ios_test_util.mm +++ b/ios/net/cookies/cookie_store_ios_test_util.mm @@ -121,12 +121,11 @@ void RecordCookieChanges(std::vector* out_cookies, std::vector* out_removes, - const net::CanonicalCookie& cookie, - net::CookieChangeCause cause) { + const net::CookieChangeInfo& change) { DCHECK(out_cookies); - out_cookies->push_back(cookie); + out_cookies->push_back(change.cookie); if (out_removes) - out_removes->push_back(net::CookieChangeCauseIsDeletion(cause)); + out_removes->push_back(net::CookieChangeCauseIsDeletion(change.cause)); } void SetCookie(const std::string& cookie_line, diff --git a/net/cookies/cookie_change_dispatcher.cc b/net/cookies/cookie_change_dispatcher.cc index c6cdf324aa829..07c6457fc4cae 100644 --- a/net/cookies/cookie_change_dispatcher.cc +++ b/net/cookies/cookie_change_dispatcher.cc @@ -34,6 +34,15 @@ const char* CookieChangeCauseToString(CookieChangeCause cause) { return cause_string; } +CookieChangeInfo::CookieChangeInfo() = default; + +CookieChangeInfo::CookieChangeInfo(const CanonicalCookie& cookie, + CookieAccessSemantics access_semantics, + CookieChangeCause cause) + : cookie(cookie), access_semantics(access_semantics), cause(cause) {} + +CookieChangeInfo::~CookieChangeInfo() = default; + bool CookieChangeCauseIsDeletion(CookieChangeCause cause) { return cause != CookieChangeCause::INSERTED; } diff --git a/net/cookies/cookie_change_dispatcher.h b/net/cookies/cookie_change_dispatcher.h index c05a6db5d3358..c1b7f516249a5 100644 --- a/net/cookies/cookie_change_dispatcher.h +++ b/net/cookies/cookie_change_dispatcher.h @@ -38,6 +38,23 @@ enum class CookieChangeCause { EXPIRED_OVERWRITE }; +struct NET_EXPORT CookieChangeInfo { + CookieChangeInfo(); + CookieChangeInfo(const CanonicalCookie& cookie, + CookieAccessSemantics access_semantics, + CookieChangeCause cause); + ~CookieChangeInfo(); + + // The cookie that changed. + CanonicalCookie cookie; + + // The access semantics of the cookie at the time of the change. + CookieAccessSemantics access_semantics = CookieAccessSemantics::UNKNOWN; + + // The reason for the change. + CookieChangeCause cause = CookieChangeCause::EXPLICIT; +}; + // Return a string corresponding to the change cause. For debugging/logging. NET_EXPORT const char* CookieChangeCauseToString(CookieChangeCause cause); @@ -48,6 +65,7 @@ NET_EXPORT bool CookieChangeCauseIsDeletion(CookieChangeCause cause); // Called when a cookie is changed in a CookieStore. // // Receives the CanonicalCookie which was added to or removed from the store, +// the CookieAccessSemantics of the cookie at the time of the change event, // and a CookieStore::ChangeCause indicating if the cookie was added, updated, // or removed. // @@ -58,8 +76,7 @@ NET_EXPORT bool CookieChangeCauseIsDeletion(CookieChangeCause cause); // The callback must not synchronously modify any cookie in the CookieStore // whose change it is observing. using CookieChangeCallback = - base::RepeatingCallback; + base::RepeatingCallback; // Records a listener's interest in CookieStore changes. // diff --git a/net/cookies/cookie_monster.cc b/net/cookies/cookie_monster.cc index adbda8bdf2c5a..5e5b1067d793f 100644 --- a/net/cookies/cookie_monster.cc +++ b/net/cookies/cookie_monster.cc @@ -1155,7 +1155,10 @@ CookieMonster::CookieMap::iterator CookieMonster::InternalInsertCookie( type_sample |= cc_ptr->IsSecure() ? 1 << COOKIE_TYPE_SECURE : 0; histogram_cookie_type_->Add(type_sample); - change_dispatcher_.DispatchChange(*cc_ptr, CookieChangeCause::INSERTED, true); + change_dispatcher_.DispatchChange( + CookieChangeInfo(*cc_ptr, GetAccessSemanticsForCookie(*cc_ptr), + CookieChangeCause::INSERTED), + true); return inserted; } @@ -1355,7 +1358,9 @@ void CookieMonster::InternalDeleteCookie(CookieMap::iterator it, sync_to_store) { store_->DeleteCookie(*cc); } - change_dispatcher_.DispatchChange(*cc, mapping.cause, mapping.notify); + change_dispatcher_.DispatchChange( + CookieChangeInfo(*cc, GetAccessSemanticsForCookie(*cc), mapping.cause), + mapping.notify); cookies_.erase(it); } diff --git a/net/cookies/cookie_monster_change_dispatcher.cc b/net/cookies/cookie_monster_change_dispatcher.cc index f15c1c90b381c..28cfe347c58f5 100644 --- a/net/cookies/cookie_monster_change_dispatcher.cc +++ b/net/cookies/cookie_monster_change_dispatcher.cc @@ -49,32 +49,33 @@ CookieMonsterChangeDispatcher::Subscription::~Subscription() { } void CookieMonsterChangeDispatcher::Subscription::DispatchChange( - const net::CanonicalCookie& cookie, - net::CookieChangeCause change_cause) { + const CookieChangeInfo& change) { DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); + const CanonicalCookie& cookie = change.cookie; + // The net::CookieOptions are hard-coded for now, but future APIs may set // different options. For example, JavaScript observers will not be allowed to // see HTTP-only changes. if (!url_.is_empty() && - !cookie.IncludeForRequestURL(url_, CookieOptions::MakeAllInclusive()) + !cookie + .IncludeForRequestURL(url_, CookieOptions::MakeAllInclusive(), + change.access_semantics) .IsInclude()) { return; } // TODO(mmenke, pwnall): Run callbacks synchronously? task_runner_->PostTask( - FROM_HERE, - base::BindOnce(&Subscription::DoDispatchChange, - weak_ptr_factory_.GetWeakPtr(), cookie, change_cause)); + FROM_HERE, base::BindOnce(&Subscription::DoDispatchChange, + weak_ptr_factory_.GetWeakPtr(), change)); } void CookieMonsterChangeDispatcher::Subscription::DoDispatchChange( - const net::CanonicalCookie& cookie, - net::CookieChangeCause change_cause) const { + const CookieChangeInfo& change) const { DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); - callback_.Run(cookie, change_cause); + callback_.Run(change); } CookieMonsterChangeDispatcher::CookieMonsterChangeDispatcher() {} @@ -151,19 +152,17 @@ CookieMonsterChangeDispatcher::AddCallbackForAllChanges( } void CookieMonsterChangeDispatcher::DispatchChange( - const CanonicalCookie& cookie, - CookieChangeCause cause, + const CookieChangeInfo& change, bool notify_global_hooks) { DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); - DispatchChangeToDomainKey(cookie, cause, DomainKey(cookie.Domain())); + DispatchChangeToDomainKey(change, DomainKey(change.cookie.Domain())); if (notify_global_hooks) - DispatchChangeToDomainKey(cookie, cause, std::string(kGlobalDomainKey)); + DispatchChangeToDomainKey(change, std::string(kGlobalDomainKey)); } void CookieMonsterChangeDispatcher::DispatchChangeToDomainKey( - const CanonicalCookie& cookie, - CookieChangeCause cause, + const CookieChangeInfo& change, const std::string& domain_key) { DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); @@ -171,14 +170,12 @@ void CookieMonsterChangeDispatcher::DispatchChangeToDomainKey( if (it == cookie_domain_map_.end()) return; - DispatchChangeToNameKey(cookie, cause, it->second, NameKey(cookie.Name())); - DispatchChangeToNameKey(cookie, cause, it->second, - std::string(kGlobalNameKey)); + DispatchChangeToNameKey(change, it->second, NameKey(change.cookie.Name())); + DispatchChangeToNameKey(change, it->second, std::string(kGlobalNameKey)); } void CookieMonsterChangeDispatcher::DispatchChangeToNameKey( - const CanonicalCookie& cookie, - CookieChangeCause cause, + const CookieChangeInfo& change, CookieNameMap& cookie_name_map, const std::string& name_key) { DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); @@ -190,7 +187,7 @@ void CookieMonsterChangeDispatcher::DispatchChangeToNameKey( SubscriptionList& subscription_list = it->second; for (base::LinkNode* node = subscription_list.head(); node != subscription_list.end(); node = node->next()) { - node->value()->DispatchChange(cookie, cause); + node->value()->DispatchChange(change); } } diff --git a/net/cookies/cookie_monster_change_dispatcher.h b/net/cookies/cookie_monster_change_dispatcher.h index 152f1461d36e5..79f73969633d5 100644 --- a/net/cookies/cookie_monster_change_dispatcher.h +++ b/net/cookies/cookie_monster_change_dispatcher.h @@ -22,14 +22,11 @@ namespace net { -class CanonicalCookie; - // CookieChangeDispatcher implementation used by CookieMonster. class CookieMonsterChangeDispatcher : public CookieChangeDispatcher { public: using CookieChangeCallbackList = - base::CallbackList; + base::CallbackList; CookieMonsterChangeDispatcher(); ~CookieMonsterChangeDispatcher() override; @@ -58,9 +55,7 @@ class CookieMonsterChangeDispatcher : public CookieChangeDispatcher { // global hooks in addition to the per-cookie hooks. // // TODO(pwnall): Remove |notify_global_hooks| and fix consumers. - void DispatchChange(const CanonicalCookie& cookie, - CookieChangeCause cause, - bool notify_global_hooks); + void DispatchChange(const CookieChangeInfo& change, bool notify_global_hooks); private: class Subscription : public base::LinkNode, @@ -84,8 +79,7 @@ class CookieMonsterChangeDispatcher : public CookieChangeDispatcher { const std::string& name_key() const { return name_key_; } // Dispatches a cookie change notification if the listener is interested. - void DispatchChange(const net::CanonicalCookie& cookie, - net::CookieChangeCause change_cause); + void DispatchChange(const CookieChangeInfo& change); private: base::WeakPtr change_dispatcher_; @@ -94,8 +88,7 @@ class CookieMonsterChangeDispatcher : public CookieChangeDispatcher { const GURL url_; // empty() means no URL-based filtering. const net::CookieChangeCallback callback_; - void DoDispatchChange(const net::CanonicalCookie& cookie, - net::CookieChangeCause change_cause) const; + void DoDispatchChange(const CookieChangeInfo& change) const; // Used to post DoDispatchChange() calls to this subscription's thread. scoped_refptr task_runner_; @@ -124,12 +117,10 @@ class CookieMonsterChangeDispatcher : public CookieChangeDispatcher { // exceed eTLD+1, so we stop there. using CookieDomainMap = std::map; - void DispatchChangeToDomainKey(const CanonicalCookie& cookie, - CookieChangeCause cause, + void DispatchChangeToDomainKey(const CookieChangeInfo& change, const std::string& domain_key); - void DispatchChangeToNameKey(const CanonicalCookie& cookie, - CookieChangeCause cause, + void DispatchChangeToNameKey(const CookieChangeInfo& change, CookieNameMap& name_map, const std::string& name_key); diff --git a/net/cookies/cookie_monster_unittest.cc b/net/cookies/cookie_monster_unittest.cc index db866787dc24b..4646e34f74fca 100644 --- a/net/cookies/cookie_monster_unittest.cc +++ b/net/cookies/cookie_monster_unittest.cc @@ -3572,12 +3572,11 @@ class CookieMonsterNotificationTest : public CookieMonsterTest { void RecordCookieChanges(std::vector* out_cookies, std::vector* out_causes, - const CanonicalCookie& cookie, - CookieChangeCause cause) { + const CookieChangeInfo& change) { DCHECK(out_cookies); - out_cookies->push_back(cookie); + out_cookies->push_back(change.cookie); if (out_causes) - out_causes->push_back(cause); + out_causes->push_back(change.cause); } TEST_F(CookieMonsterNotificationTest, GlobalNotBroadcast) { diff --git a/net/cookies/cookie_store_change_unittest.h b/net/cookies/cookie_store_change_unittest.h index 00b049138b269..c6df422ee5965 100644 --- a/net/cookies/cookie_store_change_unittest.h +++ b/net/cookies/cookie_store_change_unittest.h @@ -8,6 +8,7 @@ #include "base/bind.h" #include "net/cookies/canonical_cookie.h" #include "net/cookies/cookie_change_dispatcher_test_helpers.h" +#include "net/cookies/cookie_constants.h" #include "net/cookies/cookie_store.h" #include "net/cookies/cookie_store_unittest.h" #include "testing/gtest/include/gtest/gtest.h" @@ -17,25 +18,24 @@ namespace net { namespace { -using CookieChange = std::pair; - // Used to sort CookieChanges when testing stores without exact change ordering. // // The ordering relation must match the order in which the tests below issue // cookie calls. Changes to this method should be tested by running the tests // below with CookieMonsterTestTraits::has_exact_change_ordering set to both // true and false. -bool CookieChangeLessThan(const CookieChange& lhs, const CookieChange& rhs) { - if (lhs.first.Name() != rhs.first.Name()) - return lhs.first.Name() < rhs.first.Name(); +bool CookieChangeLessThan(const CookieChangeInfo& lhs, + const CookieChangeInfo& rhs) { + if (lhs.cookie.Name() != rhs.cookie.Name()) + return lhs.cookie.Name() < rhs.cookie.Name(); - if (lhs.first.Value() != rhs.first.Value()) - return lhs.first.Value() < rhs.first.Value(); + if (lhs.cookie.Value() != rhs.cookie.Value()) + return lhs.cookie.Value() < rhs.cookie.Value(); - if (lhs.first.Domain() != rhs.first.Domain()) - return lhs.first.Domain() < rhs.first.Domain(); + if (lhs.cookie.Domain() != rhs.cookie.Domain()) + return lhs.cookie.Domain() < rhs.cookie.Domain(); - return lhs.second < rhs.second; + return lhs.cause < rhs.cause; } } // namespace @@ -83,11 +83,15 @@ class CookieStoreChangeTestBase << "expected a deletion cause, got " << actual_cause; } - static void OnCookieChange(std::vector* changes, - const CanonicalCookie& cookie, - CookieChangeCause cause) { - CookieChange notification(cookie, cause); + bool IsExpectedAccessSemantics(net::CookieAccessSemantics expected_semantics, + net::CookieAccessSemantics actual_semantics) { + if (CookieStoreTestTraits::supports_cookie_access_semantics) + return expected_semantics == actual_semantics; + return actual_semantics == net::CookieAccessSemantics::UNKNOWN; + } + static void OnCookieChange(std::vector* changes, + const CookieChangeInfo& notification) { if (CookieStoreTestTraits::has_exact_change_ordering) { changes->push_back(notification); } else { @@ -120,7 +124,7 @@ TYPED_TEST_P(CookieStoreChangeGlobalTest, NoCookie) { return; CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes; + std::vector cookie_changes; std::unique_ptr subscription = cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating( &CookieStoreChangeTestBase::OnCookieChange, @@ -134,7 +138,7 @@ TYPED_TEST_P(CookieStoreChangeGlobalTest, InitialCookie) { return; CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes; + std::vector cookie_changes; this->SetCookie(cs, this->http_www_foo_.url(), "A=B"); this->DeliverChangeNotifications(); std::unique_ptr subscription( @@ -150,7 +154,7 @@ TYPED_TEST_P(CookieStoreChangeGlobalTest, InsertOne) { return; CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes; + std::vector cookie_changes; std::unique_ptr subscription = cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating( &CookieStoreChangeTestBase::OnCookieChange, @@ -162,11 +166,12 @@ TYPED_TEST_P(CookieStoreChangeGlobalTest, InsertOne) { this->DeliverChangeNotifications(); ASSERT_EQ(1u, cookie_changes.size()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::INSERTED, - cookie_changes[0].second)); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[0].first.Domain()); - EXPECT_EQ("A", cookie_changes[0].first.Name()); - EXPECT_EQ("B", cookie_changes[0].first.Value()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[0].cause)); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[0].cookie.Domain()); + EXPECT_EQ("A", cookie_changes[0].cookie.Name()); + EXPECT_EQ("B", cookie_changes[0].cookie.Value()); } TYPED_TEST_P(CookieStoreChangeGlobalTest, InsertMany) { @@ -174,7 +179,7 @@ TYPED_TEST_P(CookieStoreChangeGlobalTest, InsertMany) { return; CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes; + std::vector cookie_changes; std::unique_ptr subscription = cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating( &CookieStoreChangeTestBase::OnCookieChange, @@ -193,32 +198,36 @@ TYPED_TEST_P(CookieStoreChangeGlobalTest, InsertMany) { EXPECT_EQ("G=H", this->GetCookies(cs, this->http_bar_com_.url())); ASSERT_LE(1u, cookie_changes.size()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::INSERTED, - cookie_changes[0].second)); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[0].first.Domain()); - EXPECT_EQ("A", cookie_changes[0].first.Name()); - EXPECT_EQ("B", cookie_changes[0].first.Value()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[0].cause)); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[0].cookie.Domain()); + EXPECT_EQ("A", cookie_changes[0].cookie.Name()); + EXPECT_EQ("B", cookie_changes[0].cookie.Value()); ASSERT_LE(2u, cookie_changes.size()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[1].first.Domain()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::INSERTED, - cookie_changes[1].second)); - EXPECT_EQ("C", cookie_changes[1].first.Name()); - EXPECT_EQ("D", cookie_changes[1].first.Value()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[1].cookie.Domain()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[1].cause)); + EXPECT_EQ("C", cookie_changes[1].cookie.Name()); + EXPECT_EQ("D", cookie_changes[1].cookie.Value()); ASSERT_LE(3u, cookie_changes.size()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[2].first.Domain()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::INSERTED, - cookie_changes[2].second)); - EXPECT_EQ("E", cookie_changes[2].first.Name()); - EXPECT_EQ("F", cookie_changes[2].first.Value()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[2].cookie.Domain()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[2].cause)); + EXPECT_EQ("E", cookie_changes[2].cookie.Name()); + EXPECT_EQ("F", cookie_changes[2].cookie.Value()); ASSERT_LE(4u, cookie_changes.size()); - EXPECT_EQ(this->http_bar_com_.url().host(), cookie_changes[3].first.Domain()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::INSERTED, - cookie_changes[3].second)); - EXPECT_EQ("G", cookie_changes[3].first.Name()); - EXPECT_EQ("H", cookie_changes[3].first.Value()); + EXPECT_EQ(this->http_bar_com_.url().host(), + cookie_changes[3].cookie.Domain()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[3].cause)); + EXPECT_EQ("G", cookie_changes[3].cookie.Name()); + EXPECT_EQ("H", cookie_changes[3].cookie.Value()); EXPECT_EQ(4u, cookie_changes.size()); } @@ -228,7 +237,7 @@ TYPED_TEST_P(CookieStoreChangeGlobalTest, DeleteOne) { return; CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes; + std::vector cookie_changes; std::unique_ptr subscription = cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating( &CookieStoreChangeTestBase::OnCookieChange, @@ -243,11 +252,12 @@ TYPED_TEST_P(CookieStoreChangeGlobalTest, DeleteOne) { this->DeliverChangeNotifications(); ASSERT_EQ(1u, cookie_changes.size()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[0].first.Domain()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::EXPLICIT, - cookie_changes[0].second)); - EXPECT_EQ("A", cookie_changes[0].first.Name()); - EXPECT_EQ("B", cookie_changes[0].first.Value()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[0].cookie.Domain()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::EXPLICIT, cookie_changes[0].cause)); + EXPECT_EQ("A", cookie_changes[0].cookie.Name()); + EXPECT_EQ("B", cookie_changes[0].cookie.Value()); } TYPED_TEST_P(CookieStoreChangeGlobalTest, DeleteTwo) { @@ -255,7 +265,7 @@ TYPED_TEST_P(CookieStoreChangeGlobalTest, DeleteTwo) { return; CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes; + std::vector cookie_changes; std::unique_ptr subscription = cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating( &CookieStoreChangeTestBase::OnCookieChange, @@ -282,18 +292,20 @@ TYPED_TEST_P(CookieStoreChangeGlobalTest, DeleteTwo) { EXPECT_EQ("", this->GetCookies(cs, this->http_bar_com_.url())); ASSERT_LE(1u, cookie_changes.size()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[0].first.Domain()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::EXPLICIT, - cookie_changes[0].second)); - EXPECT_EQ("C", cookie_changes[0].first.Name()); - EXPECT_EQ("D", cookie_changes[0].first.Value()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[0].cookie.Domain()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::EXPLICIT, cookie_changes[0].cause)); + EXPECT_EQ("C", cookie_changes[0].cookie.Name()); + EXPECT_EQ("D", cookie_changes[0].cookie.Value()); ASSERT_EQ(2u, cookie_changes.size()); - EXPECT_EQ(this->http_bar_com_.url().host(), cookie_changes[1].first.Domain()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::EXPLICIT, - cookie_changes[1].second)); - EXPECT_EQ("G", cookie_changes[1].first.Name()); - EXPECT_EQ("H", cookie_changes[1].first.Value()); + EXPECT_EQ(this->http_bar_com_.url().host(), + cookie_changes[1].cookie.Domain()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::EXPLICIT, cookie_changes[1].cause)); + EXPECT_EQ("G", cookie_changes[1].cookie.Name()); + EXPECT_EQ("H", cookie_changes[1].cookie.Value()); } TYPED_TEST_P(CookieStoreChangeGlobalTest, Overwrite) { @@ -301,7 +313,7 @@ TYPED_TEST_P(CookieStoreChangeGlobalTest, Overwrite) { return; CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes; + std::vector cookie_changes; std::unique_ptr subscription = cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating( &CookieStoreChangeTestBase::OnCookieChange, @@ -320,18 +332,20 @@ TYPED_TEST_P(CookieStoreChangeGlobalTest, Overwrite) { this->DeliverChangeNotifications(); ASSERT_LE(1u, cookie_changes.size()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[0].first.Domain()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[0].cookie.Domain()); EXPECT_TRUE(this->MatchesCause(CookieChangeCause::OVERWRITE, - cookie_changes[0].second)); - EXPECT_EQ("A", cookie_changes[0].first.Name()); - EXPECT_EQ("B", cookie_changes[0].first.Value()); + cookie_changes[0].cause)); + EXPECT_EQ("A", cookie_changes[0].cookie.Name()); + EXPECT_EQ("B", cookie_changes[0].cookie.Value()); ASSERT_LE(2u, cookie_changes.size()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[1].first.Domain()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::INSERTED, - cookie_changes[1].second)); - EXPECT_EQ("A", cookie_changes[1].first.Name()); - EXPECT_EQ("C", cookie_changes[1].first.Value()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[1].cookie.Domain()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[1].cause)); + EXPECT_EQ("A", cookie_changes[1].cookie.Name()); + EXPECT_EQ("C", cookie_changes[1].cookie.Value()); EXPECT_EQ(2u, cookie_changes.size()); } @@ -342,7 +356,7 @@ TYPED_TEST_P(CookieStoreChangeGlobalTest, OverwriteWithHttpOnly) { // Insert a cookie "A" for path "/path1" CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes; + std::vector cookie_changes; std::unique_ptr subscription = cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating( &CookieStoreChangeTestBase::OnCookieChange, @@ -354,12 +368,13 @@ TYPED_TEST_P(CookieStoreChangeGlobalTest, OverwriteWithHttpOnly) { this->SetCookie(cs, this->http_www_foo_.url(), "A=B; path=/path1")); this->DeliverChangeNotifications(); ASSERT_EQ(1u, cookie_changes.size()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::INSERTED, - cookie_changes[0].second)); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[0].first.Domain()); - EXPECT_EQ("A", cookie_changes[0].first.Name()); - EXPECT_EQ("B", cookie_changes[0].first.Value()); - EXPECT_FALSE(cookie_changes[0].first.IsHttpOnly()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[0].cause)); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[0].cookie.Domain()); + EXPECT_EQ("A", cookie_changes[0].cookie.Name()); + EXPECT_EQ("B", cookie_changes[0].cookie.Value()); + EXPECT_FALSE(cookie_changes[0].cookie.IsHttpOnly()); cookie_changes.clear(); // Insert a cookie "A" for path "/path1", that is httponly. This should @@ -372,20 +387,22 @@ TYPED_TEST_P(CookieStoreChangeGlobalTest, OverwriteWithHttpOnly) { this->DeliverChangeNotifications(); ASSERT_LE(1u, cookie_changes.size()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[0].first.Domain()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[0].cookie.Domain()); EXPECT_TRUE(this->MatchesCause(CookieChangeCause::OVERWRITE, - cookie_changes[0].second)); - EXPECT_EQ("A", cookie_changes[0].first.Name()); - EXPECT_EQ("B", cookie_changes[0].first.Value()); - EXPECT_FALSE(cookie_changes[0].first.IsHttpOnly()); + cookie_changes[0].cause)); + EXPECT_EQ("A", cookie_changes[0].cookie.Name()); + EXPECT_EQ("B", cookie_changes[0].cookie.Value()); + EXPECT_FALSE(cookie_changes[0].cookie.IsHttpOnly()); ASSERT_LE(2u, cookie_changes.size()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[1].first.Domain()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::INSERTED, - cookie_changes[1].second)); - EXPECT_EQ("A", cookie_changes[1].first.Name()); - EXPECT_EQ("C", cookie_changes[1].first.Value()); - EXPECT_TRUE(cookie_changes[1].first.IsHttpOnly()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[1].cookie.Domain()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[1].cause)); + EXPECT_EQ("A", cookie_changes[1].cookie.Name()); + EXPECT_EQ("C", cookie_changes[1].cookie.Value()); + EXPECT_TRUE(cookie_changes[1].cookie.IsHttpOnly()); EXPECT_EQ(2u, cookie_changes.size()); } @@ -396,7 +413,7 @@ TYPED_TEST_P(CookieStoreChangeGlobalTest, Deregister) { CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes; + std::vector cookie_changes; std::unique_ptr subscription = cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating( &CookieStoreChangeTestBase::OnCookieChange, @@ -408,8 +425,8 @@ TYPED_TEST_P(CookieStoreChangeGlobalTest, Deregister) { EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B")); this->DeliverChangeNotifications(); ASSERT_EQ(1u, cookie_changes.size()); - EXPECT_EQ("A", cookie_changes[0].first.Name()); - EXPECT_EQ("B", cookie_changes[0].first.Value()); + EXPECT_EQ("A", cookie_changes[0].cookie.Name()); + EXPECT_EQ("B", cookie_changes[0].cookie.Value()); cookie_changes.clear(); // De-register the subscription. @@ -430,13 +447,13 @@ TYPED_TEST_P(CookieStoreChangeGlobalTest, DeregisterMultiple) { CookieStore* cs = this->GetCookieStore(); // Register two subscriptions. - std::vector cookie_changes_1; + std::vector cookie_changes_1; std::unique_ptr subscription1 = cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating( &CookieStoreChangeTestBase::OnCookieChange, base::Unretained(&cookie_changes_1))); - std::vector cookie_changes_2; + std::vector cookie_changes_2; std::unique_ptr subscription2 = cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating( &CookieStoreChangeTestBase::OnCookieChange, @@ -449,13 +466,13 @@ TYPED_TEST_P(CookieStoreChangeGlobalTest, DeregisterMultiple) { EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B")); this->DeliverChangeNotifications(); ASSERT_EQ(1u, cookie_changes_1.size()); - EXPECT_EQ("A", cookie_changes_1[0].first.Name()); - EXPECT_EQ("B", cookie_changes_1[0].first.Value()); + EXPECT_EQ("A", cookie_changes_1[0].cookie.Name()); + EXPECT_EQ("B", cookie_changes_1[0].cookie.Value()); cookie_changes_1.clear(); ASSERT_EQ(1u, cookie_changes_2.size()); - EXPECT_EQ("A", cookie_changes_2[0].first.Name()); - EXPECT_EQ("B", cookie_changes_2[0].first.Value()); + EXPECT_EQ("A", cookie_changes_2[0].cookie.Name()); + EXPECT_EQ("B", cookie_changes_2[0].cookie.Value()); cookie_changes_2.clear(); // De-register the second subscription. @@ -466,8 +483,8 @@ TYPED_TEST_P(CookieStoreChangeGlobalTest, DeregisterMultiple) { EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "C=D")); this->DeliverChangeNotifications(); ASSERT_EQ(1u, cookie_changes_1.size()); - EXPECT_EQ("C", cookie_changes_1[0].first.Name()); - EXPECT_EQ("D", cookie_changes_1[0].first.Value()); + EXPECT_EQ("C", cookie_changes_1[0].cookie.Name()); + EXPECT_EQ("D", cookie_changes_1[0].cookie.Value()); cookie_changes_1.clear(); ASSERT_EQ(0u, cookie_changes_2.size()); @@ -486,7 +503,7 @@ TYPED_TEST_P(CookieStoreChangeGlobalTest, DispatchRace) { // DeliverChangeNotifications() must NOT be called before the subscription is // established. - std::vector cookie_changes; + std::vector cookie_changes; std::unique_ptr subscription = cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating( &CookieStoreChangeTestBase::OnCookieChange, @@ -496,8 +513,8 @@ TYPED_TEST_P(CookieStoreChangeGlobalTest, DispatchRace) { this->DeliverChangeNotifications(); EXPECT_LE(1u, cookie_changes.size()); - EXPECT_EQ("C", cookie_changes[0].first.Name()); - EXPECT_EQ("D", cookie_changes[0].first.Value()); + EXPECT_EQ("C", cookie_changes[0].cookie.Name()); + EXPECT_EQ("D", cookie_changes[0].cookie.Value()); ASSERT_EQ(1u, cookie_changes.size()); } @@ -511,7 +528,7 @@ TYPED_TEST_P(CookieStoreChangeGlobalTest, DeregisterRace) { CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes; + std::vector cookie_changes; std::unique_ptr subscription = cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating( &CookieStoreChangeTestBase::OnCookieChange, @@ -523,8 +540,8 @@ TYPED_TEST_P(CookieStoreChangeGlobalTest, DeregisterRace) { EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B")); this->DeliverChangeNotifications(); ASSERT_EQ(1u, cookie_changes.size()); - EXPECT_EQ("A", cookie_changes[0].first.Name()); - EXPECT_EQ("B", cookie_changes[0].first.Value()); + EXPECT_EQ("A", cookie_changes[0].cookie.Name()); + EXPECT_EQ("B", cookie_changes[0].cookie.Value()); cookie_changes.clear(); // Insert a cookie, confirm it is not seen, deregister the subscription, run @@ -554,7 +571,7 @@ TYPED_TEST_P(CookieStoreChangeGlobalTest, DeregisterRaceMultiple) { CookieStore* cs = this->GetCookieStore(); // Register two subscriptions. - std::vector cookie_changes_1, cookie_changes_2; + std::vector cookie_changes_1, cookie_changes_2; std::unique_ptr subscription1 = cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating( &CookieStoreChangeTestBase::OnCookieChange, @@ -572,13 +589,13 @@ TYPED_TEST_P(CookieStoreChangeGlobalTest, DeregisterRaceMultiple) { this->DeliverChangeNotifications(); ASSERT_EQ(1u, cookie_changes_1.size()); - EXPECT_EQ("A", cookie_changes_1[0].first.Name()); - EXPECT_EQ("B", cookie_changes_1[0].first.Value()); + EXPECT_EQ("A", cookie_changes_1[0].cookie.Name()); + EXPECT_EQ("B", cookie_changes_1[0].cookie.Value()); cookie_changes_1.clear(); ASSERT_EQ(1u, cookie_changes_2.size()); - EXPECT_EQ("A", cookie_changes_2[0].first.Name()); - EXPECT_EQ("B", cookie_changes_2[0].first.Value()); + EXPECT_EQ("A", cookie_changes_2[0].cookie.Name()); + EXPECT_EQ("B", cookie_changes_2[0].cookie.Value()); cookie_changes_2.clear(); // Insert a cookie, confirm it is not seen, deregister a subscription, run @@ -598,8 +615,8 @@ TYPED_TEST_P(CookieStoreChangeGlobalTest, DeregisterRaceMultiple) { subscription2.reset(); this->DeliverChangeNotifications(); ASSERT_EQ(1u, cookie_changes_1.size()); - EXPECT_EQ("C", cookie_changes_1[0].first.Name()); - EXPECT_EQ("D", cookie_changes_1[0].first.Value()); + EXPECT_EQ("C", cookie_changes_1[0].cookie.Name()); + EXPECT_EQ("D", cookie_changes_1[0].cookie.Value()); // No late notification was received. ASSERT_EQ(0u, cookie_changes_2.size()); @@ -612,7 +629,7 @@ TYPED_TEST_P(CookieStoreChangeGlobalTest, MultipleSubscriptions) { CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes_1, cookie_changes_2; + std::vector cookie_changes_1, cookie_changes_2; std::unique_ptr subscription1 = cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating( &CookieStoreChangeTestBase::OnCookieChange, @@ -627,12 +644,60 @@ TYPED_TEST_P(CookieStoreChangeGlobalTest, MultipleSubscriptions) { this->DeliverChangeNotifications(); ASSERT_EQ(1U, cookie_changes_1.size()); - EXPECT_EQ("A", cookie_changes_1[0].first.Name()); - EXPECT_EQ("B", cookie_changes_1[0].first.Value()); + EXPECT_EQ("A", cookie_changes_1[0].cookie.Name()); + EXPECT_EQ("B", cookie_changes_1[0].cookie.Value()); ASSERT_EQ(1U, cookie_changes_2.size()); - EXPECT_EQ("A", cookie_changes_2[0].first.Name()); - EXPECT_EQ("B", cookie_changes_2[0].first.Value()); + EXPECT_EQ("A", cookie_changes_2[0].cookie.Name()); + EXPECT_EQ("B", cookie_changes_2[0].cookie.Value()); +} + +TYPED_TEST_P(CookieStoreChangeGlobalTest, ChangeIncludesCookieAccessSemantics) { + if (!TypeParam::supports_global_cookie_tracking) + return; + + CookieStore* cs = this->GetCookieStore(); + // if !supports_cookie_access_semantics, the delegate will be stored but will + // not be used. + auto access_delegate = std::make_unique(); + access_delegate->SetExpectationForCookieDomain("domain1.test", + CookieAccessSemantics::LEGACY); + access_delegate->SetExpectationForCookieDomain( + "domain2.test", CookieAccessSemantics::NONLEGACY); + access_delegate->SetExpectationForCookieDomain( + "domain3.test", CookieAccessSemantics::UNKNOWN); + cs->SetCookieAccessDelegate(std::move(access_delegate)); + + std::vector cookie_changes; + std::unique_ptr subscription = + cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating( + &CookieStoreChangeTestBase::OnCookieChange, + base::Unretained(&cookie_changes))); + + this->CreateAndSetCookie(cs, GURL("http://domain1.test"), "cookie=1", + CookieOptions::MakeAllInclusive()); + this->CreateAndSetCookie(cs, GURL("http://domain2.test"), "cookie=1", + CookieOptions::MakeAllInclusive()); + this->CreateAndSetCookie(cs, GURL("http://domain3.test"), "cookie=1", + CookieOptions::MakeAllInclusive()); + this->CreateAndSetCookie(cs, GURL("http://domain4.test"), "cookie=1", + CookieOptions::MakeAllInclusive()); + this->DeliverChangeNotifications(); + + ASSERT_EQ(4u, cookie_changes.size()); + + EXPECT_EQ("domain1.test", cookie_changes[0].cookie.Domain()); + EXPECT_TRUE(this->IsExpectedAccessSemantics( + CookieAccessSemantics::LEGACY, cookie_changes[0].access_semantics)); + EXPECT_EQ("domain2.test", cookie_changes[1].cookie.Domain()); + EXPECT_TRUE(this->IsExpectedAccessSemantics( + CookieAccessSemantics::NONLEGACY, cookie_changes[1].access_semantics)); + EXPECT_EQ("domain3.test", cookie_changes[2].cookie.Domain()); + EXPECT_TRUE(this->IsExpectedAccessSemantics( + CookieAccessSemantics::UNKNOWN, cookie_changes[2].access_semantics)); + EXPECT_EQ("domain4.test", cookie_changes[3].cookie.Domain()); + EXPECT_TRUE(this->IsExpectedAccessSemantics( + CookieAccessSemantics::UNKNOWN, cookie_changes[3].access_semantics)); } TYPED_TEST_P(CookieStoreChangeUrlTest, NoCookie) { @@ -640,7 +705,7 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, NoCookie) { return; CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes; + std::vector cookie_changes; std::unique_ptr subscription = cs->GetChangeDispatcher().AddCallbackForUrl( this->http_www_foo_.url(), @@ -656,7 +721,7 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, InitialCookie) { return; CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes; + std::vector cookie_changes; this->SetCookie(cs, this->http_www_foo_.url(), "A=B"); this->DeliverChangeNotifications(); std::unique_ptr subscription = @@ -674,7 +739,7 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, InsertOne) { return; CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes; + std::vector cookie_changes; std::unique_ptr subscription = cs->GetChangeDispatcher().AddCallbackForUrl( this->http_www_foo_.url(), @@ -688,11 +753,12 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, InsertOne) { this->DeliverChangeNotifications(); ASSERT_EQ(1u, cookie_changes.size()); - EXPECT_EQ("A", cookie_changes[0].first.Name()); - EXPECT_EQ("B", cookie_changes[0].first.Value()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[0].first.Domain()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::INSERTED, - cookie_changes[0].second)); + EXPECT_EQ("A", cookie_changes[0].cookie.Name()); + EXPECT_EQ("B", cookie_changes[0].cookie.Value()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[0].cookie.Domain()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[0].cause)); } TYPED_TEST_P(CookieStoreChangeUrlTest, InsertMany) { @@ -700,7 +766,7 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, InsertMany) { return; CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes; + std::vector cookie_changes; std::unique_ptr subscription = cs->GetChangeDispatcher().AddCallbackForUrl( this->http_www_foo_.url(), @@ -713,25 +779,28 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, InsertMany) { this->DeliverChangeNotifications(); ASSERT_LE(1u, cookie_changes.size()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::INSERTED, - cookie_changes[0].second)); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[0].first.Domain()); - EXPECT_EQ("A", cookie_changes[0].first.Name()); - EXPECT_EQ("B", cookie_changes[0].first.Value()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[0].cause)); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[0].cookie.Domain()); + EXPECT_EQ("A", cookie_changes[0].cookie.Name()); + EXPECT_EQ("B", cookie_changes[0].cookie.Value()); ASSERT_LE(2u, cookie_changes.size()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[1].first.Domain()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::INSERTED, - cookie_changes[1].second)); - EXPECT_EQ("C", cookie_changes[1].first.Name()); - EXPECT_EQ("D", cookie_changes[1].first.Value()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[1].cookie.Domain()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[1].cause)); + EXPECT_EQ("C", cookie_changes[1].cookie.Name()); + EXPECT_EQ("D", cookie_changes[1].cookie.Value()); ASSERT_LE(3u, cookie_changes.size()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[2].first.Domain()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::INSERTED, - cookie_changes[2].second)); - EXPECT_EQ("E", cookie_changes[2].first.Name()); - EXPECT_EQ("F", cookie_changes[2].first.Value()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[2].cookie.Domain()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[2].cause)); + EXPECT_EQ("E", cookie_changes[2].cookie.Name()); + EXPECT_EQ("F", cookie_changes[2].cookie.Value()); EXPECT_EQ(3u, cookie_changes.size()); } @@ -741,7 +810,7 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, InsertFiltering) { return; CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes; + std::vector cookie_changes; std::unique_ptr subscription = cs->GetChangeDispatcher().AddCallbackForUrl( this->www_foo_foo_.url(), @@ -762,28 +831,30 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, InsertFiltering) { this->DeliverChangeNotifications(); ASSERT_LE(1u, cookie_changes.size()); - EXPECT_EQ("A", cookie_changes[0].first.Name()); - EXPECT_EQ("B", cookie_changes[0].first.Value()); - EXPECT_EQ("/", cookie_changes[0].first.Path()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[0].first.Domain()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::INSERTED, - cookie_changes[0].second)); + EXPECT_EQ("A", cookie_changes[0].cookie.Name()); + EXPECT_EQ("B", cookie_changes[0].cookie.Value()); + EXPECT_EQ("/", cookie_changes[0].cookie.Path()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[0].cookie.Domain()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[0].cause)); ASSERT_LE(2u, cookie_changes.size()); - EXPECT_EQ("I", cookie_changes[1].first.Name()); - EXPECT_EQ("J", cookie_changes[1].first.Value()); - EXPECT_EQ("/foo", cookie_changes[1].first.Path()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[1].first.Domain()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::INSERTED, - cookie_changes[1].second)); + EXPECT_EQ("I", cookie_changes[1].cookie.Name()); + EXPECT_EQ("J", cookie_changes[1].cookie.Value()); + EXPECT_EQ("/foo", cookie_changes[1].cookie.Path()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[1].cookie.Domain()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[1].cause)); ASSERT_LE(3u, cookie_changes.size()); - EXPECT_EQ("K", cookie_changes[2].first.Name()); - EXPECT_EQ("L", cookie_changes[2].first.Value()); - EXPECT_EQ("/", cookie_changes[2].first.Path()); - EXPECT_EQ(".foo.com", cookie_changes[2].first.Domain()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::INSERTED, - cookie_changes[2].second)); + EXPECT_EQ("K", cookie_changes[2].cookie.Name()); + EXPECT_EQ("L", cookie_changes[2].cookie.Value()); + EXPECT_EQ("/", cookie_changes[2].cookie.Path()); + EXPECT_EQ(".foo.com", cookie_changes[2].cookie.Domain()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[2].cause)); EXPECT_EQ(3u, cookie_changes.size()); } @@ -793,7 +864,7 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, DeleteOne) { return; CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes; + std::vector cookie_changes; std::unique_ptr subscription = cs->GetChangeDispatcher().AddCallbackForUrl( this->http_www_foo_.url(), @@ -810,11 +881,12 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, DeleteOne) { this->DeliverChangeNotifications(); ASSERT_EQ(1u, cookie_changes.size()); - EXPECT_EQ("A", cookie_changes[0].first.Name()); - EXPECT_EQ("B", cookie_changes[0].first.Value()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[0].first.Domain()); - ASSERT_TRUE(this->MatchesCause(CookieChangeCause::EXPLICIT, - cookie_changes[0].second)); + EXPECT_EQ("A", cookie_changes[0].cookie.Name()); + EXPECT_EQ("B", cookie_changes[0].cookie.Value()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[0].cookie.Domain()); + ASSERT_TRUE( + this->MatchesCause(CookieChangeCause::EXPLICIT, cookie_changes[0].cause)); } TYPED_TEST_P(CookieStoreChangeUrlTest, DeleteTwo) { @@ -822,7 +894,7 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, DeleteTwo) { return; CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes; + std::vector cookie_changes; std::unique_ptr subscription = cs->GetChangeDispatcher().AddCallbackForUrl( this->http_www_foo_.url(), @@ -850,18 +922,20 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, DeleteTwo) { EXPECT_EQ("A=B; E=F", this->GetCookies(cs, this->http_www_foo_.url())); ASSERT_LE(1u, cookie_changes.size()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[0].first.Domain()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::EXPLICIT, - cookie_changes[0].second)); - EXPECT_EQ("C", cookie_changes[0].first.Name()); - EXPECT_EQ("D", cookie_changes[0].first.Value()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[0].cookie.Domain()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::EXPLICIT, cookie_changes[0].cause)); + EXPECT_EQ("C", cookie_changes[0].cookie.Name()); + EXPECT_EQ("D", cookie_changes[0].cookie.Value()); ASSERT_EQ(2u, cookie_changes.size()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[1].first.Domain()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::EXPLICIT, - cookie_changes[1].second)); - EXPECT_EQ("G", cookie_changes[1].first.Name()); - EXPECT_EQ("H", cookie_changes[1].first.Value()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[1].cookie.Domain()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::EXPLICIT, cookie_changes[1].cause)); + EXPECT_EQ("G", cookie_changes[1].cookie.Name()); + EXPECT_EQ("H", cookie_changes[1].cookie.Value()); } TYPED_TEST_P(CookieStoreChangeUrlTest, DeleteFiltering) { @@ -869,7 +943,7 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, DeleteFiltering) { return; CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes; + std::vector cookie_changes; std::unique_ptr subscription = cs->GetChangeDispatcher().AddCallbackForUrl( this->www_foo_foo_.url(), @@ -902,28 +976,30 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, DeleteFiltering) { this->DeliverChangeNotifications(); ASSERT_LE(1u, cookie_changes.size()); - EXPECT_EQ("A", cookie_changes[0].first.Name()); - EXPECT_EQ("B", cookie_changes[0].first.Value()); - EXPECT_EQ("/", cookie_changes[0].first.Path()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[0].first.Domain()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::EXPLICIT, - cookie_changes[0].second)); + EXPECT_EQ("A", cookie_changes[0].cookie.Name()); + EXPECT_EQ("B", cookie_changes[0].cookie.Value()); + EXPECT_EQ("/", cookie_changes[0].cookie.Path()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[0].cookie.Domain()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::EXPLICIT, cookie_changes[0].cause)); ASSERT_LE(2u, cookie_changes.size()); - EXPECT_EQ("I", cookie_changes[1].first.Name()); - EXPECT_EQ("J", cookie_changes[1].first.Value()); - EXPECT_EQ("/foo", cookie_changes[1].first.Path()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[1].first.Domain()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::EXPLICIT, - cookie_changes[1].second)); + EXPECT_EQ("I", cookie_changes[1].cookie.Name()); + EXPECT_EQ("J", cookie_changes[1].cookie.Value()); + EXPECT_EQ("/foo", cookie_changes[1].cookie.Path()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[1].cookie.Domain()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::EXPLICIT, cookie_changes[1].cause)); ASSERT_LE(3u, cookie_changes.size()); - EXPECT_EQ("K", cookie_changes[2].first.Name()); - EXPECT_EQ("L", cookie_changes[2].first.Value()); - EXPECT_EQ("/", cookie_changes[2].first.Path()); - EXPECT_EQ(".foo.com", cookie_changes[2].first.Domain()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::EXPLICIT, - cookie_changes[2].second)); + EXPECT_EQ("K", cookie_changes[2].cookie.Name()); + EXPECT_EQ("L", cookie_changes[2].cookie.Value()); + EXPECT_EQ("/", cookie_changes[2].cookie.Path()); + EXPECT_EQ(".foo.com", cookie_changes[2].cookie.Domain()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::EXPLICIT, cookie_changes[2].cause)); EXPECT_EQ(3u, cookie_changes.size()); } @@ -933,7 +1009,7 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, Overwrite) { return; CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes; + std::vector cookie_changes; std::unique_ptr subscription = cs->GetChangeDispatcher().AddCallbackForUrl( this->http_www_foo_.url(), @@ -954,18 +1030,20 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, Overwrite) { this->DeliverChangeNotifications(); ASSERT_LE(1u, cookie_changes.size()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[0].first.Domain()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[0].cookie.Domain()); EXPECT_TRUE(this->MatchesCause(CookieChangeCause::OVERWRITE, - cookie_changes[0].second)); - EXPECT_EQ("A", cookie_changes[0].first.Name()); - EXPECT_EQ("B", cookie_changes[0].first.Value()); + cookie_changes[0].cause)); + EXPECT_EQ("A", cookie_changes[0].cookie.Name()); + EXPECT_EQ("B", cookie_changes[0].cookie.Value()); ASSERT_LE(2u, cookie_changes.size()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[1].first.Domain()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::INSERTED, - cookie_changes[1].second)); - EXPECT_EQ("A", cookie_changes[1].first.Name()); - EXPECT_EQ("C", cookie_changes[1].first.Value()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[1].cookie.Domain()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[1].cause)); + EXPECT_EQ("A", cookie_changes[1].cookie.Name()); + EXPECT_EQ("C", cookie_changes[1].cookie.Value()); EXPECT_EQ(2u, cookie_changes.size()); } @@ -975,7 +1053,7 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, OverwriteFiltering) { return; CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes; + std::vector cookie_changes; std::unique_ptr subscription = cs->GetChangeDispatcher().AddCallbackForUrl( this->www_foo_foo_.url(), @@ -1010,53 +1088,57 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, OverwriteFiltering) { this->DeliverChangeNotifications(); ASSERT_LE(1u, cookie_changes.size()); - EXPECT_EQ("A", cookie_changes[0].first.Name()); - EXPECT_EQ("B", cookie_changes[0].first.Value()); - EXPECT_EQ("/", cookie_changes[0].first.Path()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[0].first.Domain()); + EXPECT_EQ("A", cookie_changes[0].cookie.Name()); + EXPECT_EQ("B", cookie_changes[0].cookie.Value()); + EXPECT_EQ("/", cookie_changes[0].cookie.Path()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[0].cookie.Domain()); EXPECT_TRUE(this->MatchesCause(CookieChangeCause::OVERWRITE, - cookie_changes[0].second)); + cookie_changes[0].cause)); ASSERT_LE(2u, cookie_changes.size()); - EXPECT_EQ("A", cookie_changes[1].first.Name()); - EXPECT_EQ("b", cookie_changes[1].first.Value()); - EXPECT_EQ("/", cookie_changes[1].first.Path()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[1].first.Domain()); - EXPECT_EQ(CookieChangeCause::INSERTED, cookie_changes[1].second); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::INSERTED, - cookie_changes[1].second)); + EXPECT_EQ("A", cookie_changes[1].cookie.Name()); + EXPECT_EQ("b", cookie_changes[1].cookie.Value()); + EXPECT_EQ("/", cookie_changes[1].cookie.Path()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[1].cookie.Domain()); + EXPECT_EQ(CookieChangeCause::INSERTED, cookie_changes[1].cause); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[1].cause)); ASSERT_LE(3u, cookie_changes.size()); - EXPECT_EQ("I", cookie_changes[2].first.Name()); - EXPECT_EQ("J", cookie_changes[2].first.Value()); - EXPECT_EQ("/foo", cookie_changes[2].first.Path()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[2].first.Domain()); + EXPECT_EQ("I", cookie_changes[2].cookie.Name()); + EXPECT_EQ("J", cookie_changes[2].cookie.Value()); + EXPECT_EQ("/foo", cookie_changes[2].cookie.Path()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[2].cookie.Domain()); EXPECT_TRUE(this->MatchesCause(CookieChangeCause::OVERWRITE, - cookie_changes[2].second)); + cookie_changes[2].cause)); ASSERT_LE(4u, cookie_changes.size()); - EXPECT_EQ("I", cookie_changes[3].first.Name()); - EXPECT_EQ("j", cookie_changes[3].first.Value()); - EXPECT_EQ("/foo", cookie_changes[3].first.Path()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[3].first.Domain()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::INSERTED, - cookie_changes[3].second)); + EXPECT_EQ("I", cookie_changes[3].cookie.Name()); + EXPECT_EQ("j", cookie_changes[3].cookie.Value()); + EXPECT_EQ("/foo", cookie_changes[3].cookie.Path()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[3].cookie.Domain()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[3].cause)); ASSERT_LE(5u, cookie_changes.size()); - EXPECT_EQ("K", cookie_changes[4].first.Name()); - EXPECT_EQ("L", cookie_changes[4].first.Value()); - EXPECT_EQ("/", cookie_changes[4].first.Path()); - EXPECT_EQ(".foo.com", cookie_changes[4].first.Domain()); + EXPECT_EQ("K", cookie_changes[4].cookie.Name()); + EXPECT_EQ("L", cookie_changes[4].cookie.Value()); + EXPECT_EQ("/", cookie_changes[4].cookie.Path()); + EXPECT_EQ(".foo.com", cookie_changes[4].cookie.Domain()); EXPECT_TRUE(this->MatchesCause(CookieChangeCause::OVERWRITE, - cookie_changes[4].second)); + cookie_changes[4].cause)); ASSERT_LE(6u, cookie_changes.size()); - EXPECT_EQ("K", cookie_changes[5].first.Name()); - EXPECT_EQ("l", cookie_changes[5].first.Value()); - EXPECT_EQ("/", cookie_changes[5].first.Path()); - EXPECT_EQ(".foo.com", cookie_changes[5].first.Domain()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::INSERTED, - cookie_changes[5].second)); + EXPECT_EQ("K", cookie_changes[5].cookie.Name()); + EXPECT_EQ("l", cookie_changes[5].cookie.Value()); + EXPECT_EQ("/", cookie_changes[5].cookie.Path()); + EXPECT_EQ(".foo.com", cookie_changes[5].cookie.Domain()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[5].cause)); EXPECT_EQ(6u, cookie_changes.size()); } @@ -1067,7 +1149,7 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, OverwriteWithHttpOnly) { // Insert a cookie "A" for path "/foo". CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes; + std::vector cookie_changes; std::unique_ptr subscription = cs->GetChangeDispatcher().AddCallbackForUrl( this->www_foo_foo_.url(), @@ -1080,12 +1162,13 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, OverwriteWithHttpOnly) { EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B; path=/foo")); this->DeliverChangeNotifications(); ASSERT_EQ(1u, cookie_changes.size()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::INSERTED, - cookie_changes[0].second)); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[0].first.Domain()); - EXPECT_EQ("A", cookie_changes[0].first.Name()); - EXPECT_EQ("B", cookie_changes[0].first.Value()); - EXPECT_FALSE(cookie_changes[0].first.IsHttpOnly()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[0].cause)); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[0].cookie.Domain()); + EXPECT_EQ("A", cookie_changes[0].cookie.Name()); + EXPECT_EQ("B", cookie_changes[0].cookie.Value()); + EXPECT_FALSE(cookie_changes[0].cookie.IsHttpOnly()); cookie_changes.clear(); // Insert a cookie "A" for path "/foo", that is httponly. This should @@ -1098,20 +1181,22 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, OverwriteWithHttpOnly) { this->DeliverChangeNotifications(); ASSERT_LE(1u, cookie_changes.size()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[0].first.Domain()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[0].cookie.Domain()); EXPECT_TRUE(this->MatchesCause(CookieChangeCause::OVERWRITE, - cookie_changes[0].second)); - EXPECT_EQ("A", cookie_changes[0].first.Name()); - EXPECT_EQ("B", cookie_changes[0].first.Value()); - EXPECT_FALSE(cookie_changes[0].first.IsHttpOnly()); + cookie_changes[0].cause)); + EXPECT_EQ("A", cookie_changes[0].cookie.Name()); + EXPECT_EQ("B", cookie_changes[0].cookie.Value()); + EXPECT_FALSE(cookie_changes[0].cookie.IsHttpOnly()); ASSERT_LE(2u, cookie_changes.size()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[1].first.Domain()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::INSERTED, - cookie_changes[1].second)); - EXPECT_EQ("A", cookie_changes[1].first.Name()); - EXPECT_EQ("C", cookie_changes[1].first.Value()); - EXPECT_TRUE(cookie_changes[1].first.IsHttpOnly()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[1].cookie.Domain()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[1].cause)); + EXPECT_EQ("A", cookie_changes[1].cookie.Name()); + EXPECT_EQ("C", cookie_changes[1].cookie.Value()); + EXPECT_TRUE(cookie_changes[1].cookie.IsHttpOnly()); EXPECT_EQ(2u, cookie_changes.size()); } @@ -1122,7 +1207,7 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, Deregister) { CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes; + std::vector cookie_changes; std::unique_ptr subscription = cs->GetChangeDispatcher().AddCallbackForUrl( this->http_www_foo_.url(), @@ -1136,8 +1221,8 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, Deregister) { EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B")); this->DeliverChangeNotifications(); ASSERT_EQ(1u, cookie_changes.size()); - EXPECT_EQ("A", cookie_changes[0].first.Name()); - EXPECT_EQ("B", cookie_changes[0].first.Value()); + EXPECT_EQ("A", cookie_changes[0].cookie.Name()); + EXPECT_EQ("B", cookie_changes[0].cookie.Value()); cookie_changes.clear(); // De-register the subscription. @@ -1158,7 +1243,7 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, DeregisterMultiple) { CookieStore* cs = this->GetCookieStore(); // Register two subscriptions. - std::vector cookie_changes_1, cookie_changes_2; + std::vector cookie_changes_1, cookie_changes_2; std::unique_ptr subscription1 = cs->GetChangeDispatcher().AddCallbackForUrl( this->http_www_foo_.url(), @@ -1179,13 +1264,13 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, DeregisterMultiple) { EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B")); this->DeliverChangeNotifications(); ASSERT_EQ(1u, cookie_changes_1.size()); - EXPECT_EQ("A", cookie_changes_1[0].first.Name()); - EXPECT_EQ("B", cookie_changes_1[0].first.Value()); + EXPECT_EQ("A", cookie_changes_1[0].cookie.Name()); + EXPECT_EQ("B", cookie_changes_1[0].cookie.Value()); cookie_changes_1.clear(); ASSERT_EQ(1u, cookie_changes_2.size()); - EXPECT_EQ("A", cookie_changes_2[0].first.Name()); - EXPECT_EQ("B", cookie_changes_2[0].first.Value()); + EXPECT_EQ("A", cookie_changes_2[0].cookie.Name()); + EXPECT_EQ("B", cookie_changes_2[0].cookie.Value()); cookie_changes_2.clear(); // De-register the second registration. @@ -1196,8 +1281,8 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, DeregisterMultiple) { EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "C=D")); this->DeliverChangeNotifications(); ASSERT_EQ(1u, cookie_changes_1.size()); - EXPECT_EQ("C", cookie_changes_1[0].first.Name()); - EXPECT_EQ("D", cookie_changes_1[0].first.Value()); + EXPECT_EQ("C", cookie_changes_1[0].cookie.Name()); + EXPECT_EQ("D", cookie_changes_1[0].cookie.Value()); EXPECT_EQ(0u, cookie_changes_2.size()); } @@ -1215,7 +1300,7 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, DispatchRace) { // DeliverChangeNotifications() must NOT be called before the subscription is // established. - std::vector cookie_changes; + std::vector cookie_changes; std::unique_ptr subscription = cs->GetChangeDispatcher().AddCallbackForUrl( this->http_www_foo_.url(), @@ -1227,8 +1312,8 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, DispatchRace) { this->DeliverChangeNotifications(); EXPECT_LE(1u, cookie_changes.size()); - EXPECT_EQ("C", cookie_changes[0].first.Name()); - EXPECT_EQ("D", cookie_changes[0].first.Value()); + EXPECT_EQ("C", cookie_changes[0].cookie.Name()); + EXPECT_EQ("D", cookie_changes[0].cookie.Value()); ASSERT_EQ(1u, cookie_changes.size()); } @@ -1242,7 +1327,7 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, DeregisterRace) { CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes; + std::vector cookie_changes; std::unique_ptr subscription = cs->GetChangeDispatcher().AddCallbackForUrl( this->http_www_foo_.url(), @@ -1256,8 +1341,8 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, DeregisterRace) { EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B")); this->DeliverChangeNotifications(); ASSERT_EQ(1u, cookie_changes.size()); - EXPECT_EQ("A", cookie_changes[0].first.Name()); - EXPECT_EQ("B", cookie_changes[0].first.Value()); + EXPECT_EQ("A", cookie_changes[0].cookie.Name()); + EXPECT_EQ("B", cookie_changes[0].cookie.Value()); cookie_changes.clear(); // Insert a cookie, confirm it is not seen, deregister the subscription, run @@ -1287,7 +1372,7 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, DeregisterRaceMultiple) { CookieStore* cs = this->GetCookieStore(); // Register two subscriptions. - std::vector cookie_changes_1, cookie_changes_2; + std::vector cookie_changes_1, cookie_changes_2; std::unique_ptr subscription1 = cs->GetChangeDispatcher().AddCallbackForUrl( this->http_www_foo_.url(), @@ -1309,13 +1394,13 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, DeregisterRaceMultiple) { this->DeliverChangeNotifications(); ASSERT_EQ(1u, cookie_changes_1.size()); - EXPECT_EQ("A", cookie_changes_1[0].first.Name()); - EXPECT_EQ("B", cookie_changes_1[0].first.Value()); + EXPECT_EQ("A", cookie_changes_1[0].cookie.Name()); + EXPECT_EQ("B", cookie_changes_1[0].cookie.Value()); cookie_changes_1.clear(); ASSERT_EQ(1u, cookie_changes_2.size()); - EXPECT_EQ("A", cookie_changes_2[0].first.Name()); - EXPECT_EQ("B", cookie_changes_2[0].first.Value()); + EXPECT_EQ("A", cookie_changes_2[0].cookie.Name()); + EXPECT_EQ("B", cookie_changes_2[0].cookie.Value()); cookie_changes_2.clear(); // Insert a cookie, confirm it is not seen, deregister a subscription, run @@ -1335,8 +1420,8 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, DeregisterRaceMultiple) { subscription2.reset(); this->DeliverChangeNotifications(); ASSERT_EQ(1u, cookie_changes_1.size()); - EXPECT_EQ("C", cookie_changes_1[0].first.Name()); - EXPECT_EQ("D", cookie_changes_1[0].first.Value()); + EXPECT_EQ("C", cookie_changes_1[0].cookie.Name()); + EXPECT_EQ("D", cookie_changes_1[0].cookie.Value()); // No late notification was received. ASSERT_EQ(0u, cookie_changes_2.size()); @@ -1348,7 +1433,7 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, DifferentSubscriptionsDisjoint) { CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes_1, cookie_changes_2; + std::vector cookie_changes_1, cookie_changes_2; std::unique_ptr subscription1 = cs->GetChangeDispatcher().AddCallbackForUrl( this->http_www_foo_.url(), @@ -1374,16 +1459,16 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, DifferentSubscriptionsDisjoint) { this->DeliverChangeNotifications(); ASSERT_EQ(1u, cookie_changes_1.size()); - EXPECT_EQ("A", cookie_changes_1[0].first.Name()); - EXPECT_EQ("B", cookie_changes_1[0].first.Value()); + EXPECT_EQ("A", cookie_changes_1[0].cookie.Name()); + EXPECT_EQ("B", cookie_changes_1[0].cookie.Value()); EXPECT_EQ(this->http_www_foo_.url().host(), - cookie_changes_1[0].first.Domain()); + cookie_changes_1[0].cookie.Domain()); ASSERT_EQ(1u, cookie_changes_2.size()); - EXPECT_EQ("C", cookie_changes_2[0].first.Name()); - EXPECT_EQ("D", cookie_changes_2[0].first.Value()); + EXPECT_EQ("C", cookie_changes_2[0].cookie.Name()); + EXPECT_EQ("D", cookie_changes_2[0].cookie.Value()); EXPECT_EQ(this->http_bar_com_.url().host(), - cookie_changes_2[0].first.Domain()); + cookie_changes_2[0].cookie.Domain()); } TYPED_TEST_P(CookieStoreChangeUrlTest, DifferentSubscriptionsDomains) { @@ -1392,7 +1477,7 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, DifferentSubscriptionsDomains) { CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes_1, cookie_changes_2; + std::vector cookie_changes_1, cookie_changes_2; std::unique_ptr subscription1 = cs->GetChangeDispatcher().AddCallbackForUrl( this->http_www_foo_.url(), @@ -1418,16 +1503,16 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, DifferentSubscriptionsDomains) { this->DeliverChangeNotifications(); ASSERT_EQ(1u, cookie_changes_1.size()); - EXPECT_EQ("A", cookie_changes_1[0].first.Name()); - EXPECT_EQ("B", cookie_changes_1[0].first.Value()); + EXPECT_EQ("A", cookie_changes_1[0].cookie.Name()); + EXPECT_EQ("B", cookie_changes_1[0].cookie.Value()); EXPECT_EQ(this->http_www_foo_.url().host(), - cookie_changes_1[0].first.Domain()); + cookie_changes_1[0].cookie.Domain()); ASSERT_EQ(1u, cookie_changes_2.size()); - EXPECT_EQ("C", cookie_changes_2[0].first.Name()); - EXPECT_EQ("D", cookie_changes_2[0].first.Value()); + EXPECT_EQ("C", cookie_changes_2[0].cookie.Name()); + EXPECT_EQ("D", cookie_changes_2[0].cookie.Value()); EXPECT_EQ(this->http_bar_com_.url().host(), - cookie_changes_2[0].first.Domain()); + cookie_changes_2[0].cookie.Domain()); } TYPED_TEST_P(CookieStoreChangeUrlTest, DifferentSubscriptionsPaths) { @@ -1436,7 +1521,7 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, DifferentSubscriptionsPaths) { CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes_1, cookie_changes_2; + std::vector cookie_changes_1, cookie_changes_2; std::unique_ptr subscription1 = cs->GetChangeDispatcher().AddCallbackForUrl( this->http_www_foo_.url(), @@ -1462,25 +1547,25 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, DifferentSubscriptionsPaths) { this->DeliverChangeNotifications(); ASSERT_EQ(1u, cookie_changes_1.size()); - EXPECT_EQ("A", cookie_changes_1[0].first.Name()); - EXPECT_EQ("B", cookie_changes_1[0].first.Value()); - EXPECT_EQ("/", cookie_changes_1[0].first.Path()); + EXPECT_EQ("A", cookie_changes_1[0].cookie.Name()); + EXPECT_EQ("B", cookie_changes_1[0].cookie.Value()); + EXPECT_EQ("/", cookie_changes_1[0].cookie.Path()); EXPECT_EQ(this->http_www_foo_.url().host(), - cookie_changes_1[0].first.Domain()); + cookie_changes_1[0].cookie.Domain()); ASSERT_LE(1u, cookie_changes_2.size()); - EXPECT_EQ("A", cookie_changes_2[0].first.Name()); - EXPECT_EQ("B", cookie_changes_2[0].first.Value()); - EXPECT_EQ("/", cookie_changes_2[0].first.Path()); + EXPECT_EQ("A", cookie_changes_2[0].cookie.Name()); + EXPECT_EQ("B", cookie_changes_2[0].cookie.Value()); + EXPECT_EQ("/", cookie_changes_2[0].cookie.Path()); EXPECT_EQ(this->http_www_foo_.url().host(), - cookie_changes_2[0].first.Domain()); + cookie_changes_2[0].cookie.Domain()); ASSERT_LE(2u, cookie_changes_2.size()); - EXPECT_EQ("C", cookie_changes_2[1].first.Name()); - EXPECT_EQ("D", cookie_changes_2[1].first.Value()); - EXPECT_EQ("/foo", cookie_changes_2[1].first.Path()); + EXPECT_EQ("C", cookie_changes_2[1].cookie.Name()); + EXPECT_EQ("D", cookie_changes_2[1].cookie.Value()); + EXPECT_EQ("/foo", cookie_changes_2[1].cookie.Path()); EXPECT_EQ(this->http_www_foo_.url().host(), - cookie_changes_2[1].first.Domain()); + cookie_changes_2[1].cookie.Domain()); EXPECT_EQ(2u, cookie_changes_2.size()); } @@ -1491,8 +1576,8 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, DifferentSubscriptionsFiltering) { CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes_1, cookie_changes_2; - std::vector cookie_changes_3; + std::vector cookie_changes_1, cookie_changes_2; + std::vector cookie_changes_3; std::unique_ptr subscription1 = cs->GetChangeDispatcher().AddCallbackForUrl( this->http_www_foo_.url(), @@ -1532,32 +1617,32 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, DifferentSubscriptionsFiltering) { this->DeliverChangeNotifications(); ASSERT_LE(1u, cookie_changes_1.size()); - EXPECT_EQ("A", cookie_changes_1[0].first.Name()); - EXPECT_EQ("B", cookie_changes_1[0].first.Value()); + EXPECT_EQ("A", cookie_changes_1[0].cookie.Name()); + EXPECT_EQ("B", cookie_changes_1[0].cookie.Value()); EXPECT_EQ(this->http_www_foo_.url().host(), - cookie_changes_1[0].first.Domain()); + cookie_changes_1[0].cookie.Domain()); EXPECT_EQ(1u, cookie_changes_1.size()); ASSERT_LE(1u, cookie_changes_2.size()); - EXPECT_EQ("C", cookie_changes_2[0].first.Name()); - EXPECT_EQ("D", cookie_changes_2[0].first.Value()); + EXPECT_EQ("C", cookie_changes_2[0].cookie.Name()); + EXPECT_EQ("D", cookie_changes_2[0].cookie.Value()); EXPECT_EQ(this->http_bar_com_.url().host(), - cookie_changes_2[0].first.Domain()); + cookie_changes_2[0].cookie.Domain()); EXPECT_EQ(1u, cookie_changes_2.size()); ASSERT_LE(1u, cookie_changes_3.size()); - EXPECT_EQ("A", cookie_changes_3[0].first.Name()); - EXPECT_EQ("B", cookie_changes_3[0].first.Value()); - EXPECT_EQ("/", cookie_changes_3[0].first.Path()); + EXPECT_EQ("A", cookie_changes_3[0].cookie.Name()); + EXPECT_EQ("B", cookie_changes_3[0].cookie.Value()); + EXPECT_EQ("/", cookie_changes_3[0].cookie.Path()); EXPECT_EQ(this->http_www_foo_.url().host(), - cookie_changes_3[0].first.Domain()); + cookie_changes_3[0].cookie.Domain()); ASSERT_LE(2u, cookie_changes_3.size()); - EXPECT_EQ("E", cookie_changes_3[1].first.Name()); - EXPECT_EQ("F", cookie_changes_3[1].first.Value()); - EXPECT_EQ("/foo", cookie_changes_3[1].first.Path()); + EXPECT_EQ("E", cookie_changes_3[1].cookie.Name()); + EXPECT_EQ("F", cookie_changes_3[1].cookie.Value()); + EXPECT_EQ("/foo", cookie_changes_3[1].cookie.Path()); EXPECT_EQ(this->http_www_foo_.url().host(), - cookie_changes_3[1].first.Domain()); + cookie_changes_3[1].cookie.Domain()); EXPECT_EQ(2u, cookie_changes_3.size()); } @@ -1569,7 +1654,7 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, MultipleSubscriptions) { CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes_1, cookie_changes_2; + std::vector cookie_changes_1, cookie_changes_2; std::unique_ptr subscription1 = cs->GetChangeDispatcher().AddCallbackForUrl( this->http_www_foo_.url(), @@ -1588,12 +1673,43 @@ TYPED_TEST_P(CookieStoreChangeUrlTest, MultipleSubscriptions) { this->DeliverChangeNotifications(); ASSERT_EQ(1U, cookie_changes_1.size()); - EXPECT_EQ("A", cookie_changes_1[0].first.Name()); - EXPECT_EQ("B", cookie_changes_1[0].first.Value()); + EXPECT_EQ("A", cookie_changes_1[0].cookie.Name()); + EXPECT_EQ("B", cookie_changes_1[0].cookie.Value()); ASSERT_EQ(1U, cookie_changes_2.size()); - EXPECT_EQ("A", cookie_changes_2[0].first.Name()); - EXPECT_EQ("B", cookie_changes_2[0].first.Value()); + EXPECT_EQ("A", cookie_changes_2[0].cookie.Name()); + EXPECT_EQ("B", cookie_changes_2[0].cookie.Value()); +} + +TYPED_TEST_P(CookieStoreChangeUrlTest, ChangeIncludesCookieAccessSemantics) { + if (!TypeParam::supports_url_cookie_tracking) + return; + + CookieStore* cs = this->GetCookieStore(); + // if !supports_cookie_access_semantics, the delegate will be stored but will + // not be used. + auto access_delegate = std::make_unique(); + access_delegate->SetExpectationForCookieDomain("domain1.test", + CookieAccessSemantics::LEGACY); + cs->SetCookieAccessDelegate(std::move(access_delegate)); + + std::vector cookie_changes; + std::unique_ptr subscription = + cs->GetChangeDispatcher().AddCallbackForUrl( + GURL("http://domain1.test"), + base::BindRepeating( + &CookieStoreChangeTestBase::OnCookieChange, + base::Unretained(&cookie_changes))); + + this->CreateAndSetCookie(cs, GURL("http://domain1.test"), "cookie=1", + CookieOptions::MakeAllInclusive()); + this->DeliverChangeNotifications(); + + ASSERT_EQ(1u, cookie_changes.size()); + + EXPECT_EQ("domain1.test", cookie_changes[0].cookie.Domain()); + EXPECT_TRUE(this->IsExpectedAccessSemantics( + CookieAccessSemantics::LEGACY, cookie_changes[0].access_semantics)); } TYPED_TEST_P(CookieStoreChangeNamedTest, NoCookie) { @@ -1601,7 +1717,7 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, NoCookie) { return; CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes; + std::vector cookie_changes; std::unique_ptr subscription = cs->GetChangeDispatcher().AddCallbackForCookie( this->http_www_foo_.url(), "abc", @@ -1617,7 +1733,7 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, InitialCookie) { return; CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes; + std::vector cookie_changes; this->SetCookie(cs, this->http_www_foo_.url(), "abc=def"); this->DeliverChangeNotifications(); std::unique_ptr subscription = @@ -1635,7 +1751,7 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, InsertOne) { return; CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes; + std::vector cookie_changes; std::unique_ptr subscription = cs->GetChangeDispatcher().AddCallbackForCookie( this->http_www_foo_.url(), "abc", @@ -1649,11 +1765,12 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, InsertOne) { this->DeliverChangeNotifications(); ASSERT_EQ(1u, cookie_changes.size()); - EXPECT_EQ("abc", cookie_changes[0].first.Name()); - EXPECT_EQ("def", cookie_changes[0].first.Value()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[0].first.Domain()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::INSERTED, - cookie_changes[0].second)); + EXPECT_EQ("abc", cookie_changes[0].cookie.Name()); + EXPECT_EQ("def", cookie_changes[0].cookie.Value()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[0].cookie.Domain()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[0].cause)); } TYPED_TEST_P(CookieStoreChangeNamedTest, InsertTwo) { @@ -1661,7 +1778,7 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, InsertTwo) { return; CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes; + std::vector cookie_changes; std::unique_ptr subscription = cs->GetChangeDispatcher().AddCallbackForCookie( this->www_foo_foo_.url(), "abc", @@ -1677,20 +1794,22 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, InsertTwo) { this->DeliverChangeNotifications(); ASSERT_LE(1u, cookie_changes.size()); - EXPECT_EQ("abc", cookie_changes[0].first.Name()); - EXPECT_EQ("def", cookie_changes[0].first.Value()); - EXPECT_EQ("/", cookie_changes[0].first.Path()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[0].first.Domain()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::INSERTED, - cookie_changes[0].second)); + EXPECT_EQ("abc", cookie_changes[0].cookie.Name()); + EXPECT_EQ("def", cookie_changes[0].cookie.Value()); + EXPECT_EQ("/", cookie_changes[0].cookie.Path()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[0].cookie.Domain()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[0].cause)); ASSERT_LE(2u, cookie_changes.size()); - EXPECT_EQ("abc", cookie_changes[1].first.Name()); - EXPECT_EQ("hij", cookie_changes[1].first.Value()); - EXPECT_EQ("/foo", cookie_changes[1].first.Path()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[1].first.Domain()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::INSERTED, - cookie_changes[1].second)); + EXPECT_EQ("abc", cookie_changes[1].cookie.Name()); + EXPECT_EQ("hij", cookie_changes[1].cookie.Value()); + EXPECT_EQ("/foo", cookie_changes[1].cookie.Path()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[1].cookie.Domain()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[1].cause)); EXPECT_EQ(2u, cookie_changes.size()); } @@ -1700,7 +1819,7 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, InsertFiltering) { return; CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes; + std::vector cookie_changes; std::unique_ptr subscription = cs->GetChangeDispatcher().AddCallbackForCookie( this->www_foo_foo_.url(), "abc", @@ -1726,28 +1845,30 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, InsertFiltering) { this->DeliverChangeNotifications(); ASSERT_LE(1u, cookie_changes.size()); - EXPECT_EQ("abc", cookie_changes[0].first.Name()); - EXPECT_EQ("def", cookie_changes[0].first.Value()); - EXPECT_EQ("/", cookie_changes[0].first.Path()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[0].first.Domain()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::INSERTED, - cookie_changes[0].second)); + EXPECT_EQ("abc", cookie_changes[0].cookie.Name()); + EXPECT_EQ("def", cookie_changes[0].cookie.Value()); + EXPECT_EQ("/", cookie_changes[0].cookie.Path()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[0].cookie.Domain()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[0].cause)); ASSERT_LE(2u, cookie_changes.size()); - EXPECT_EQ("abc", cookie_changes[1].first.Name()); - EXPECT_EQ("pqr", cookie_changes[1].first.Value()); - EXPECT_EQ("/foo", cookie_changes[1].first.Path()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[1].first.Domain()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::INSERTED, - cookie_changes[1].second)); + EXPECT_EQ("abc", cookie_changes[1].cookie.Name()); + EXPECT_EQ("pqr", cookie_changes[1].cookie.Value()); + EXPECT_EQ("/foo", cookie_changes[1].cookie.Path()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[1].cookie.Domain()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[1].cause)); ASSERT_LE(3u, cookie_changes.size()); - EXPECT_EQ("abc", cookie_changes[2].first.Name()); - EXPECT_EQ("stu", cookie_changes[2].first.Value()); - EXPECT_EQ("/", cookie_changes[2].first.Path()); - EXPECT_EQ(".foo.com", cookie_changes[2].first.Domain()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::INSERTED, - cookie_changes[2].second)); + EXPECT_EQ("abc", cookie_changes[2].cookie.Name()); + EXPECT_EQ("stu", cookie_changes[2].cookie.Value()); + EXPECT_EQ("/", cookie_changes[2].cookie.Path()); + EXPECT_EQ(".foo.com", cookie_changes[2].cookie.Domain()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[2].cause)); EXPECT_EQ(3u, cookie_changes.size()); } @@ -1757,7 +1878,7 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, DeleteOne) { return; CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes; + std::vector cookie_changes; std::unique_ptr subscription = cs->GetChangeDispatcher().AddCallbackForCookie( this->http_www_foo_.url(), "abc", @@ -1774,11 +1895,12 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, DeleteOne) { this->DeliverChangeNotifications(); ASSERT_EQ(1u, cookie_changes.size()); - EXPECT_EQ("abc", cookie_changes[0].first.Name()); - EXPECT_EQ("def", cookie_changes[0].first.Value()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[0].first.Domain()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::EXPLICIT, - cookie_changes[0].second)); + EXPECT_EQ("abc", cookie_changes[0].cookie.Name()); + EXPECT_EQ("def", cookie_changes[0].cookie.Value()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[0].cookie.Domain()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::EXPLICIT, cookie_changes[0].cause)); } TYPED_TEST_P(CookieStoreChangeNamedTest, DeleteTwo) { @@ -1786,7 +1908,7 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, DeleteTwo) { return; CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes; + std::vector cookie_changes; std::unique_ptr subscription = cs->GetChangeDispatcher().AddCallbackForCookie( this->www_foo_foo_.url(), "abc", @@ -1807,20 +1929,22 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, DeleteTwo) { this->DeliverChangeNotifications(); ASSERT_LE(1u, cookie_changes.size()); - EXPECT_EQ("abc", cookie_changes[0].first.Name()); - EXPECT_EQ("def", cookie_changes[0].first.Value()); - EXPECT_EQ("/", cookie_changes[0].first.Path()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[0].first.Domain()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::EXPLICIT, - cookie_changes[0].second)); + EXPECT_EQ("abc", cookie_changes[0].cookie.Name()); + EXPECT_EQ("def", cookie_changes[0].cookie.Value()); + EXPECT_EQ("/", cookie_changes[0].cookie.Path()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[0].cookie.Domain()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::EXPLICIT, cookie_changes[0].cause)); ASSERT_EQ(2u, cookie_changes.size()); - EXPECT_EQ("abc", cookie_changes[1].first.Name()); - EXPECT_EQ("hij", cookie_changes[1].first.Value()); - EXPECT_EQ("/foo", cookie_changes[1].first.Path()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[1].first.Domain()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::EXPLICIT, - cookie_changes[1].second)); + EXPECT_EQ("abc", cookie_changes[1].cookie.Name()); + EXPECT_EQ("hij", cookie_changes[1].cookie.Value()); + EXPECT_EQ("/foo", cookie_changes[1].cookie.Path()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[1].cookie.Domain()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::EXPLICIT, cookie_changes[1].cause)); } TYPED_TEST_P(CookieStoreChangeNamedTest, DeleteFiltering) { @@ -1828,7 +1952,7 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, DeleteFiltering) { return; CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes; + std::vector cookie_changes; std::unique_ptr subscription = cs->GetChangeDispatcher().AddCallbackForCookie( this->www_foo_foo_.url(), "abc", @@ -1865,28 +1989,30 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, DeleteFiltering) { this->DeliverChangeNotifications(); ASSERT_LE(1u, cookie_changes.size()); - EXPECT_EQ("abc", cookie_changes[0].first.Name()); - EXPECT_EQ("mno", cookie_changes[0].first.Value()); - EXPECT_EQ("/foo", cookie_changes[0].first.Path()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[0].first.Domain()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::EXPLICIT, - cookie_changes[0].second)); + EXPECT_EQ("abc", cookie_changes[0].cookie.Name()); + EXPECT_EQ("mno", cookie_changes[0].cookie.Value()); + EXPECT_EQ("/foo", cookie_changes[0].cookie.Path()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[0].cookie.Domain()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::EXPLICIT, cookie_changes[0].cause)); ASSERT_LE(2u, cookie_changes.size()); - EXPECT_EQ("abc", cookie_changes[1].first.Name()); - EXPECT_EQ("pqr", cookie_changes[1].first.Value()); - EXPECT_EQ("/", cookie_changes[1].first.Path()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[1].first.Domain()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::EXPLICIT, - cookie_changes[1].second)); + EXPECT_EQ("abc", cookie_changes[1].cookie.Name()); + EXPECT_EQ("pqr", cookie_changes[1].cookie.Value()); + EXPECT_EQ("/", cookie_changes[1].cookie.Path()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[1].cookie.Domain()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::EXPLICIT, cookie_changes[1].cause)); ASSERT_LE(3u, cookie_changes.size()); - EXPECT_EQ("abc", cookie_changes[2].first.Name()); - EXPECT_EQ("stu", cookie_changes[2].first.Value()); - EXPECT_EQ("/", cookie_changes[2].first.Path()); - EXPECT_EQ(".foo.com", cookie_changes[2].first.Domain()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::EXPLICIT, - cookie_changes[2].second)); + EXPECT_EQ("abc", cookie_changes[2].cookie.Name()); + EXPECT_EQ("stu", cookie_changes[2].cookie.Value()); + EXPECT_EQ("/", cookie_changes[2].cookie.Path()); + EXPECT_EQ(".foo.com", cookie_changes[2].cookie.Domain()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::EXPLICIT, cookie_changes[2].cause)); EXPECT_EQ(3u, cookie_changes.size()); } @@ -1896,7 +2022,7 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, Overwrite) { return; CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes; + std::vector cookie_changes; std::unique_ptr subscription = cs->GetChangeDispatcher().AddCallbackForCookie( this->http_www_foo_.url(), "abc", @@ -1917,18 +2043,20 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, Overwrite) { this->DeliverChangeNotifications(); EXPECT_LE(1u, cookie_changes.size()); - EXPECT_EQ("abc", cookie_changes[0].first.Name()); - EXPECT_EQ("def", cookie_changes[0].first.Value()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[0].first.Domain()); + EXPECT_EQ("abc", cookie_changes[0].cookie.Name()); + EXPECT_EQ("def", cookie_changes[0].cookie.Value()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[0].cookie.Domain()); EXPECT_TRUE(this->MatchesCause(CookieChangeCause::OVERWRITE, - cookie_changes[0].second)); + cookie_changes[0].cause)); EXPECT_LE(2u, cookie_changes.size()); - EXPECT_EQ("abc", cookie_changes[1].first.Name()); - EXPECT_EQ("ghi", cookie_changes[1].first.Value()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[1].first.Domain()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::INSERTED, - cookie_changes[1].second)); + EXPECT_EQ("abc", cookie_changes[1].cookie.Name()); + EXPECT_EQ("ghi", cookie_changes[1].cookie.Value()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[1].cookie.Domain()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[1].cause)); EXPECT_EQ(2u, cookie_changes.size()); } @@ -1938,7 +2066,7 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, OverwriteFiltering) { return; CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes; + std::vector cookie_changes; std::unique_ptr subscription = cs->GetChangeDispatcher().AddCallbackForCookie( this->www_foo_foo_.url(), "abc", @@ -1981,52 +2109,56 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, OverwriteFiltering) { this->DeliverChangeNotifications(); ASSERT_LE(1u, cookie_changes.size()); - EXPECT_EQ("abc", cookie_changes[0].first.Name()); - EXPECT_EQ("mno1", cookie_changes[0].first.Value()); - EXPECT_EQ("/foo", cookie_changes[0].first.Path()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[0].first.Domain()); + EXPECT_EQ("abc", cookie_changes[0].cookie.Name()); + EXPECT_EQ("mno1", cookie_changes[0].cookie.Value()); + EXPECT_EQ("/foo", cookie_changes[0].cookie.Path()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[0].cookie.Domain()); EXPECT_TRUE(this->MatchesCause(CookieChangeCause::OVERWRITE, - cookie_changes[0].second)); + cookie_changes[0].cause)); ASSERT_LE(2u, cookie_changes.size()); - EXPECT_EQ("abc", cookie_changes[1].first.Name()); - EXPECT_EQ("mno2", cookie_changes[1].first.Value()); - EXPECT_EQ("/foo", cookie_changes[1].first.Path()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[1].first.Domain()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::INSERTED, - cookie_changes[1].second)); + EXPECT_EQ("abc", cookie_changes[1].cookie.Name()); + EXPECT_EQ("mno2", cookie_changes[1].cookie.Value()); + EXPECT_EQ("/foo", cookie_changes[1].cookie.Path()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[1].cookie.Domain()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[1].cause)); ASSERT_LE(3u, cookie_changes.size()); - EXPECT_EQ("abc", cookie_changes[2].first.Name()); - EXPECT_EQ("pqr1", cookie_changes[2].first.Value()); - EXPECT_EQ("/", cookie_changes[2].first.Path()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[2].first.Domain()); + EXPECT_EQ("abc", cookie_changes[2].cookie.Name()); + EXPECT_EQ("pqr1", cookie_changes[2].cookie.Value()); + EXPECT_EQ("/", cookie_changes[2].cookie.Path()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[2].cookie.Domain()); EXPECT_TRUE(this->MatchesCause(CookieChangeCause::OVERWRITE, - cookie_changes[2].second)); + cookie_changes[2].cause)); ASSERT_LE(4u, cookie_changes.size()); - EXPECT_EQ("abc", cookie_changes[3].first.Name()); - EXPECT_EQ("pqr2", cookie_changes[3].first.Value()); - EXPECT_EQ("/", cookie_changes[3].first.Path()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[3].first.Domain()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::INSERTED, - cookie_changes[3].second)); + EXPECT_EQ("abc", cookie_changes[3].cookie.Name()); + EXPECT_EQ("pqr2", cookie_changes[3].cookie.Value()); + EXPECT_EQ("/", cookie_changes[3].cookie.Path()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[3].cookie.Domain()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[3].cause)); ASSERT_LE(5u, cookie_changes.size()); - EXPECT_EQ("abc", cookie_changes[4].first.Name()); - EXPECT_EQ("stu1", cookie_changes[4].first.Value()); - EXPECT_EQ("/", cookie_changes[4].first.Path()); - EXPECT_EQ(".foo.com", cookie_changes[4].first.Domain()); + EXPECT_EQ("abc", cookie_changes[4].cookie.Name()); + EXPECT_EQ("stu1", cookie_changes[4].cookie.Value()); + EXPECT_EQ("/", cookie_changes[4].cookie.Path()); + EXPECT_EQ(".foo.com", cookie_changes[4].cookie.Domain()); EXPECT_TRUE(this->MatchesCause(CookieChangeCause::OVERWRITE, - cookie_changes[4].second)); + cookie_changes[4].cause)); ASSERT_LE(6u, cookie_changes.size()); - EXPECT_EQ("abc", cookie_changes[5].first.Name()); - EXPECT_EQ("stu2", cookie_changes[5].first.Value()); - EXPECT_EQ("/", cookie_changes[5].first.Path()); - EXPECT_EQ(".foo.com", cookie_changes[5].first.Domain()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::INSERTED, - cookie_changes[5].second)); + EXPECT_EQ("abc", cookie_changes[5].cookie.Name()); + EXPECT_EQ("stu2", cookie_changes[5].cookie.Value()); + EXPECT_EQ("/", cookie_changes[5].cookie.Path()); + EXPECT_EQ(".foo.com", cookie_changes[5].cookie.Domain()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[5].cause)); EXPECT_EQ(6u, cookie_changes.size()); } @@ -2037,7 +2169,7 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, OverwriteWithHttpOnly) { // Insert a cookie "abc" for path "/foo". CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes; + std::vector cookie_changes; std::unique_ptr subscription = cs->GetChangeDispatcher().AddCallbackForCookie( this->www_foo_foo_.url(), "abc", @@ -2051,12 +2183,13 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, OverwriteWithHttpOnly) { this->SetCookie(cs, this->http_www_foo_.url(), "abc=def; path=/foo")); this->DeliverChangeNotifications(); ASSERT_EQ(1u, cookie_changes.size()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::INSERTED, - cookie_changes[0].second)); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[0].first.Domain()); - EXPECT_EQ("abc", cookie_changes[0].first.Name()); - EXPECT_EQ("def", cookie_changes[0].first.Value()); - EXPECT_FALSE(cookie_changes[0].first.IsHttpOnly()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[0].cause)); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[0].cookie.Domain()); + EXPECT_EQ("abc", cookie_changes[0].cookie.Name()); + EXPECT_EQ("def", cookie_changes[0].cookie.Value()); + EXPECT_FALSE(cookie_changes[0].cookie.IsHttpOnly()); cookie_changes.clear(); // Insert a cookie "a" for path "/foo", that is httponly. This should @@ -2069,20 +2202,22 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, OverwriteWithHttpOnly) { this->DeliverChangeNotifications(); ASSERT_LE(1u, cookie_changes.size()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[0].first.Domain()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[0].cookie.Domain()); EXPECT_TRUE(this->MatchesCause(CookieChangeCause::OVERWRITE, - cookie_changes[0].second)); - EXPECT_EQ("abc", cookie_changes[0].first.Name()); - EXPECT_EQ("def", cookie_changes[0].first.Value()); - EXPECT_FALSE(cookie_changes[0].first.IsHttpOnly()); + cookie_changes[0].cause)); + EXPECT_EQ("abc", cookie_changes[0].cookie.Name()); + EXPECT_EQ("def", cookie_changes[0].cookie.Value()); + EXPECT_FALSE(cookie_changes[0].cookie.IsHttpOnly()); ASSERT_LE(2u, cookie_changes.size()); - EXPECT_EQ(this->http_www_foo_.url().host(), cookie_changes[1].first.Domain()); - EXPECT_TRUE(this->MatchesCause(CookieChangeCause::INSERTED, - cookie_changes[1].second)); - EXPECT_EQ("abc", cookie_changes[1].first.Name()); - EXPECT_EQ("hij", cookie_changes[1].first.Value()); - EXPECT_TRUE(cookie_changes[1].first.IsHttpOnly()); + EXPECT_EQ(this->http_www_foo_.url().host(), + cookie_changes[1].cookie.Domain()); + EXPECT_TRUE( + this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[1].cause)); + EXPECT_EQ("abc", cookie_changes[1].cookie.Name()); + EXPECT_EQ("hij", cookie_changes[1].cookie.Value()); + EXPECT_TRUE(cookie_changes[1].cookie.IsHttpOnly()); EXPECT_EQ(2u, cookie_changes.size()); } @@ -2093,7 +2228,7 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, Deregister) { CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes; + std::vector cookie_changes; std::unique_ptr subscription = cs->GetChangeDispatcher().AddCallbackForCookie( this->www_foo_foo_.url(), "abc", @@ -2108,9 +2243,9 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, Deregister) { this->SetCookie(cs, this->http_www_foo_.url(), "abc=def; path=/foo")); this->DeliverChangeNotifications(); ASSERT_EQ(1u, cookie_changes.size()); - EXPECT_EQ("abc", cookie_changes[0].first.Name()); - EXPECT_EQ("def", cookie_changes[0].first.Value()); - EXPECT_EQ("/foo", cookie_changes[0].first.Path()); + EXPECT_EQ("abc", cookie_changes[0].cookie.Name()); + EXPECT_EQ("def", cookie_changes[0].cookie.Value()); + EXPECT_EQ("/foo", cookie_changes[0].cookie.Path()); cookie_changes.clear(); // De-register the subscription. @@ -2132,7 +2267,7 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, DeregisterMultiple) { CookieStore* cs = this->GetCookieStore(); // Register two subscriptions. - std::vector cookie_changes_1, cookie_changes_2; + std::vector cookie_changes_1, cookie_changes_2; std::unique_ptr subscription1 = cs->GetChangeDispatcher().AddCallbackForCookie( this->www_foo_foo_.url(), "abc", @@ -2154,15 +2289,15 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, DeregisterMultiple) { this->SetCookie(cs, this->http_www_foo_.url(), "abc=def; path=/foo")); this->DeliverChangeNotifications(); ASSERT_EQ(1u, cookie_changes_1.size()); - EXPECT_EQ("abc", cookie_changes_1[0].first.Name()); - EXPECT_EQ("def", cookie_changes_1[0].first.Value()); - EXPECT_EQ("/foo", cookie_changes_1[0].first.Path()); + EXPECT_EQ("abc", cookie_changes_1[0].cookie.Name()); + EXPECT_EQ("def", cookie_changes_1[0].cookie.Value()); + EXPECT_EQ("/foo", cookie_changes_1[0].cookie.Path()); cookie_changes_1.clear(); ASSERT_EQ(1u, cookie_changes_2.size()); - EXPECT_EQ("abc", cookie_changes_2[0].first.Name()); - EXPECT_EQ("def", cookie_changes_2[0].first.Value()); - EXPECT_EQ("/foo", cookie_changes_2[0].first.Path()); + EXPECT_EQ("abc", cookie_changes_2[0].cookie.Name()); + EXPECT_EQ("def", cookie_changes_2[0].cookie.Value()); + EXPECT_EQ("/foo", cookie_changes_2[0].cookie.Path()); cookie_changes_2.clear(); // De-register the second registration. @@ -2174,9 +2309,9 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, DeregisterMultiple) { this->SetCookie(cs, this->http_www_foo_.url(), "abc=hij; path=/")); this->DeliverChangeNotifications(); ASSERT_EQ(1u, cookie_changes_1.size()); - EXPECT_EQ("abc", cookie_changes_1[0].first.Name()); - EXPECT_EQ("hij", cookie_changes_1[0].first.Value()); - EXPECT_EQ("/", cookie_changes_1[0].first.Path()); + EXPECT_EQ("abc", cookie_changes_1[0].cookie.Name()); + EXPECT_EQ("hij", cookie_changes_1[0].cookie.Value()); + EXPECT_EQ("/", cookie_changes_1[0].cookie.Path()); EXPECT_EQ(0u, cookie_changes_2.size()); } @@ -2195,7 +2330,7 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, DispatchRace) { // DeliverChangeNotifications() must NOT be called before the subscription is // established. - std::vector cookie_changes; + std::vector cookie_changes; std::unique_ptr subscription = cs->GetChangeDispatcher().AddCallbackForCookie( this->www_foo_foo_.url(), "abc", @@ -2208,9 +2343,9 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, DispatchRace) { this->DeliverChangeNotifications(); EXPECT_LE(1u, cookie_changes.size()); - EXPECT_EQ("abc", cookie_changes[0].first.Name()); - EXPECT_EQ("hij", cookie_changes[0].first.Value()); - EXPECT_EQ("/", cookie_changes[0].first.Path()); + EXPECT_EQ("abc", cookie_changes[0].cookie.Name()); + EXPECT_EQ("hij", cookie_changes[0].cookie.Value()); + EXPECT_EQ("/", cookie_changes[0].cookie.Path()); ASSERT_EQ(1u, cookie_changes.size()); } @@ -2224,7 +2359,7 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, DeregisterRace) { CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes; + std::vector cookie_changes; std::unique_ptr subscription = cs->GetChangeDispatcher().AddCallbackForCookie( this->www_foo_foo_.url(), "abc", @@ -2239,9 +2374,9 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, DeregisterRace) { this->SetCookie(cs, this->http_www_foo_.url(), "abc=def; path=/foo")); this->DeliverChangeNotifications(); ASSERT_EQ(1u, cookie_changes.size()); - EXPECT_EQ("abc", cookie_changes[0].first.Name()); - EXPECT_EQ("def", cookie_changes[0].first.Value()); - EXPECT_EQ("/foo", cookie_changes[0].first.Path()); + EXPECT_EQ("abc", cookie_changes[0].cookie.Name()); + EXPECT_EQ("def", cookie_changes[0].cookie.Value()); + EXPECT_EQ("/foo", cookie_changes[0].cookie.Path()); cookie_changes.clear(); // Insert a cookie, confirm it is not seen, deregister the subscription, run @@ -2271,7 +2406,7 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, DeregisterRaceMultiple) { CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes_1, cookie_changes_2; + std::vector cookie_changes_1, cookie_changes_2; std::unique_ptr subscription1 = cs->GetChangeDispatcher().AddCallbackForCookie( this->www_foo_foo_.url(), "abc", @@ -2294,15 +2429,15 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, DeregisterRaceMultiple) { this->DeliverChangeNotifications(); ASSERT_EQ(1u, cookie_changes_1.size()); - EXPECT_EQ("abc", cookie_changes_1[0].first.Name()); - EXPECT_EQ("def", cookie_changes_1[0].first.Value()); - EXPECT_EQ("/foo", cookie_changes_1[0].first.Path()); + EXPECT_EQ("abc", cookie_changes_1[0].cookie.Name()); + EXPECT_EQ("def", cookie_changes_1[0].cookie.Value()); + EXPECT_EQ("/foo", cookie_changes_1[0].cookie.Path()); cookie_changes_1.clear(); ASSERT_EQ(1u, cookie_changes_2.size()); - EXPECT_EQ("abc", cookie_changes_2[0].first.Name()); - EXPECT_EQ("def", cookie_changes_2[0].first.Value()); - EXPECT_EQ("/foo", cookie_changes_2[0].first.Path()); + EXPECT_EQ("abc", cookie_changes_2[0].cookie.Name()); + EXPECT_EQ("def", cookie_changes_2[0].cookie.Value()); + EXPECT_EQ("/foo", cookie_changes_2[0].cookie.Path()); cookie_changes_2.clear(); // Insert a cookie, confirm it is not seen, deregister a subscription, run @@ -2323,9 +2458,9 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, DeregisterRaceMultiple) { subscription2.reset(); this->DeliverChangeNotifications(); ASSERT_EQ(1u, cookie_changes_1.size()); - EXPECT_EQ("abc", cookie_changes_1[0].first.Name()); - EXPECT_EQ("hij", cookie_changes_1[0].first.Value()); - EXPECT_EQ("/", cookie_changes_1[0].first.Path()); + EXPECT_EQ("abc", cookie_changes_1[0].cookie.Name()); + EXPECT_EQ("hij", cookie_changes_1[0].cookie.Value()); + EXPECT_EQ("/", cookie_changes_1[0].cookie.Path()); // No late notification was received. ASSERT_EQ(0u, cookie_changes_2.size()); @@ -2337,7 +2472,7 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, DifferentSubscriptionsDisjoint) { CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes_1, cookie_changes_2; + std::vector cookie_changes_1, cookie_changes_2; std::unique_ptr subscription1 = cs->GetChangeDispatcher().AddCallbackForCookie( this->http_www_foo_.url(), "abc", @@ -2363,16 +2498,16 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, DifferentSubscriptionsDisjoint) { this->DeliverChangeNotifications(); ASSERT_EQ(1u, cookie_changes_1.size()); - EXPECT_EQ("abc", cookie_changes_1[0].first.Name()); - EXPECT_EQ("def", cookie_changes_1[0].first.Value()); + EXPECT_EQ("abc", cookie_changes_1[0].cookie.Name()); + EXPECT_EQ("def", cookie_changes_1[0].cookie.Value()); EXPECT_EQ(this->http_www_foo_.url().host(), - cookie_changes_1[0].first.Domain()); + cookie_changes_1[0].cookie.Domain()); ASSERT_EQ(1u, cookie_changes_2.size()); - EXPECT_EQ("ghi", cookie_changes_2[0].first.Name()); - EXPECT_EQ("jkl", cookie_changes_2[0].first.Value()); + EXPECT_EQ("ghi", cookie_changes_2[0].cookie.Name()); + EXPECT_EQ("jkl", cookie_changes_2[0].cookie.Value()); EXPECT_EQ(this->http_bar_com_.url().host(), - cookie_changes_2[0].first.Domain()); + cookie_changes_2[0].cookie.Domain()); } TYPED_TEST_P(CookieStoreChangeNamedTest, DifferentSubscriptionsDomains) { @@ -2381,7 +2516,7 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, DifferentSubscriptionsDomains) { CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes_1, cookie_changes_2; + std::vector cookie_changes_1, cookie_changes_2; std::unique_ptr subscription1 = cs->GetChangeDispatcher().AddCallbackForCookie( this->http_www_foo_.url(), "abc", @@ -2407,16 +2542,16 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, DifferentSubscriptionsDomains) { this->DeliverChangeNotifications(); ASSERT_EQ(1u, cookie_changes_1.size()); - EXPECT_EQ("abc", cookie_changes_1[0].first.Name()); - EXPECT_EQ("def", cookie_changes_1[0].first.Value()); + EXPECT_EQ("abc", cookie_changes_1[0].cookie.Name()); + EXPECT_EQ("def", cookie_changes_1[0].cookie.Value()); EXPECT_EQ(this->http_www_foo_.url().host(), - cookie_changes_1[0].first.Domain()); + cookie_changes_1[0].cookie.Domain()); ASSERT_EQ(1u, cookie_changes_2.size()); - EXPECT_EQ("abc", cookie_changes_2[0].first.Name()); - EXPECT_EQ("ghi", cookie_changes_2[0].first.Value()); + EXPECT_EQ("abc", cookie_changes_2[0].cookie.Name()); + EXPECT_EQ("ghi", cookie_changes_2[0].cookie.Value()); EXPECT_EQ(this->http_bar_com_.url().host(), - cookie_changes_2[0].first.Domain()); + cookie_changes_2[0].cookie.Domain()); } TYPED_TEST_P(CookieStoreChangeNamedTest, DifferentSubscriptionsNames) { @@ -2425,7 +2560,7 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, DifferentSubscriptionsNames) { CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes_1, cookie_changes_2; + std::vector cookie_changes_1, cookie_changes_2; std::unique_ptr subscription1 = cs->GetChangeDispatcher().AddCallbackForCookie( this->http_www_foo_.url(), "abc", @@ -2451,16 +2586,16 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, DifferentSubscriptionsNames) { this->DeliverChangeNotifications(); ASSERT_EQ(1u, cookie_changes_1.size()); - EXPECT_EQ("abc", cookie_changes_1[0].first.Name()); - EXPECT_EQ("def", cookie_changes_1[0].first.Value()); + EXPECT_EQ("abc", cookie_changes_1[0].cookie.Name()); + EXPECT_EQ("def", cookie_changes_1[0].cookie.Value()); EXPECT_EQ(this->http_www_foo_.url().host(), - cookie_changes_1[0].first.Domain()); + cookie_changes_1[0].cookie.Domain()); ASSERT_EQ(1u, cookie_changes_2.size()); - EXPECT_EQ("ghi", cookie_changes_2[0].first.Name()); - EXPECT_EQ("jkl", cookie_changes_2[0].first.Value()); + EXPECT_EQ("ghi", cookie_changes_2[0].cookie.Name()); + EXPECT_EQ("jkl", cookie_changes_2[0].cookie.Value()); EXPECT_EQ(this->http_www_foo_.url().host(), - cookie_changes_2[0].first.Domain()); + cookie_changes_2[0].cookie.Domain()); } TYPED_TEST_P(CookieStoreChangeNamedTest, DifferentSubscriptionsPaths) { @@ -2469,7 +2604,7 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, DifferentSubscriptionsPaths) { CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes_1, cookie_changes_2; + std::vector cookie_changes_1, cookie_changes_2; std::unique_ptr subscription1 = cs->GetChangeDispatcher().AddCallbackForCookie( this->http_www_foo_.url(), "abc", @@ -2496,25 +2631,25 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, DifferentSubscriptionsPaths) { this->DeliverChangeNotifications(); ASSERT_EQ(1u, cookie_changes_1.size()); - EXPECT_EQ("abc", cookie_changes_1[0].first.Name()); - EXPECT_EQ("def", cookie_changes_1[0].first.Value()); - EXPECT_EQ("/", cookie_changes_1[0].first.Path()); + EXPECT_EQ("abc", cookie_changes_1[0].cookie.Name()); + EXPECT_EQ("def", cookie_changes_1[0].cookie.Value()); + EXPECT_EQ("/", cookie_changes_1[0].cookie.Path()); EXPECT_EQ(this->http_www_foo_.url().host(), - cookie_changes_1[0].first.Domain()); + cookie_changes_1[0].cookie.Domain()); ASSERT_LE(1u, cookie_changes_2.size()); - EXPECT_EQ("abc", cookie_changes_2[0].first.Name()); - EXPECT_EQ("def", cookie_changes_2[0].first.Value()); - EXPECT_EQ("/", cookie_changes_2[0].first.Path()); + EXPECT_EQ("abc", cookie_changes_2[0].cookie.Name()); + EXPECT_EQ("def", cookie_changes_2[0].cookie.Value()); + EXPECT_EQ("/", cookie_changes_2[0].cookie.Path()); EXPECT_EQ(this->http_www_foo_.url().host(), - cookie_changes_2[0].first.Domain()); + cookie_changes_2[0].cookie.Domain()); ASSERT_LE(2u, cookie_changes_2.size()); - EXPECT_EQ("abc", cookie_changes_2[1].first.Name()); - EXPECT_EQ("ghi", cookie_changes_2[1].first.Value()); - EXPECT_EQ("/foo", cookie_changes_2[1].first.Path()); + EXPECT_EQ("abc", cookie_changes_2[1].cookie.Name()); + EXPECT_EQ("ghi", cookie_changes_2[1].cookie.Value()); + EXPECT_EQ("/foo", cookie_changes_2[1].cookie.Path()); EXPECT_EQ(this->http_www_foo_.url().host(), - cookie_changes_2[1].first.Domain()); + cookie_changes_2[1].cookie.Domain()); EXPECT_EQ(2u, cookie_changes_2.size()); } @@ -2525,8 +2660,8 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, DifferentSubscriptionsFiltering) { CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes_1, cookie_changes_2; - std::vector cookie_changes_3, cookie_changes_4; + std::vector cookie_changes_1, cookie_changes_2; + std::vector cookie_changes_3, cookie_changes_4; std::unique_ptr subscription1 = cs->GetChangeDispatcher().AddCallbackForCookie( this->http_www_foo_.url(), "abc", @@ -2586,39 +2721,39 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, DifferentSubscriptionsFiltering) { this->DeliverChangeNotifications(); ASSERT_LE(1u, cookie_changes_1.size()); - EXPECT_EQ("abc", cookie_changes_1[0].first.Name()); - EXPECT_EQ("def", cookie_changes_1[0].first.Value()); + EXPECT_EQ("abc", cookie_changes_1[0].cookie.Name()); + EXPECT_EQ("def", cookie_changes_1[0].cookie.Value()); EXPECT_EQ(this->http_www_foo_.url().host(), - cookie_changes_1[0].first.Domain()); + cookie_changes_1[0].cookie.Domain()); EXPECT_EQ(1u, cookie_changes_1.size()); ASSERT_LE(1u, cookie_changes_2.size()); - EXPECT_EQ("hij", cookie_changes_2[0].first.Name()); - EXPECT_EQ("mno", cookie_changes_2[0].first.Value()); + EXPECT_EQ("hij", cookie_changes_2[0].cookie.Name()); + EXPECT_EQ("mno", cookie_changes_2[0].cookie.Value()); EXPECT_EQ(this->http_www_foo_.url().host(), - cookie_changes_2[0].first.Domain()); + cookie_changes_2[0].cookie.Domain()); EXPECT_EQ(1u, cookie_changes_2.size()); ASSERT_LE(1u, cookie_changes_3.size()); - EXPECT_EQ("abc", cookie_changes_3[0].first.Name()); - EXPECT_EQ("stu", cookie_changes_3[0].first.Value()); + EXPECT_EQ("abc", cookie_changes_3[0].cookie.Name()); + EXPECT_EQ("stu", cookie_changes_3[0].cookie.Value()); EXPECT_EQ(this->http_bar_com_.url().host(), - cookie_changes_3[0].first.Domain()); + cookie_changes_3[0].cookie.Domain()); EXPECT_EQ(1u, cookie_changes_3.size()); ASSERT_LE(1u, cookie_changes_4.size()); - EXPECT_EQ("abc", cookie_changes_4[0].first.Name()); - EXPECT_EQ("def", cookie_changes_4[0].first.Value()); - EXPECT_EQ("/", cookie_changes_4[0].first.Path()); + EXPECT_EQ("abc", cookie_changes_4[0].cookie.Name()); + EXPECT_EQ("def", cookie_changes_4[0].cookie.Value()); + EXPECT_EQ("/", cookie_changes_4[0].cookie.Path()); EXPECT_EQ(this->http_www_foo_.url().host(), - cookie_changes_4[0].first.Domain()); + cookie_changes_4[0].cookie.Domain()); ASSERT_LE(2u, cookie_changes_4.size()); - EXPECT_EQ("abc", cookie_changes_4[1].first.Name()); - EXPECT_EQ("vwx", cookie_changes_4[1].first.Value()); - EXPECT_EQ("/foo", cookie_changes_4[1].first.Path()); + EXPECT_EQ("abc", cookie_changes_4[1].cookie.Name()); + EXPECT_EQ("vwx", cookie_changes_4[1].cookie.Value()); + EXPECT_EQ("/foo", cookie_changes_4[1].cookie.Path()); EXPECT_EQ(this->http_www_foo_.url().host(), - cookie_changes_4[1].first.Domain()); + cookie_changes_4[1].cookie.Domain()); EXPECT_EQ(2u, cookie_changes_4.size()); } @@ -2630,7 +2765,7 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, MultipleSubscriptions) { CookieStore* cs = this->GetCookieStore(); - std::vector cookie_changes_1, cookie_changes_2; + std::vector cookie_changes_1, cookie_changes_2; std::unique_ptr subscription1 = cs->GetChangeDispatcher().AddCallbackForCookie( this->http_www_foo_.url(), "abc", @@ -2650,13 +2785,13 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, MultipleSubscriptions) { this->DeliverChangeNotifications(); ASSERT_EQ(1U, cookie_changes_1.size()); - EXPECT_EQ("abc", cookie_changes_1[0].first.Name()); - EXPECT_EQ("def", cookie_changes_1[0].first.Value()); + EXPECT_EQ("abc", cookie_changes_1[0].cookie.Name()); + EXPECT_EQ("def", cookie_changes_1[0].cookie.Value()); cookie_changes_1.clear(); ASSERT_EQ(1U, cookie_changes_2.size()); - EXPECT_EQ("abc", cookie_changes_2[0].first.Name()); - EXPECT_EQ("def", cookie_changes_2[0].first.Value()); + EXPECT_EQ("abc", cookie_changes_2[0].cookie.Name()); + EXPECT_EQ("def", cookie_changes_2[0].cookie.Value()); cookie_changes_2.clear(); } @@ -2664,7 +2799,7 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, SubscriptionOutlivesStore) { if (!TypeParam::supports_named_cookie_tracking) return; - std::vector cookie_changes; + std::vector cookie_changes; std::unique_ptr subscription = this->GetCookieStore()->GetChangeDispatcher().AddCallbackForCookie( this->http_www_foo_.url(), "abc", @@ -2677,6 +2812,37 @@ TYPED_TEST_P(CookieStoreChangeNamedTest, SubscriptionOutlivesStore) { subscription.reset(); } +TYPED_TEST_P(CookieStoreChangeNamedTest, ChangeIncludesCookieAccessSemantics) { + if (!TypeParam::supports_named_cookie_tracking) + return; + + CookieStore* cs = this->GetCookieStore(); + // if !supports_cookie_access_semantics, the delegate will be stored but will + // not be used. + auto access_delegate = std::make_unique(); + access_delegate->SetExpectationForCookieDomain("domain1.test", + CookieAccessSemantics::LEGACY); + cs->SetCookieAccessDelegate(std::move(access_delegate)); + + std::vector cookie_changes; + std::unique_ptr subscription = + cs->GetChangeDispatcher().AddCallbackForCookie( + GURL("http://domain1.test"), "cookie", + base::BindRepeating( + &CookieStoreChangeTestBase::OnCookieChange, + base::Unretained(&cookie_changes))); + + this->CreateAndSetCookie(cs, GURL("http://domain1.test"), "cookie=1", + CookieOptions::MakeAllInclusive()); + this->DeliverChangeNotifications(); + + ASSERT_EQ(1u, cookie_changes.size()); + EXPECT_EQ("domain1.test", cookie_changes[0].cookie.Domain()); + EXPECT_EQ("cookie", cookie_changes[0].cookie.Name()); + EXPECT_TRUE(this->IsExpectedAccessSemantics( + CookieAccessSemantics::LEGACY, cookie_changes[0].access_semantics)); +} + REGISTER_TYPED_TEST_SUITE_P(CookieStoreChangeGlobalTest, NoCookie, InitialCookie, @@ -2691,7 +2857,8 @@ REGISTER_TYPED_TEST_SUITE_P(CookieStoreChangeGlobalTest, DispatchRace, DeregisterRace, DeregisterRaceMultiple, - MultipleSubscriptions); + MultipleSubscriptions, + ChangeIncludesCookieAccessSemantics); REGISTER_TYPED_TEST_SUITE_P(CookieStoreChangeUrlTest, NoCookie, @@ -2714,7 +2881,8 @@ REGISTER_TYPED_TEST_SUITE_P(CookieStoreChangeUrlTest, DifferentSubscriptionsDomains, DifferentSubscriptionsPaths, DifferentSubscriptionsFiltering, - MultipleSubscriptions); + MultipleSubscriptions, + ChangeIncludesCookieAccessSemantics); REGISTER_TYPED_TEST_SUITE_P(CookieStoreChangeNamedTest, NoCookie, @@ -2739,7 +2907,8 @@ REGISTER_TYPED_TEST_SUITE_P(CookieStoreChangeNamedTest, DifferentSubscriptionsPaths, DifferentSubscriptionsFiltering, MultipleSubscriptions, - SubscriptionOutlivesStore); + SubscriptionOutlivesStore, + ChangeIncludesCookieAccessSemantics); } // namespace net diff --git a/net/cookies/cookie_store_unittest.h b/net/cookies/cookie_store_unittest.h index d91026b1ff397..891fa67ceedf8 100644 --- a/net/cookies/cookie_store_unittest.h +++ b/net/cookies/cookie_store_unittest.h @@ -106,6 +106,7 @@ const char kValidCookieLine[] = "A=B; path=/"; // // The cookie store supports setting a CookieAccessDelegate and using it to // // get the access semantics for each cookie via // // CookieStore::GetAllCookiesWithAccessSemanticsAsync(). +// // If this is not supported, all access semantics will show up as UNKNOWN. // static const bool supports_cookie_access_semantics; // }; @@ -612,12 +613,12 @@ TYPED_TEST_P(CookieStoreTest, SetCanonicalCookieTest) { // A HttpOnly cookie can be created, but is rejected // upon setting if the options do not specify include_httponly. - CanonicalCookie::CookieInclusionStatus status; - auto c = CanonicalCookie::Create(this->http_www_foo_.url(), - "bar=1; HttpOnly", base::Time::Now(), - base::nullopt /* server_time */, &status); + CanonicalCookie::CookieInclusionStatus create_status; + auto c = CanonicalCookie::Create( + this->http_www_foo_.url(), "bar=1; HttpOnly", base::Time::Now(), + base::nullopt /* server_time */, &create_status); EXPECT_TRUE(c->IsHttpOnly()); - EXPECT_TRUE(status.IsInclude()); + EXPECT_TRUE(create_status.IsInclude()); EXPECT_TRUE( this->SetCanonicalCookieReturnStatus(cs, std::move(c), "http", false /* can_modify_httponly */) @@ -1671,8 +1672,8 @@ TYPED_TEST_P(CookieStoreTest, GetAllCookiesWithAccessSemanticsAsync) { CookieStore* cs = this->GetCookieStore(); auto access_delegate = std::make_unique(); TestCookieAccessDelegate* test_delegate = access_delegate.get(); - // if !supports_cookie_access_semantics, setting a delegate here will do - // nothing. + // if !supports_cookie_access_semantics, the delegate will be stored but will + // not be used. cs->SetCookieAccessDelegate(std::move(access_delegate)); test_delegate->SetExpectationForCookieDomain("domain1.test", diff --git a/services/network/BUILD.gn b/services/network/BUILD.gn index 7ea25b5e48f2f..e03c70fb231a3 100644 --- a/services/network/BUILD.gn +++ b/services/network/BUILD.gn @@ -18,8 +18,6 @@ jumbo_component("network_service") { "cookie_access_delegate_impl.h", "cookie_manager.cc", "cookie_manager.h", - "cookie_managers_shared.cc", - "cookie_managers_shared.h", "cookie_settings.cc", "cookie_settings.h", "cors/cors_url_loader.cc", diff --git a/services/network/cookie_manager.cc b/services/network/cookie_manager.cc index 5a087228a2f14..79f5342aca1d8 100644 --- a/services/network/cookie_manager.cc +++ b/services/network/cookie_manager.cc @@ -18,7 +18,6 @@ #include "net/cookies/cookie_options.h" #include "net/cookies/cookie_store.h" #include "net/cookies/cookie_util.h" -#include "services/network/cookie_managers_shared.h" #include "services/network/session_cleanup_cookie_store.h" #include "url/gurl.h" @@ -38,9 +37,8 @@ CookieManager::ListenerRegistration::ListenerRegistration() {} CookieManager::ListenerRegistration::~ListenerRegistration() {} void CookieManager::ListenerRegistration::DispatchCookieStoreChange( - const net::CanonicalCookie& cookie, - net::CookieChangeCause cause) { - listener->OnCookieChange(cookie, ToCookieChangeCause(cause)); + const net::CookieChangeInfo& change) { + listener->OnCookieChange(change); } CookieManager::CookieManager( diff --git a/services/network/cookie_manager.h b/services/network/cookie_manager.h index 9a76752907257..c77f7cec11797 100644 --- a/services/network/cookie_manager.h +++ b/services/network/cookie_manager.h @@ -109,8 +109,7 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) CookieManager ~ListenerRegistration(); // Translates a CookieStore change callback to a CookieChangeListener call. - void DispatchCookieStoreChange(const net::CanonicalCookie& cookie, - net::CookieChangeCause cause); + void DispatchCookieStoreChange(const net::CookieChangeInfo& change); // Owns the callback registration in the store. std::unique_ptr subscription; diff --git a/services/network/cookie_manager_unittest.cc b/services/network/cookie_manager_unittest.cc index 39dfb0e78a898..0bbba99286f09 100644 --- a/services/network/cookie_manager_unittest.cc +++ b/services/network/cookie_manager_unittest.cc @@ -1781,15 +1781,6 @@ TEST_F(CookieManagerTest, DeleteByAll) { // Receives and records notifications from the mojom::CookieManager. class CookieChangeListener : public mojom::CookieChangeListener { public: - // Records a cookie change received from CookieManager. - struct Change { - Change(const net::CanonicalCookie& cookie, mojom::CookieChangeCause cause) - : cookie(cookie), cause(cause) {} - - net::CanonicalCookie cookie; - mojom::CookieChangeCause cause; - }; - CookieChangeListener( mojo::PendingReceiver receiver) : run_loop_(nullptr), receiver_(this, std::move(receiver)) {} @@ -1806,20 +1797,19 @@ class CookieChangeListener : public mojom::CookieChangeListener { void ClearObservedChanges() { observed_changes_.clear(); } - const std::vector& observed_changes() const { + const std::vector& observed_changes() const { return observed_changes_; } // mojom::CookieChangeListener - void OnCookieChange(const net::CanonicalCookie& cookie, - mojom::CookieChangeCause cause) override { - observed_changes_.push_back(Change(cookie, cause)); + void OnCookieChange(const net::CookieChangeInfo& change) override { + observed_changes_.push_back(change); if (run_loop_) run_loop_->Quit(); } private: - std::vector observed_changes_; + std::vector observed_changes_; // Loop to signal on receiving a notification if not null. base::RunLoop* run_loop_; @@ -1882,12 +1872,12 @@ TEST_F(CookieManagerTest, AddCookieChangeListener) { // Expect to observe a cookie change. listener.WaitForChange(); - std::vector observed_changes = + std::vector observed_changes = listener.observed_changes(); ASSERT_EQ(1u, observed_changes.size()); EXPECT_EQ(listener_cookie_name, observed_changes[0].cookie.Name()); EXPECT_EQ(listener_url_host, observed_changes[0].cookie.Domain()); - EXPECT_EQ(mojom::CookieChangeCause::INSERTED, observed_changes[0].cause); + EXPECT_EQ(net::CookieChangeCause::INSERTED, observed_changes[0].cause); listener.ClearObservedChanges(); // Delete all cookies matching the domain. This includes one for which @@ -1906,7 +1896,7 @@ TEST_F(CookieManagerTest, AddCookieChangeListener) { ASSERT_EQ(1u, observed_changes.size()); EXPECT_EQ(listener_cookie_name, observed_changes[0].cookie.Name()); EXPECT_EQ(listener_url_host, observed_changes[0].cookie.Domain()); - EXPECT_EQ(mojom::CookieChangeCause::EXPLICIT, observed_changes[0].cause); + EXPECT_EQ(net::CookieChangeCause::EXPLICIT, observed_changes[0].cause); } TEST_F(CookieManagerTest, AddGlobalChangeListener) { @@ -1936,14 +1926,14 @@ TEST_F(CookieManagerTest, AddGlobalChangeListener) { EXPECT_EQ(0u, listener.observed_changes().size()); base::RunLoop().RunUntilIdle(); - std::vector observed_changes = + std::vector observed_changes = listener.observed_changes(); ASSERT_EQ(1u, observed_changes.size()); EXPECT_EQ("Thing1", observed_changes[0].cookie.Name()); EXPECT_EQ("val", observed_changes[0].cookie.Value()); EXPECT_EQ(kExampleHost, observed_changes[0].cookie.Domain()); EXPECT_EQ("/", observed_changes[0].cookie.Path()); - EXPECT_EQ(mojom::CookieChangeCause::INSERTED, observed_changes[0].cause); + EXPECT_EQ(net::CookieChangeCause::INSERTED, observed_changes[0].cause); listener.ClearObservedChanges(); // Set two cookies in a row on different domains and confirm they are both @@ -1967,9 +1957,9 @@ TEST_F(CookieManagerTest, AddGlobalChangeListener) { observed_changes = listener.observed_changes(); ASSERT_EQ(2u, observed_changes.size()); EXPECT_EQ("Thing1", observed_changes[0].cookie.Name()); - EXPECT_EQ(mojom::CookieChangeCause::INSERTED, observed_changes[0].cause); + EXPECT_EQ(net::CookieChangeCause::INSERTED, observed_changes[0].cause); EXPECT_EQ("Thing2", observed_changes[1].cookie.Name()); - EXPECT_EQ(mojom::CookieChangeCause::INSERTED, observed_changes[1].cause); + EXPECT_EQ(net::CookieChangeCause::INSERTED, observed_changes[1].cause); listener.ClearObservedChanges(); // Delete cookies matching one domain; should produce one notification. @@ -1986,7 +1976,7 @@ TEST_F(CookieManagerTest, AddGlobalChangeListener) { ASSERT_EQ(1u, observed_changes.size()); EXPECT_EQ("Thing1", observed_changes[0].cookie.Name()); EXPECT_EQ(kThisHost, observed_changes[0].cookie.Domain()); - EXPECT_EQ(mojom::CookieChangeCause::EXPLICIT, observed_changes[0].cause); + EXPECT_EQ(net::CookieChangeCause::EXPLICIT, observed_changes[0].cause); } // Confirm the service operates properly if a returned notification interface diff --git a/services/network/cookie_managers_shared.cc b/services/network/cookie_managers_shared.cc deleted file mode 100644 index a7651e0ab10fb..0000000000000 --- a/services/network/cookie_managers_shared.cc +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2019 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 "services/network/cookie_managers_shared.h" - -#include - -#include "base/bind.h" -#include "net/cookies/cookie_change_dispatcher.h" - -namespace network { - -mojom::CookieChangeCause ToCookieChangeCause(net::CookieChangeCause net_cause) { - switch (net_cause) { - case net::CookieChangeCause::INSERTED: - return mojom::CookieChangeCause::INSERTED; - case net::CookieChangeCause::EXPLICIT: - return mojom::CookieChangeCause::EXPLICIT; - case net::CookieChangeCause::UNKNOWN_DELETION: - return mojom::CookieChangeCause::UNKNOWN_DELETION; - case net::CookieChangeCause::OVERWRITE: - return mojom::CookieChangeCause::OVERWRITE; - case net::CookieChangeCause::EXPIRED: - return mojom::CookieChangeCause::EXPIRED; - case net::CookieChangeCause::EVICTED: - return mojom::CookieChangeCause::EVICTED; - case net::CookieChangeCause::EXPIRED_OVERWRITE: - return mojom::CookieChangeCause::EXPIRED_OVERWRITE; - } - NOTREACHED(); - return mojom::CookieChangeCause::EXPLICIT; -} - -} // namespace network diff --git a/services/network/cookie_managers_shared.h b/services/network/cookie_managers_shared.h deleted file mode 100644 index d38ae8f32479a..0000000000000 --- a/services/network/cookie_managers_shared.h +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2019 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 SERVICES_NETWORK_COOKIE_MANAGERS_SHARED_H_ -#define SERVICES_NETWORK_COOKIE_MANAGERS_SHARED_H_ - -#include "net/cookies/cookie_store.h" -#include "services/network/public/mojom/cookie_manager.mojom.h" - -namespace net { -enum class CookieChangeCause; -} - -namespace network { - -mojom::CookieChangeCause ToCookieChangeCause(net::CookieChangeCause net_cause); - -} // namespace network - -#endif // SERVICES_NETWORK_COOKIE_MANAGERS_SHARED_H_ diff --git a/services/network/public/cpp/cookie_manager.typemap b/services/network/public/cpp/cookie_manager.typemap index a365737178ce7..0d196187e3a0c 100644 --- a/services/network/public/cpp/cookie_manager.typemap +++ b/services/network/public/cpp/cookie_manager.typemap @@ -3,6 +3,7 @@ public_headers = [ "//ipc/ipc_message_utils.h", "//net/cookies/cookie_options.h", "//net/cookies/canonical_cookie.h", + "//net/cookies/cookie_change_dispatcher.h", "//net/cookies/cookie_constants.h", ] traits_headers = @@ -24,4 +25,6 @@ type_mappings = [ "network.mojom.CookieInclusionStatus=::net::CanonicalCookie::CookieInclusionStatus[move_only]", "network.mojom.CookieWithStatus=::net::CookieWithStatus", "network.mojom.CookieAndLineWithStatus=::net::CookieAndLineWithStatus", + "network.mojom.CookieChangeCause=::net::CookieChangeCause", + "network.mojom.CookieChangeInfo=::net::CookieChangeInfo", ] diff --git a/services/network/public/cpp/cookie_manager_mojom_traits.cc b/services/network/public/cpp/cookie_manager_mojom_traits.cc index 067058d806341..df5f0e95a5d04 100644 --- a/services/network/public/cpp/cookie_manager_mojom_traits.cc +++ b/services/network/public/cpp/cookie_manager_mojom_traits.cc @@ -219,6 +219,62 @@ bool EnumTraits::ToMojom( + net::CookieChangeCause input) { + switch (input) { + case net::CookieChangeCause::INSERTED: + return network::mojom::CookieChangeCause::INSERTED; + case net::CookieChangeCause::EXPLICIT: + return network::mojom::CookieChangeCause::EXPLICIT; + case net::CookieChangeCause::UNKNOWN_DELETION: + return network::mojom::CookieChangeCause::UNKNOWN_DELETION; + case net::CookieChangeCause::OVERWRITE: + return network::mojom::CookieChangeCause::OVERWRITE; + case net::CookieChangeCause::EXPIRED: + return network::mojom::CookieChangeCause::EXPIRED; + case net::CookieChangeCause::EVICTED: + return network::mojom::CookieChangeCause::EVICTED; + case net::CookieChangeCause::EXPIRED_OVERWRITE: + return network::mojom::CookieChangeCause::EXPIRED_OVERWRITE; + default: + break; + } + NOTREACHED(); + return static_cast(input); +} + +bool EnumTraits:: + FromMojom(network::mojom::CookieChangeCause input, + net::CookieChangeCause* output) { + switch (input) { + case network::mojom::CookieChangeCause::INSERTED: + *output = net::CookieChangeCause::INSERTED; + return true; + case network::mojom::CookieChangeCause::EXPLICIT: + *output = net::CookieChangeCause::EXPLICIT; + return true; + case network::mojom::CookieChangeCause::UNKNOWN_DELETION: + *output = net::CookieChangeCause::UNKNOWN_DELETION; + return true; + case network::mojom::CookieChangeCause::OVERWRITE: + *output = net::CookieChangeCause::OVERWRITE; + return true; + case network::mojom::CookieChangeCause::EXPIRED: + *output = net::CookieChangeCause::EXPIRED; + return true; + case network::mojom::CookieChangeCause::EVICTED: + *output = net::CookieChangeCause::EVICTED; + return true; + case network::mojom::CookieChangeCause::EXPIRED_OVERWRITE: + *output = net::CookieChangeCause::EXPIRED_OVERWRITE; + return true; + default: + break; + } + return false; +} + bool StructTraits:: Read(network::mojom::CookieOptionsDataView mojo_options, net::CookieOptions* cookie_options) { @@ -341,4 +397,23 @@ bool StructTraits::Read(network::mojom::CookieChangeInfoDataView info, + net::CookieChangeInfo* out) { + net::CanonicalCookie cookie; + net::CookieAccessSemantics access_semantics = + net::CookieAccessSemantics::UNKNOWN; + net::CookieChangeCause cause = net::CookieChangeCause::EXPLICIT; + if (!info.ReadCookie(&cookie)) + return false; + if (!info.ReadAccessSemantics(&access_semantics)) + return false; + if (!info.ReadCause(&cause)) + return false; + + *out = net::CookieChangeInfo(cookie, access_semantics, cause); + return true; +} + } // namespace mojo diff --git a/services/network/public/cpp/cookie_manager_mojom_traits.h b/services/network/public/cpp/cookie_manager_mojom_traits.h index 8730de54dff08..67b7e2d86add2 100644 --- a/services/network/public/cpp/cookie_manager_mojom_traits.h +++ b/services/network/public/cpp/cookie_manager_mojom_traits.h @@ -8,6 +8,7 @@ #include "ipc/ipc_message_utils.h" #include "mojo/public/cpp/bindings/enum_traits.h" #include "net/cookies/canonical_cookie.h" +#include "net/cookies/cookie_change_dispatcher.h" #include "net/cookies/cookie_constants.h" #include "net/cookies/cookie_options.h" #include "services/network/public/mojom/cookie_manager.mojom.h" @@ -57,6 +58,15 @@ struct EnumTraits +struct EnumTraits { + static network::mojom::CookieChangeCause ToMojom( + net::CookieChangeCause input); + + static bool FromMojom(network::mojom::CookieChangeCause input, + net::CookieChangeCause* output); +}; + template <> struct StructTraits { static bool exclude_httponly(const net::CookieOptions& o) { @@ -162,6 +172,23 @@ struct StructTraits +struct StructTraits { + static const net::CanonicalCookie& cookie(const net::CookieChangeInfo& c) { + return c.cookie; + } + static net::CookieAccessSemantics access_semantics( + const net::CookieChangeInfo& c) { + return c.access_semantics; + } + static net::CookieChangeCause cause(const net::CookieChangeInfo& c) { + return c.cause; + } + static bool Read(network::mojom::CookieChangeInfoDataView info, + net::CookieChangeInfo* out); +}; + } // namespace mojo #endif // SERVICES_NETWORK_PUBLIC_CPP_COOKIE_MANAGER_MOJOM_TRAITS_H_ diff --git a/services/network/public/cpp/cookie_manager_mojom_traits_unittest.cc b/services/network/public/cpp/cookie_manager_mojom_traits_unittest.cc index b87238cd6f101..f52554e310cd2 100644 --- a/services/network/public/cpp/cookie_manager_mojom_traits_unittest.cc +++ b/services/network/public/cpp/cookie_manager_mojom_traits_unittest.cc @@ -89,8 +89,9 @@ TEST(CookieManagerTraitsTest, Roundtrips_CookieInclusionStatus) { TEST(CookieManagerTraitsTest, Roundtrips_CookieWithStatus) { net::CanonicalCookie original_cookie( - "A", "B", "x.y", "/path", base::Time(), base::Time(), base::Time(), false, - false, net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_LOW); + "A", "B", "x.y", "/path", base::Time(), base::Time(), base::Time(), + /* secure = */ true, /* http_only = */ false, + net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_LOW); net::CookieWithStatus original = { original_cookie, net::CanonicalCookie::CookieInclusionStatus()}; @@ -138,6 +139,20 @@ TEST(CookieManagerTraitsTest, Roundtrips_CookieAccessSemantics) { } } +TEST(CookieManagerTraitsTest, Roundtrips_CookieChangeCause) { + for (net::CookieChangeCause change_cause : + {net::CookieChangeCause::INSERTED, net::CookieChangeCause::EXPLICIT, + net::CookieChangeCause::UNKNOWN_DELETION, + net::CookieChangeCause::OVERWRITE, net::CookieChangeCause::EXPIRED, + net::CookieChangeCause::EVICTED, + net::CookieChangeCause::EXPIRED_OVERWRITE}) { + net::CookieChangeCause roundtrip; + ASSERT_TRUE(SerializeAndDeserializeEnum( + change_cause, &roundtrip)); + EXPECT_EQ(change_cause, roundtrip); + } +} + TEST(CookieManagerTraitsTest, Roundtrips_CookieSameSiteContext) { for (net::CookieOptions::SameSiteCookieContext context_state : {net::CookieOptions::SameSiteCookieContext::CROSS_SITE, @@ -196,6 +211,36 @@ TEST(CookieManagerTraitsTest, Roundtrips_CookieOptions) { } } +TEST(CookieManagerTraitsTest, Roundtrips_CookieChangeInfo) { + net::CanonicalCookie original_cookie( + "A", "B", "x.y", "/path", base::Time(), base::Time(), base::Time(), + /* secure = */ false, /* http_only = */ false, + net::CookieSameSite::UNSPECIFIED, net::COOKIE_PRIORITY_LOW); + + net::CookieChangeInfo original(original_cookie, + net::CookieAccessSemantics::LEGACY, + net::CookieChangeCause::EXPLICIT); + + net::CookieChangeInfo copied; + + EXPECT_TRUE(mojo::test::SerializeAndDeserialize( + &original, &copied)); + + EXPECT_EQ(original.cookie.Name(), copied.cookie.Name()); + EXPECT_EQ(original.cookie.Value(), copied.cookie.Value()); + EXPECT_EQ(original.cookie.Domain(), copied.cookie.Domain()); + EXPECT_EQ(original.cookie.Path(), copied.cookie.Path()); + EXPECT_EQ(original.cookie.CreationDate(), copied.cookie.CreationDate()); + EXPECT_EQ(original.cookie.LastAccessDate(), copied.cookie.LastAccessDate()); + EXPECT_EQ(original.cookie.ExpiryDate(), copied.cookie.ExpiryDate()); + EXPECT_EQ(original.cookie.IsSecure(), copied.cookie.IsSecure()); + EXPECT_EQ(original.cookie.IsHttpOnly(), copied.cookie.IsHttpOnly()); + EXPECT_EQ(original.cookie.SameSite(), copied.cookie.SameSite()); + EXPECT_EQ(original.cookie.Priority(), copied.cookie.Priority()); + EXPECT_EQ(original.access_semantics, copied.access_semantics); + EXPECT_EQ(original.cause, copied.cause); +} + // TODO: Add tests for CookiePriority, more extensive CookieOptions ones } // namespace diff --git a/services/network/public/mojom/cookie_manager.mojom b/services/network/public/mojom/cookie_manager.mojom index c69b2085d3700..dbd745d566acc 100644 --- a/services/network/public/mojom/cookie_manager.mojom +++ b/services/network/public/mojom/cookie_manager.mojom @@ -121,8 +121,7 @@ struct CookieAndLineWithStatus { CookieInclusionStatus status; }; -// Keep values here in sync with net::CookieStore::ChangeCause. -// (Not typemapped to avoid forcing clients to know about net::CookieStore.) +// Keep values here in sync with net::CookieChangeCause. enum CookieChangeCause { // The cookie was inserted. INSERTED, @@ -141,6 +140,14 @@ enum CookieChangeCause { EXPIRED_OVERWRITE }; +struct CookieChangeInfo { + // The cookie that changed, in its post-change state. + CanonicalCookie cookie; + // Access semantics of the cookie at the time of the change. + CookieAccessSemantics access_semantics; + CookieChangeCause cause; +}; + // Session cookies are cookies that expire at the end of the browser session. // That is represented in canonical cookies by a null expiry time. enum CookieDeletionSessionControl { @@ -209,7 +216,7 @@ struct CookieDeletionFilter { interface CookieChangeListener { // TODO(rdsmith): Should this be made a batch interface? - OnCookieChange(CanonicalCookie cookie, CookieChangeCause cause); + OnCookieChange(CookieChangeInfo change); }; interface CookieManager { diff --git a/services/network/restricted_cookie_manager.cc b/services/network/restricted_cookie_manager.cc index 4179cc963ff89..50f6170145413 100644 --- a/services/network/restricted_cookie_manager.cc +++ b/services/network/restricted_cookie_manager.cc @@ -24,7 +24,6 @@ #include "net/cookies/cookie_options.h" #include "net/cookies/cookie_store.h" #include "net/cookies/cookie_util.h" -#include "services/network/cookie_managers_shared.h" #include "services/network/cookie_settings.h" #include "services/network/public/mojom/network_context.mojom.h" #include "services/network/public/mojom/network_service.mojom.h" @@ -113,21 +112,24 @@ class RestrictedCookieManager::Listener : public base::LinkNode { private: // net::CookieChangeDispatcher callback. - void OnCookieChange(const net::CanonicalCookie& cookie, - net::CookieChangeCause cause) { + void OnCookieChange(const net::CookieChangeInfo& change) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - if (!cookie.IncludeForRequestURL(url_, options_).IsInclude()) + if (!change.cookie + .IncludeForRequestURL(url_, options_, change.access_semantics) + .IsInclude()) { return; + } // When a user blocks a site's access to cookies, the existing cookies are // not deleted. This check prevents the site from observing their cookies // being deleted at a later time, which can happen due to eviction or due to // the user explicitly deleting all cookies. if (!restricted_cookie_manager_->cookie_settings()->IsCookieAccessAllowed( - url_, site_for_cookies_, top_frame_origin_)) + url_, site_for_cookies_, top_frame_origin_)) { return; + } - mojo_listener_->OnCookieChange(cookie, ToCookieChangeCause(cause)); + mojo_listener_->OnCookieChange(change); } // The CookieChangeDispatcher subscription used by this listener. diff --git a/services/network/restricted_cookie_manager_unittest.cc b/services/network/restricted_cookie_manager_unittest.cc index bc3e63b599523..0a44f8eb78b3b 100644 --- a/services/network/restricted_cookie_manager_unittest.cc +++ b/services/network/restricted_cookie_manager_unittest.cc @@ -22,6 +22,7 @@ #include "net/cookies/cookie_monster.h" #include "net/cookies/cookie_store.h" #include "net/cookies/cookie_store_test_callbacks.h" +#include "net/cookies/test_cookie_access_delegate.h" #include "services/network/cookie_settings.h" #include "services/network/public/mojom/cookie_manager.mojom.h" #include "services/network/test/test_network_context_client.h" @@ -169,9 +170,9 @@ class RestrictedCookieManagerTest GetParam(), &cookie_monster_, &cookie_settings_, - url::Origin::Create(GURL("http://example.com")), - GURL("http://example.com"), - url::Origin::Create(GURL("http://example.com")), + url::Origin::Create(GURL("https://example.com")), + GURL("https://example.com") /* site_for_cookies */, + url::Origin::Create(GURL("https://example.com")), &recording_client_, false /* is_service_worker*/, kProcessId, @@ -194,6 +195,7 @@ class RestrictedCookieManagerTest } // Set a canonical cookie directly into the store. + // Uses a cross-site SameSite cookie context. bool SetCanonicalCookie(const net::CanonicalCookie& cookie, std::string source_scheme, bool can_modify_httponly) { @@ -292,8 +294,8 @@ TEST_P(RestrictedCookieManagerTest, GetAllForUrlBlankFilter) { options->name = ""; options->match_type = mojom::CookieMatchType::STARTS_WITH; std::vector cookies = sync_service_->GetAllForUrl( - GURL("http://example.com/test/"), GURL("http://example.com"), - url::Origin::Create(GURL("http://example.com")), std::move(options)); + GURL("https://example.com/test/"), GURL("https://example.com"), + url::Origin::Create(GURL("https://example.com")), std::move(options)); ASSERT_THAT(cookies, testing::SizeIs(2)); std::sort(cookies.begin(), cookies.end(), &CompareCanonicalCookies); @@ -307,8 +309,8 @@ TEST_P(RestrictedCookieManagerTest, GetAllForUrlBlankFilter) { // Can also use the document.cookie-style API to get the same info. std::string cookies_out; EXPECT_TRUE(backend()->GetCookiesString( - GURL("http://example.com/test/"), GURL("http://example.com"), - url::Origin::Create(GURL("http://example.com")), &cookies_out)); + GURL("https://example.com/test/"), GURL("https://example.com"), + url::Origin::Create(GURL("https://example.com")), &cookies_out)); EXPECT_EQ("cookie-name=cookie-value; cookie-name-2=cookie-value-2", cookies_out); } @@ -320,8 +322,8 @@ TEST_P(RestrictedCookieManagerTest, GetAllForUrlEmptyFilter) { options->name = ""; options->match_type = mojom::CookieMatchType::EQUALS; std::vector cookies = sync_service_->GetAllForUrl( - GURL("http://example.com/test/"), GURL("http://example.com"), - url::Origin::Create(GURL("http://example.com")), std::move(options)); + GURL("https://example.com/test/"), GURL("https://example.com"), + url::Origin::Create(GURL("https://example.com")), std::move(options)); ASSERT_THAT(cookies, testing::SizeIs(0)); } @@ -334,8 +336,8 @@ TEST_P(RestrictedCookieManagerTest, GetAllForUrlEqualsMatch) { options->name = "cookie-name"; options->match_type = mojom::CookieMatchType::EQUALS; std::vector cookies = sync_service_->GetAllForUrl( - GURL("http://example.com/test/"), GURL("http://example.com"), - url::Origin::Create(GURL("http://example.com")), std::move(options)); + GURL("https://example.com/test/"), GURL("https://example.com"), + url::Origin::Create(GURL("https://example.com")), std::move(options)); ASSERT_THAT(cookies, testing::SizeIs(1)); @@ -353,8 +355,8 @@ TEST_P(RestrictedCookieManagerTest, GetAllForUrlStartsWithMatch) { options->name = "cookie-name-2"; options->match_type = mojom::CookieMatchType::STARTS_WITH; std::vector cookies = sync_service_->GetAllForUrl( - GURL("http://example.com/test/"), GURL("http://example.com"), - url::Origin::Create(GURL("http://example.com")), std::move(options)); + GURL("https://example.com/test/"), GURL("https://example.com"), + url::Origin::Create(GURL("https://example.com")), std::move(options)); ASSERT_THAT(cookies, testing::SizeIs(2)); std::sort(cookies.begin(), cookies.end(), &CompareCanonicalCookies); @@ -375,8 +377,8 @@ TEST_P(RestrictedCookieManagerTest, GetAllForUrlHttpOnly) { options->name = "cookie-name"; options->match_type = mojom::CookieMatchType::STARTS_WITH; std::vector cookies = sync_service_->GetAllForUrl( - GURL("http://example.com/test/"), GURL("http://example.com"), - url::Origin::Create(GURL("http://example.com")), std::move(options)); + GURL("https://example.com/test/"), GURL("https://example.com"), + url::Origin::Create(GURL("https://example.com")), std::move(options)); if (GetParam() == mojom::RestrictedCookieManagerRole::SCRIPT) { ASSERT_THAT(cookies, testing::SizeIs(1)); @@ -403,8 +405,8 @@ TEST_P(RestrictedCookieManagerTest, GetAllForUrlFromWrongOrigin) { options->match_type = mojom::CookieMatchType::STARTS_WITH; ExpectBadMessage(); std::vector cookies = sync_service_->GetAllForUrl( - GURL("http://not-example.com/test/"), GURL("http://example.com"), - url::Origin::Create(GURL("http://example.com")), std::move(options)); + GURL("https://not-example.com/test/"), GURL("https://example.com"), + url::Origin::Create(GURL("https://example.com")), std::move(options)); EXPECT_TRUE(received_bad_message()); ASSERT_THAT(cookies, testing::SizeIs(0)); @@ -419,14 +421,14 @@ TEST_P(RestrictedCookieManagerTest, GetCookieStringFromWrongOrigin) { ExpectBadMessage(); std::string cookies_out; EXPECT_TRUE(backend()->GetCookiesString( - GURL("http://notexample.com/test/"), GURL("http://example.com"), - url::Origin::Create(GURL("http://example.com")), &cookies_out)); + GURL("https://notexample.com/test/"), GURL("https://example.com"), + url::Origin::Create(GURL("https://example.com")), &cookies_out)); EXPECT_TRUE(received_bad_message()); EXPECT_TRUE(cookies_out.empty()); } TEST_P(RestrictedCookieManagerTest, GetAllForUrlPolicy) { - service_->OverrideSiteForCookiesForTesting(GURL("http://notexample.com")); + service_->OverrideSiteForCookiesForTesting(GURL("https://notexample.com")); SetSessionCookie("cookie-name", "cookie-value", "example.com", "/"); // With default policy, should be able to get all cookies, even third-party. @@ -436,8 +438,8 @@ TEST_P(RestrictedCookieManagerTest, GetAllForUrlPolicy) { options->match_type = mojom::CookieMatchType::STARTS_WITH; std::vector cookies = sync_service_->GetAllForUrl( - GURL("http://example.com/test/"), GURL("http://notexample.com"), - url::Origin::Create(GURL("http://example.com")), std::move(options)); + GURL("https://example.com/test/"), GURL("https://notexample.com"), + url::Origin::Create(GURL("https://example.com")), std::move(options)); ASSERT_THAT(cookies, testing::SizeIs(1)); EXPECT_EQ("cookie-name", cookies[0].Name()); EXPECT_EQ("cookie-value", cookies[0].Value()); @@ -445,8 +447,8 @@ TEST_P(RestrictedCookieManagerTest, GetAllForUrlPolicy) { ASSERT_EQ(1u, recorded_activity().size()); EXPECT_EQ(recorded_activity()[0].get, true); - EXPECT_EQ(recorded_activity()[0].url, "http://example.com/test/"); - EXPECT_EQ(recorded_activity()[0].site_for_cookies, "http://notexample.com/"); + EXPECT_EQ(recorded_activity()[0].url, "https://example.com/test/"); + EXPECT_EQ(recorded_activity()[0].site_for_cookies, "https://notexample.com/"); EXPECT_THAT(recorded_activity()[0].cookie, net::MatchesCookieLine("cookie-name=cookie-value")); EXPECT_TRUE(recorded_activity()[0].status.IsInclude()); @@ -462,15 +464,15 @@ TEST_P(RestrictedCookieManagerTest, GetAllForUrlPolicy) { options->match_type = mojom::CookieMatchType::STARTS_WITH; std::vector cookies = sync_service_->GetAllForUrl( - GURL("http://example.com/test/"), GURL("http://notexample.com"), - url::Origin::Create(GURL("http://example.com")), std::move(options)); + GURL("https://example.com/test/"), GURL("https://notexample.com"), + url::Origin::Create(GURL("https://example.com")), std::move(options)); ASSERT_THAT(cookies, testing::SizeIs(0)); } ASSERT_EQ(2u, recorded_activity().size()); EXPECT_EQ(recorded_activity()[1].get, true); - EXPECT_EQ(recorded_activity()[1].url, "http://example.com/test/"); - EXPECT_EQ(recorded_activity()[1].site_for_cookies, "http://notexample.com/"); + EXPECT_EQ(recorded_activity()[1].url, "https://example.com/test/"); + EXPECT_EQ(recorded_activity()[1].site_for_cookies, "https://notexample.com/"); EXPECT_THAT(recorded_activity()[1].cookie, net::MatchesCookieLine("cookie-name=cookie-value")); EXPECT_TRUE( @@ -480,7 +482,7 @@ TEST_P(RestrictedCookieManagerTest, GetAllForUrlPolicy) { } TEST_P(RestrictedCookieManagerTest, GetAllForUrlPolicyWarnActual) { - service_->OverrideSiteForCookiesForTesting(GURL("http://notexample.com")); + service_->OverrideSiteForCookiesForTesting(GURL("https://notexample.com")); SetSessionCookie("cookie-name", "cookie-value", "example.com", "/"); base::test::ScopedFeatureList feature_list; feature_list.InitWithFeatures( @@ -495,16 +497,16 @@ TEST_P(RestrictedCookieManagerTest, GetAllForUrlPolicyWarnActual) { options->match_type = mojom::CookieMatchType::STARTS_WITH; std::vector cookies = sync_service_->GetAllForUrl( - GURL("http://example.com/test/"), GURL("http://notexample.com"), - url::Origin::Create(GURL("http://example.com")), std::move(options)); + GURL("https://example.com/test/"), GURL("https://notexample.com"), + url::Origin::Create(GURL("https://example.com")), std::move(options)); EXPECT_TRUE(cookies.empty()); } ASSERT_EQ(1u, recorded_activity().size()); EXPECT_EQ(recorded_activity()[0].get, true); - EXPECT_EQ(recorded_activity()[0].url, "http://example.com/test/"); - EXPECT_EQ(recorded_activity()[0].site_for_cookies, "http://notexample.com/"); + EXPECT_EQ(recorded_activity()[0].url, "https://example.com/test/"); + EXPECT_EQ(recorded_activity()[0].site_for_cookies, "https://notexample.com/"); EXPECT_THAT(recorded_activity()[0].cookie, net::MatchesCookieLine("cookie-name=cookie-value")); EXPECT_TRUE( @@ -520,15 +522,15 @@ TEST_P(RestrictedCookieManagerTest, SetCanonicalCookie) { base::Time(), base::Time(), /* secure = */ false, /* httponly = */ false, net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_DEFAULT), - GURL("http://example.com/test/"), GURL("http://example.com"), - url::Origin::Create(GURL("http://example.com")))); + GURL("https://example.com/test/"), GURL("https://example.com"), + url::Origin::Create(GURL("https://example.com")))); auto options = mojom::CookieManagerGetOptions::New(); options->name = "new-name"; options->match_type = mojom::CookieMatchType::EQUALS; std::vector cookies = sync_service_->GetAllForUrl( - GURL("http://example.com/test/"), GURL("http://example.com"), - url::Origin::Create(GURL("http://example.com")), std::move(options)); + GURL("https://example.com/test/"), GURL("https://example.com"), + url::Origin::Create(GURL("https://example.com")), std::move(options)); ASSERT_THAT(cookies, testing::SizeIs(1)); @@ -544,15 +546,15 @@ TEST_P(RestrictedCookieManagerTest, SetCanonicalCookieHttpOnly) { base::Time(), base::Time(), /* secure = */ false, /* httponly = */ true, net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_DEFAULT), - GURL("http://example.com/test/"), GURL("http://example.com"), - url::Origin::Create(GURL("http://example.com")))); + GURL("https://example.com/test/"), GURL("https://example.com"), + url::Origin::Create(GURL("https://example.com")))); auto options = mojom::CookieManagerGetOptions::New(); options->name = "new-name"; options->match_type = mojom::CookieMatchType::EQUALS; std::vector cookies = sync_service_->GetAllForUrl( - GURL("http://example.com/test/"), GURL("http://example.com"), - url::Origin::Create(GURL("http://example.com")), std::move(options)); + GURL("https://example.com/test/"), GURL("https://example.com"), + url::Origin::Create(GURL("https://example.com")), std::move(options)); if (GetParam() == mojom::RestrictedCookieManagerRole::SCRIPT) { ASSERT_THAT(cookies, testing::SizeIs(0)); @@ -571,8 +573,8 @@ TEST_P(RestrictedCookieManagerTest, SetCanonicalCookieValidateDomain) { base::nullopt); ASSERT_EQ(".not-example.com", cookie->Domain()); EXPECT_FALSE(sync_service_->SetCanonicalCookie( - *cookie, GURL("http://example.com/test"), GURL("http://example.com"), - url::Origin::Create(GURL("http://example.com")))); + *cookie, GURL("https://example.com/test"), GURL("https://example.com"), + url::Origin::Create(GURL("https://example.com")))); ASSERT_EQ(1u, recorded_activity().size()); EXPECT_TRUE(recorded_activity()[0].status.HasExclusionReason( net::CanonicalCookie::CookieInclusionStatus::EXCLUDE_DOMAIN_MISMATCH)); @@ -581,22 +583,22 @@ TEST_P(RestrictedCookieManagerTest, SetCanonicalCookieValidateDomain) { options->name = "cookie"; options->match_type = mojom::CookieMatchType::EQUALS; std::vector cookies = sync_service_->GetAllForUrl( - GURL("http://example.com/test/"), GURL("http://example.com"), - url::Origin::Create(GURL("http://example.com")), std::move(options)); + GURL("https://example.com/test/"), GURL("https://example.com"), + url::Origin::Create(GURL("https://example.com")), std::move(options)); EXPECT_THAT(cookies, testing::SizeIs(0)); } TEST_P(RestrictedCookieManagerTest, SetCookieFromString) { EXPECT_TRUE(backend()->SetCookieFromString( - GURL("http://example.com/test/"), GURL("http://example.com"), - url::Origin::Create(GURL("http://example.com")), + GURL("https://example.com/test/"), GURL("https://example.com"), + url::Origin::Create(GURL("https://example.com")), "new-name=new-value;path=/")); auto options = mojom::CookieManagerGetOptions::New(); options->name = "new-name"; options->match_type = mojom::CookieMatchType::EQUALS; std::vector cookies = sync_service_->GetAllForUrl( - GURL("http://example.com/test/"), GURL("http://example.com"), - url::Origin::Create(GURL("http://example.com")), std::move(options)); + GURL("https://example.com/test/"), GURL("https://example.com"), + url::Origin::Create(GURL("https://example.com")), std::move(options)); ASSERT_THAT(cookies, testing::SizeIs(1)); @@ -612,59 +614,59 @@ TEST_P(RestrictedCookieManagerTest, SetCanonicalCookieFromWrongOrigin) { base::Time(), base::Time(), /* secure = */ false, /* httponly = */ false, net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_DEFAULT), - GURL("http://not-example.com/test/"), GURL("http://example.com"), - url::Origin::Create(GURL("http://example.com")))); + GURL("https://not-example.com/test/"), GURL("https://example.com"), + url::Origin::Create(GURL("https://example.com")))); ASSERT_TRUE(received_bad_message()); } TEST_P(RestrictedCookieManagerTest, SetCookieFromStringWrongOrigin) { ExpectBadMessage(); EXPECT_TRUE(backend()->SetCookieFromString( - GURL("http://notexample.com/test/"), GURL("http://example.com"), - url::Origin::Create(GURL("http://example.com")), + GURL("https://notexample.com/test/"), GURL("https://example.com"), + url::Origin::Create(GURL("https://example.com")), "new-name=new-value;path=/")); ASSERT_TRUE(received_bad_message()); } TEST_P(RestrictedCookieManagerTest, SetCanonicalCookiePolicy) { - service_->OverrideSiteForCookiesForTesting(GURL("http://notexample.com")); + service_->OverrideSiteForCookiesForTesting(GURL("https://notexample.com")); { // With default settings object, setting a third-party cookie is OK. - auto cookie = net::CanonicalCookie::Create(GURL("http://example.com"), + auto cookie = net::CanonicalCookie::Create(GURL("https://example.com"), "A=B", base::Time::Now(), base::nullopt /* server_time */); EXPECT_TRUE(sync_service_->SetCanonicalCookie( - *cookie, GURL("http://example.com"), GURL("http://notexample.com"), - url::Origin::Create(GURL("http://example.com")))); + *cookie, GURL("https://example.com"), GURL("https://notexample.com"), + url::Origin::Create(GURL("https://example.com")))); } ASSERT_EQ(1u, recorded_activity().size()); EXPECT_EQ(recorded_activity()[0].get, false); - EXPECT_EQ(recorded_activity()[0].url, "http://example.com/"); - EXPECT_EQ(recorded_activity()[0].site_for_cookies, "http://notexample.com/"); + EXPECT_EQ(recorded_activity()[0].url, "https://example.com/"); + EXPECT_EQ(recorded_activity()[0].site_for_cookies, "https://notexample.com/"); EXPECT_THAT(recorded_activity()[0].cookie, net::MatchesCookieLine("A=B")); EXPECT_TRUE(recorded_activity()[0].status.IsInclude()); EXPECT_EQ(net::CanonicalCookie::CookieInclusionStatus::WarningReason:: WARN_SAMESITE_UNSPECIFIED_CROSS_SITE_CONTEXT, recorded_activity()[0].status.warning()); - service_->OverrideSiteForCookiesForTesting(GURL("http://otherexample.com")); + service_->OverrideSiteForCookiesForTesting(GURL("https://otherexample.com")); { // Not if third-party cookies are disabled, though. cookie_settings_.set_block_third_party_cookies(true); - auto cookie = net::CanonicalCookie::Create(GURL("http://example.com"), + auto cookie = net::CanonicalCookie::Create(GURL("https://example.com"), "A2=B2", base::Time::Now(), base::nullopt /* server_time */); EXPECT_FALSE(sync_service_->SetCanonicalCookie( - *cookie, GURL("http://example.com"), GURL("http://otherexample.com"), - url::Origin::Create(GURL("http://example.com")))); + *cookie, GURL("https://example.com"), GURL("https://otherexample.com"), + url::Origin::Create(GURL("https://example.com")))); } ASSERT_EQ(2u, recorded_activity().size()); EXPECT_EQ(recorded_activity()[1].get, false); - EXPECT_EQ(recorded_activity()[1].url, "http://example.com/"); + EXPECT_EQ(recorded_activity()[1].url, "https://example.com/"); EXPECT_EQ(recorded_activity()[1].site_for_cookies, - "http://otherexample.com/"); + "https://otherexample.com/"); EXPECT_THAT(recorded_activity()[1].cookie, net::MatchesCookieLine("A2=B2")); EXPECT_TRUE( recorded_activity()[1].status.HasExactlyExclusionReasonsForTesting( @@ -676,40 +678,40 @@ TEST_P(RestrictedCookieManagerTest, SetCanonicalCookiePolicy) { options->name = "A"; options->match_type = mojom::CookieMatchType::STARTS_WITH; - service_->OverrideSiteForCookiesForTesting(GURL("http://example.com")); + service_->OverrideSiteForCookiesForTesting(GURL("https://example.com")); std::vector cookies = sync_service_->GetAllForUrl( - GURL("http://example.com/test/"), GURL("http://example.com/"), - url::Origin::Create(GURL("http://example.com")), std::move(options)); + GURL("https://example.com/test/"), GURL("https://example.com/"), + url::Origin::Create(GURL("https://example.com")), std::move(options)); ASSERT_THAT(cookies, testing::SizeIs(1)); EXPECT_EQ("A", cookies[0].Name()); EXPECT_EQ("B", cookies[0].Value()); ASSERT_EQ(3u, recorded_activity().size()); EXPECT_EQ(recorded_activity()[2].get, true); - EXPECT_EQ(recorded_activity()[2].url, "http://example.com/test/"); - EXPECT_EQ(recorded_activity()[2].site_for_cookies, "http://example.com/"); + EXPECT_EQ(recorded_activity()[2].url, "https://example.com/test/"); + EXPECT_EQ(recorded_activity()[2].site_for_cookies, "https://example.com/"); EXPECT_THAT(recorded_activity()[2].cookie, net::MatchesCookieLine("A=B")); EXPECT_TRUE(recorded_activity()[2].status.IsInclude()); } TEST_P(RestrictedCookieManagerTest, SetCanonicalCookiePolicyWarnActual) { - service_->OverrideSiteForCookiesForTesting(GURL("http://notexample.com")); + service_->OverrideSiteForCookiesForTesting(GURL("https://notexample.com")); // Make sure the deprecation warnings are also produced when the feature // to enable the new behavior is on. base::test::ScopedFeatureList feature_list; feature_list.InitAndEnableFeature(net::features::kSameSiteByDefaultCookies); - auto cookie = net::CanonicalCookie::Create(GURL("http://example.com"), "A=B", + auto cookie = net::CanonicalCookie::Create(GURL("https://example.com"), "A=B", base::Time::Now(), base::nullopt /* server_time */); EXPECT_FALSE(sync_service_->SetCanonicalCookie( - *cookie, GURL("http://example.com"), GURL("http://notexample.com"), - url::Origin::Create(GURL("http://example.com")))); + *cookie, GURL("https://example.com"), GURL("https://notexample.com"), + url::Origin::Create(GURL("https://example.com")))); ASSERT_EQ(1u, recorded_activity().size()); EXPECT_EQ(recorded_activity()[0].get, false); - EXPECT_EQ(recorded_activity()[0].url, "http://example.com/"); - EXPECT_EQ(recorded_activity()[0].site_for_cookies, "http://notexample.com/"); + EXPECT_EQ(recorded_activity()[0].url, "https://example.com/"); + EXPECT_EQ(recorded_activity()[0].site_for_cookies, "https://notexample.com/"); EXPECT_THAT(recorded_activity()[0].cookie, net::MatchesCookieLine("A=B")); EXPECT_TRUE( recorded_activity()[0].status.HasExactlyExclusionReasonsForTesting( @@ -718,26 +720,26 @@ TEST_P(RestrictedCookieManagerTest, SetCanonicalCookiePolicyWarnActual) { } TEST_P(RestrictedCookieManagerTest, CookiesEnabledFor) { - service_->OverrideSiteForCookiesForTesting(GURL("http://notexample.com")); + service_->OverrideSiteForCookiesForTesting(GURL("https://notexample.com")); // Default, third-party access is OK. bool result = false; EXPECT_TRUE(backend()->CookiesEnabledFor( - GURL("http://example.com"), GURL("http://notexample.com"), - url::Origin::Create(GURL("http://example.com")), &result)); + GURL("https://example.com"), GURL("https://notexample.com"), + url::Origin::Create(GURL("https://example.com")), &result)); EXPECT_TRUE(result); // Third-part cookies disabled. cookie_settings_.set_block_third_party_cookies(true); EXPECT_TRUE(backend()->CookiesEnabledFor( - GURL("http://example.com"), GURL("http://notexample.com"), - url::Origin::Create(GURL("http://example.com")), &result)); + GURL("https://example.com"), GURL("https://notexample.com"), + url::Origin::Create(GURL("https://example.com")), &result)); EXPECT_FALSE(result); // First-party ones still OK. - service_->OverrideSiteForCookiesForTesting(GURL("http://example.com")); + service_->OverrideSiteForCookiesForTesting(GURL("https://example.com")); EXPECT_TRUE(backend()->CookiesEnabledFor( - GURL("http://example.com"), GURL("http://example.com"), - url::Origin::Create(GURL("http://example.com")), &result)); + GURL("https://example.com"), GURL("https://example.com"), + url::Origin::Create(GURL("https://example.com")), &result)); EXPECT_TRUE(result); } @@ -746,16 +748,6 @@ namespace { // Stashes the cookie changes it receives, for testing. class TestCookieChangeListener : public network::mojom::CookieChangeListener { public: - // Records a cookie change received from RestrictedCookieManager. - struct Change { - Change(const net::CanonicalCookie& cookie, - network::mojom::CookieChangeCause change_cause) - : cookie(cookie), change_cause(change_cause) {} - - net::CanonicalCookie cookie; - network::mojom::CookieChangeCause change_cause; - }; - TestCookieChangeListener( mojo::PendingReceiver receiver) : receiver_(this, std::move(receiver)) {} @@ -770,21 +762,20 @@ class TestCookieChangeListener : public network::mojom::CookieChangeListener { } // Changes received by this listener. - const std::vector& observed_changes() const { + const std::vector& observed_changes() const { return observed_changes_; } // network::mojom::CookieChangeListener - void OnCookieChange(const net::CanonicalCookie& cookie, - network::mojom::CookieChangeCause change_cause) override { - observed_changes_.emplace_back(cookie, change_cause); + void OnCookieChange(const net::CookieChangeInfo& change) override { + observed_changes_.emplace_back(change); if (run_loop_) // Set in WaitForChange(). run_loop_->Quit(); } private: - std::vector observed_changes_; + std::vector observed_changes_; mojo::Receiver receiver_; // If not null, will be stopped when a cookie change notification is received. @@ -798,8 +789,8 @@ TEST_P(RestrictedCookieManagerTest, ChangeDispatch) { mojo::PendingReceiver receiver = listener_remote.InitWithNewPipeAndPassReceiver(); sync_service_->AddChangeListener( - GURL("http://example.com/test/"), GURL("http://example.com"), - url::Origin::Create(GURL("http://example.com")), + GURL("https://example.com/test/"), GURL("https://example.com"), + url::Origin::Create(GURL("https://example.com")), std::move(listener_remote)); TestCookieChangeListener listener(std::move(receiver)); @@ -809,20 +800,20 @@ TEST_P(RestrictedCookieManagerTest, ChangeDispatch) { listener.WaitForChange(); ASSERT_THAT(listener.observed_changes(), testing::SizeIs(1)); - EXPECT_EQ(network::mojom::CookieChangeCause::INSERTED, - listener.observed_changes()[0].change_cause); + EXPECT_EQ(net::CookieChangeCause::INSERTED, + listener.observed_changes()[0].cause); EXPECT_EQ("cookie-name", listener.observed_changes()[0].cookie.Name()); EXPECT_EQ("cookie-value", listener.observed_changes()[0].cookie.Value()); } TEST_P(RestrictedCookieManagerTest, ChangeSettings) { - service_->OverrideSiteForCookiesForTesting(GURL("http://notexample.com/")); + service_->OverrideSiteForCookiesForTesting(GURL("https://notexample.com/")); mojo::PendingRemote listener_remote; mojo::PendingReceiver receiver = listener_remote.InitWithNewPipeAndPassReceiver(); sync_service_->AddChangeListener( - GURL("http://example.com/test/"), GURL("http://notexample.com"), - url::Origin::Create(GURL("http://example.com")), + GURL("https://example.com/test/"), GURL("https://notexample.com"), + url::Origin::Create(GURL("https://example.com")), std::move(listener_remote)); TestCookieChangeListener listener(std::move(receiver)); @@ -840,8 +831,8 @@ TEST_P(RestrictedCookieManagerTest, AddChangeListenerFromWrongOrigin) { bad_listener_remote.InitWithNewPipeAndPassReceiver(); ExpectBadMessage(); sync_service_->AddChangeListener( - GURL("http://not-example.com/test/"), GURL("http://example.com"), - url::Origin::Create(GURL("http://example.com")), + GURL("https://not-example.com/test/"), GURL("https://example.com"), + url::Origin::Create(GURL("https://example.com")), std::move(bad_listener_remote)); EXPECT_TRUE(received_bad_message()); TestCookieChangeListener bad_listener(std::move(bad_receiver)); @@ -851,8 +842,8 @@ TEST_P(RestrictedCookieManagerTest, AddChangeListenerFromWrongOrigin) { mojo::PendingReceiver good_receiver = good_listener_remote.InitWithNewPipeAndPassReceiver(); sync_service_->AddChangeListener( - GURL("http://example.com/test/"), GURL("http://example.com"), - url::Origin::Create(GURL("http://example.com")), + GURL("https://example.com/test/"), GURL("https://example.com"), + url::Origin::Create(GURL("https://example.com")), std::move(good_listener_remote)); TestCookieChangeListener good_listener(std::move(good_receiver)); @@ -867,12 +858,136 @@ TEST_P(RestrictedCookieManagerTest, AddChangeListenerFromWrongOrigin) { EXPECT_THAT(bad_listener.observed_changes(), testing::SizeIs(0)); ASSERT_THAT(good_listener.observed_changes(), testing::SizeIs(1)); - EXPECT_EQ(network::mojom::CookieChangeCause::INSERTED, - good_listener.observed_changes()[0].change_cause); + EXPECT_EQ(net::CookieChangeCause::INSERTED, + good_listener.observed_changes()[0].cause); EXPECT_EQ("cookie-name", good_listener.observed_changes()[0].cookie.Name()); EXPECT_EQ("cookie-value", good_listener.observed_changes()[0].cookie.Value()); } +// Test that the Change listener receives the access semantics, and that they +// are taken into account when deciding when to dispatch the change. +TEST_P(RestrictedCookieManagerTest, ChangeNotificationIncludesAccessSemantics) { + // Turn on SameSiteByDefaultCookies. + base::test::ScopedFeatureList feature_list; + feature_list.InitAndEnableFeature(net::features::kSameSiteByDefaultCookies); + + auto cookie_access_delegate = + std::make_unique(); + cookie_access_delegate->SetExpectationForCookieDomain( + "example.com", net::CookieAccessSemantics::LEGACY); + cookie_monster_.SetCookieAccessDelegate(std::move(cookie_access_delegate)); + + mojo::PendingRemote listener_remote; + mojo::PendingReceiver receiver = + listener_remote.InitWithNewPipeAndPassReceiver(); + + // Use a cross-site site_for_cookies. + service_->OverrideSiteForCookiesForTesting(GURL("https://not-example.com")); + sync_service_->AddChangeListener( + GURL("https://example.com/test/"), + GURL("https://not-example.com") /* site_for_cookies */, + url::Origin::Create(GURL("https://example.com")), + std::move(listener_remote)); + TestCookieChangeListener listener(std::move(receiver)); + + ASSERT_THAT(listener.observed_changes(), testing::SizeIs(0)); + + auto cookie = net::CanonicalCookie::Create( + GURL("https://example.com"), "cookie_with_no_samesite=unspecified", + base::Time::Now(), base::nullopt); + + // Set cookie directly into the CookieMonster, using all-inclusive options. + net::ResultSavingCookieCallback + callback; + cookie_monster_.SetCanonicalCookieAsync( + std::move(cookie), "https", net::CookieOptions::MakeAllInclusive(), + base::BindOnce(&net::ResultSavingCookieCallback< + net::CanonicalCookie::CookieInclusionStatus>::Run, + base::Unretained(&callback))); + callback.WaitUntilDone(); + ASSERT_TRUE(callback.result().IsInclude()); + + // The listener only receives the change because the cookie is legacy. + listener.WaitForChange(); + + ASSERT_THAT(listener.observed_changes(), testing::SizeIs(1)); + EXPECT_EQ(net::CookieAccessSemantics::LEGACY, + listener.observed_changes()[0].access_semantics); +} + +TEST_P(RestrictedCookieManagerTest, NoChangeNotificationForNonlegacyCookie) { + // Turn on SameSiteByDefaultCookies. + base::test::ScopedFeatureList feature_list; + feature_list.InitAndEnableFeature(net::features::kSameSiteByDefaultCookies); + + auto cookie_access_delegate = + std::make_unique(); + cookie_access_delegate->SetExpectationForCookieDomain( + "example.com", net::CookieAccessSemantics::NONLEGACY); + cookie_monster_.SetCookieAccessDelegate(std::move(cookie_access_delegate)); + + mojo::PendingRemote listener_remote; + mojo::PendingReceiver receiver = + listener_remote.InitWithNewPipeAndPassReceiver(); + + // Use a cross-site site_for_cookies. + service_->OverrideSiteForCookiesForTesting(GURL("https://not-example.com")); + sync_service_->AddChangeListener( + GURL("https://example.com/test/"), + GURL("https://not-example.com") /* site_for_cookies */, + url::Origin::Create(GURL("https://example.com")), + std::move(listener_remote)); + TestCookieChangeListener listener(std::move(receiver)); + + ASSERT_THAT(listener.observed_changes(), testing::SizeIs(0)); + + auto unspecified_cookie = net::CanonicalCookie::Create( + GURL("https://example.com"), "cookie_with_no_samesite=unspecified", + base::Time::Now(), base::nullopt); + + auto samesite_none_cookie = net::CanonicalCookie::Create( + GURL("https://example.com"), + "samesite_none_cookie=none; SameSite=None; Secure", base::Time::Now(), + base::nullopt); + + // Set cookies directly into the CookieMonster, using all-inclusive options. + net::ResultSavingCookieCallback + callback1; + cookie_monster_.SetCanonicalCookieAsync( + std::move(unspecified_cookie), "https", + net::CookieOptions::MakeAllInclusive(), + base::BindOnce(&net::ResultSavingCookieCallback< + net::CanonicalCookie::CookieInclusionStatus>::Run, + base::Unretained(&callback1))); + callback1.WaitUntilDone(); + ASSERT_TRUE(callback1.result().IsInclude()); + + // Listener doesn't receive notification because cookie is not included for + // request URL for being unspecified and treated as lax. + base::RunLoop().RunUntilIdle(); + ASSERT_THAT(listener.observed_changes(), testing::SizeIs(0)); + + net::ResultSavingCookieCallback + callback2; + cookie_monster_.SetCanonicalCookieAsync( + std::move(samesite_none_cookie), "https", + net::CookieOptions::MakeAllInclusive(), + base::BindOnce(&net::ResultSavingCookieCallback< + net::CanonicalCookie::CookieInclusionStatus>::Run, + base::Unretained(&callback2))); + callback2.WaitUntilDone(); + ASSERT_TRUE(callback2.result().IsInclude()); + + // Listener only receives notification about the SameSite=None cookie. + listener.WaitForChange(); + ASSERT_THAT(listener.observed_changes(), testing::SizeIs(1)); + + EXPECT_EQ("samesite_none_cookie", + listener.observed_changes()[0].cookie.Name()); + EXPECT_EQ(net::CookieAccessSemantics::NONLEGACY, + listener.observed_changes()[0].access_semantics); +} + INSTANTIATE_TEST_SUITE_P( , RestrictedCookieManagerTest, diff --git a/services/network/test/test_cookie_manager.cc b/services/network/test/test_cookie_manager.cc index 2de701e6f154a..de8f59b2ed964 100644 --- a/services/network/test/test_cookie_manager.cc +++ b/services/network/test/test_cookie_manager.cc @@ -36,10 +36,9 @@ void TestCookieManager::AddCookieChangeListener( } void TestCookieManager::DispatchCookieChange( - const net::CanonicalCookie& cookie, - network::mojom::CookieChangeCause cause) { + const net::CookieChangeInfo& change) { for (auto& cookie_change_listener_ : cookie_change_listeners_) { - cookie_change_listener_->OnCookieChange(cookie, cause); + cookie_change_listener_->OnCookieChange(change); } } diff --git a/services/network/test/test_cookie_manager.h b/services/network/test/test_cookie_manager.h index fc197a1765e42..5bc07a5b84274 100644 --- a/services/network/test/test_cookie_manager.h +++ b/services/network/test/test_cookie_manager.h @@ -57,8 +57,7 @@ class TestCookieManager : public network::mojom::CookieManager { void SetContentSettingsForLegacyCookieAccess( const std::vector<::ContentSettingPatternSource>& settings) override {} - void DispatchCookieChange(const net::CanonicalCookie& cookie, - network::mojom::CookieChangeCause cause); + void DispatchCookieChange(const net::CookieChangeInfo& change); private: // List of observers receiving cookie change notifications. diff --git a/third_party/blink/public/mojom/service_worker/service_worker.mojom b/third_party/blink/public/mojom/service_worker/service_worker.mojom index 3e141c7a4d8a9..2dd155a959d7e 100644 --- a/third_party/blink/public/mojom/service_worker/service_worker.mojom +++ b/third_party/blink/public/mojom/service_worker/service_worker.mojom @@ -203,9 +203,7 @@ interface ServiceWorker { // https://github.com/WICG/cookie-store/ // The callback is called once the event handler has run and the waitUntil() // promise has settled. - DispatchCookieChangeEvent( - network.mojom.CanonicalCookie cookie, - network.mojom.CookieChangeCause cause) + DispatchCookieChangeEvent(network.mojom.CookieChangeInfo change) => (ServiceWorkerEventStatus status); // The Dispatch*FetchEvent() callback is called once the event finishes, diff --git a/third_party/blink/renderer/modules/cookie_store/cookie_store.cc b/third_party/blink/renderer/modules/cookie_store/cookie_store.cc index 3585a840a94d6..adb0c2f93f05f 100644 --- a/third_party/blink/renderer/modules/cookie_store/cookie_store.cc +++ b/third_party/blink/renderer/modules/cookie_store/cookie_store.cc @@ -424,10 +424,9 @@ void CookieStore::RemoveAllEventListeners() { } void CookieStore::OnCookieChange( - const WebCanonicalCookie& backend_cookie, - network::mojom::blink::CookieChangeCause change_cause) { + network::mojom::blink::CookieChangeInfoPtr change) { HeapVector> changed, deleted; - CookieChangeEvent::ToEventInfo(backend_cookie, change_cause, changed, + CookieChangeEvent::ToEventInfo(change->cookie, change->cause, changed, deleted); if (changed.IsEmpty() && deleted.IsEmpty()) { // The backend only reported OVERWRITE events, which are dropped. diff --git a/third_party/blink/renderer/modules/cookie_store/cookie_store.h b/third_party/blink/renderer/modules/cookie_store/cookie_store.h index 692c0840e4b73..031eeda80f9a2 100644 --- a/third_party/blink/renderer/modules/cookie_store/cookie_store.h +++ b/third_party/blink/renderer/modules/cookie_store/cookie_store.h @@ -86,8 +86,8 @@ class CookieStore final : public EventTargetWithInlineData, void RemoveAllEventListeners() override; // RestrictedCookieChangeListener - void OnCookieChange(const WebCanonicalCookie&, - network::mojom::blink::CookieChangeCause) override; + void OnCookieChange( + network::mojom::blink::CookieChangeInfoPtr change) override; protected: // EventTarget overrides. diff --git a/third_party/blink/renderer/modules/service_worker/service_worker_global_scope.cc b/third_party/blink/renderer/modules/service_worker/service_worker_global_scope.cc index a5da03583b957..395ec6c174665 100644 --- a/third_party/blink/renderer/modules/service_worker/service_worker_global_scope.cc +++ b/third_party/blink/renderer/modules/service_worker/service_worker_global_scope.cc @@ -1956,8 +1956,7 @@ void ServiceWorkerGlobalScope::DispatchPaymentRequestEvent( } void ServiceWorkerGlobalScope::DispatchCookieChangeEvent( - const WebCanonicalCookie& cookie, - ::network::mojom::CookieChangeCause change_cause, + network::mojom::blink::CookieChangeInfoPtr change, DispatchCookieChangeEventCallback callback) { DCHECK(IsContextThread()); int event_id = timeout_timer_->StartEvent( @@ -1974,7 +1973,8 @@ void ServiceWorkerGlobalScope::DispatchCookieChangeEvent( HeapVector> changed; HeapVector> deleted; - CookieChangeEvent::ToEventInfo(cookie, change_cause, changed, deleted); + CookieChangeEvent::ToEventInfo(change->cookie, change->cause, changed, + deleted); Event* event = ExtendableCookieChangeEvent::Create( event_type_names::kCookiechange, std::move(changed), std::move(deleted), observer); diff --git a/third_party/blink/renderer/modules/service_worker/service_worker_global_scope.h b/third_party/blink/renderer/modules/service_worker/service_worker_global_scope.h index 3a3b110be203d..a31bb47b7102d 100644 --- a/third_party/blink/renderer/modules/service_worker/service_worker_global_scope.h +++ b/third_party/blink/renderer/modules/service_worker/service_worker_global_scope.h @@ -447,8 +447,7 @@ class MODULES_EXPORT ServiceWorkerGlobalScope final response_callback, DispatchPaymentRequestEventCallback callback) override; void DispatchCookieChangeEvent( - const WebCanonicalCookie& cookie, - ::network::mojom::blink::CookieChangeCause cause, + network::mojom::blink::CookieChangeInfoPtr change, DispatchCookieChangeEventCallback callback) override; void DispatchContentDeleteEvent( const String& id,