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

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

Issue 9404011: Explicitly wait for user policy before completing login. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 months 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 a8ae3182dfde5789aa9685da794b3931099de0fe..927772c6c888ac09074a933255cb674139c7a856 100644
--- a/chrome/browser/policy/device_token_fetcher_unittest.cc
+++ b/chrome/browser/policy/device_token_fetcher_unittest.cc
@@ -4,6 +4,8 @@
#include "chrome/browser/policy/device_token_fetcher.h"
+#include "base/bind.h"
+#include "base/callback.h"
#include "base/message_loop.h"
#include "base/scoped_temp_dir.h"
#include "chrome/browser/policy/cloud_policy_data_store.h"
@@ -30,7 +32,8 @@ using testing::_;
class DeviceTokenFetcherTest : public testing::Test {
protected:
DeviceTokenFetcherTest()
- : ui_thread_(BrowserThread::UI, &loop_),
+ : ready_callback_was_invoked_(false),
+ ui_thread_(BrowserThread::UI, &loop_),
file_thread_(BrowserThread::FILE, &loop_) {
EXPECT_TRUE(temp_user_data_dir_.CreateUniqueTempDir());
successful_registration_response_.mutable_register_response()->
@@ -40,7 +43,8 @@ class DeviceTokenFetcherTest : public testing::Test {
virtual void SetUp() {
cache_.reset(new UserPolicyCache(
temp_user_data_dir_.path().AppendASCII("DeviceTokenFetcherTest"),
- false /* wait_for_policy_fetch */));
+ false, /* wait_for_policy_fetch */
+ base::Closure() /* ready_callback */));
EXPECT_CALL(service_, StartJob(_)).Times(AnyNumber());
data_store_.reset(CloudPolicyDataStore::CreateForUserPolicies());
data_store_->AddObserver(&observer_);
@@ -58,15 +62,23 @@ class DeviceTokenFetcherTest : public testing::Test {
}
void CreateNewWaitingCache() {
+ ready_callback_was_invoked_ = false;
cache_.reset(new UserPolicyCache(
temp_user_data_dir_.path().AppendASCII("DeviceTokenFetcherTest"),
- true /* wait_for_policy_fetch */));
+ true, /* wait_for_policy_fetch */
+ base::Bind(&DeviceTokenFetcherTest::ReadyCallback,
+ base::Unretained(this))));
// Make this cache's disk cache ready, but have it still waiting for a
// policy fetch.
cache_->Load();
loop_.RunAllPending();
ASSERT_TRUE(cache_->last_policy_refresh_time().is_null());
ASSERT_FALSE(cache_->IsReady());
+ ASSERT_FALSE(ready_callback_was_invoked_);
+ }
+
+ void ReadyCallback() {
Mattias Nissler (ping if slow) 2012/02/16 10:24:11 ditto
+ ready_callback_was_invoked_ = true;
}
MessageLoop loop_;
@@ -77,6 +89,7 @@ class DeviceTokenFetcherTest : public testing::Test {
PolicyNotifier notifier_;
ScopedTempDir temp_user_data_dir_;
em::DeviceManagementResponse successful_registration_response_;
+ bool ready_callback_was_invoked_;
private:
content::TestBrowserThread ui_thread_;
@@ -163,6 +176,7 @@ TEST_F(DeviceTokenFetcherTest, DontSetFetchingDone) {
DeviceTokenFetcher fetcher(&service_, cache_.get(), data_store_.get(),
&notifier_);
EXPECT_FALSE(cache_->IsReady());
+ EXPECT_FALSE(ready_callback_was_invoked_);
}
TEST_F(DeviceTokenFetcherTest, DontSetFetchingDoneWithoutPolicyFetch) {
@@ -179,6 +193,7 @@ TEST_F(DeviceTokenFetcherTest, DontSetFetchingDoneWithoutPolicyFetch) {
// step is to fetch policy. Only failures to fetch the token should make
// the cache ready.
EXPECT_FALSE(cache_->IsReady());
+ EXPECT_FALSE(ready_callback_was_invoked_);
}
TEST_F(DeviceTokenFetcherTest, SetFetchingDoneWhenUnmanaged) {
@@ -187,6 +202,7 @@ TEST_F(DeviceTokenFetcherTest, SetFetchingDoneWhenUnmanaged) {
DeviceTokenFetcher fetcher(&service_, cache_.get(), data_store_.get(),
&notifier_);
EXPECT_TRUE(cache_->IsReady());
+ EXPECT_TRUE(ready_callback_was_invoked_);
}
TEST_F(DeviceTokenFetcherTest, SetFetchingDoneOnFailures) {
@@ -200,6 +216,7 @@ TEST_F(DeviceTokenFetcherTest, SetFetchingDoneOnFailures) {
loop_.RunAllPending();
// This is the opposite case of DontSetFetchingDone1.
EXPECT_TRUE(cache_->IsReady());
+ EXPECT_TRUE(ready_callback_was_invoked_);
}
TEST_F(DeviceTokenFetcherTest, SetKnownMachineId) {

Powered by Google App Engine
This is Rietveld 408576698