BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / download / download_dir_policy_handler_unittest.cc
blobd713ba7bcef37cdb1fff827a1acb41d247bbb0d8
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
3 // found in the LICENSE file.
5 #include <string>
7 #include "base/compiler_specific.h"
8 #include "base/files/file_path.h"
9 #include "base/values.h"
10 #include "chrome/browser/download/download_dir_policy_handler.h"
11 #include "chrome/browser/download/download_prefs.h"
12 #include "chrome/common/pref_names.h"
13 #include "components/drive/drive_pref_names.h"
14 #include "components/policy/core/browser/configuration_policy_handler_parameters.h"
15 #include "components/policy/core/browser/configuration_policy_pref_store.h"
16 #include "components/policy/core/browser/configuration_policy_pref_store_test.h"
17 #include "components/policy/core/common/policy_details.h"
18 #include "components/policy/core/common/policy_map.h"
19 #include "components/policy/core/common/policy_types.h"
20 #include "policy/policy_constants.h"
22 #if defined(OS_CHROMEOS)
23 #include "chrome/browser/chromeos/drive/file_system_util.h"
24 #endif
26 namespace {
28 const char* kUserIDHash = "deadbeef";
30 #if defined(OS_CHROMEOS)
31 const char* kDriveNamePolicyVariableName = "${google_drive}";
32 const base::FilePath::CharType* kRootRelativeToDriveMount =
33 FILE_PATH_LITERAL("root");
34 const char* kRelativeToDriveRoot = "/home/";
36 std::string GetExpectedDownloadDirectory() {
37 return drive::util::GetDriveMountPointPathForUserIdHash(kUserIDHash)
38 .Append(kRootRelativeToDriveMount)
39 .value();
42 #endif
44 } // namespace
46 class DownloadDirPolicyHandlerTest
47 : public policy::ConfigurationPolicyPrefStoreTest {
48 public:
49 void SetUp() override {
50 recommended_store_ = new policy::ConfigurationPolicyPrefStore(
51 policy_service_.get(),
52 &handler_list_,
53 policy::POLICY_LEVEL_RECOMMENDED);
54 handler_list_.AddHandler(
55 make_scoped_ptr<policy::ConfigurationPolicyHandler>(
56 new DownloadDirPolicyHandler));
59 void PopulatePolicyHandlerParameters(
60 policy::PolicyHandlerParameters* parameters) override {
61 parameters->user_id_hash = kUserIDHash;
64 protected:
65 scoped_refptr<policy::ConfigurationPolicyPrefStore> recommended_store_;
68 #if !defined(OS_CHROMEOS)
69 TEST_F(DownloadDirPolicyHandlerTest, SetDownloadDirectory) {
70 policy::PolicyMap policy;
71 EXPECT_FALSE(store_->GetValue(prefs::kPromptForDownload, NULL));
72 policy.Set(policy::key::kDownloadDirectory,
73 policy::POLICY_LEVEL_MANDATORY,
74 policy::POLICY_SCOPE_USER,
75 policy::POLICY_SOURCE_CLOUD,
76 new base::StringValue(std::string()),
77 NULL);
78 UpdateProviderPolicy(policy);
80 // Setting a DownloadDirectory should disable the PromptForDownload pref.
81 const base::Value* value = NULL;
82 EXPECT_TRUE(store_->GetValue(prefs::kPromptForDownload, &value));
83 ASSERT_TRUE(value);
84 bool prompt_for_download = true;
85 bool result = value->GetAsBoolean(&prompt_for_download);
86 ASSERT_TRUE(result);
87 EXPECT_FALSE(prompt_for_download);
89 #endif
91 #if defined(OS_CHROMEOS)
92 TEST_F(DownloadDirPolicyHandlerTest, SetDownloadToDrive) {
93 EXPECT_FALSE(store_->GetValue(prefs::kPromptForDownload, NULL));
95 policy::PolicyMap policy;
96 policy.Set(policy::key::kDownloadDirectory,
97 policy::POLICY_LEVEL_MANDATORY,
98 policy::POLICY_SCOPE_USER,
99 policy::POLICY_SOURCE_CLOUD,
100 new base::StringValue(kDriveNamePolicyVariableName),
101 NULL);
102 UpdateProviderPolicy(policy);
104 const base::Value* value = NULL;
105 bool prompt_for_download;
106 EXPECT_TRUE(store_->GetValue(prefs::kPromptForDownload, &value));
107 EXPECT_TRUE(value);
108 EXPECT_TRUE(value->GetAsBoolean(&prompt_for_download));
109 EXPECT_FALSE(prompt_for_download);
111 bool disable_drive;
112 EXPECT_TRUE(store_->GetValue(drive::prefs::kDisableDrive, &value));
113 EXPECT_TRUE(value);
114 EXPECT_TRUE(value->GetAsBoolean(&disable_drive));
115 EXPECT_FALSE(disable_drive);
117 std::string download_directory;
118 EXPECT_TRUE(store_->GetValue(prefs::kDownloadDefaultDirectory, &value));
119 EXPECT_TRUE(value);
120 EXPECT_TRUE(value->GetAsString(&download_directory));
121 EXPECT_EQ(GetExpectedDownloadDirectory(), download_directory);
123 policy.Set(policy::key::kDownloadDirectory,
124 policy::POLICY_LEVEL_MANDATORY,
125 policy::POLICY_SCOPE_USER,
126 policy::POLICY_SOURCE_CLOUD,
127 new base::StringValue(kUserIDHash),
128 NULL);
129 UpdateProviderPolicy(policy);
130 EXPECT_FALSE(recommended_store_->GetValue(drive::prefs::kDisableDrive, NULL));
132 policy.Set(policy::key::kDownloadDirectory,
133 policy::POLICY_LEVEL_RECOMMENDED,
134 policy::POLICY_SCOPE_USER,
135 policy::POLICY_SOURCE_CLOUD,
136 new base::StringValue(std::string(kDriveNamePolicyVariableName) +
137 kRelativeToDriveRoot),
138 NULL);
139 UpdateProviderPolicy(policy);
141 EXPECT_FALSE(recommended_store_->GetValue(prefs::kPromptForDownload, NULL));
142 EXPECT_FALSE(recommended_store_->GetValue(drive::prefs::kDisableDrive, NULL));
144 EXPECT_TRUE(
145 recommended_store_->GetValue(prefs::kDownloadDefaultDirectory, &value));
146 EXPECT_TRUE(value);
147 EXPECT_TRUE(value->GetAsString(&download_directory));
148 EXPECT_EQ(GetExpectedDownloadDirectory() + kRelativeToDriveRoot,
149 download_directory);
151 policy.Set(policy::key::kDownloadDirectory,
152 policy::POLICY_LEVEL_RECOMMENDED,
153 policy::POLICY_SCOPE_USER,
154 policy::POLICY_SOURCE_CLOUD,
155 new base::StringValue(kUserIDHash),
156 NULL);
157 UpdateProviderPolicy(policy);
159 EXPECT_FALSE(recommended_store_->GetValue(prefs::kPromptForDownload, NULL));
160 EXPECT_FALSE(recommended_store_->GetValue(drive::prefs::kDisableDrive, NULL));
162 EXPECT_TRUE(
163 recommended_store_->GetValue(prefs::kDownloadDefaultDirectory, &value));
164 EXPECT_TRUE(value);
165 EXPECT_TRUE(value->GetAsString(&download_directory));
166 EXPECT_EQ(kUserIDHash, download_directory);
168 #endif