summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorstepco@chromium.org <stepco@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-12 21:36:16 +0000
committerstepco@chromium.org <stepco@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-12 21:36:16 +0000
commitdf8a7a360b3454d8b71071d3972fc8694734b80c (patch)
treeac10cd830fc7af3f5c0e20ec0d19f1b3804010f0
parent334d615861c5ee13b13250005fb06a83c379ed2e (diff)
downloadchromium_src-df8a7a360b3454d8b71071d3972fc8694734b80c.zip
chromium_src-df8a7a360b3454d8b71071d3972fc8694734b80c.tar.gz
chromium_src-df8a7a360b3454d8b71071d3972fc8694734b80c.tar.bz2
Test that policy is fetched by CloudPolicyInvalidator.
The unit test currently does not verify that FetchPolicy is actually called when the invalidator refreshes the policy. Improve the unit test fixture to make this check. Remove CloudPolicyInvalidator::policy_refresh_count_, which was used previously to test if the policy was refreshed or not. BUG=286213 Review URL: https://chromiumcodereview.appspot.com/23601030 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@222873 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/policy/cloud/cloud_policy_invalidator.cc4
-rw-r--r--chrome/browser/policy/cloud/cloud_policy_invalidator.h9
-rw-r--r--chrome/browser/policy/cloud/cloud_policy_invalidator_unittest.cc35
3 files changed, 30 insertions, 18 deletions
diff --git a/chrome/browser/policy/cloud/cloud_policy_invalidator.cc b/chrome/browser/policy/cloud/cloud_policy_invalidator.cc
index afc06e9..17ede20 100644
--- a/chrome/browser/policy/cloud/cloud_policy_invalidator.cc
+++ b/chrome/browser/policy/cloud/cloud_policy_invalidator.cc
@@ -45,8 +45,7 @@ CloudPolicyInvalidator::CloudPolicyInvalidator(
ack_handle_(syncer::AckHandle::InvalidAckHandle()),
weak_factory_(this),
max_fetch_delay_(kMaxFetchDelayDefault),
- policy_hash_value_(0),
- policy_refresh_count_(0) {
+ policy_hash_value_(0) {
DCHECK(core);
DCHECK(task_runner.get());
}
@@ -312,7 +311,6 @@ void CloudPolicyInvalidator::RefreshPolicy(bool is_missing_payload) {
if (is_missing_payload)
core_->client()->SetInvalidationInfo(invalidation_version_, std::string());
core_->refresh_scheduler()->RefreshSoon();
- policy_refresh_count_++;
}
void CloudPolicyInvalidator::AcknowledgeInvalidation() {
diff --git a/chrome/browser/policy/cloud/cloud_policy_invalidator.h b/chrome/browser/policy/cloud/cloud_policy_invalidator.h
index 67ed544..5ad66db 100644
--- a/chrome/browser/policy/cloud/cloud_policy_invalidator.h
+++ b/chrome/browser/policy/cloud/cloud_policy_invalidator.h
@@ -79,12 +79,6 @@ class CloudPolicyInvalidator : public syncer::InvalidationHandler,
virtual void OnStoreLoaded(CloudPolicyStore* store) OVERRIDE;
virtual void OnStoreError(CloudPolicyStore* store) OVERRIDE;
- // Expose the number of times the invalidator has refreshed the policy. For
- // testing only.
- int policy_refresh_count() {
- return policy_refresh_count_;
- }
-
private:
// Handle an invalidation to the policy.
void HandleInvalidation(const syncer::Invalidation& invalidation);
@@ -189,9 +183,6 @@ class CloudPolicyInvalidator : public syncer::InvalidationHandler,
// thread.
base::ThreadChecker thread_checker_;
- // Policy refresh counter used for testing.
- int policy_refresh_count_;
-
DISALLOW_COPY_AND_ASSIGN(CloudPolicyInvalidator);
};
diff --git a/chrome/browser/policy/cloud/cloud_policy_invalidator_unittest.cc b/chrome/browser/policy/cloud/cloud_policy_invalidator_unittest.cc
index fac683b..3f92b4a 100644
--- a/chrome/browser/policy/cloud/cloud_policy_invalidator_unittest.cc
+++ b/chrome/browser/policy/cloud/cloud_policy_invalidator_unittest.cc
@@ -13,6 +13,7 @@
#include "base/metrics/histogram_samples.h"
#include "base/metrics/sample_map.h"
#include "base/metrics/statistics_recorder.h"
+#include "base/run_loop.h"
#include "base/test/test_simple_task_runner.h"
#include "base/time/time.h"
#include "base/values.h"
@@ -151,6 +152,9 @@ class CloudPolicyInvalidatorTest : public testing::Test {
// base delay.
bool CheckPolicyRefreshed(base::TimeDelta delay);
+ // Checks that the policy was refreshed the given number of times.
+ bool CheckPolicyRefreshCount(int count);
+
// Returns the object id of the given policy object.
const invalidation::ObjectId& GetPolicyObjectId(PolicyObject object) const;
@@ -162,6 +166,7 @@ class CloudPolicyInvalidatorTest : public testing::Test {
invalidation::FakeInvalidationService invalidation_service_;
MockCloudPolicyStore store_;
CloudPolicyCore core_;
+ MockCloudPolicyClient* client_;
scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
// The invalidator which will be tested.
@@ -196,6 +201,7 @@ CloudPolicyInvalidatorTest::CloudPolicyInvalidatorTest()
: core_(PolicyNamespaceKey(dm_protocol::kChromeUserPolicyType,
std::string()),
&store_),
+ client_(NULL),
task_runner_(new base::TestSimpleTaskRunner()),
object_id_a_(135, "asdf"),
object_id_b_(246, "zxcv"),
@@ -242,7 +248,9 @@ void CloudPolicyInvalidatorTest::DestroyInvalidator() {
}
void CloudPolicyInvalidatorTest::ConnectCore() {
- core_.Connect(scoped_ptr<CloudPolicyClient>(new MockCloudPolicyClient()));
+ client_ = new MockCloudPolicyClient();
+ client_->SetDMToken("dm");
+ core_.Connect(scoped_ptr<CloudPolicyClient>(client_));
}
void CloudPolicyInvalidatorTest::StartRefreshScheduler() {
@@ -250,6 +258,7 @@ void CloudPolicyInvalidatorTest::StartRefreshScheduler() {
}
void CloudPolicyInvalidatorTest::DisconnectCore() {
+ client_ = NULL;
core_.Disconnect();
}
@@ -320,9 +329,7 @@ bool CloudPolicyInvalidatorTest::CheckInvalidationInfo(
}
bool CloudPolicyInvalidatorTest::CheckPolicyNotRefreshed() {
- const int start_count = invalidator_->policy_refresh_count();
- task_runner_->RunUntilIdle();
- return invalidator_->policy_refresh_count() == start_count;
+ return CheckPolicyRefreshCount(0);
}
bool CloudPolicyInvalidatorTest::CheckPolicyRefreshed() {
@@ -371,9 +378,25 @@ bool CloudPolicyInvalidatorTest::CheckPolicyRefreshed(base::TimeDelta delay) {
EXPECT_GE(actual_delay, delay);
EXPECT_LE(actual_delay, max_delay);
- const int start_count = invalidator_->policy_refresh_count();
+ return CheckPolicyRefreshCount(1);
+}
+
+bool CloudPolicyInvalidatorTest::CheckPolicyRefreshCount(int count) {
+ if (!client_) {
+ task_runner_->RunUntilIdle();
+ return count == 0;
+ }
+
+ // Clear any non-invalidation refreshes which may be pending.
+ EXPECT_CALL(*client_, FetchPolicy()).Times(testing::AnyNumber());
+ base::RunLoop().RunUntilIdle();
+ testing::Mock::VerifyAndClearExpectations(client_);
+
+ // Run the invalidator tasks then check for invalidation refreshes.
+ EXPECT_CALL(*client_, FetchPolicy()).Times(count);
task_runner_->RunUntilIdle();
- return invalidator_->policy_refresh_count() == start_count + 1;
+ base::RunLoop().RunUntilIdle();
+ return testing::Mock::VerifyAndClearExpectations(client_);
}
const invalidation::ObjectId& CloudPolicyInvalidatorTest::GetPolicyObjectId(