Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / download / download_dir_policy_handler_unittest.cc
blob2729242d0fe0f1e34c5af1341956bcc88f34b41d
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/policy/core/browser/configuration_policy_handler_parameters.h"
14 #include "components/policy/core/browser/configuration_policy_pref_store.h"
15 #include "components/policy/core/browser/configuration_policy_pref_store_test.h"
16 #include "components/policy/core/common/policy_details.h"
17 #include "components/policy/core/common/policy_map.h"
18 #include "components/policy/core/common/policy_types.h"
19 #include "policy/policy_constants.h"
21 #if defined(OS_CHROMEOS)
22 #include "chrome/browser/chromeos/drive/file_system_util.h"
23 #endif
25 namespace {
27 const char* kUserIDHash = "deadbeef";
29 #if defined(OS_CHROMEOS)
30 const char* kDriveNamePolicyVariableName = "${google_drive}";
31 const base::FilePath::CharType* kRootRelativeToDriveMount =
32 FILE_PATH_LITERAL("root");
33 const char* kRelativeToDriveRoot = "/home/";
35 std::string GetExpectedDownloadDirectory() {
36 return drive::util::GetDriveMountPointPathForUserIdHash(kUserIDHash)
37 .Append(kRootRelativeToDriveMount)
38 .value();
41 #endif
43 } // namespace
45 class DownloadDirPolicyHandlerTest
46 : public policy::ConfigurationPolicyPrefStoreTest {
47 public:
48 virtual void SetUp() OVERRIDE {
49 recommended_store_ = new policy::ConfigurationPolicyPrefStore(
50 policy_service_.get(),
51 &handler_list_,
52 policy::POLICY_LEVEL_RECOMMENDED);
53 handler_list_.AddHandler(
54 make_scoped_ptr<policy::ConfigurationPolicyHandler>(
55 new DownloadDirPolicyHandler));
58 virtual void PopulatePolicyHandlerParameters(
59 policy::PolicyHandlerParameters* parameters) OVERRIDE {
60 parameters->user_id_hash = kUserIDHash;
63 protected:
64 scoped_refptr<policy::ConfigurationPolicyPrefStore> recommended_store_;
67 #if !defined(OS_CHROMEOS)
68 TEST_F(DownloadDirPolicyHandlerTest, SetDownloadDirectory) {
69 policy::PolicyMap policy;
70 EXPECT_FALSE(store_->GetValue(prefs::kPromptForDownload, NULL));
71 policy.Set(policy::key::kDownloadDirectory,
72 policy::POLICY_LEVEL_MANDATORY,
73 policy::POLICY_SCOPE_USER,
74 base::Value::CreateStringValue(std::string()),
75 NULL);
76 UpdateProviderPolicy(policy);
78 // Setting a DownloadDirectory should disable the PromptForDownload pref.
79 const base::Value* value = NULL;
80 EXPECT_TRUE(store_->GetValue(prefs::kPromptForDownload, &value));
81 ASSERT_TRUE(value);
82 bool prompt_for_download = true;
83 bool result = value->GetAsBoolean(&prompt_for_download);
84 ASSERT_TRUE(result);
85 EXPECT_FALSE(prompt_for_download);
87 #endif
89 #if defined(OS_CHROMEOS)
90 TEST_F(DownloadDirPolicyHandlerTest, SetDownloadToDrive) {
91 EXPECT_FALSE(store_->GetValue(prefs::kPromptForDownload, NULL));
93 policy::PolicyMap policy;
94 policy.Set(policy::key::kDownloadDirectory,
95 policy::POLICY_LEVEL_MANDATORY,
96 policy::POLICY_SCOPE_USER,
97 new base::StringValue(kDriveNamePolicyVariableName),
98 NULL);
99 UpdateProviderPolicy(policy);
101 const base::Value* value = NULL;
102 bool prompt_for_download;
103 EXPECT_TRUE(store_->GetValue(prefs::kPromptForDownload, &value));
104 EXPECT_TRUE(value);
105 EXPECT_TRUE(value->GetAsBoolean(&prompt_for_download));
106 EXPECT_FALSE(prompt_for_download);
108 std::string download_directory;
109 EXPECT_TRUE(store_->GetValue(prefs::kDownloadDefaultDirectory, &value));
110 EXPECT_TRUE(value);
111 EXPECT_TRUE(value->GetAsString(&download_directory));
112 EXPECT_EQ(GetExpectedDownloadDirectory(), download_directory);
114 policy.Set(policy::key::kDownloadDirectory,
115 policy::POLICY_LEVEL_RECOMMENDED,
116 policy::POLICY_SCOPE_USER,
117 new base::StringValue(std::string(kDriveNamePolicyVariableName) +
118 kRelativeToDriveRoot),
119 NULL);
120 UpdateProviderPolicy(policy);
122 EXPECT_FALSE(recommended_store_->GetValue(prefs::kPromptForDownload, NULL));
124 EXPECT_TRUE(
125 recommended_store_->GetValue(prefs::kDownloadDefaultDirectory, &value));
126 EXPECT_TRUE(value);
127 EXPECT_TRUE(value->GetAsString(&download_directory));
128 EXPECT_EQ(GetExpectedDownloadDirectory() + kRelativeToDriveRoot,
129 download_directory);
131 policy.Set(policy::key::kDownloadDirectory,
132 policy::POLICY_LEVEL_RECOMMENDED,
133 policy::POLICY_SCOPE_USER,
134 new base::StringValue(kUserIDHash),
135 NULL);
136 UpdateProviderPolicy(policy);
138 EXPECT_FALSE(recommended_store_->GetValue(prefs::kPromptForDownload, NULL));
140 EXPECT_TRUE(
141 recommended_store_->GetValue(prefs::kDownloadDefaultDirectory, &value));
142 EXPECT_TRUE(value);
143 EXPECT_TRUE(value->GetAsString(&download_directory));
144 EXPECT_EQ(kUserIDHash, download_directory);
146 #endif