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

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 build errors 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 #include <string>
bartfab (slow) 2014/03/14 13:43:45 Nit: Add blank line before.
4 5
6 #include "base/compiler_specific.h"
5 #include "base/values.h" 7 #include "base/values.h"
6 #include "chrome/browser/download/download_dir_policy_handler.h" 8 #include "chrome/browser/download/download_dir_policy_handler.h"
7 #include "chrome/browser/download/download_prefs.h" 9 #include "chrome/browser/download/download_prefs.h"
8 #include "chrome/common/pref_names.h" 10 #include "chrome/common/pref_names.h"
11 #include "chrome/test/base/scoped_testing_local_state.h"
12 #include "components/policy/core/browser/configuration_policy_handler_parameters .h"
9 #include "components/policy/core/browser/configuration_policy_pref_store.h" 13 #include "components/policy/core/browser/configuration_policy_pref_store.h"
10 #include "components/policy/core/browser/configuration_policy_pref_store_test.h" 14 #include "components/policy/core/browser/configuration_policy_pref_store_test.h"
11 #include "components/policy/core/common/policy_map.h" 15 #include "components/policy/core/common/policy_map.h"
12 #include "policy/policy_constants.h" 16 #include "policy/policy_constants.h"
13 17
18 namespace {
19
20 const char* kUserName = "dummy@downloaddirpolicyhandlertest.com";
bartfab (slow) 2014/03/14 13:43:45 Nit 1: s/downloaddirpolicyhandlertest.com/example.
21
22 #if defined(OS_CHROMEOS)
23 const char* kDriveNamePolicyVariableName = "${google_drive}";
24 #endif
25
26 } // namespace
27
14 class DownloadDirPolicyHandlerTest 28 class DownloadDirPolicyHandlerTest
15 : public policy::ConfigurationPolicyPrefStoreTest { 29 : public policy::ConfigurationPolicyPrefStoreTest {
16 public: 30 public:
17 virtual void SetUp() OVERRIDE { 31 virtual void SetUp() OVERRIDE {
18 handler_list_.AddHandler( 32 handler_list_.AddHandler(
19 make_scoped_ptr<policy::ConfigurationPolicyHandler>( 33 make_scoped_ptr<policy::ConfigurationPolicyHandler>(
20 new DownloadDirPolicyHandler)); 34 new DownloadDirPolicyHandler));
21 } 35 }
36 virtual void PopulatePolicyHandlerParameters(
bartfab (slow) 2014/03/14 13:43:45 Nit: Add blank line before.
37 policy::PolicyHandlerParameters* perf) OVERRIDE {
bartfab (slow) 2014/03/14 13:43:45 Nit: s/perf/parameters/
38 perf->user_id_hash = kUserName;
bartfab (slow) 2014/03/14 13:43:45 You are setting the user ID hash to a user ID. The
39 }
40
41 std::string GetStringFromStore(const std::string& key) {
42 const base::Value* value = NULL;
43 std::string string_value;
44 EXPECT_TRUE(store_->GetValue(key, &value));
45 EXPECT_TRUE(value);
46 EXPECT_TRUE(value->GetAsString(&string_value));
47 return string_value;
48 }
22 }; 49 };
23 50
51 #if !defined(OS_CHROMEOS)
24 TEST_F(DownloadDirPolicyHandlerTest, SetDownloadDirectory) { 52 TEST_F(DownloadDirPolicyHandlerTest, SetDownloadDirectory) {
25 policy::PolicyMap policy; 53 policy::PolicyMap policy;
26 EXPECT_FALSE(store_->GetValue(prefs::kPromptForDownload, NULL)); 54 EXPECT_FALSE(store_->GetValue(prefs::kPromptForDownload, NULL));
27 policy.Set(policy::key::kDownloadDirectory, 55 policy.Set(policy::key::kDownloadDirectory,
28 policy::POLICY_LEVEL_MANDATORY, 56 policy::POLICY_LEVEL_MANDATORY,
29 policy::POLICY_SCOPE_USER, 57 policy::POLICY_SCOPE_USER,
30 base::Value::CreateStringValue(std::string()), 58 base::Value::CreateStringValue(std::string()),
31 NULL); 59 NULL);
32 UpdateProviderPolicy(policy); 60 UpdateProviderPolicy(policy);
33 61
34 // Setting a DownloadDirectory should disable the PromptForDownload pref. 62 // Setting a DownloadDirectory should disable the PromptForDownload pref.
35 const base::Value* value = NULL; 63 const base::Value* value = NULL;
36 EXPECT_TRUE(store_->GetValue(prefs::kPromptForDownload, &value)); 64 EXPECT_TRUE(store_->GetValue(prefs::kPromptForDownload, &value));
37 ASSERT_TRUE(value); 65 ASSERT_TRUE(value);
38 bool prompt_for_download = true; 66 bool prompt_for_download = true;
39 bool result = value->GetAsBoolean(&prompt_for_download); 67 bool result = value->GetAsBoolean(&prompt_for_download);
40 ASSERT_TRUE(result); 68 ASSERT_TRUE(result);
41 EXPECT_FALSE(prompt_for_download); 69 EXPECT_FALSE(prompt_for_download);
42 } 70 }
71 #endif
72
73 #if defined(OS_CHROMEOS)
74 TEST_F(DownloadDirPolicyHandlerTest, SetDownloadToDrive) {
75 policy::PolicyMap policy;
76 const base::Value* value = NULL;
bartfab (slow) 2014/03/14 13:43:45 Nit: No need for this. You could just use NULL ins
77
78 EXPECT_FALSE(store_->GetValue(prefs::kPromptForDownload, NULL));
79
80 policy.Set(policy::key::kDownloadDirectory,
bartfab (slow) 2014/03/14 13:43:45 What is this testing? The policy is not supported
81 policy::POLICY_LEVEL_MANDATORY,
82 policy::POLICY_SCOPE_MACHINE,
83 new base::StringValue(kDriveNamePolicyVariableName),
84 NULL);
85 UpdateProviderPolicy(policy);
86
87 EXPECT_FALSE(store_->GetValue(prefs::kPromptForDownload, &value));
88 EXPECT_FALSE(store_->GetValue(prefs::kDownloadDefaultDirectory, &value));
89
90 EXPECT_FALSE(store_->GetValue(prefs::kPromptForDownload, NULL));
bartfab (slow) 2014/03/14 13:43:45 Nit: You just checked the value of |prefs::kPrompt
91 policy.Set(policy::key::kDownloadDirectory,
bartfab (slow) 2014/03/14 13:43:45 What is this testing? The policy cannot be recomme
92 policy::POLICY_LEVEL_RECOMMENDED,
93 policy::POLICY_SCOPE_MACHINE,
94 new base::StringValue(kDriveNamePolicyVariableName),
95 NULL);
96 UpdateProviderPolicy(policy);
97
98 EXPECT_FALSE(store_->GetValue(prefs::kPromptForDownload, &value));
99 EXPECT_FALSE(store_->GetValue(prefs::kDownloadDefaultDirectory, &value));
100
101 policy.Set(policy::key::kDownloadDirectory,
102 policy::POLICY_LEVEL_MANDATORY,
103 policy::POLICY_SCOPE_USER,
104 new base::StringValue(kDriveNamePolicyVariableName),
105 NULL);
106 UpdateProviderPolicy(policy);
107
108 EXPECT_FALSE(store_->GetValue(prefs::kPromptForDownload, &value));
109 std::string download_directory =
110 GetStringFromStore(prefs::kDownloadDefaultDirectory);
111 EXPECT_TRUE(download_directory.find(kUserName) != std::string::npos);
bartfab (slow) 2014/03/14 13:43:45 1: Why not use drive::util::GetDriveMountPointPath
112
113 #if 0
dconnelly 2014/03/14 12:53:18 ?
bartfab (slow) 2014/03/14 13:43:45 Either extend the policy to support being recommen
114 policy.Clear();
115 UpdateProviderPolicy(policy);
116 policy.Set(policy::key::kDownloadDirectory,
117 policy::POLICY_LEVEL_RECOMMENDED,
118 policy::POLICY_SCOPE_USER,
119 new base::StringValue(kDriveNamePolicyVariableName),
120 NULL);
121 UpdateProviderPolicy(policy);
122
123 EXPECT_FALSE(store_->GetValue(prefs::kPromptForDownload, &value));
124 download_directory = GetStringFromStore(prefs::kDownloadDefaultDirectory);
125 EXPECT_TRUE(download_directory.find(kUserName) != std::string::npos);
126 #endif
127 }
128 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698