Chromium Code Reviews| 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> | |
| 6 | |
| 7 #include "base/compiler_specific.h" | |
| 5 #include "base/values.h" | 8 #include "base/values.h" |
| 6 #include "chrome/browser/download/download_dir_policy_handler.h" | 9 #include "chrome/browser/download/download_dir_policy_handler.h" |
| 7 #include "chrome/browser/download/download_prefs.h" | 10 #include "chrome/browser/download/download_prefs.h" |
| 8 #include "chrome/common/pref_names.h" | 11 #include "chrome/common/pref_names.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" |
| 15 #include "components/policy/core/common/policy_details.h" | |
| 11 #include "components/policy/core/common/policy_map.h" | 16 #include "components/policy/core/common/policy_map.h" |
| 12 #include "policy/policy_constants.h" | 17 #include "policy/policy_constants.h" |
| 13 | 18 |
| 19 #if defined(OS_CHROMEOS) | |
| 20 #include "chrome/browser/chromeos/drive/file_system_util.h" | |
| 21 #endif | |
| 22 | |
| 23 namespace { | |
| 24 | |
| 25 const base::FilePath::CharType* kUserIDHash = "deadbeef"; | |
|
bartfab (slow)
2014/03/14 16:16:45
Nit: This one should be a char*.
| |
| 26 | |
| 27 #if defined(OS_CHROMEOS) | |
| 28 const base::FilePath::CharType* kDriveNamePolicyVariableName = | |
|
bartfab (slow)
2014/03/14 16:16:45
Nit: This one should be a char*.
| |
| 29 "${google_drive}"; | |
| 30 const base::FilePath::CharType* kRootRelativeToDriveMount = | |
|
bartfab (slow)
2014/03/14 16:16:45
Nit: #include "base/files/file_path.h"
| |
| 31 FILE_PATH_LITERAL("/root/"); | |
| 32 const base::FilePath::CharType* kRelativeToDriveRoot = | |
| 33 FILE_PATH_LITERAL("/home/"); | |
| 34 #endif | |
| 35 | |
| 36 } // namespace | |
| 37 | |
| 14 class DownloadDirPolicyHandlerTest | 38 class DownloadDirPolicyHandlerTest |
| 15 : public policy::ConfigurationPolicyPrefStoreTest { | 39 : public policy::ConfigurationPolicyPrefStoreTest { |
| 16 public: | 40 public: |
| 17 virtual void SetUp() OVERRIDE { | 41 virtual void SetUp() OVERRIDE { |
| 42 store2_ = new policy::ConfigurationPolicyPrefStore( | |
| 43 policy_service_.get(), | |
| 44 &handler_list_, | |
| 45 policy::POLICY_LEVEL_RECOMMENDED); | |
|
bartfab (slow)
2014/03/14 16:16:45
Nit: #include "components/policy/core/common/polic
| |
| 18 handler_list_.AddHandler( | 46 handler_list_.AddHandler( |
| 19 make_scoped_ptr<policy::ConfigurationPolicyHandler>( | 47 make_scoped_ptr<policy::ConfigurationPolicyHandler>( |
| 20 new DownloadDirPolicyHandler)); | 48 new DownloadDirPolicyHandler)); |
| 21 } | 49 } |
| 50 | |
| 51 virtual void PopulatePolicyHandlerParameters( | |
| 52 policy::PolicyHandlerParameters* parameters) OVERRIDE { | |
| 53 parameters->user_id_hash = kUserIDHash; | |
| 54 } | |
| 55 | |
| 56 #if defined(OS_CHROMEOS) | |
| 57 std::string GetDownloadFolder() { | |
|
bartfab (slow)
2014/03/14 16:16:45
Nit 1: This does not access any members. It can be
| |
| 58 return drive::util::GetDriveMountPointPathForUserIdHash(kUserIDHash) | |
|
bartfab (slow)
2014/03/14 16:16:45
Nit: A better way to do this is GetDriveMountPoint
| |
| 59 .value() + | |
| 60 base::FilePath::StringType(kRootRelativeToDriveMount); | |
| 61 } | |
| 62 #endif | |
| 63 | |
| 64 protected: | |
| 65 scoped_refptr<policy::ConfigurationPolicyPrefStore> store2_; | |
|
bartfab (slow)
2014/03/14 16:16:45
Nit 1: #include "base/memory/ref_counted.h"
Nit 2:
| |
| 22 }; | 66 }; |
| 23 | 67 |
| 68 #if !defined(OS_CHROMEOS) | |
| 24 TEST_F(DownloadDirPolicyHandlerTest, SetDownloadDirectory) { | 69 TEST_F(DownloadDirPolicyHandlerTest, SetDownloadDirectory) { |
| 25 policy::PolicyMap policy; | 70 policy::PolicyMap policy; |
| 26 EXPECT_FALSE(store_->GetValue(prefs::kPromptForDownload, NULL)); | 71 EXPECT_FALSE(store_->GetValue(prefs::kPromptForDownload, NULL)); |
| 27 policy.Set(policy::key::kDownloadDirectory, | 72 policy.Set(policy::key::kDownloadDirectory, |
| 28 policy::POLICY_LEVEL_MANDATORY, | 73 policy::POLICY_LEVEL_MANDATORY, |
| 29 policy::POLICY_SCOPE_USER, | 74 policy::POLICY_SCOPE_USER, |
| 30 base::Value::CreateStringValue(std::string()), | 75 base::Value::CreateStringValue(std::string()), |
| 31 NULL); | 76 NULL); |
| 32 UpdateProviderPolicy(policy); | 77 UpdateProviderPolicy(policy); |
| 33 | 78 |
| 34 // Setting a DownloadDirectory should disable the PromptForDownload pref. | 79 // Setting a DownloadDirectory should disable the PromptForDownload pref. |
| 35 const base::Value* value = NULL; | 80 const base::Value* value = NULL; |
| 36 EXPECT_TRUE(store_->GetValue(prefs::kPromptForDownload, &value)); | 81 EXPECT_TRUE(store_->GetValue(prefs::kPromptForDownload, &value)); |
| 37 ASSERT_TRUE(value); | 82 ASSERT_TRUE(value); |
| 38 bool prompt_for_download = true; | 83 bool prompt_for_download = true; |
| 39 bool result = value->GetAsBoolean(&prompt_for_download); | 84 bool result = value->GetAsBoolean(&prompt_for_download); |
| 40 ASSERT_TRUE(result); | 85 ASSERT_TRUE(result); |
| 41 EXPECT_FALSE(prompt_for_download); | 86 EXPECT_FALSE(prompt_for_download); |
| 42 } | 87 } |
| 88 #endif | |
| 89 | |
| 90 #if defined(OS_CHROMEOS) | |
| 91 TEST_F(DownloadDirPolicyHandlerTest, SetDownloadToDrive) { | |
| 92 policy::PolicyMap policy; | |
| 93 const base::Value* value = NULL; | |
|
bartfab (slow)
2014/03/14 16:16:45
Nit: Define variables when you actually use them,
| |
| 94 std::string download_directory; | |
| 95 bool prompt_for_download; | |
| 96 | |
| 97 EXPECT_FALSE(store_->GetValue(prefs::kPromptForDownload, NULL)); | |
| 98 | |
| 99 policy.Set(policy::key::kDownloadDirectory, | |
| 100 policy::POLICY_LEVEL_MANDATORY, | |
| 101 policy::POLICY_SCOPE_USER, | |
| 102 new base::StringValue(kDriveNamePolicyVariableName), | |
| 103 NULL); | |
| 104 UpdateProviderPolicy(policy); | |
| 105 | |
| 106 EXPECT_TRUE(store_->GetValue(prefs::kPromptForDownload, &value)); | |
| 107 EXPECT_TRUE(value); | |
| 108 EXPECT_TRUE(value->GetAsBoolean(&prompt_for_download)); | |
| 109 EXPECT_EQ(prompt_for_download, false); | |
|
bartfab (slow)
2014/03/14 16:16:45
Nit 1: The arguments go the other way around: Expe
| |
| 110 | |
| 111 EXPECT_TRUE(store_->GetValue(prefs::kDownloadDefaultDirectory, &value)); | |
| 112 EXPECT_TRUE(value); | |
| 113 EXPECT_TRUE(value->GetAsString(&download_directory)); | |
| 114 EXPECT_EQ(download_directory, GetDownloadFolder()); | |
|
bartfab (slow)
2014/03/14 16:16:45
Nit: The arguments go the other way around: Expect
| |
| 115 | |
| 116 policy.Set(policy::key::kDownloadDirectory, | |
| 117 policy::POLICY_LEVEL_RECOMMENDED, | |
| 118 policy::POLICY_SCOPE_USER, | |
| 119 new base::StringValue( | |
| 120 base::FilePath::StringType(kDriveNamePolicyVariableName) + | |
| 121 kRelativeToDriveRoot), | |
|
bartfab (slow)
2014/03/14 16:16:45
Why are you appending kRelativeToDriveRoot here?
| |
| 122 NULL); | |
| 123 UpdateProviderPolicy(policy); | |
| 124 | |
| 125 EXPECT_FALSE(store2_->GetValue(prefs::kPromptForDownload, &value)); | |
| 126 EXPECT_TRUE(store2_->GetValue(prefs::kDownloadDefaultDirectory, &value)); | |
| 127 EXPECT_TRUE(value); | |
| 128 EXPECT_TRUE(value->GetAsString(&download_directory)); | |
| 129 EXPECT_EQ( | |
| 130 download_directory, | |
| 131 GetDownloadFolder() + base::FilePath::StringType(kRelativeToDriveRoot)); | |
|
bartfab (slow)
2014/03/14 16:16:45
Why are you appending kRelativeToDriveRoot here?
| |
| 132 } | |
| 133 #endif | |
| OLD | NEW |