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

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: address comments 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..393195c1a4ef0b27be1aaa6da48e10a768c4c771 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);
+ DeviceTokenFetcher::ObserverRegistrar registrar;
+ registrar.Init(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.RemoveAll();
+ fetcher_ = NewTestFetcher(temp_user_data_dir_.path());
+ registrar.Init(fetcher_);
fetcher_->StartFetching();
ASSERT_TRUE(fetcher_->IsTokenPending());
loop_.RunAllPending();
@@ -170,6 +170,12 @@ TEST_F(DeviceTokenFetcherTest, FetchBetweenBrowserLaunchAndNotify) {
}
TEST_F(DeviceTokenFetcherTest, FailedServerRequest) {
+ MockTokenAvailableObserver observer;
+ DeviceTokenFetcher::ObserverRegistrar registrar;
+ registrar.Init(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 +185,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));
}
« no previous file with comments | « chrome/browser/policy/device_token_fetcher.cc ('k') | chrome/browser/policy/mock_device_management_backend.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698