Index: chrome/browser/chromeos/arc/arc_auth_service_unittest.cc |
diff --git a/chrome/browser/chromeos/arc/arc_auth_service_unittest.cc b/chrome/browser/chromeos/arc/arc_auth_service_unittest.cc |
index f3546b863de356992f2a8b4fc9e69d2a00090130..96984acc274c1ef0d014573d74a51855d2ad59a4 100644 |
--- a/chrome/browser/chromeos/arc/arc_auth_service_unittest.cc |
+++ b/chrome/browser/chromeos/arc/arc_auth_service_unittest.cc |
@@ -17,7 +17,6 @@ |
#include "chrome/common/pref_names.h" |
#include "chrome/test/base/testing_profile.h" |
#include "components/arc/arc_bridge_service.h" |
-#include "components/arc/auth/arc_auth_fetcher.h" |
#include "components/arc/test/fake_arc_bridge_service.h" |
#include "components/prefs/pref_service.h" |
#include "components/syncable_prefs/testing_pref_service_syncable.h" |
@@ -26,8 +25,6 @@ |
#include "google_apis/gaia/gaia_constants.h" |
#include "google_apis/gaia/gaia_urls.h" |
#include "net/http/http_status_code.h" |
-#include "net/url_request/test_url_fetcher_factory.h" |
-#include "net/url_request/url_fetcher.h" |
#include "sync/api/fake_sync_change_processor.h" |
#include "sync/api/sync_error_factory_mock.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -44,11 +41,7 @@ const char kTestAuthCode[] = "4/Qa3CPIhh-WcMfWSf9HZaYcGUhEeax-F9sQK9CNRhZWs"; |
class ArcAuthServiceTest : public testing::Test { |
public: |
ArcAuthServiceTest() |
- : thread_bundle_(new content::TestBrowserThreadBundle(kThreadOptions)), |
- url_fetcher_factory_( |
- nullptr, |
- base::Bind(&ArcAuthServiceTest::FakeURLFetcherCreator, |
- base::Unretained(this))) {} |
+ : thread_bundle_(new content::TestBrowserThreadBundle(kThreadOptions)) {} |
~ArcAuthServiceTest() override = default; |
void SetUp() override { |
@@ -78,37 +71,7 @@ class ArcAuthServiceTest : public testing::Test { |
FakeArcBridgeService* bridge_service() { return bridge_service_.get(); } |
ArcAuthService* auth_service() { return auth_service_.get(); } |
- void PrepareURLResponse(net::HttpStatusCode code, bool enable_auth_code) { |
- const GURL gaia_gurl = ArcAuthFetcher::CreateURL(); |
- url_fetcher_factory_.SetFakeResponse(gaia_gurl, std::string(), code, |
- net::URLRequestStatus::SUCCESS); |
- if (enable_auth_code) { |
- std::string cookie = "oauth_code="; |
- cookie += kTestAuthCode; |
- cookie += "; Path=/o/oauth2/programmatic_auth; Secure; HttpOnly"; |
- rt_cookie_ = cookie; |
- } |
- } |
- |
private: |
- scoped_ptr<net::FakeURLFetcher> FakeURLFetcherCreator( |
- const GURL& url, |
- net::URLFetcherDelegate* delegate, |
- const std::string& response_data, |
- net::HttpStatusCode response_code, |
- net::URLRequestStatus::Status status) { |
- scoped_ptr<net::FakeURLFetcher> fetcher(new net::FakeURLFetcher( |
- url, delegate, response_data, response_code, status)); |
- // Use cookie only once. |
- if (!rt_cookie_.empty()) { |
- net::ResponseCookies cookies; |
- cookies.push_back(rt_cookie_); |
- fetcher->set_cookies(cookies); |
- rt_cookie_.clear(); |
- } |
- return fetcher; |
- } |
- |
void StartPreferenceSyncing() const { |
PrefServiceSyncableFromProfile(profile_.get()) |
->GetSyncableService(syncer::PREFERENCES) |
@@ -120,12 +83,10 @@ class ArcAuthServiceTest : public testing::Test { |
} |
scoped_ptr<content::TestBrowserThreadBundle> thread_bundle_; |
- net::FakeURLFetcherFactory url_fetcher_factory_; |
scoped_ptr<arc::FakeArcBridgeService> bridge_service_; |
scoped_ptr<arc::ArcAuthService> auth_service_; |
scoped_ptr<TestingProfile> profile_; |
base::ScopedTempDir temp_dir_; |
- std::string rt_cookie_; |
DISALLOW_COPY_AND_ASSIGN(ArcAuthServiceTest); |
}; |
@@ -139,7 +100,6 @@ TEST_F(ArcAuthServiceTest, PrefChangeTriggersService) { |
auth_service()->OnPrimaryUserProfilePrepared(profile()); |
ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); |
- PrepareURLResponse(net::HTTP_OK, false); |
pref->SetBoolean(prefs::kArcEnabled, true); |
ASSERT_EQ(ArcAuthService::State::FETCHING_CODE, auth_service()->state()); |
@@ -155,7 +115,6 @@ TEST_F(ArcAuthServiceTest, BaseWorkflow) { |
ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); |
ASSERT_EQ(std::string(), auth_service()->GetAndResetAuthCode()); |
- PrepareURLResponse(net::HTTP_OK, true); |
auth_service()->OnPrimaryUserProfilePrepared(profile()); |
// By default ARC is not enabled. |
@@ -166,8 +125,7 @@ TEST_F(ArcAuthServiceTest, BaseWorkflow) { |
// Setting profile and pref initiates a code fetching process. |
ASSERT_EQ(ArcAuthService::State::FETCHING_CODE, auth_service()->state()); |
- content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
- base::RunLoop().RunUntilIdle(); |
+ auth_service()->SetAuthCodeAndStartArc(kTestAuthCode); |
ASSERT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); |
ASSERT_EQ(ArcBridgeService::State::READY, bridge_service()->state()); |
@@ -192,24 +150,11 @@ TEST_F(ArcAuthServiceTest, BaseWorkflow) { |
// UI is disabled in unit tests and this code is unchanged. |
ASSERT_EQ(ArcAuthService::State::FETCHING_CODE, auth_service()->state()); |
- // Send error response. |
- PrepareURLResponse(net::HTTP_BAD_REQUEST, false); |
- auth_service()->Shutdown(); |
- ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); |
- auth_service()->OnPrimaryUserProfilePrepared(profile()); |
- |
- ASSERT_EQ(ArcAuthService::State::FETCHING_CODE, auth_service()->state()); |
- content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
- base::RunLoop().RunUntilIdle(); |
- |
- ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); |
- |
// Correctly stop service. |
auth_service()->Shutdown(); |
} |
TEST_F(ArcAuthServiceTest, CancelFetchingDisablesArc) { |
- PrepareURLResponse(net::HTTP_OK, false); |
PrefService* pref = profile()->GetPrefs(); |
auth_service()->OnPrimaryUserProfilePrepared(profile()); |
@@ -225,14 +170,12 @@ TEST_F(ArcAuthServiceTest, CancelFetchingDisablesArc) { |
} |
TEST_F(ArcAuthServiceTest, CloseUIKeepsArcEnabled) { |
- PrepareURLResponse(net::HTTP_OK, true); |
PrefService* pref = profile()->GetPrefs(); |
auth_service()->OnPrimaryUserProfilePrepared(profile()); |
pref->SetBoolean(prefs::kArcEnabled, true); |
- content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
- base::RunLoop().RunUntilIdle(); |
+ auth_service()->SetAuthCodeAndStartArc(kTestAuthCode); |
ASSERT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); |
@@ -245,7 +188,6 @@ TEST_F(ArcAuthServiceTest, CloseUIKeepsArcEnabled) { |
} |
TEST_F(ArcAuthServiceTest, EnableDisablesArc) { |
- PrepareURLResponse(net::HTTP_OK, false); |
PrefService* pref = profile()->GetPrefs(); |
auth_service()->OnPrimaryUserProfilePrepared(profile()); |
@@ -262,14 +204,12 @@ TEST_F(ArcAuthServiceTest, EnableDisablesArc) { |
TEST_F(ArcAuthServiceTest, SignInStatus) { |
PrefService* prefs = profile()->GetPrefs(); |
- PrepareURLResponse(net::HTTP_OK, true); |
EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); |
prefs->SetBoolean(prefs::kArcEnabled, true); |
auth_service()->OnPrimaryUserProfilePrepared(profile()); |
EXPECT_EQ(ArcAuthService::State::FETCHING_CODE, auth_service()->state()); |
- content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
- base::RunLoop().RunUntilIdle(); |
+ auth_service()->SetAuthCodeAndStartArc(kTestAuthCode); |
EXPECT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); |
EXPECT_EQ(ArcBridgeService::State::READY, bridge_service()->state()); |
EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); |