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

Side by Side Diff: chrome/browser/download/download_dir_policy_handler_unittest.cc

Issue 197013007: Set drive as the default download folder (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes test failure and enables a new test Created 6 years, 9 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 unified diff | Download patch
OLDNEW
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>
6
7 #include "base/compiler_specific.h"
8 #include "base/files/file_path.h"
5 #include "base/values.h" 9 #include "base/values.h"
6 #include "chrome/browser/download/download_dir_policy_handler.h" 10 #include "chrome/browser/download/download_dir_policy_handler.h"
7 #include "chrome/browser/download/download_prefs.h" 11 #include "chrome/browser/download/download_prefs.h"
8 #include "chrome/common/pref_names.h" 12 #include "chrome/common/pref_names.h"
13 #include "components/policy/core/browser/configuration_policy_handler_parameters .h"
9 #include "components/policy/core/browser/configuration_policy_pref_store.h" 14 #include "components/policy/core/browser/configuration_policy_pref_store.h"
10 #include "components/policy/core/browser/configuration_policy_pref_store_test.h" 15 #include "components/policy/core/browser/configuration_policy_pref_store_test.h"
16 #include "components/policy/core/common/policy_details.h"
11 #include "components/policy/core/common/policy_map.h" 17 #include "components/policy/core/common/policy_map.h"
18 #include "components/policy/core/common/policy_types.h"
12 #include "policy/policy_constants.h" 19 #include "policy/policy_constants.h"
13 20
21 #if defined(OS_CHROMEOS)
22 #include "chrome/browser/chromeos/drive/file_system_util.h"
23 #endif
24
25 namespace {
26
27 const char* kUserIDHash = "deadbeef";
28
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/";
34
35 std::string GetExpectedDownloadDirectory() {
36 return drive::util::GetDriveMountPointPathForUserIdHash(kUserIDHash)
37 .Append(kRootRelativeToDriveMount)
38 .value();
39 }
40
41 #endif
42
43 } // namespace
44
14 class DownloadDirPolicyHandlerTest 45 class DownloadDirPolicyHandlerTest
15 : public policy::ConfigurationPolicyPrefStoreTest { 46 : public policy::ConfigurationPolicyPrefStoreTest {
16 public: 47 public:
17 virtual void SetUp() OVERRIDE { 48 virtual void SetUp() OVERRIDE {
49 recommended_store_ = new policy::ConfigurationPolicyPrefStore(
50 policy_service_.get(),
51 &handler_list_,
52 policy::POLICY_LEVEL_RECOMMENDED);
18 handler_list_.AddHandler( 53 handler_list_.AddHandler(
19 make_scoped_ptr<policy::ConfigurationPolicyHandler>( 54 make_scoped_ptr<policy::ConfigurationPolicyHandler>(
20 new DownloadDirPolicyHandler)); 55 new DownloadDirPolicyHandler));
21 } 56 }
57
58 virtual void PopulatePolicyHandlerParameters(
59 policy::PolicyHandlerParameters* parameters) OVERRIDE {
60 parameters->user_id_hash = kUserIDHash;
61 }
62
63 protected:
64 scoped_refptr<policy::ConfigurationPolicyPrefStore> recommended_store_;
22 }; 65 };
23 66
67 #if !defined(OS_CHROMEOS)
24 TEST_F(DownloadDirPolicyHandlerTest, SetDownloadDirectory) { 68 TEST_F(DownloadDirPolicyHandlerTest, SetDownloadDirectory) {
25 policy::PolicyMap policy; 69 policy::PolicyMap policy;
26 EXPECT_FALSE(store_->GetValue(prefs::kPromptForDownload, NULL)); 70 EXPECT_FALSE(store_->GetValue(prefs::kPromptForDownload, NULL));
27 policy.Set(policy::key::kDownloadDirectory, 71 policy.Set(policy::key::kDownloadDirectory,
28 policy::POLICY_LEVEL_MANDATORY, 72 policy::POLICY_LEVEL_MANDATORY,
29 policy::POLICY_SCOPE_USER, 73 policy::POLICY_SCOPE_USER,
30 base::Value::CreateStringValue(std::string()), 74 base::Value::CreateStringValue(std::string()),
31 NULL); 75 NULL);
32 UpdateProviderPolicy(policy); 76 UpdateProviderPolicy(policy);
33 77
34 // Setting a DownloadDirectory should disable the PromptForDownload pref. 78 // Setting a DownloadDirectory should disable the PromptForDownload pref.
35 const base::Value* value = NULL; 79 const base::Value* value = NULL;
36 EXPECT_TRUE(store_->GetValue(prefs::kPromptForDownload, &value)); 80 EXPECT_TRUE(store_->GetValue(prefs::kPromptForDownload, &value));
37 ASSERT_TRUE(value); 81 ASSERT_TRUE(value);
38 bool prompt_for_download = true; 82 bool prompt_for_download = true;
39 bool result = value->GetAsBoolean(&prompt_for_download); 83 bool result = value->GetAsBoolean(&prompt_for_download);
40 ASSERT_TRUE(result); 84 ASSERT_TRUE(result);
41 EXPECT_FALSE(prompt_for_download); 85 EXPECT_FALSE(prompt_for_download);
42 } 86 }
87 #endif
88
89 #if defined(OS_CHROMEOS)
90 TEST_F(DownloadDirPolicyHandlerTest, SetDownloadToDrive) {
91 EXPECT_FALSE(store_->GetValue(prefs::kPromptForDownload, NULL));
92
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);
100
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);
107
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);
113
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);
121
122 EXPECT_TRUE(recommended_store_->GetValue(prefs::kPromptForDownload, &value));
123 EXPECT_TRUE(value);
124 EXPECT_TRUE(value->GetAsBoolean(&prompt_for_download));
125 EXPECT_FALSE(prompt_for_download);
126
127 EXPECT_TRUE(
128 recommended_store_->GetValue(prefs::kDownloadDefaultDirectory, &value));
129 EXPECT_TRUE(value);
130 EXPECT_TRUE(value->GetAsString(&download_directory));
131 EXPECT_EQ(GetExpectedDownloadDirectory() + kRelativeToDriveRoot,
132 download_directory);
133 }
134 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698