Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1012)

Unified Diff: chrome/browser/chromeos/settings/device_oauth2_token_service_unittest.cc

Issue 892633003: Do not announce robot account token before account ID is available (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/settings/device_oauth2_token_service_unittest.cc
diff --git a/chrome/browser/chromeos/settings/device_oauth2_token_service_unittest.cc b/chrome/browser/chromeos/settings/device_oauth2_token_service_unittest.cc
index 8ddfdace5be0d5349d6e1681d628c21592d0cd2d..e499498ff375b88ac8310911b9dae83e3cac2bac 100644
--- a/chrome/browser/chromeos/settings/device_oauth2_token_service_unittest.cc
+++ b/chrome/browser/chromeos/settings/device_oauth2_token_service_unittest.cc
@@ -28,10 +28,29 @@
#include "net/url_request/test_url_fetcher_factory.h"
#include "net/url_request/url_fetcher_delegate.h"
#include "net/url_request/url_request_test_util.h"
+#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace chromeos {
+namespace {
+
+class MockOAuth2TokenServiceObserver : public OAuth2TokenService::Observer {
+ public:
+ MockOAuth2TokenServiceObserver();
+ ~MockOAuth2TokenServiceObserver() override;
+
+ MOCK_METHOD1(OnRefreshTokenAvailable, void(const std::string&));
+};
+
+MockOAuth2TokenServiceObserver::MockOAuth2TokenServiceObserver() {
+}
+
+MockOAuth2TokenServiceObserver::~MockOAuth2TokenServiceObserver() {
+}
+
+} // namespace
+
static const int kOAuthTokenServiceUrlFetcherId = 0;
static const int kValidatorUrlFetcherId = gaia::GaiaOAuthClient::kUrlFetcherId;
@@ -96,6 +115,7 @@ class DeviceOAuth2TokenServiceTest : public testing::Test {
}
void TearDown() override {
+ oauth2_service_.reset();
CrosSettings::Shutdown();
TestingBrowserProcess::GetGlobal()->SetBrowserPolicyConnector(NULL);
content::BrowserThread::GetBlockingPool()->FlushForTesting();
@@ -430,4 +450,25 @@ TEST_F(DeviceOAuth2TokenServiceTest, RefreshTokenValidation_Retry) {
AssertConsumerTokensAndErrors(1, 1);
}
+TEST_F(DeviceOAuth2TokenServiceTest, DoNotAnnounceTokenWithoutAccountID) {
+ CreateService();
+
+ testing::StrictMock<MockOAuth2TokenServiceObserver> observer;
+ oauth2_service_->AddObserver(&observer);
+
+ // Make a token available during enrollment. Verify that the token is not
+ // announced yet.
+ oauth2_service_->SetAndSaveRefreshToken(
+ "test-token", DeviceOAuth2TokenService::StatusCallback());
+ testing::Mock::VerifyAndClearExpectations(&observer);
+
+ // Also make the robot account ID available. Verify that the token is
+ // announced now.
+ EXPECT_CALL(observer, OnRefreshTokenAvailable("robot@example.com"));
+ SetRobotAccountId("robot@example.com");
+ testing::Mock::VerifyAndClearExpectations(&observer);
+
+ oauth2_service_->RemoveObserver(&observer);
+}
+
} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698