Index: chrome/browser/policy/device_token_fetcher_unittest.cc |
diff --git a/chrome/browser/policy/device_token_fetcher_unittest.cc b/chrome/browser/policy/device_token_fetcher_unittest.cc |
index 754628615a0a01aa7e63e646caadd32d8b2f1862..10f6882c05834fe94771195cd5b18b37e0fb153b 100644 |
--- a/chrome/browser/policy/device_token_fetcher_unittest.cc |
+++ b/chrome/browser/policy/device_token_fetcher_unittest.cc |
@@ -13,6 +13,8 @@ |
#include "chrome/browser/policy/mock_device_management_backend.h" |
#include "chrome/common/net/gaia/gaia_constants.h" |
#include "chrome/common/notification_service.h" |
+#include "chrome/test/testing_device_token_fetcher.h" |
+#include "chrome/test/testing_profile.h" |
#include "testing/gmock/include/gmock/gmock.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -49,23 +51,24 @@ class DeviceTokenFetcherTest : public testing::Test { |
virtual void TearDown() { |
backend_.reset(); |
- token_service_.reset(); |
+ profile_.reset(); |
loop_.RunAllPending(); |
} |
- void SimulateSuccessfulLoginAndRunPending() { |
+ void SimulateSuccessfulLoginAndRunPending(const std::string& username) { |
loop_.RunAllPending(); |
- token_service_->IssueAuthTokenForTest( |
+ profile_->GetTokenService()->IssueAuthTokenForTest( |
GaiaConstants::kDeviceManagementService, kTestToken); |
+ fetcher_->SimulateLogin(username); |
loop_.RunAllPending(); |
} |
- DeviceTokenFetcher* NewTestFetcher(const FilePath& token_dir) { |
- token_service_.reset(new TokenService); |
+ TestingDeviceTokenFetcher* NewTestFetcher(const FilePath& token_dir) { |
+ profile_.reset(new TestingProfile()); |
backend_.reset(new MockDeviceManagementBackend()); |
- return new DeviceTokenFetcher( |
+ return new TestingDeviceTokenFetcher( |
backend_.get(), |
- token_service_.get(), |
+ profile_.get(), |
token_dir.Append(FILE_PATH_LITERAL("test-token-file.txt"))); |
} |
@@ -79,10 +82,10 @@ class DeviceTokenFetcherTest : public testing::Test { |
} |
MessageLoop loop_; |
- scoped_ptr<TokenService> token_service_; |
scoped_ptr<MockDeviceManagementBackend> backend_; |
ScopedTempDir temp_user_data_dir_; |
- scoped_refptr<DeviceTokenFetcher> fetcher_; |
+ scoped_refptr<TestingDeviceTokenFetcher> fetcher_; |
+ scoped_ptr<Profile> profile_; |
private: |
BrowserThread ui_thread_; |
@@ -93,14 +96,14 @@ TEST_F(DeviceTokenFetcherTest, IsPending) { |
ASSERT_TRUE(fetcher_->IsTokenPending()); |
backend_->AllShouldSucceed(); |
EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).Times(1); |
- SimulateSuccessfulLoginAndRunPending(); |
+ SimulateSuccessfulLoginAndRunPending(kTestDasherDomainUsername); |
ASSERT_FALSE(fetcher_->IsTokenPending()); |
} |
TEST_F(DeviceTokenFetcherTest, StoreAndLoad) { |
backend_->AllShouldSucceed(); |
EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).Times(1); |
- SimulateSuccessfulLoginAndRunPending(); |
+ SimulateSuccessfulLoginAndRunPending(kTestDasherDomainUsername); |
ASSERT_FALSE(fetcher_->IsTokenPending()); |
std::string device_token = fetcher_->GetDeviceToken(); |
std::string device_id = fetcher_->GetDeviceID(); |
@@ -109,7 +112,8 @@ TEST_F(DeviceTokenFetcherTest, StoreAndLoad) { |
FilePath token_path; |
GetDeviceTokenPath(fetcher_, &token_path); |
scoped_refptr<DeviceTokenFetcher> fetcher2( |
- new DeviceTokenFetcher(backend_.get(), token_service_.get(), token_path)); |
+ new TestingDeviceTokenFetcher( |
+ backend_.get(), profile_.get(), token_path)); |
fetcher2->StartFetching(); |
loop_.RunAllPending(); |
ASSERT_EQ(device_id, fetcher2->GetDeviceID()); |
@@ -119,7 +123,7 @@ TEST_F(DeviceTokenFetcherTest, StoreAndLoad) { |
TEST_F(DeviceTokenFetcherTest, SimpleFetchSingleLogin) { |
backend_->AllShouldSucceed(); |
EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).Times(1); |
- SimulateSuccessfulLoginAndRunPending(); |
+ SimulateSuccessfulLoginAndRunPending(kTestDasherDomainUsername); |
ASSERT_FALSE(fetcher_->IsTokenPending()); |
ASSERT_TRUE(fetcher_->IsTokenValid()); |
const std::string token(fetcher_->GetDeviceToken()); |
@@ -129,12 +133,12 @@ TEST_F(DeviceTokenFetcherTest, SimpleFetchSingleLogin) { |
TEST_F(DeviceTokenFetcherTest, SimpleFetchDoubleLogin) { |
backend_->AllShouldSucceed(); |
EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).Times(1); |
- SimulateSuccessfulLoginAndRunPending(); |
+ SimulateSuccessfulLoginAndRunPending(kTestDasherDomainUsername); |
ASSERT_FALSE(fetcher_->IsTokenPending()); |
const std::string token(fetcher_->GetDeviceToken()); |
EXPECT_NE("", token); |
- SimulateSuccessfulLoginAndRunPending(); |
+ SimulateSuccessfulLoginAndRunPending(kTestDasherDomainUsername); |
ASSERT_FALSE(fetcher_->IsTokenPending()); |
const std::string token2(fetcher_->GetDeviceToken()); |
EXPECT_NE("", token2); |
@@ -150,7 +154,7 @@ TEST_F(DeviceTokenFetcherTest, FetchBetweenBrowserLaunchAndNotify) { |
EXPECT_CALL(observer, Observe(_, _, _)).Times(1); |
backend_->AllShouldSucceed(); |
EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).Times(1); |
- SimulateSuccessfulLoginAndRunPending(); |
+ SimulateSuccessfulLoginAndRunPending(kTestDasherDomainUsername); |
ASSERT_FALSE(fetcher_->IsTokenPending()); |
const std::string token(fetcher_->GetDeviceToken()); |
EXPECT_NE("", token); |
@@ -172,7 +176,7 @@ TEST_F(DeviceTokenFetcherTest, FetchBetweenBrowserLaunchAndNotify) { |
TEST_F(DeviceTokenFetcherTest, FailedServerRequest) { |
backend_->AllShouldFail(); |
EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).Times(1); |
- SimulateSuccessfulLoginAndRunPending(); |
+ SimulateSuccessfulLoginAndRunPending(kTestDasherDomainUsername); |
ASSERT_FALSE(fetcher_->IsTokenPending()); |
const std::string token(fetcher_->GetDeviceToken()); |
EXPECT_EQ("", token); |
@@ -181,7 +185,7 @@ TEST_F(DeviceTokenFetcherTest, FailedServerRequest) { |
TEST_F(DeviceTokenFetcherTest, UnmanagedDevice) { |
backend_->UnmanagedDevice(); |
EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).Times(1); |
- SimulateSuccessfulLoginAndRunPending(); |
+ SimulateSuccessfulLoginAndRunPending(kTestDasherDomainUsername); |
ASSERT_FALSE(fetcher_->IsTokenPending()); |
ASSERT_EQ("", fetcher_->GetDeviceToken()); |
ASSERT_EQ("", device_id(fetcher_)); |
@@ -190,4 +194,26 @@ TEST_F(DeviceTokenFetcherTest, UnmanagedDevice) { |
ASSERT_FALSE(file_util::PathExists(token_path)); |
} |
+TEST_F(DeviceTokenFetcherTest, FetchBetweenTokenNotifyAndLoginNotify) { |
+ backend_->AllShouldSucceed(); |
+ EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).Times(0); |
+ SimulateSuccessfulLoginAndRunPending("___@gmail.com"); |
+ ASSERT_TRUE(fetcher_->IsTokenPending()); |
+ ASSERT_FALSE(fetcher_->IsTokenValid()); |
+} |
+ |
+TEST_F(DeviceTokenFetcherTest, FetchWithNonDasherUsername) { |
+ backend_->AllShouldSucceed(); |
+ EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).Times(0); |
+ |
+ // Simulate an available user, but without available user name. |
+ loop_.RunAllPending(); |
+ profile_->GetTokenService()->IssueAuthTokenForTest( |
+ GaiaConstants::kDeviceManagementService, kTestToken); |
+ loop_.RunAllPending(); |
+ |
+ ASSERT_TRUE(fetcher_->IsTokenPending()); |
Mattias Nissler (ping if slow)
2010/11/22 20:36:08
I think IsTokenPending() should return false at th
gfeher
2010/11/23 13:47:51
I've mixed up the names of these two tests. :/
Don
|
+ ASSERT_FALSE(fetcher_->IsTokenValid()); |
+} |
+ |
} // namespace policy |