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

Unified Diff: chrome/browser/policy/cloud_policy_controller_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/cloud_policy_controller_unittest.cc
diff --git a/chrome/browser/policy/cloud_policy_controller_unittest.cc b/chrome/browser/policy/cloud_policy_controller_unittest.cc
index faedef328a52e3879284cd9abe2e0cd704785c18..f1c247f68a63451a98fb9b49094ceb97d3ad4940 100644
--- a/chrome/browser/policy/cloud_policy_controller_unittest.cc
+++ b/chrome/browser/policy/cloud_policy_controller_unittest.cc
@@ -4,6 +4,8 @@
#include "chrome/browser/policy/cloud_policy_controller.h"
+#include "base/bind.h"
+#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
#include "base/scoped_temp_dir.h"
@@ -48,7 +50,8 @@ class MockDeviceTokenFetcher : public DeviceTokenFetcher {
class CloudPolicyControllerTest : public testing::Test {
public:
CloudPolicyControllerTest()
- : ui_thread_(BrowserThread::UI, &loop_),
+ : ready_callback_was_invoked_(false),
+ ui_thread_(BrowserThread::UI, &loop_),
file_thread_(BrowserThread::FILE, &loop_) {
em::PolicyData signed_response;
em::CloudPolicySettings settings;
@@ -74,7 +77,8 @@ class CloudPolicyControllerTest : public testing::Test {
ASSERT_TRUE(temp_user_data_dir_.CreateUniqueTempDir());
cache_.reset(new UserPolicyCache(
temp_user_data_dir_.path().AppendASCII("CloudPolicyControllerTest"),
- false /* wait_for_policy_fetch */));
+ false, /* wait_for_policy_fetch */
+ base::Closure() /* ready_callback */));
token_fetcher_.reset(new MockDeviceTokenFetcher(cache_.get()));
EXPECT_CALL(service_, StartJob(_)).Times(AnyNumber());
data_store_.reset(CloudPolicyDataStore::CreateForUserPolicies());
@@ -92,15 +96,19 @@ class CloudPolicyControllerTest : public testing::Test {
}
void CreateNewWaitingCache() {
+ ready_callback_was_invoked_ = false;
cache_.reset(new UserPolicyCache(
temp_user_data_dir_.path().AppendASCII("CloudPolicyControllerTest"),
- true /* wait_for_policy_fetch */));
+ true, // wait_for_policy_fetch
+ base::Bind(&CloudPolicyControllerTest::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 ExpectHasSpdyPolicy() {
@@ -109,6 +117,10 @@ class CloudPolicyControllerTest : public testing::Test {
cache_->policy()->GetValue(key::kDisableSpdy)));
}
+ void ReadyCallback() {
Mattias Nissler (ping if slow) 2012/02/16 10:24:11 Suggestion: You can actually declare this as a MOC
+ ready_callback_was_invoked_ = true;
+ }
+
protected:
scoped_ptr<CloudPolicyCacheBase> cache_;
scoped_ptr<CloudPolicyController> controller_;
@@ -119,6 +131,7 @@ class CloudPolicyControllerTest : public testing::Test {
ScopedTempDir temp_user_data_dir_;
MessageLoop loop_;
em::DeviceManagementResponse spdy_policy_response_;
+ bool ready_callback_was_invoked_;
private:
content::TestBrowserThread ui_thread_;
@@ -276,10 +289,12 @@ TEST_F(CloudPolicyControllerTest, DontSetFetchingDoneWithoutTokens) {
// This means the controller is still waiting for an oauth token fetch.
loop_.RunAllPending();
EXPECT_FALSE(cache_->IsReady());
+ EXPECT_FALSE(ready_callback_was_invoked_);
controller_->OnDeviceTokenChanged();
loop_.RunAllPending();
EXPECT_FALSE(cache_->IsReady());
+ EXPECT_FALSE(ready_callback_was_invoked_);
}
TEST_F(CloudPolicyControllerTest, RefreshPoliciesWithoutMaterial) {
@@ -287,12 +302,14 @@ TEST_F(CloudPolicyControllerTest, RefreshPoliciesWithoutMaterial) {
CreateNewController();
loop_.RunAllPending();
EXPECT_FALSE(cache_->IsReady());
+ EXPECT_FALSE(ready_callback_was_invoked_);
// Same scenario as the last test, but the RefreshPolicies call must always
// notify the cache.
controller_->RefreshPolicies(false);
loop_.RunAllPending();
EXPECT_TRUE(cache_->IsReady());
+ EXPECT_TRUE(ready_callback_was_invoked_);
}
TEST_F(CloudPolicyControllerTest, DontSetFetchingDoneWithoutFetching) {
@@ -304,6 +321,7 @@ TEST_F(CloudPolicyControllerTest, DontSetFetchingDoneWithoutFetching) {
// This means the controller has an oauth token and should fetch the next
// token, which is the dm server register token.
EXPECT_FALSE(cache_->IsReady());
+ EXPECT_FALSE(ready_callback_was_invoked_);
}
TEST_F(CloudPolicyControllerTest, SetFetchingDoneForUnmanagedUsers) {
@@ -314,6 +332,7 @@ TEST_F(CloudPolicyControllerTest, SetFetchingDoneForUnmanagedUsers) {
loop_.RunAllPending();
// User is in an unmanaged domain.
EXPECT_TRUE(cache_->IsReady());
+ EXPECT_TRUE(ready_callback_was_invoked_);
EXPECT_TRUE(cache_->last_policy_refresh_time().is_null());
}
@@ -328,6 +347,7 @@ TEST_F(CloudPolicyControllerTest, SetFetchingDoneAfterPolicyFetch) {
CreateNewController();
loop_.RunAllPending();
EXPECT_TRUE(cache_->IsReady());
+ EXPECT_TRUE(ready_callback_was_invoked_);
EXPECT_FALSE(cache_->last_policy_refresh_time().is_null());
}
@@ -342,6 +362,7 @@ TEST_F(CloudPolicyControllerTest, SetFetchingDoneAfterPolicyFetchFails) {
CreateNewController();
loop_.RunAllPending();
EXPECT_TRUE(cache_->IsReady());
+ EXPECT_TRUE(ready_callback_was_invoked_);
EXPECT_TRUE(cache_->last_policy_refresh_time().is_null());
}

Powered by Google App Engine
This is Rietveld 408576698