Commit 644ea57d authored by Paula Vidas's avatar Paula Vidas Committed by Commit Bot

Reland "[SyncInvalidations] Add signout and signin integration test."

This is a reland of 291faaf5

The original version of the test was flaky. The bug was in assuming the
entities are ordered by arrival time. They are actually ordered by
some unique id, which is random, and so the order was "wrong" about half
of the time.

Original change's description:
> [SyncInvalidations] Add signout and signin integration test.
>
> This CL adds a test that checks the following:
> - On signout, the FCM registration token should be cleared.
> - On signin, it should be requested again.
>
> Bug: 1135167
> Change-Id: Ie1b1967b9ed317c0a36d4b751aef0dfeb81c45d8
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2467979
> Commit-Queue: Paula Vidas <paulavidas@google.com>
> Reviewed-by: Marc Treib <treib@chromium.org>
> Reviewed-by: Rushan Suleymanov <rushans@google.com>
> Cr-Commit-Position: refs/heads/master@{#817408}

Bug: 1135167
Change-Id: I5ea7c873d6782bf53ccff040d956c2a03845acd3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2485105
Commit-Queue: Paula Vidas <paulavidas@google.com>
Reviewed-by: default avatarRushan Suleymanov <rushans@google.com>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#818840}
parent f37c8f2f
...@@ -25,6 +25,7 @@ using testing::AllOf; ...@@ -25,6 +25,7 @@ using testing::AllOf;
using testing::ElementsAre; using testing::ElementsAre;
using testing::Not; using testing::Not;
using testing::NotNull; using testing::NotNull;
using testing::UnorderedElementsAre;
const char kSyncedBookmarkURL[] = "http://www.mybookmark.com"; const char kSyncedBookmarkURL[] = "http://www.mybookmark.com";
...@@ -263,4 +264,42 @@ IN_PROC_BROWSER_TEST_F( ...@@ -263,4 +264,42 @@ IN_PROC_BROWSER_TEST_F(
GURL(kSyncedBookmarkURL))); GURL(kSyncedBookmarkURL)));
} }
// ChromeOS doesn't have the concept of sign-out.
#if !defined(OS_CHROMEOS)
IN_PROC_BROWSER_TEST_F(
SingleClientWithUseSyncInvalidationsForWalletAndOfferTest,
SignoutAndSignin) {
ASSERT_TRUE(SetupSync());
// The local device should eventually be committed to the server. The FCM
// token should be present in device info.
std::string old_token =
SyncInvalidationsServiceFactory::GetForProfile(GetProfile(0))
->GetFCMRegistrationToken();
EXPECT_TRUE(ServerDeviceInfoMatchChecker(
GetFakeServer(), ElementsAre(HasInstanceIdToken(old_token)))
.Wait());
// Sign out. The FCM token should be cleared.
GetClient(0)->SignOutPrimaryAccount();
EXPECT_TRUE(SyncInvalidationsServiceFactory::GetForProfile(GetProfile(0))
->GetFCMRegistrationToken()
.empty());
// Sign in again.
ASSERT_TRUE(GetClient(0)->SignInPrimaryAccount());
std::string new_token =
SyncInvalidationsServiceFactory::GetForProfile(GetProfile(0))
->GetFCMRegistrationToken();
EXPECT_NE(new_token, old_token);
EXPECT_FALSE(new_token.empty());
// New device info should eventually be committed to the server (but the old
// device info will remain on the server). The FCM token should be present.
EXPECT_TRUE(ServerDeviceInfoMatchChecker(
GetFakeServer(), UnorderedElementsAre(HasInstanceIdToken(old_token),
HasInstanceIdToken(new_token)))
.Wait());
}
#endif // !OS_CHROMEOS
} // namespace } // namespace
...@@ -221,18 +221,19 @@ instance_id::InstanceIDDriver* GetOrCreateInstanceIDDriver( ...@@ -221,18 +221,19 @@ instance_id::InstanceIDDriver* GetOrCreateInstanceIDDriver(
profile_to_instance_id_driver_map) { profile_to_instance_id_driver_map) {
if (!profile_to_instance_id_driver_map->count(profile)) { if (!profile_to_instance_id_driver_map->count(profile)) {
(*profile_to_instance_id_driver_map)[profile] = (*profile_to_instance_id_driver_map)[profile] =
std::make_unique<SyncTest::FakeInstanceIDDriver>(); std::make_unique<SyncTest::FakeInstanceIDDriver>(
/*gcm_driver=*/gcm::GCMProfileServiceFactory::GetForProfile(profile)
->driver());
} }
return (*profile_to_instance_id_driver_map)[profile].get(); return (*profile_to_instance_id_driver_map)[profile].get();
} }
} // namespace } // namespace
int SyncTest::FakeInstanceID::next_token_id_ = 1; SyncTest::FakeInstanceID::FakeInstanceID(const std::string& app_id,
gcm::GCMDriver* gcm_driver)
SyncTest::FakeInstanceID::FakeInstanceID(const std::string& app_id) : instance_id::InstanceID(app_id, gcm_driver),
: instance_id::InstanceID(app_id, /*gcm_driver = */ nullptr), token_(GenerateNextToken()) {}
token_(base::StringPrintf("token %d", next_token_id_++)) {}
void SyncTest::FakeInstanceID::GetToken( void SyncTest::FakeInstanceID::GetToken(
const std::string& authorized_entity, const std::string& authorized_entity,
...@@ -244,15 +245,27 @@ void SyncTest::FakeInstanceID::GetToken( ...@@ -244,15 +245,27 @@ void SyncTest::FakeInstanceID::GetToken(
std::move(callback).Run(token_, instance_id::InstanceID::Result::SUCCESS); std::move(callback).Run(token_, instance_id::InstanceID::Result::SUCCESS);
} }
SyncTest::FakeInstanceIDDriver::FakeInstanceIDDriver() // Deleting the InstanceID also clears any associated token.
: instance_id::InstanceIDDriver(/*gcm_driver=*/nullptr) {} void SyncTest::FakeInstanceID::DeleteIDImpl(DeleteIDCallback callback) {
token_ = GenerateNextToken();
std::move(callback).Run(instance_id::InstanceID::Result::SUCCESS);
}
std::string SyncTest::FakeInstanceID::GenerateNextToken() {
static int next_token_id_ = 1;
return base::StringPrintf("token %d", next_token_id_++);
}
SyncTest::FakeInstanceIDDriver::FakeInstanceIDDriver(gcm::GCMDriver* gcm_driver)
: instance_id::InstanceIDDriver(gcm_driver), gcm_driver_(gcm_driver) {}
SyncTest::FakeInstanceIDDriver::~FakeInstanceIDDriver() = default; SyncTest::FakeInstanceIDDriver::~FakeInstanceIDDriver() = default;
instance_id::InstanceID* SyncTest::FakeInstanceIDDriver::GetInstanceID( instance_id::InstanceID* SyncTest::FakeInstanceIDDriver::GetInstanceID(
const std::string& app_id) { const std::string& app_id) {
if (!fake_instance_ids_.count(app_id)) { if (!fake_instance_ids_.count(app_id)) {
fake_instance_ids_[app_id] = std::make_unique<FakeInstanceID>(app_id); fake_instance_ids_[app_id] =
std::make_unique<FakeInstanceID>(app_id, gcm_driver_);
} }
return fake_instance_ids_[app_id].get(); return fake_instance_ids_[app_id].get();
} }
......
...@@ -105,7 +105,8 @@ class SyncTest : public PlatformBrowserTest { ...@@ -105,7 +105,8 @@ class SyncTest : public PlatformBrowserTest {
class FakeInstanceID : public instance_id::InstanceID { class FakeInstanceID : public instance_id::InstanceID {
public: public:
explicit FakeInstanceID(const std::string& app_id); explicit FakeInstanceID(const std::string& app_id,
gcm::GCMDriver* gcm_driver);
~FakeInstanceID() override = default; ~FakeInstanceID() override = default;
void GetID(GetIDCallback callback) override {} void GetID(GetIDCallback callback) override {}
...@@ -132,23 +133,26 @@ class SyncTest : public PlatformBrowserTest { ...@@ -132,23 +133,26 @@ class SyncTest : public PlatformBrowserTest {
void DeleteTokenImpl(const std::string& authorized_entity, void DeleteTokenImpl(const std::string& authorized_entity,
const std::string& scope, const std::string& scope,
DeleteTokenCallback callback) override {} DeleteTokenCallback callback) override {}
void DeleteIDImpl(DeleteIDCallback callback) override {}
void DeleteIDImpl(DeleteIDCallback callback) override;
private: private:
static int next_token_id_; static std::string GenerateNextToken();
const std::string token_;
std::string token_;
DISALLOW_COPY_AND_ASSIGN(FakeInstanceID); DISALLOW_COPY_AND_ASSIGN(FakeInstanceID);
}; };
class FakeInstanceIDDriver : public instance_id::InstanceIDDriver { class FakeInstanceIDDriver : public instance_id::InstanceIDDriver {
public: public:
FakeInstanceIDDriver(); explicit FakeInstanceIDDriver(gcm::GCMDriver* gcm_driver);
~FakeInstanceIDDriver() override; ~FakeInstanceIDDriver() override;
instance_id::InstanceID* GetInstanceID(const std::string& app_id) override; instance_id::InstanceID* GetInstanceID(const std::string& app_id) override;
void RemoveInstanceID(const std::string& app_id) override {} void RemoveInstanceID(const std::string& app_id) override {}
bool ExistsInstanceID(const std::string& app_id) const override; bool ExistsInstanceID(const std::string& app_id) const override;
private: private:
gcm::GCMDriver* gcm_driver_;
std::map<std::string, std::unique_ptr<FakeInstanceID>> fake_instance_ids_; std::map<std::string, std::unique_ptr<FakeInstanceID>> fake_instance_ids_;
DISALLOW_COPY_AND_ASSIGN(FakeInstanceIDDriver); DISALLOW_COPY_AND_ASSIGN(FakeInstanceIDDriver);
}; };
......
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