OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/at_exit.h" | 6 #include "base/at_exit.h" |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "base/win/registry.h" | 11 #include "base/win/registry.h" |
12 #include "chrome_frame/policy_settings.h" | 12 #include "chrome_frame/policy_settings.h" |
13 #include "chrome_frame/test/chrome_frame_test_utils.h" | 13 #include "chrome_frame/test/chrome_frame_test_utils.h" |
14 #include "content/public/common/content_switches.h" | |
14 #include "policy/policy_constants.h" | 15 #include "policy/policy_constants.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 | 17 |
17 using base::win::RegKey; | 18 using base::win::RegKey; |
18 using chrome_frame_test::ScopedVirtualizeHklmAndHkcu; | 19 using chrome_frame_test::ScopedVirtualizeHklmAndHkcu; |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 // A best effort way to zap CF policy entries that may be in the registry. | 23 // A best effort way to zap CF policy entries that may be in the registry. |
23 void DeleteChromeFramePolicyEntries(HKEY root) { | 24 void DeleteChromeFramePolicyEntries(HKEY root) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 RegKey policy_key; | 82 RegKey policy_key; |
82 if (!InitializePolicyKey(policy_root, &policy_key)) | 83 if (!InitializePolicyKey(policy_root, &policy_key)) |
83 return false; | 84 return false; |
84 | 85 |
85 std::wstring type_list(ASCIIToWide(policy::key::kChromeFrameContentTypes)); | 86 std::wstring type_list(ASCIIToWide(policy::key::kChromeFrameContentTypes)); |
86 WritePolicyList(&policy_key, type_list.c_str(), content_types, count); | 87 WritePolicyList(&policy_key, type_list.c_str(), content_types, count); |
87 | 88 |
88 return true; | 89 return true; |
89 } | 90 } |
90 | 91 |
91 bool SetChromeApplicationLocale(HKEY policy_root, const wchar_t* locale) { | 92 bool SetCFPolicyString(HKEY policy_root, const char* policy_name, |
Mattias Nissler (ping if slow)
2012/03/26 11:04:41
nit: declare each parameter on separate line
tommi (sloooow) - chröme
2012/03/26 11:24:37
this is the convention in this file so if you don'
Mattias Nissler (ping if slow)
2012/03/26 11:40:55
I'd rather encourage you to fix the entire file, b
tommi (sloooow) - chröme
2012/03/26 11:48:18
Done.
| |
93 const wchar_t* value) { | |
92 RegKey policy_key; | 94 RegKey policy_key; |
93 if (!InitializePolicyKey(policy_root, &policy_key)) | 95 if (!InitializePolicyKey(policy_root, &policy_key)) |
94 return false; | 96 return false; |
95 | 97 |
96 std::wstring application_locale_value( | 98 std::wstring policy_name_str(ASCIIToWide(policy_name)); |
97 ASCIIToWide(policy::key::kApplicationLocaleValue)); | |
98 EXPECT_EQ(ERROR_SUCCESS, | 99 EXPECT_EQ(ERROR_SUCCESS, |
99 policy_key.WriteValue(application_locale_value.c_str(), locale)); | 100 policy_key.WriteValue(policy_name_str.c_str(), value)); |
100 return true; | 101 return true; |
101 } | 102 } |
102 | 103 |
103 } // end namespace | 104 } // end namespace |
104 | 105 |
105 class PolicySettingsTest : public testing::Test { | 106 class PolicySettingsTest : public testing::Test { |
106 protected: | 107 protected: |
107 void SetUp() { | 108 void SetUp() { |
108 ResetPolicySettings(); | 109 ResetPolicySettings(); |
109 } | 110 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 } | 200 } |
200 } | 201 } |
201 | 202 |
202 TEST_F(PolicySettingsTest, ApplicationLocale) { | 203 TEST_F(PolicySettingsTest, ApplicationLocale) { |
203 EXPECT_TRUE(PolicySettings::GetInstance()->ApplicationLocale().empty()); | 204 EXPECT_TRUE(PolicySettings::GetInstance()->ApplicationLocale().empty()); |
204 | 205 |
205 static const wchar_t kTestApplicationLocale[] = L"fr-CA"; | 206 static const wchar_t kTestApplicationLocale[] = L"fr-CA"; |
206 | 207 |
207 HKEY root[] = { HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER }; | 208 HKEY root[] = { HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER }; |
208 for (int i = 0; i < arraysize(root); ++i) { | 209 for (int i = 0; i < arraysize(root); ++i) { |
209 SetChromeApplicationLocale(root[i], kTestApplicationLocale); | 210 SetCFPolicyString(root[i], policy::key::kApplicationLocaleValue, |
211 kTestApplicationLocale); | |
210 ResetPolicySettings(); | 212 ResetPolicySettings(); |
211 EXPECT_EQ(std::wstring(kTestApplicationLocale), | 213 EXPECT_EQ(std::wstring(kTestApplicationLocale), |
212 PolicySettings::GetInstance()->ApplicationLocale()); | 214 PolicySettings::GetInstance()->ApplicationLocale()); |
213 | 215 |
214 DeleteChromeFramePolicyEntries(root[i]); | 216 DeleteChromeFramePolicyEntries(root[i]); |
215 } | 217 } |
216 } | 218 } |
219 | |
220 TEST_F(PolicySettingsTest, AdditionalLaunchParameters) { | |
221 EXPECT_TRUE(PolicySettings::GetInstance()-> | |
222 AdditionalLaunchParameters().GetProgram().empty()); | |
223 | |
224 std::string test_switches("--"); | |
225 test_switches += switches::kEnableMediaStream; | |
226 test_switches += " --"; | |
227 test_switches += switches::kEnableMediaSource; | |
228 | |
229 HKEY root[] = { HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER }; | |
230 for (int i = 0; i < arraysize(root); ++i) { | |
231 SetCFPolicyString(root[i], policy::key::kAdditionalLaunchParameters, | |
232 ASCIIToWide(test_switches).c_str()); | |
233 ResetPolicySettings(); | |
234 const CommandLine& additional_params = | |
235 PolicySettings::GetInstance()->AdditionalLaunchParameters(); | |
236 EXPECT_TRUE(additional_params.HasSwitch(switches::kEnableMediaStream)); | |
237 EXPECT_TRUE(additional_params.HasSwitch(switches::kEnableMediaSource)); | |
238 | |
239 FilePath program_path(FILE_PATH_LITERAL("my_chrome.exe")); | |
240 CommandLine new_cmd_line(program_path); | |
241 new_cmd_line.AppendArguments(additional_params, false); | |
242 EXPECT_NE(new_cmd_line.GetProgram(), additional_params.GetProgram()); | |
243 EXPECT_TRUE(new_cmd_line.HasSwitch(switches::kEnableMediaStream)); | |
244 EXPECT_TRUE(new_cmd_line.HasSwitch(switches::kEnableMediaSource)); | |
245 | |
246 DeleteChromeFramePolicyEntries(root[i]); | |
247 } | |
248 } | |
OLD | NEW |