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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/download/download_dir_policy_handler.h" | 10 #include "chrome/browser/download/download_dir_policy_handler.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 scoped_refptr<policy::ConfigurationPolicyPrefStore> recommended_store_; | 65 scoped_refptr<policy::ConfigurationPolicyPrefStore> recommended_store_; |
66 }; | 66 }; |
67 | 67 |
68 #if !defined(OS_CHROMEOS) | 68 #if !defined(OS_CHROMEOS) |
69 TEST_F(DownloadDirPolicyHandlerTest, SetDownloadDirectory) { | 69 TEST_F(DownloadDirPolicyHandlerTest, SetDownloadDirectory) { |
70 policy::PolicyMap policy; | 70 policy::PolicyMap policy; |
71 EXPECT_FALSE(store_->GetValue(prefs::kPromptForDownload, NULL)); | 71 EXPECT_FALSE(store_->GetValue(prefs::kPromptForDownload, NULL)); |
72 policy.Set(policy::key::kDownloadDirectory, | 72 policy.Set(policy::key::kDownloadDirectory, |
73 policy::POLICY_LEVEL_MANDATORY, | 73 policy::POLICY_LEVEL_MANDATORY, |
74 policy::POLICY_SCOPE_USER, | 74 policy::POLICY_SCOPE_USER, |
75 policy::POLICY_SOURCE_CLOUD, | |
76 new base::StringValue(std::string()), | 75 new base::StringValue(std::string()), |
77 NULL); | 76 NULL); |
78 UpdateProviderPolicy(policy); | 77 UpdateProviderPolicy(policy); |
79 | 78 |
80 // Setting a DownloadDirectory should disable the PromptForDownload pref. | 79 // Setting a DownloadDirectory should disable the PromptForDownload pref. |
81 const base::Value* value = NULL; | 80 const base::Value* value = NULL; |
82 EXPECT_TRUE(store_->GetValue(prefs::kPromptForDownload, &value)); | 81 EXPECT_TRUE(store_->GetValue(prefs::kPromptForDownload, &value)); |
83 ASSERT_TRUE(value); | 82 ASSERT_TRUE(value); |
84 bool prompt_for_download = true; | 83 bool prompt_for_download = true; |
85 bool result = value->GetAsBoolean(&prompt_for_download); | 84 bool result = value->GetAsBoolean(&prompt_for_download); |
86 ASSERT_TRUE(result); | 85 ASSERT_TRUE(result); |
87 EXPECT_FALSE(prompt_for_download); | 86 EXPECT_FALSE(prompt_for_download); |
88 } | 87 } |
89 #endif | 88 #endif |
90 | 89 |
91 #if defined(OS_CHROMEOS) | 90 #if defined(OS_CHROMEOS) |
92 TEST_F(DownloadDirPolicyHandlerTest, SetDownloadToDrive) { | 91 TEST_F(DownloadDirPolicyHandlerTest, SetDownloadToDrive) { |
93 EXPECT_FALSE(store_->GetValue(prefs::kPromptForDownload, NULL)); | 92 EXPECT_FALSE(store_->GetValue(prefs::kPromptForDownload, NULL)); |
94 | 93 |
95 policy::PolicyMap policy; | 94 policy::PolicyMap policy; |
96 policy.Set(policy::key::kDownloadDirectory, | 95 policy.Set(policy::key::kDownloadDirectory, |
97 policy::POLICY_LEVEL_MANDATORY, | 96 policy::POLICY_LEVEL_MANDATORY, |
98 policy::POLICY_SCOPE_USER, | 97 policy::POLICY_SCOPE_USER, |
99 policy::POLICY_SOURCE_CLOUD, | |
100 new base::StringValue(kDriveNamePolicyVariableName), | 98 new base::StringValue(kDriveNamePolicyVariableName), |
101 NULL); | 99 NULL); |
102 UpdateProviderPolicy(policy); | 100 UpdateProviderPolicy(policy); |
103 | 101 |
104 const base::Value* value = NULL; | 102 const base::Value* value = NULL; |
105 bool prompt_for_download; | 103 bool prompt_for_download; |
106 EXPECT_TRUE(store_->GetValue(prefs::kPromptForDownload, &value)); | 104 EXPECT_TRUE(store_->GetValue(prefs::kPromptForDownload, &value)); |
107 EXPECT_TRUE(value); | 105 EXPECT_TRUE(value); |
108 EXPECT_TRUE(value->GetAsBoolean(&prompt_for_download)); | 106 EXPECT_TRUE(value->GetAsBoolean(&prompt_for_download)); |
109 EXPECT_FALSE(prompt_for_download); | 107 EXPECT_FALSE(prompt_for_download); |
110 | 108 |
111 bool disable_drive; | 109 bool disable_drive; |
112 EXPECT_TRUE(store_->GetValue(drive::prefs::kDisableDrive, &value)); | 110 EXPECT_TRUE(store_->GetValue(drive::prefs::kDisableDrive, &value)); |
113 EXPECT_TRUE(value); | 111 EXPECT_TRUE(value); |
114 EXPECT_TRUE(value->GetAsBoolean(&disable_drive)); | 112 EXPECT_TRUE(value->GetAsBoolean(&disable_drive)); |
115 EXPECT_FALSE(disable_drive); | 113 EXPECT_FALSE(disable_drive); |
116 | 114 |
117 std::string download_directory; | 115 std::string download_directory; |
118 EXPECT_TRUE(store_->GetValue(prefs::kDownloadDefaultDirectory, &value)); | 116 EXPECT_TRUE(store_->GetValue(prefs::kDownloadDefaultDirectory, &value)); |
119 EXPECT_TRUE(value); | 117 EXPECT_TRUE(value); |
120 EXPECT_TRUE(value->GetAsString(&download_directory)); | 118 EXPECT_TRUE(value->GetAsString(&download_directory)); |
121 EXPECT_EQ(GetExpectedDownloadDirectory(), download_directory); | 119 EXPECT_EQ(GetExpectedDownloadDirectory(), download_directory); |
122 | 120 |
123 policy.Set(policy::key::kDownloadDirectory, | 121 policy.Set(policy::key::kDownloadDirectory, |
124 policy::POLICY_LEVEL_MANDATORY, | 122 policy::POLICY_LEVEL_MANDATORY, |
125 policy::POLICY_SCOPE_USER, | 123 policy::POLICY_SCOPE_USER, |
126 policy::POLICY_SOURCE_CLOUD, | |
127 new base::StringValue(kUserIDHash), | 124 new base::StringValue(kUserIDHash), |
128 NULL); | 125 NULL); |
129 UpdateProviderPolicy(policy); | 126 UpdateProviderPolicy(policy); |
130 EXPECT_FALSE(recommended_store_->GetValue(drive::prefs::kDisableDrive, NULL)); | 127 EXPECT_FALSE(recommended_store_->GetValue(drive::prefs::kDisableDrive, NULL)); |
131 | 128 |
132 policy.Set(policy::key::kDownloadDirectory, | 129 policy.Set(policy::key::kDownloadDirectory, |
133 policy::POLICY_LEVEL_RECOMMENDED, | 130 policy::POLICY_LEVEL_RECOMMENDED, |
134 policy::POLICY_SCOPE_USER, | 131 policy::POLICY_SCOPE_USER, |
135 policy::POLICY_SOURCE_CLOUD, | |
136 new base::StringValue(std::string(kDriveNamePolicyVariableName) + | 132 new base::StringValue(std::string(kDriveNamePolicyVariableName) + |
137 kRelativeToDriveRoot), | 133 kRelativeToDriveRoot), |
138 NULL); | 134 NULL); |
139 UpdateProviderPolicy(policy); | 135 UpdateProviderPolicy(policy); |
140 | 136 |
141 EXPECT_FALSE(recommended_store_->GetValue(prefs::kPromptForDownload, NULL)); | 137 EXPECT_FALSE(recommended_store_->GetValue(prefs::kPromptForDownload, NULL)); |
142 EXPECT_FALSE(recommended_store_->GetValue(drive::prefs::kDisableDrive, NULL)); | 138 EXPECT_FALSE(recommended_store_->GetValue(drive::prefs::kDisableDrive, NULL)); |
143 | 139 |
144 EXPECT_TRUE( | 140 EXPECT_TRUE( |
145 recommended_store_->GetValue(prefs::kDownloadDefaultDirectory, &value)); | 141 recommended_store_->GetValue(prefs::kDownloadDefaultDirectory, &value)); |
146 EXPECT_TRUE(value); | 142 EXPECT_TRUE(value); |
147 EXPECT_TRUE(value->GetAsString(&download_directory)); | 143 EXPECT_TRUE(value->GetAsString(&download_directory)); |
148 EXPECT_EQ(GetExpectedDownloadDirectory() + kRelativeToDriveRoot, | 144 EXPECT_EQ(GetExpectedDownloadDirectory() + kRelativeToDriveRoot, |
149 download_directory); | 145 download_directory); |
150 | 146 |
151 policy.Set(policy::key::kDownloadDirectory, | 147 policy.Set(policy::key::kDownloadDirectory, |
152 policy::POLICY_LEVEL_RECOMMENDED, | 148 policy::POLICY_LEVEL_RECOMMENDED, |
153 policy::POLICY_SCOPE_USER, | 149 policy::POLICY_SCOPE_USER, |
154 policy::POLICY_SOURCE_CLOUD, | |
155 new base::StringValue(kUserIDHash), | 150 new base::StringValue(kUserIDHash), |
156 NULL); | 151 NULL); |
157 UpdateProviderPolicy(policy); | 152 UpdateProviderPolicy(policy); |
158 | 153 |
159 EXPECT_FALSE(recommended_store_->GetValue(prefs::kPromptForDownload, NULL)); | 154 EXPECT_FALSE(recommended_store_->GetValue(prefs::kPromptForDownload, NULL)); |
160 EXPECT_FALSE(recommended_store_->GetValue(drive::prefs::kDisableDrive, NULL)); | 155 EXPECT_FALSE(recommended_store_->GetValue(drive::prefs::kDisableDrive, NULL)); |
161 | 156 |
162 EXPECT_TRUE( | 157 EXPECT_TRUE( |
163 recommended_store_->GetValue(prefs::kDownloadDefaultDirectory, &value)); | 158 recommended_store_->GetValue(prefs::kDownloadDefaultDirectory, &value)); |
164 EXPECT_TRUE(value); | 159 EXPECT_TRUE(value); |
165 EXPECT_TRUE(value->GetAsString(&download_directory)); | 160 EXPECT_TRUE(value->GetAsString(&download_directory)); |
166 EXPECT_EQ(kUserIDHash, download_directory); | 161 EXPECT_EQ(kUserIDHash, download_directory); |
167 } | 162 } |
168 #endif | 163 #endif |
OLD | NEW |