OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/values.h" | 5 #include "base/values.h" |
6 #include "chrome/browser/download/download_dir_policy_handler.h" | 6 #include "chrome/browser/download/download_dir_policy_handler.h" |
7 #include "chrome/browser/download/download_prefs.h" | 7 #include "chrome/browser/download/download_prefs.h" |
8 #include "chrome/browser/policy/configuration_policy_pref_store_test.h" | 8 #include "chrome/browser/policy/configuration_policy_pref_store_test.h" |
9 #include "chrome/common/pref_names.h" | 9 #include "chrome/common/pref_names.h" |
10 #include "chrome/test/base/scoped_testing_local_state.h" | |
10 #include "components/policy/core/browser/configuration_policy_pref_store.h" | 11 #include "components/policy/core/browser/configuration_policy_pref_store.h" |
11 #include "components/policy/core/common/policy_map.h" | 12 #include "components/policy/core/common/policy_map.h" |
12 #include "policy/policy_constants.h" | 13 #include "policy/policy_constants.h" |
13 | 14 |
15 #if defined(OS_CHROMEOS) | |
16 #include "chrome/browser/chromeos/login/fake_user_manager.h" | |
17 #include "chrome/browser/chromeos/login/user.h" | |
18 #endif | |
19 | |
14 class DownloadDirPolicyHandlerTest | 20 class DownloadDirPolicyHandlerTest |
15 : public policy::ConfigurationPolicyPrefStoreTest { | 21 : public policy::ConfigurationPolicyPrefStoreTest { |
16 public: | 22 public: |
17 virtual void SetUp() OVERRIDE { | 23 virtual void SetUp() OVERRIDE { |
18 handler_list_.AddHandler( | 24 handler_list_.AddHandler( |
19 make_scoped_ptr<policy::ConfigurationPolicyHandler>( | 25 make_scoped_ptr<policy::ConfigurationPolicyHandler>( |
20 new DownloadDirPolicyHandler)); | 26 new DownloadDirPolicyHandler)); |
21 } | 27 } |
28 | |
29 bool GetBooleanFromStore(const std::string& key) { | |
bartfab (slow)
2014/03/13 13:20:00
Nit: #include <string>
| |
30 const base::Value* value = NULL; | |
31 bool return_flag; | |
bartfab (slow)
2014/03/13 13:20:00
Nit: How about "boolean_value" instead?
| |
32 EXPECT_TRUE(store_->GetValue(key, &value)); | |
33 EXPECT_TRUE(value != NULL); | |
bartfab (slow)
2014/03/13 13:20:00
Nit: No need for "!= NULL". EXPECT_TRUE(value) is
| |
34 EXPECT_TRUE(value->GetAsBoolean(&return_flag)); | |
35 return return_flag; | |
36 } | |
37 | |
38 bool StringValueEquals(const std::string& key, const std::string& expected) { | |
bartfab (slow)
2014/03/13 13:20:00
Nit 1: Better implement a GetStringFromStore() and
| |
39 const base::Value* value = NULL; | |
40 std::string string_value; | |
41 EXPECT_TRUE(store_->GetValue(key, &value)); | |
42 EXPECT_TRUE(value != NULL); | |
bartfab (slow)
2014/03/13 13:20:00
Nit: No need for "!= NULL". EXPECT_TRUE(value) is
| |
43 EXPECT_TRUE(value->GetAsString(&string_value)); | |
44 return string_value.compare(expected) == 0; | |
bartfab (slow)
2014/03/13 13:20:00
Nit: std::string provides an operator==(), so you
| |
45 } | |
22 }; | 46 }; |
23 | 47 |
24 TEST_F(DownloadDirPolicyHandlerTest, SetDownloadDirectory) { | 48 TEST_F(DownloadDirPolicyHandlerTest, SetDownloadDirectory) { |
25 policy::PolicyMap policy; | 49 policy::PolicyMap policy; |
26 EXPECT_FALSE(store_->GetValue(prefs::kPromptForDownload, NULL)); | 50 EXPECT_FALSE(store_->GetValue(prefs::kPromptForDownload, NULL)); |
27 policy.Set(policy::key::kDownloadDirectory, | 51 policy.Set(policy::key::kDownloadDirectory, |
28 policy::POLICY_LEVEL_MANDATORY, | 52 policy::POLICY_LEVEL_MANDATORY, |
29 policy::POLICY_SCOPE_USER, | 53 policy::POLICY_SCOPE_USER, |
30 base::Value::CreateStringValue(std::string()), | 54 base::Value::CreateStringValue(std::string()), |
31 NULL); | 55 NULL); |
32 UpdateProviderPolicy(policy); | 56 UpdateProviderPolicy(policy); |
33 | 57 |
34 // Setting a DownloadDirectory should disable the PromptForDownload pref. | 58 // Setting a DownloadDirectory should disable the PromptForDownload pref. |
35 const base::Value* value = NULL; | 59 const base::Value* value = NULL; |
36 EXPECT_TRUE(store_->GetValue(prefs::kPromptForDownload, &value)); | 60 EXPECT_TRUE(store_->GetValue(prefs::kPromptForDownload, &value)); |
37 ASSERT_TRUE(value); | 61 ASSERT_TRUE(value); |
38 bool prompt_for_download = true; | 62 bool prompt_for_download = true; |
39 bool result = value->GetAsBoolean(&prompt_for_download); | 63 bool result = value->GetAsBoolean(&prompt_for_download); |
40 ASSERT_TRUE(result); | 64 ASSERT_TRUE(result); |
41 EXPECT_FALSE(prompt_for_download); | 65 EXPECT_FALSE(prompt_for_download); |
42 } | 66 } |
67 | |
68 #if 0 // defined(OS_CHROMEOS) | |
kinaba
2014/03/13 03:56:50
could this test be enabled?
| |
69 TEST_F(DownloadDirPolicyHandlerTest, SetDownloadToDrive) { | |
70 const char* kDriveNamePolicyVarName = "${drive_name}"; | |
71 | |
72 policy::PolicyMap policy; | |
73 EXPECT_FALSE(store_->GetValue(prefs::kPromptForDownload, NULL)); | |
74 policy.Set(policy::key::kDownloadDirectory, | |
75 policy::POLICY_LEVEL_MANDATORY, | |
bartfab (slow)
2014/03/13 13:20:00
Now that the policy supports both mandatory and re
| |
76 policy::POLICY_SCOPE_MACHINE, | |
bartfab (slow)
2014/03/13 13:20:00
I see no reason to test this with machine and user
| |
77 base::Value::CreateStringValue(kDriveNamePolicyVarName), | |
bartfab (slow)
2014/03/13 13:20:00
Nit: CreateStringValue() is deprecated. Use "new b
| |
78 NULL); | |
79 UpdateProviderPolicy(policy); | |
80 | |
81 EXPECT_FALSE(GetBooleanFromStore(prefs::kPromptForDownload)); | |
82 EXPECT_TRUE(StringValueEquals(prefs::kDownloadDefaultDirectory, "")); | |
83 | |
84 policy.Set(policy::key::kDownloadDirectory, | |
85 policy::POLICY_LEVEL_MANDATORY, | |
86 policy::POLICY_SCOPE_USER, | |
87 base::Value::CreateStringValue(kDriveNamePolicyVarName), | |
88 NULL); | |
89 UpdateProviderPolicy(policy); | |
90 | |
91 EXPECT_TRUE(GetBooleanFromStore(prefs::kPromptForDownload)); | |
92 EXPECT_TRUE(StringValueEquals(prefs::kDownloadDefaultDirectory, "")); | |
93 | |
94 chromeos::FakeUserManager* user_manager = new chromeos::FakeUserManager(); | |
95 chromeos::ScopedUserManagerEnabler user_manager_enabler(user_manager); | |
bartfab (slow)
2014/03/13 13:20:00
Nit: #include "chrome/browser/chromeos/login/user_
| |
96 const char test_user_email[] = "test_user@example.com"; | |
bartfab (slow)
2014/03/13 13:20:00
Nit 1: s/email/user_id/
Nit 2: Place constants in
| |
97 user_manager->AddUser(test_user_email); | |
98 user_manager->LoginUser(test_user_email); | |
99 } | |
bartfab (slow)
2014/03/13 13:20:00
This test looks incomplete. It logs in as a test u
| |
100 #endif | |
OLD | NEW |