Commit b2aa6e32 authored by Daniel Rubery's avatar Daniel Rubery Committed by Commit Bot

Add test for Advanced Protection being disabled after sign in

To make sure the refresh logic works in the
AdvancedProtectionStatusManager, add a test that skips the 24 hour timer.

Bug: 919708
Change-Id: I3643ea968be58b5dcd9ce30565a6152a10ab5294
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1495744
Commit-Queue: Daniel Rubery <drubery@chromium.org>
Reviewed-by: default avatarNathan Parker <nparker@chromium.org>
Cr-Commit-Position: refs/heads/master@{#637809}
parent c472571c
......@@ -68,6 +68,10 @@ class AdvancedProtectionStatusManager
AlreadySignedInAndUnderAPIncognito);
FRIEND_TEST_ALL_PREFIXES(AdvancedProtectionStatusManagerTest,
AlreadySignedInAndNotUnderAPIncognito);
FRIEND_TEST_ALL_PREFIXES(AdvancedProtectionStatusManagerTest,
AdvancedProtectionDisabledAfterSignin);
FRIEND_TEST_ALL_PREFIXES(AdvancedProtectionStatusManagerTest,
StartupAfterLongWaitRefreshesImmediately);
void Initialize();
......
......@@ -4,6 +4,8 @@
#include "chrome/browser/safe_browsing/advanced_protection_status_manager.h"
#include <string>
#include "base/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "chrome/browser/safe_browsing/advanced_protection_status_manager_factory.h"
......@@ -51,9 +53,8 @@ class AdvancedProtectionStatusManagerTest : public testing::Test {
AccountInfo account_info = identity_test_env()->MakeAccountAvailable(email);
account_info.is_under_advanced_protection = is_under_advanced_protection;
identity_test_env()->UpdateAccountInfoForAccount(account_info);
identity_test_env()->SetPrimaryAccount(account_info.email);
identity_test_env()->UpdateAccountInfoForAccount(account_info);
return account_info.account_id;
}
......@@ -360,4 +361,58 @@ TEST_F(AdvancedProtectionStatusManagerTest, AccountRemoval) {
aps_manager.UnsubscribeFromSigninEvents();
}
TEST_F(AdvancedProtectionStatusManagerTest,
AdvancedProtectionDisabledAfterSignin) {
AdvancedProtectionStatusManager aps_manager(
testing_profile_.get(), base::TimeDelta() /*no min delay*/);
// There is no account, so the timer should not run at startup.
EXPECT_FALSE(aps_manager.IsRefreshScheduled());
std::string account_id =
SignIn("test@test.com", /* is_under_advanced_protection = */ true);
base::RunLoop().RunUntilIdle();
// Now that we've signed into Advanced Protection, we should have a scheduled
// refresh.
EXPECT_TRUE(aps_manager.is_under_advanced_protection());
EXPECT_TRUE(aps_manager.IsRefreshScheduled());
// Skip the 24 hour wait, and try to refresh the token now.
aps_manager.timer_.FireNow();
MakeOAuthTokenFetchSucceed(account_id,
/* is_under_advanced_protection = */ false);
EXPECT_FALSE(aps_manager.is_under_advanced_protection());
EXPECT_FALSE(aps_manager.IsRefreshScheduled());
aps_manager.UnsubscribeFromSigninEvents();
}
TEST_F(AdvancedProtectionStatusManagerTest,
StartupAfterLongWaitRefreshesImmediately) {
std::string account_id =
SignIn("test@test.com", /* is_under_advanced_protection = */ true);
base::RunLoop().RunUntilIdle();
base::Time last_refresh_time =
base::Time::Now() - base::TimeDelta::FromDays(1);
testing_profile_->GetPrefs()->SetInt64(
prefs::kAdvancedProtectionLastRefreshInUs,
last_refresh_time.ToDeltaSinceWindowsEpoch().InMicroseconds());
AdvancedProtectionStatusManager aps_manager(
testing_profile_.get(), base::TimeDelta() /*no min delay*/);
ASSERT_FALSE(aps_manager.GetPrimaryAccountId().empty());
ASSERT_TRUE(aps_manager.is_under_advanced_protection());
EXPECT_TRUE(aps_manager.IsRefreshScheduled());
MakeOAuthTokenFetchSucceed(account_id,
/* is_under_advanced_protection = */ false);
EXPECT_FALSE(aps_manager.is_under_advanced_protection());
EXPECT_FALSE(aps_manager.IsRefreshScheduled());
aps_manager.UnsubscribeFromSigninEvents();
}
} // namespace safe_browsing
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