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

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

Issue 9403010: Add support for kiosk mode on the client. Make sure the settings are written in the lockbox. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed nitty nit. 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..00c019eb8ff5bd1366bc54a8303b93f599880897 100644
--- a/chrome/browser/policy/device_token_fetcher_unittest.cc
+++ b/chrome/browser/policy/device_token_fetcher_unittest.cc
@@ -27,6 +27,20 @@ using testing::AnyNumber;
using testing::Mock;
using testing::_;
+ACTION_P(VerifyRegisterRequest, known_machine_id) {
+ ASSERT_TRUE(arg0);
+ ASSERT_TRUE(arg0->GetRequest());
+ ASSERT_TRUE(arg0->GetRequest()->has_register_request());
+ const em::DeviceRegisterRequest& request =
+ arg0->GetRequest()->register_request();
+ if (known_machine_id) {
+ EXPECT_TRUE(request.has_known_machine_id());
+ EXPECT_TRUE(request.known_machine_id());
+ } else {
+ EXPECT_FALSE(request.has_known_machine_id());
+ }
+}
+
class DeviceTokenFetcherTest : public testing::Test {
protected:
DeviceTokenFetcherTest()
@@ -35,6 +49,8 @@ class DeviceTokenFetcherTest : public testing::Test {
EXPECT_TRUE(temp_user_data_dir_.CreateUniqueTempDir());
successful_registration_response_.mutable_register_response()->
set_device_management_token("fake_token");
+ successful_registration_response_.mutable_register_response()->
+ set_enrollment_type(em::DeviceRegisterResponse::ENTERPRISE);
}
virtual void SetUp() {
@@ -51,9 +67,9 @@ class DeviceTokenFetcherTest : public testing::Test {
data_store_->RemoveObserver(&observer_);
}
- void FetchToken(DeviceTokenFetcher* fetcher) {
- data_store_->SetupForTesting("", "fake_device_id", "fake_user_name",
- "fake_auth_token", true);
+ void FetchToken(DeviceTokenFetcher* fetcher, CloudPolicyDataStore* store) {
+ store->SetupForTesting("", "fake_device_id", "fake_user_name",
+ "fake_auth_token", true);
fetcher->FetchToken();
}
@@ -69,6 +85,14 @@ class DeviceTokenFetcherTest : public testing::Test {
ASSERT_FALSE(cache_->IsReady());
}
+ void SetUpSuccessfulRegistrationExpectation(bool known_machine_id) {
+ EXPECT_CALL(service_,
+ CreateJob(DeviceManagementRequestJob::TYPE_REGISTRATION))
+ .WillOnce(service_.SucceedJob(successful_registration_response_));
+ EXPECT_CALL(service_, StartJob(_))
+ .WillOnce(VerifyRegisterRequest(known_machine_id));
+ }
+
MessageLoop loop_;
MockDeviceManagementService service_;
scoped_ptr<CloudPolicyCacheBase> cache_;
@@ -83,35 +107,21 @@ class DeviceTokenFetcherTest : public testing::Test {
content::TestBrowserThread file_thread_;
};
-ACTION_P(VerifyRegisterRequest, known_machine_id) {
- ASSERT_TRUE(arg0);
- ASSERT_TRUE(arg0->GetRequest());
- ASSERT_TRUE(arg0->GetRequest()->has_register_request());
- const em::DeviceRegisterRequest& request =
- arg0->GetRequest()->register_request();
- if (known_machine_id) {
- EXPECT_TRUE(request.has_known_machine_id());
- EXPECT_TRUE(request.known_machine_id());
- } else {
- EXPECT_FALSE(request.has_known_machine_id());
- }
-}
-
TEST_F(DeviceTokenFetcherTest, FetchToken) {
testing::InSequence s;
- EXPECT_CALL(service_,
- CreateJob(DeviceManagementRequestJob::TYPE_REGISTRATION))
- .WillOnce(service_.SucceedJob(successful_registration_response_));
- EXPECT_CALL(service_, StartJob(_)).WillOnce(VerifyRegisterRequest(false));
+ SetUpSuccessfulRegistrationExpectation(false);
DeviceTokenFetcher fetcher(&service_, cache_.get(), data_store_.get(),
&notifier_);
EXPECT_CALL(observer_, OnDeviceTokenChanged());
EXPECT_EQ("", data_store_->device_token());
- FetchToken(&fetcher);
+ EXPECT_EQ(DEVICE_MODE_UNKNOWN, data_store_->device_mode());
+ FetchToken(&fetcher, data_store_.get());
loop_.RunAllPending();
Mock::VerifyAndClearExpectations(&observer_);
std::string token = data_store_->device_token();
EXPECT_NE("", token);
+ // User policy registration should not set enrollment mode.
+ EXPECT_EQ(DEVICE_MODE_UNKNOWN, data_store_->device_mode());
// Calling FetchToken() again should result in a new token being fetched.
successful_registration_response_.mutable_register_response()->
@@ -120,7 +130,7 @@ TEST_F(DeviceTokenFetcherTest, FetchToken) {
CreateJob(DeviceManagementRequestJob::TYPE_REGISTRATION))
.WillOnce(service_.SucceedJob(successful_registration_response_));
EXPECT_CALL(observer_, OnDeviceTokenChanged());
- FetchToken(&fetcher);
+ FetchToken(&fetcher, data_store_.get());
loop_.RunAllPending();
Mock::VerifyAndClearExpectations(&observer_);
std::string token2 = data_store_->device_token();
@@ -128,6 +138,43 @@ TEST_F(DeviceTokenFetcherTest, FetchToken) {
EXPECT_NE(token, token2);
}
+TEST_F(DeviceTokenFetcherTest, FetchDeviceToken) {
+ testing::InSequence s;
+ scoped_ptr<CloudPolicyDataStore> data_store(
+ CloudPolicyDataStore::CreateForDevicePolicies());
+ SetUpSuccessfulRegistrationExpectation(false);
+ DeviceTokenFetcher fetcher(&service_, cache_.get(), data_store.get(),
+ &notifier_);
+ EXPECT_EQ("", data_store->device_token());
+ EXPECT_EQ(DEVICE_MODE_UNKNOWN, data_store->device_mode());
+ FetchToken(&fetcher, data_store.get());
+ loop_.RunAllPending();
+ EXPECT_NE("", data_store->device_token());
+ // For device registrations, the fetcher needs to determine device mode.
+ EXPECT_EQ(DEVICE_MODE_ENTERPRISE, data_store->device_mode());
+}
+
+// TODO(pastarmovj): This test must be changed in accordance with
+// http://crosbug.com/26624.
+TEST_F(DeviceTokenFetcherTest, FetchDeviceTokenMissingMode) {
+ testing::InSequence s;
+ scoped_ptr<CloudPolicyDataStore> data_store(
+ CloudPolicyDataStore::CreateForDevicePolicies());
+ SetUpSuccessfulRegistrationExpectation(false);
+ DeviceTokenFetcher fetcher(&service_, cache_.get(), data_store.get(),
+ &notifier_);
+ EXPECT_EQ("", data_store->device_token());
+ EXPECT_EQ(DEVICE_MODE_UNKNOWN, data_store->device_mode());
+ successful_registration_response_.mutable_register_response()->
+ clear_enrollment_type();
+ FetchToken(&fetcher, data_store.get());
+ loop_.RunAllPending();
+ Mock::VerifyAndClearExpectations(&observer_);
+ EXPECT_NE("", data_store->device_token());
+ // TODO(pastarmovj): Modify when http://crosbug.com/26624 is resolved.
+ EXPECT_EQ(DEVICE_MODE_ENTERPRISE, data_store->device_mode());
+}
+
TEST_F(DeviceTokenFetcherTest, RetryOnError) {
testing::InSequence s;
EXPECT_CALL(service_,
@@ -137,7 +184,7 @@ TEST_F(DeviceTokenFetcherTest, RetryOnError) {
DeviceTokenFetcher fetcher(&service_, cache_.get(), data_store_.get(),
&notifier_, new DummyWorkScheduler);
EXPECT_CALL(observer_, OnDeviceTokenChanged());
- FetchToken(&fetcher);
+ FetchToken(&fetcher, data_store_.get());
loop_.RunAllPending();
Mock::VerifyAndClearExpectations(&observer_);
EXPECT_NE("", data_store_->device_token());
@@ -151,7 +198,7 @@ TEST_F(DeviceTokenFetcherTest, UnmanagedDevice) {
DeviceTokenFetcher fetcher(&service_, cache_.get(), data_store_.get(),
&notifier_);
EXPECT_CALL(observer_, OnDeviceTokenChanged()).Times(0);
- FetchToken(&fetcher);
+ FetchToken(&fetcher, data_store_.get());
loop_.RunAllPending();
Mock::VerifyAndClearExpectations(&observer_);
EXPECT_EQ("", data_store_->device_token());
@@ -173,7 +220,7 @@ TEST_F(DeviceTokenFetcherTest, DontSetFetchingDoneWithoutPolicyFetch) {
EXPECT_CALL(observer_, OnDeviceTokenChanged());
DeviceTokenFetcher fetcher(&service_, cache_.get(), data_store_.get(),
&notifier_);
- FetchToken(&fetcher);
+ FetchToken(&fetcher, data_store_.get());
loop_.RunAllPending();
// On successful token fetching the cache isn't set to ready, since the next
// step is to fetch policy. Only failures to fetch the token should make
@@ -196,17 +243,14 @@ TEST_F(DeviceTokenFetcherTest, SetFetchingDoneOnFailures) {
.WillOnce(service_.FailJob(DM_STATUS_REQUEST_FAILED));
DeviceTokenFetcher fetcher(&service_, cache_.get(), data_store_.get(),
&notifier_);
- FetchToken(&fetcher);
+ FetchToken(&fetcher, data_store_.get());
loop_.RunAllPending();
// This is the opposite case of DontSetFetchingDone1.
EXPECT_TRUE(cache_->IsReady());
}
TEST_F(DeviceTokenFetcherTest, SetKnownMachineId) {
- EXPECT_CALL(service_,
- CreateJob(DeviceManagementRequestJob::TYPE_REGISTRATION))
- .WillOnce(service_.SucceedJob(successful_registration_response_));
- EXPECT_CALL(service_, StartJob(_)).WillOnce(VerifyRegisterRequest(true));
+ SetUpSuccessfulRegistrationExpectation(true);
DeviceTokenFetcher fetcher(&service_, cache_.get(), data_store_.get(),
&notifier_);
@@ -214,7 +258,7 @@ TEST_F(DeviceTokenFetcherTest, SetKnownMachineId) {
EXPECT_EQ("", data_store_->device_token());
data_store_->set_known_machine_id(true);
- FetchToken(&fetcher);
+ FetchToken(&fetcher, data_store_.get());
loop_.RunAllPending();
Mock::VerifyAndClearExpectations(&observer_);
« no previous file with comments | « chrome/browser/policy/device_token_fetcher.cc ('k') | chrome/browser/policy/enterprise_install_attributes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698