Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
|
robertshield
2012/03/26 13:36:42
2012
tommi (sloooow) - chröme
2012/03/26 15:33:24
Done.
| |
| 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) { |
| 24 RegKey key; | 25 RegKey key; |
| 25 if (key.Open(root, policy::kRegistryMandatorySubKey, | 26 if (key.Open(root, policy::kRegistryMandatorySubKey, |
| 26 KEY_ALL_ACCESS) == ERROR_SUCCESS) { | 27 KEY_ALL_ACCESS) == ERROR_SUCCESS) { |
| 27 key.DeleteValue( | 28 key.DeleteValue( |
| 28 ASCIIToWide(policy::key::kChromeFrameRendererSettings).c_str()); | 29 ASCIIToWide(policy::key::kChromeFrameRendererSettings).c_str()); |
| 29 key.DeleteKey(ASCIIToWide(policy::key::kRenderInChromeFrameList).c_str()); | 30 key.DeleteKey(ASCIIToWide(policy::key::kRenderInChromeFrameList).c_str()); |
| 30 key.DeleteKey(ASCIIToWide(policy::key::kRenderInHostList).c_str()); | 31 key.DeleteKey(ASCIIToWide(policy::key::kRenderInHostList).c_str()); |
| 31 key.DeleteKey(ASCIIToWide(policy::key::kChromeFrameContentTypes).c_str()); | 32 key.DeleteKey(ASCIIToWide(policy::key::kChromeFrameContentTypes).c_str()); |
| 32 key.DeleteKey(ASCIIToWide(policy::key::kApplicationLocaleValue).c_str()); | 33 key.DeleteKey(ASCIIToWide(policy::key::kApplicationLocaleValue).c_str()); |
| 33 } | 34 } |
| 34 } | 35 } |
| 35 | 36 |
| 36 bool InitializePolicyKey(HKEY policy_root, RegKey* policy_key) { | 37 bool InitializePolicyKey(HKEY policy_root, RegKey* policy_key) { |
| 37 EXPECT_EQ(ERROR_SUCCESS, policy_key->Create(policy_root, | 38 EXPECT_EQ(ERROR_SUCCESS, policy_key->Create(policy_root, |
| 38 policy::kRegistryMandatorySubKey, KEY_ALL_ACCESS)); | 39 policy::kRegistryMandatorySubKey, KEY_ALL_ACCESS)); |
| 39 return policy_key->Valid(); | 40 return policy_key->Valid(); |
| 40 } | 41 } |
| 41 | 42 |
| 42 void WritePolicyList(RegKey* policy_key, const wchar_t* list_name, | 43 void WritePolicyList(RegKey* policy_key, |
| 44 const wchar_t* list_name, | |
| 43 const wchar_t* values[], int count) { | 45 const wchar_t* values[], int count) { |
| 44 DCHECK(policy_key); | 46 DCHECK(policy_key); |
| 45 // Remove any previous settings | 47 // Remove any previous settings |
| 46 policy_key->DeleteKey(list_name); | 48 policy_key->DeleteKey(list_name); |
| 47 | 49 |
| 48 RegKey list_key; | 50 RegKey list_key; |
| 49 EXPECT_EQ(ERROR_SUCCESS, list_key.Create(policy_key->Handle(), list_name, | 51 EXPECT_EQ(ERROR_SUCCESS, list_key.Create(policy_key->Handle(), list_name, |
| 50 KEY_ALL_ACCESS)); | 52 KEY_ALL_ACCESS)); |
| 51 for (int i = 0; i < count; ++i) { | 53 for (int i = 0; i < count; ++i) { |
| 52 EXPECT_EQ(ERROR_SUCCESS, | 54 EXPECT_EQ(ERROR_SUCCESS, |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 69 std::wstring in_cf(ASCIIToWide(policy::key::kRenderInChromeFrameList)); | 71 std::wstring in_cf(ASCIIToWide(policy::key::kRenderInChromeFrameList)); |
| 70 std::wstring in_host(ASCIIToWide(policy::key::kRenderInHostList)); | 72 std::wstring in_host(ASCIIToWide(policy::key::kRenderInHostList)); |
| 71 std::wstring exclusion_list( | 73 std::wstring exclusion_list( |
| 72 renderer == PolicySettings::RENDER_IN_CHROME_FRAME ? in_host : in_cf); | 74 renderer == PolicySettings::RENDER_IN_CHROME_FRAME ? in_host : in_cf); |
| 73 WritePolicyList(&policy_key, exclusion_list.c_str(), exclusions, | 75 WritePolicyList(&policy_key, exclusion_list.c_str(), exclusions, |
| 74 exclusion_count); | 76 exclusion_count); |
| 75 | 77 |
| 76 return true; | 78 return true; |
| 77 } | 79 } |
| 78 | 80 |
| 79 bool SetCFContentTypes(HKEY policy_root, const wchar_t* content_types[], | 81 bool SetCFContentTypes(HKEY policy_root, |
| 82 const wchar_t* content_types[], | |
| 80 int count) { | 83 int count) { |
| 81 RegKey policy_key; | 84 RegKey policy_key; |
| 82 if (!InitializePolicyKey(policy_root, &policy_key)) | 85 if (!InitializePolicyKey(policy_root, &policy_key)) |
| 83 return false; | 86 return false; |
| 84 | 87 |
| 85 std::wstring type_list(ASCIIToWide(policy::key::kChromeFrameContentTypes)); | 88 std::wstring type_list(ASCIIToWide(policy::key::kChromeFrameContentTypes)); |
| 86 WritePolicyList(&policy_key, type_list.c_str(), content_types, count); | 89 WritePolicyList(&policy_key, type_list.c_str(), content_types, count); |
| 87 | 90 |
| 88 return true; | 91 return true; |
| 89 } | 92 } |
| 90 | 93 |
| 91 bool SetChromeApplicationLocale(HKEY policy_root, const wchar_t* locale) { | 94 bool SetCFPolicyString(HKEY policy_root, |
| 95 const char* policy_name, | |
| 96 const wchar_t* value) { | |
| 92 RegKey policy_key; | 97 RegKey policy_key; |
| 93 if (!InitializePolicyKey(policy_root, &policy_key)) | 98 if (!InitializePolicyKey(policy_root, &policy_key)) |
| 94 return false; | 99 return false; |
| 95 | 100 |
| 96 std::wstring application_locale_value( | 101 std::wstring policy_name_str(ASCIIToWide(policy_name)); |
| 97 ASCIIToWide(policy::key::kApplicationLocaleValue)); | |
| 98 EXPECT_EQ(ERROR_SUCCESS, | 102 EXPECT_EQ(ERROR_SUCCESS, |
| 99 policy_key.WriteValue(application_locale_value.c_str(), locale)); | 103 policy_key.WriteValue(policy_name_str.c_str(), value)); |
| 100 return true; | 104 return true; |
| 101 } | 105 } |
| 102 | 106 |
| 103 } // end namespace | 107 } // end namespace |
| 104 | 108 |
| 105 class PolicySettingsTest : public testing::Test { | 109 class PolicySettingsTest : public testing::Test { |
| 106 protected: | 110 protected: |
| 107 void SetUp() { | 111 void SetUp() { |
| 108 ResetPolicySettings(); | 112 ResetPolicySettings(); |
| 109 } | 113 } |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 199 } | 203 } |
| 200 } | 204 } |
| 201 | 205 |
| 202 TEST_F(PolicySettingsTest, ApplicationLocale) { | 206 TEST_F(PolicySettingsTest, ApplicationLocale) { |
| 203 EXPECT_TRUE(PolicySettings::GetInstance()->ApplicationLocale().empty()); | 207 EXPECT_TRUE(PolicySettings::GetInstance()->ApplicationLocale().empty()); |
| 204 | 208 |
| 205 static const wchar_t kTestApplicationLocale[] = L"fr-CA"; | 209 static const wchar_t kTestApplicationLocale[] = L"fr-CA"; |
| 206 | 210 |
| 207 HKEY root[] = { HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER }; | 211 HKEY root[] = { HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER }; |
| 208 for (int i = 0; i < arraysize(root); ++i) { | 212 for (int i = 0; i < arraysize(root); ++i) { |
| 209 SetChromeApplicationLocale(root[i], kTestApplicationLocale); | 213 SetCFPolicyString(root[i], policy::key::kApplicationLocaleValue, |
| 214 kTestApplicationLocale); | |
| 210 ResetPolicySettings(); | 215 ResetPolicySettings(); |
| 211 EXPECT_EQ(std::wstring(kTestApplicationLocale), | 216 EXPECT_EQ(std::wstring(kTestApplicationLocale), |
| 212 PolicySettings::GetInstance()->ApplicationLocale()); | 217 PolicySettings::GetInstance()->ApplicationLocale()); |
| 213 | 218 |
| 214 DeleteChromeFramePolicyEntries(root[i]); | 219 DeleteChromeFramePolicyEntries(root[i]); |
| 215 } | 220 } |
| 216 } | 221 } |
| 222 | |
| 223 TEST_F(PolicySettingsTest, AdditionalLaunchParameters) { | |
| 224 EXPECT_TRUE(PolicySettings::GetInstance()-> | |
| 225 AdditionalLaunchParameters().GetProgram().empty()); | |
| 226 | |
| 227 std::string test_switches("--"); | |
| 228 test_switches += switches::kEnableMediaStream; | |
| 229 test_switches += " --"; | |
| 230 test_switches += switches::kEnableMediaSource; | |
| 231 | |
| 232 HKEY root[] = { HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER }; | |
| 233 for (int i = 0; i < arraysize(root); ++i) { | |
| 234 SetCFPolicyString(root[i], policy::key::kAdditionalLaunchParameters, | |
| 235 ASCIIToWide(test_switches).c_str()); | |
| 236 ResetPolicySettings(); | |
| 237 const CommandLine& additional_params = | |
| 238 PolicySettings::GetInstance()->AdditionalLaunchParameters(); | |
| 239 EXPECT_TRUE(additional_params.HasSwitch(switches::kEnableMediaStream)); | |
| 240 EXPECT_TRUE(additional_params.HasSwitch(switches::kEnableMediaSource)); | |
| 241 | |
| 242 FilePath program_path(FILE_PATH_LITERAL("my_chrome.exe")); | |
| 243 CommandLine new_cmd_line(program_path); | |
| 244 new_cmd_line.AppendArguments(additional_params, false); | |
| 245 EXPECT_NE(new_cmd_line.GetProgram(), additional_params.GetProgram()); | |
| 246 EXPECT_TRUE(new_cmd_line.HasSwitch(switches::kEnableMediaStream)); | |
| 247 EXPECT_TRUE(new_cmd_line.HasSwitch(switches::kEnableMediaSource)); | |
| 248 | |
| 249 DeleteChromeFramePolicyEntries(root[i]); | |
| 250 } | |
| 251 } | |
| OLD | NEW |