| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/policy/cloud_policy_core.h" | |
| 6 | |
| 7 #include "base/basictypes.h" | |
| 8 #include "base/message_loop.h" | |
| 9 #include "base/prefs/testing_pref_service.h" | |
| 10 #include "chrome/browser/policy/cloud_policy_constants.h" | |
| 11 #include "chrome/browser/policy/cloud_policy_refresh_scheduler.h" | |
| 12 #include "chrome/browser/policy/mock_cloud_policy_client.h" | |
| 13 #include "chrome/browser/policy/mock_cloud_policy_store.h" | |
| 14 #include "chrome/browser/prefs/browser_prefs.h" | |
| 15 #include "chrome/common/pref_names.h" | |
| 16 #include "testing/gtest/include/gtest/gtest.h" | |
| 17 | |
| 18 namespace policy { | |
| 19 | |
| 20 class CloudPolicyCoreTest : public testing::Test { | |
| 21 protected: | |
| 22 CloudPolicyCoreTest() | |
| 23 : core_(PolicyNamespaceKey(dm_protocol::kChromeUserPolicyType, | |
| 24 std::string()), | |
| 25 &store_) { | |
| 26 chrome::RegisterLocalState(prefs_.registry()); | |
| 27 } | |
| 28 | |
| 29 MessageLoop loop_; | |
| 30 | |
| 31 TestingPrefServiceSimple prefs_; | |
| 32 MockCloudPolicyStore store_; | |
| 33 CloudPolicyCore core_; | |
| 34 | |
| 35 private: | |
| 36 DISALLOW_COPY_AND_ASSIGN(CloudPolicyCoreTest); | |
| 37 }; | |
| 38 | |
| 39 TEST_F(CloudPolicyCoreTest, ConnectAndDisconnect) { | |
| 40 EXPECT_TRUE(core_.store()); | |
| 41 EXPECT_FALSE(core_.client()); | |
| 42 EXPECT_FALSE(core_.service()); | |
| 43 EXPECT_FALSE(core_.refresh_scheduler()); | |
| 44 | |
| 45 // Connect() brings up client and service. | |
| 46 core_.Connect(scoped_ptr<CloudPolicyClient>(new MockCloudPolicyClient())); | |
| 47 EXPECT_TRUE(core_.client()); | |
| 48 EXPECT_TRUE(core_.service()); | |
| 49 EXPECT_FALSE(core_.refresh_scheduler()); | |
| 50 | |
| 51 // Disconnect() goes back to no client and service. | |
| 52 core_.Disconnect(); | |
| 53 EXPECT_FALSE(core_.client()); | |
| 54 EXPECT_FALSE(core_.service()); | |
| 55 EXPECT_FALSE(core_.refresh_scheduler()); | |
| 56 | |
| 57 // Calling Disconnect() twice doesn't do bad things. | |
| 58 core_.Disconnect(); | |
| 59 EXPECT_FALSE(core_.client()); | |
| 60 EXPECT_FALSE(core_.service()); | |
| 61 EXPECT_FALSE(core_.refresh_scheduler()); | |
| 62 } | |
| 63 | |
| 64 TEST_F(CloudPolicyCoreTest, RefreshScheduler) { | |
| 65 EXPECT_FALSE(core_.refresh_scheduler()); | |
| 66 core_.Connect(scoped_ptr<CloudPolicyClient>(new MockCloudPolicyClient())); | |
| 67 core_.StartRefreshScheduler(); | |
| 68 ASSERT_TRUE(core_.refresh_scheduler()); | |
| 69 | |
| 70 int default_refresh_delay = core_.refresh_scheduler()->refresh_delay(); | |
| 71 | |
| 72 const int kRefreshRate = 1000 * 60 * 60; | |
| 73 prefs_.SetInteger(prefs::kUserPolicyRefreshRate, kRefreshRate); | |
| 74 core_.TrackRefreshDelayPref(&prefs_, prefs::kUserPolicyRefreshRate); | |
| 75 EXPECT_EQ(kRefreshRate, core_.refresh_scheduler()->refresh_delay()); | |
| 76 | |
| 77 prefs_.ClearPref(prefs::kUserPolicyRefreshRate); | |
| 78 EXPECT_EQ(default_refresh_delay, core_.refresh_scheduler()->refresh_delay()); | |
| 79 } | |
| 80 | |
| 81 } // namespace policy | |
| OLD | NEW |