Index: chrome/browser/managed_mode/managed_user_registration_service_unittest.cc |
diff --git a/chrome/browser/managed_mode/managed_user_registration_service_unittest.cc b/chrome/browser/managed_mode/managed_user_registration_service_unittest.cc |
index f3b3f3c2891dd927e1b6286acf5dfd6c448840c6..cca5d439c002e187288fc332e592c49703566cb0 100644 |
--- a/chrome/browser/managed_mode/managed_user_registration_service_unittest.cc |
+++ b/chrome/browser/managed_mode/managed_user_registration_service_unittest.cc |
@@ -5,7 +5,10 @@ |
#include <string> |
#include "base/bind.h" |
+#include "base/message_loop.h" |
+#include "base/run_loop.h" |
#include "base/strings/utf_string_conversions.h" |
+#include "chrome/browser/managed_mode/managed_user_refresh_token_fetcher.h" |
#include "chrome/browser/managed_mode/managed_user_registration_service.h" |
#include "chrome/browser/prefs/scoped_user_pref_update.h" |
#include "chrome/common/pref_names.h" |
@@ -16,7 +19,7 @@ |
#include "sync/protocol/sync.pb.h" |
#include "testing/gtest/include/gtest/gtest.h" |
-using ::sync_pb::ManagedUserSpecifics; |
+using sync_pb::ManagedUserSpecifics; |
using syncer::MANAGED_USERS; |
using syncer::SyncChange; |
using syncer::SyncChangeList; |
@@ -29,6 +32,8 @@ using syncer::SyncMergeResult; |
namespace { |
+const char kManagedUserToken[] = "managedusertoken"; |
+ |
class MockChangeProcessor : public SyncChangeProcessor { |
public: |
MockChangeProcessor() {} |
@@ -62,6 +67,22 @@ SyncChange MockChangeProcessor::GetChange(const std::string& id) const { |
return SyncChange(); |
} |
+class MockManagedUserRefreshTokenFetcher |
+ : public ManagedUserRefreshTokenFetcher { |
+ public: |
+ MockManagedUserRefreshTokenFetcher() {} |
+ virtual ~MockManagedUserRefreshTokenFetcher() {} |
+ |
+ // ManagedUserRefreshTokenFetcher implementation: |
+ virtual void Start(const std::string& managed_user_id, |
+ const string16& name, |
+ const std::string& device_name, |
+ const TokenCallback& callback) OVERRIDE { |
+ GoogleServiceAuthError error(GoogleServiceAuthError::NONE); |
+ callback.Run(error, kManagedUserToken); |
+ } |
+}; |
+ |
} // namespace |
class ManagedUserRegistrationServiceTest : public ::testing::Test { |
@@ -69,6 +90,8 @@ class ManagedUserRegistrationServiceTest : public ::testing::Test { |
ManagedUserRegistrationServiceTest(); |
virtual ~ManagedUserRegistrationServiceTest(); |
+ virtual void TearDown() OVERRIDE; |
+ |
protected: |
scoped_ptr<SyncChangeProcessor> CreateChangeProcessor(); |
scoped_ptr<SyncErrorFactory> CreateErrorFactory(); |
@@ -94,6 +117,8 @@ class ManagedUserRegistrationServiceTest : public ::testing::Test { |
void OnManagedUserRegistered(const GoogleServiceAuthError& error, |
const std::string& token); |
+ base::MessageLoop message_loop_; |
+ base::RunLoop run_loop_; |
base::WeakPtrFactory<ManagedUserRegistrationServiceTest> weak_ptr_factory_; |
TestingPrefServiceSyncable prefs_; |
scoped_ptr<ManagedUserRegistrationService> service_; |
@@ -114,18 +139,25 @@ class ManagedUserRegistrationServiceTest : public ::testing::Test { |
ManagedUserRegistrationServiceTest::ManagedUserRegistrationServiceTest() |
: weak_ptr_factory_(this), |
- service_(new ManagedUserRegistrationService(&prefs_)), |
change_processor_(NULL), |
sync_data_id_(0), |
received_callback_(false), |
error_(GoogleServiceAuthError::NUM_STATES) { |
ManagedUserRegistrationService::RegisterUserPrefs(prefs_.registry()); |
+ scoped_ptr<ManagedUserRefreshTokenFetcher> token_fetcher( |
+ new MockManagedUserRefreshTokenFetcher); |
+ service_.reset( |
+ new ManagedUserRegistrationService(&prefs_, token_fetcher.Pass())); |
} |
ManagedUserRegistrationServiceTest::~ManagedUserRegistrationServiceTest() { |
EXPECT_FALSE(weak_ptr_factory_.HasWeakPtrs()); |
} |
+void ManagedUserRegistrationServiceTest::TearDown() { |
+ base::RunLoop().RunUntilIdle(); |
+} |
+ |
scoped_ptr<SyncChangeProcessor> |
ManagedUserRegistrationServiceTest::CreateChangeProcessor() { |
EXPECT_FALSE(change_processor_); |
@@ -180,6 +212,8 @@ void ManagedUserRegistrationServiceTest::Acknowledge() { |
SyncData::CreateRemoteData(++sync_data_id_, specifics))); |
} |
service()->ProcessSyncChanges(FROM_HERE, new_changes); |
+ |
+ run_loop_.Run(); |
} |
void ManagedUserRegistrationServiceTest::ResetService() { |
@@ -194,6 +228,7 @@ void ManagedUserRegistrationServiceTest::OnManagedUserRegistered( |
received_callback_ = true; |
error_ = error; |
token_ = token; |
+ run_loop_.Quit(); |
} |
TEST_F(ManagedUserRegistrationServiceTest, MergeEmpty) { |