Commit 5e3d6b0f authored by Nohemi Fernandez's avatar Nohemi Fernandez Committed by Chromium LUCI CQ

[iOS] Trigger full navigation for GAIA cookie update tests.

Clean up for AccountConsistencyServiceTest that removes unneeded code
and reformats GAIA cookie update tests to use full URL navigation rather
than GAIA-only shortcut method.

Bug: 1131027
Change-Id: If942fc4cafa349860f9341314c82a1fc544746eb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2577201
Commit-Queue: Nohemi Fernandez <fernandex@chromium.org>
Reviewed-by: default avatarJérôme Lebel <jlebel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#835686}
parent c7326b7f
...@@ -215,6 +215,21 @@ class AccountConsistencyServiceTest : public PlatformTest { ...@@ -215,6 +215,21 @@ class AccountConsistencyServiceTest : public PlatformTest {
/*domain=*/std::string())); /*domain=*/std::string()));
} }
void CheckDomainHasChromeConnectedCookieWithUpdateTime(
const std::string& domain,
base::Time time) {
CheckDomainHasChromeConnectedCookie(domain);
EXPECT_EQ(time,
account_consistency_service_->last_cookie_update_map_[domain]);
}
// Verifies the time that the Gaia cookie was last updated for google.com.
void CheckGaiaCookieWithUpdateTime(base::Time time) {
EXPECT_EQ(
time,
account_consistency_service_->last_gaia_cookie_verification_time_);
}
// Navigation APIs. // Navigation APIs.
void SimulateNavigateToURL(NSURLResponse* response, void SimulateNavigateToURL(NSURLResponse* response,
id<ManageAccountsDelegate> delegate) { id<ManageAccountsDelegate> delegate) {
...@@ -240,14 +255,6 @@ class AccountConsistencyServiceTest : public PlatformTest { ...@@ -240,14 +255,6 @@ class AccountConsistencyServiceTest : public PlatformTest {
} }
// Cookie APIs. // Cookie APIs.
void CheckDomainHasChromeConnectedCookieWithUpdateTime(
const std::string& domain,
base::Time time) {
CheckDomainHasChromeConnectedCookie(domain);
EXPECT_EQ(time,
account_consistency_service_->last_cookie_update_map_[domain]);
}
void WaitUntilAllCookieRequestsAreApplied() { void WaitUntilAllCookieRequestsAreApplied() {
// Spinning the runloop is needed to ensure that the cookie manager requests // Spinning the runloop is needed to ensure that the cookie manager requests
// are executed. // are executed.
...@@ -278,17 +285,6 @@ class AccountConsistencyServiceTest : public PlatformTest { ...@@ -278,17 +285,6 @@ class AccountConsistencyServiceTest : public PlatformTest {
base::OnceCallback<void(uint)>()); base::OnceCallback<void(uint)>());
} }
// Simulates updating the Gaia cookie on the Google domain at the designated
// time interval. Returns the time at which the cookie was updated.
void SimulateUpdateGaiaCookie(base::OnceClosure callback) {
account_consistency_service_->SetGaiaCookiesIfDeleted(std::move(callback));
}
// Returns time the Gaia cookie was last updated for Google domains.
base::Time GetGaiaLastUpdateTime() {
return account_consistency_service_->last_gaia_cookie_verification_time_;
}
// Properties available for tests. // Properties available for tests.
// Creates test threads, necessary for ActiveStateManager that needs a UI // Creates test threads, necessary for ActiveStateManager that needs a UI
// thread. // thread.
...@@ -543,7 +539,6 @@ TEST_F(AccountConsistencyServiceTest, ...@@ -543,7 +539,6 @@ TEST_F(AccountConsistencyServiceTest,
HTTPVersion:@"HTTP/1.1" HTTPVersion:@"HTTP/1.1"
headerFields:headersAddAccount]; headerFields:headersAddAccount];
account_consistency_service_->RemoveWebStateHandler(&web_state_);
SimulateNavigateToURLWithInterruption(responseAddAccount, delegate); SimulateNavigateToURLWithInterruption(responseAddAccount, delegate);
EXPECT_OCMOCK_VERIFY(delegate); EXPECT_OCMOCK_VERIFY(delegate);
...@@ -648,6 +643,9 @@ TEST_F(AccountConsistencyServiceTest, DomainsClearedOnBrowsingDataRemoved) { ...@@ -648,6 +643,9 @@ TEST_F(AccountConsistencyServiceTest, DomainsClearedOnBrowsingDataRemoved) {
->size()); ->size());
} }
// Tests that the CHROME_CONNECTED cookie is set on Google-associated domains,
// but not on Google domains if the account consistency service runs before the
// scheduled cookie update time.
TEST_F(AccountConsistencyServiceTest, TEST_F(AccountConsistencyServiceTest,
SetChromeConnectedCookieBeforeUpdateTime) { SetChromeConnectedCookieBeforeUpdateTime) {
SignIn(); SignIn();
...@@ -676,6 +674,9 @@ TEST_F(AccountConsistencyServiceTest, ...@@ -676,6 +674,9 @@ TEST_F(AccountConsistencyServiceTest,
CheckNoChromeConnectedCookieForDomain(kGoogleDomain); CheckNoChromeConnectedCookieForDomain(kGoogleDomain);
} }
// Tests that the CHROME_CONNECTED cookie is set on Google and Google-associated
// domains when the
// account consistency service runs at the scheduled cookie update time.
TEST_F(AccountConsistencyServiceTest, SetChromeConnectedCookieAtUpdateTime) { TEST_F(AccountConsistencyServiceTest, SetChromeConnectedCookieAtUpdateTime) {
SignIn(); SignIn();
...@@ -700,80 +701,76 @@ TEST_F(AccountConsistencyServiceTest, SetChromeConnectedCookieAtUpdateTime) { ...@@ -700,80 +701,76 @@ TEST_F(AccountConsistencyServiceTest, SetChromeConnectedCookieAtUpdateTime) {
CheckDomainHasChromeConnectedCookieWithUpdateTime(kGoogleDomain, CheckDomainHasChromeConnectedCookieWithUpdateTime(kGoogleDomain,
base::Time::Now()); base::Time::Now());
CheckDomainHasChromeConnectedCookieWithUpdateTime(kYoutubeDomain,
base::Time::Now());
} }
// Tests that the GAIA cookie update time is not updated before the scheduled
// interval.
TEST_F(AccountConsistencyServiceTest, SetGaiaCookieUpdateNotUpdateTime) { TEST_F(AccountConsistencyServiceTest, SetGaiaCookieUpdateNotUpdateTime) {
SignIn(); SignIn();
SimulateUpdateGaiaCookie(base::OnceClosure());
// HTTP response URL is eligible for Mirror (the test does not use google.com
// since the CHROME_CONNECTED cookie is generated for it by default.
NSHTTPURLResponse* response = [[NSHTTPURLResponse alloc]
initWithURL:[NSURL URLWithString:@"https://youtube.com"]
statusCode:200
HTTPVersion:@"HTTP/1.1"
headerFields:@{}];
SimulateNavigateToURL(response, nil);
// Advance clock, but stay within the one-hour Gaia update time. // Advance clock, but stay within the one-hour Gaia update time.
const base::Time first_update_time = base::Time::Now(); base::TimeDelta oneMinuteDelta = base::TimeDelta::FromMinutes(1);
task_environment_.FastForwardBy(base::TimeDelta::FromMinutes(1)); task_environment_.FastForwardBy(oneMinuteDelta);
SimulateUpdateGaiaCookie(base::OnceClosure()); SimulateNavigateToURL(response, nil);
EXPECT_EQ(first_update_time, GetGaiaLastUpdateTime()); CheckGaiaCookieWithUpdateTime(base::Time::Now() - oneMinuteDelta);
} }
// Tests that the GAIA cookie update time is updated at the scheduled interval.
TEST_F(AccountConsistencyServiceTest, SetGaiaCookieUpdateAtUpdateTime) { TEST_F(AccountConsistencyServiceTest, SetGaiaCookieUpdateAtUpdateTime) {
SignIn(); SignIn();
SimulateUpdateGaiaCookie(base::OnceClosure());
// HTTP response URL is eligible for Mirror (the test does not use google.com
// since the CHROME_CONNECTED cookie is generated for it by default.
NSHTTPURLResponse* response = [[NSHTTPURLResponse alloc]
initWithURL:[NSURL URLWithString:@"https://youtube.com"]
statusCode:200
HTTPVersion:@"HTTP/1.1"
headerFields:@{}];
SimulateNavigateToURL(response, nil);
// Advance clock past one-hour Gaia update time. // Advance clock past one-hour Gaia update time.
task_environment_.FastForwardBy(base::TimeDelta::FromHours(2)); task_environment_.FastForwardBy(base::TimeDelta::FromHours(2));
const base::Time second_update_time = base::Time::Now(); SimulateNavigateToURL(response, nil);
SimulateUpdateGaiaCookie(base::OnceClosure());
EXPECT_EQ(second_update_time, GetGaiaLastUpdateTime()); CheckGaiaCookieWithUpdateTime(base::Time::Now());
} }
// Ensures that the presence or absence of GAIA cookies is logged even if the // Ensures that the presence or absence of GAIA cookies is logged even if the
// |kRestoreGAIACookiesIfDeleted| experiment is disabled. // |kRestoreGAIACookiesIfDeleted| experiment is disabled.
TEST_F(AccountConsistencyServiceTest, GAIACookieStatusLoggedProperly) { TEST_F(AccountConsistencyServiceTest, GAIACookieStatusLoggedProperly) {
base::HistogramTester histogram_tester; // HTTP response URL is eligible for Mirror (the test does not use google.com
__block bool cookie_updated = false; // since the CHROME_CONNECTED cookie is generated for it by default.
base::OnceClosure callback = base::BindOnce(^() { NSHTTPURLResponse* response = [[NSHTTPURLResponse alloc]
cookie_updated = true; initWithURL:[NSURL URLWithString:@"https://youtube.com"]
}); statusCode:200
HTTPVersion:@"HTTP/1.1"
histogram_tester.ExpectTotalCount(kGAIACookieOnNavigationHistogram, 0); headerFields:@{}];
SimulateUpdateGaiaCookie(std::move(callback));
base::RunLoop().RunUntilIdle();
histogram_tester.ExpectTotalCount(kGAIACookieOnNavigationHistogram, 0);
ASSERT_FALSE(cookie_updated);
SignIn();
SimulateUpdateGaiaCookie(std::move(callback));
base::RunLoop().RunUntilIdle();
histogram_tester.ExpectTotalCount(kGAIACookieOnNavigationHistogram, 1);
ASSERT_FALSE(cookie_updated);
}
// Ensures that in the case Gaia cookies are restored the restoration callback
// is completed.
TEST_F(AccountConsistencyServiceTest, GAIACookieRestoreCallbackFinished) {
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(
signin::kRestoreGaiaCookiesIfDeleted);
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
histogram_tester.ExpectTotalCount(kGAIACookieOnNavigationHistogram, 0); histogram_tester.ExpectTotalCount(kGAIACookieOnNavigationHistogram, 0);
__block bool cookie_updated = false; SimulateNavigateToURL(response, nil);
SimulateUpdateGaiaCookie(base::BindOnce(^{
cookie_updated = true;
}));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
histogram_tester.ExpectTotalCount(kGAIACookieOnNavigationHistogram, 0); histogram_tester.ExpectTotalCount(kGAIACookieOnNavigationHistogram, 0);
ASSERT_FALSE(cookie_updated);
SignIn(); SignIn();
SimulateUpdateGaiaCookie(base::BindOnce(^{ SimulateNavigateToURL(response, nil);
cookie_updated = true;
}));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
histogram_tester.ExpectTotalCount(kGAIACookieOnNavigationHistogram, 1); histogram_tester.ExpectTotalCount(kGAIACookieOnNavigationHistogram, 1);
ASSERT_TRUE(cookie_updated);
} }
// Tests that navigating to accounts.google.com without a GAIA cookie is logged // Tests that navigating to accounts.google.com without a GAIA cookie is logged
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment