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

Unified Diff: chrome/browser/policy/device_token_fetcher_unittest.cc

Issue 5219006: Refresh policies from DM server periodically (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix build on Win; fix behavior for unmanaged devices Created 10 years, 1 month 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/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..4863a51e41a7bc65d1e3902751255b4334736e96 100644
--- a/chrome/browser/policy/device_token_fetcher_unittest.cc
+++ b/chrome/browser/policy/device_token_fetcher_unittest.cc
@@ -23,15 +23,14 @@ const char kTestToken[] = "device_token_fetcher_test_auth_token";
using testing::_;
using testing::Mock;
-class MockTokenAvailableObserver : public NotificationObserver {
+class MockTokenAvailableObserver : public DeviceTokenFetcher::Observer {
public:
MockTokenAvailableObserver() {}
virtual ~MockTokenAvailableObserver() {}
- MOCK_METHOD3(Observe, void(
- NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details));
+ MOCK_METHOD0(OnTokenSuccess, void());
+ MOCK_METHOD0(OnTokenError, void());
+ MOCK_METHOD0(OnNotManaged, void());
private:
DISALLOW_COPY_AND_ASSIGN(MockTokenAvailableObserver);
@@ -142,12 +141,12 @@ TEST_F(DeviceTokenFetcherTest, SimpleFetchDoubleLogin) {
}
TEST_F(DeviceTokenFetcherTest, FetchBetweenBrowserLaunchAndNotify) {
- NotificationRegistrar registrar;
MockTokenAvailableObserver observer;
- registrar.Add(&observer,
- NotificationType::DEVICE_TOKEN_AVAILABLE,
- NotificationService::AllSources());
- EXPECT_CALL(observer, Observe(_, _, _)).Times(1);
+ scoped_ptr<DeviceTokenFetcher::ObserverRegistrar> registrar(
+ new DeviceTokenFetcher::ObserverRegistrar(fetcher_));
+ registrar->AddObserver(&observer);
+ EXPECT_CALL(observer, OnTokenSuccess()).Times(1);
+ EXPECT_CALL(observer, OnTokenError()).Times(0);
backend_->AllShouldSucceed();
EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).Times(1);
SimulateSuccessfulLoginAndRunPending();
@@ -158,8 +157,9 @@ TEST_F(DeviceTokenFetcherTest, FetchBetweenBrowserLaunchAndNotify) {
// Swap out the fetchers, including copying the device management token on
// disk to where the new fetcher expects it.
- fetcher_ = NewTestFetcher(
- temp_user_data_dir_.path());
+ registrar.reset(NULL);
danno 2010/11/23 12:10:14 Aternitavely, you can add a RemoveObserver method
Jakob Kummerow (corp) 2010/11/23 12:25:26 That's the alternative, yes. It would mean more co
+ fetcher_ = NewTestFetcher(temp_user_data_dir_.path());
+ registrar.reset(new DeviceTokenFetcher::ObserverRegistrar(fetcher_));
fetcher_->StartFetching();
ASSERT_TRUE(fetcher_->IsTokenPending());
loop_.RunAllPending();
@@ -170,6 +170,11 @@ TEST_F(DeviceTokenFetcherTest, FetchBetweenBrowserLaunchAndNotify) {
}
TEST_F(DeviceTokenFetcherTest, FailedServerRequest) {
+ MockTokenAvailableObserver observer;
+ DeviceTokenFetcher::ObserverRegistrar registrar(fetcher_);
+ registrar.AddObserver(&observer);
+ EXPECT_CALL(observer, OnTokenSuccess()).Times(0);
+ EXPECT_CALL(observer, OnTokenError()).Times(1);
backend_->AllShouldFail();
EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).Times(1);
SimulateSuccessfulLoginAndRunPending();
@@ -179,14 +184,16 @@ TEST_F(DeviceTokenFetcherTest, FailedServerRequest) {
}
TEST_F(DeviceTokenFetcherTest, UnmanagedDevice) {
+ FilePath token_path;
+ GetDeviceTokenPath(fetcher_, &token_path);
+ file_util::WriteFile(token_path, "foo", 3);
+ ASSERT_TRUE(file_util::PathExists(token_path));
backend_->UnmanagedDevice();
EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).Times(1);
SimulateSuccessfulLoginAndRunPending();
ASSERT_FALSE(fetcher_->IsTokenPending());
ASSERT_EQ("", fetcher_->GetDeviceToken());
ASSERT_EQ("", device_id(fetcher_));
- FilePath token_path;
- GetDeviceTokenPath(fetcher_, &token_path);
ASSERT_FALSE(file_util::PathExists(token_path));
}

Powered by Google App Engine
This is Rietveld 408576698