| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/file_path.h" | 5 #include "base/file_path.h" |
| 6 #include "base/file_version_info.h" | 6 #include "base/file_version_info.h" |
| 7 #include "base/file_version_info_win.h" | 7 #include "base/file_version_info_win.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "base/win/registry.h" | 10 #include "base/win/registry.h" |
| 11 #include "chrome_frame/navigation_constraints.h" | 11 #include "chrome_frame/navigation_constraints.h" |
| 12 #include "chrome_frame/test/chrome_frame_test_utils.h" | 12 #include "chrome_frame/test/chrome_frame_test_utils.h" |
| 13 #include "chrome_frame/registry_list_preferences_holder.h" |
| 13 #include "chrome_frame/utils.h" | 14 #include "chrome_frame/utils.h" |
| 14 | 15 |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 17 | 18 |
| 18 using base::win::RegKey; | 19 using base::win::RegKey; |
| 19 | 20 |
| 20 const wchar_t kChannelName[] = L"-dev"; | 21 const wchar_t kChannelName[] = L"-dev"; |
| 21 const wchar_t kSuffix[] = L"-fix"; | 22 const wchar_t kSuffix[] = L"-fix"; |
| 22 | 23 |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 if (!config_key.Valid() || !opt_for_gcf.Valid() || !opt_for_host.Valid()) | 446 if (!config_key.Valid() || !opt_for_gcf.Valid() || !opt_for_host.Valid()) |
| 446 return; | 447 return; |
| 447 | 448 |
| 448 const wchar_t kTestFilter[] = L"*.testing.chromium.org"; | 449 const wchar_t kTestFilter[] = L"*.testing.chromium.org"; |
| 449 const wchar_t kTestUrl[] = L"www.testing.chromium.org"; | 450 const wchar_t kTestUrl[] = L"www.testing.chromium.org"; |
| 450 | 451 |
| 451 // Save the current state of the registry. | 452 // Save the current state of the registry. |
| 452 DWORD saved_default_renderer = 0; | 453 DWORD saved_default_renderer = 0; |
| 453 config_key.ReadValueDW(kEnableGCFRendererByDefault, &saved_default_renderer); | 454 config_key.ReadValueDW(kEnableGCFRendererByDefault, &saved_default_renderer); |
| 454 | 455 |
| 456 // We need to manually reset the holder between checks. |
| 457 // TODO(robertshield): Remove this when the RegistryWatcher is wired up. |
| 458 RegistryListPreferencesHolder& renderer_type_preferences_holder = |
| 459 GetRendererTypePreferencesHolderForTesting(); |
| 460 |
| 455 // Make sure the host is the default renderer. | 461 // Make sure the host is the default renderer. |
| 456 config_key.WriteValue(kEnableGCFRendererByDefault, static_cast<DWORD>(0)); | 462 config_key.WriteValue(kEnableGCFRendererByDefault, static_cast<DWORD>(0)); |
| 457 EXPECT_FALSE(IsGcfDefaultRenderer()); | 463 EXPECT_FALSE(IsGcfDefaultRenderer()); |
| 458 | 464 |
| 459 opt_for_gcf.DeleteValue(kTestFilter); // Just in case this exists | 465 opt_for_gcf.DeleteValue(kTestFilter); // Just in case this exists |
| 460 EXPECT_EQ(RENDERER_TYPE_UNDETERMINED, RendererTypeForUrl(kTestUrl)); | 466 EXPECT_EQ(RENDERER_TYPE_UNDETERMINED, RendererTypeForUrl(kTestUrl)); |
| 461 opt_for_gcf.WriteValue(kTestFilter, L""); | 467 opt_for_gcf.WriteValue(kTestFilter, L""); |
| 468 renderer_type_preferences_holder.ResetForTesting(); |
| 462 EXPECT_EQ(RENDERER_TYPE_CHROME_OPT_IN_URL, RendererTypeForUrl(kTestUrl)); | 469 EXPECT_EQ(RENDERER_TYPE_CHROME_OPT_IN_URL, RendererTypeForUrl(kTestUrl)); |
| 463 | 470 |
| 464 // Now set GCF as the default renderer. | 471 // Now set GCF as the default renderer. |
| 465 config_key.WriteValue(kEnableGCFRendererByDefault, static_cast<DWORD>(1)); | 472 config_key.WriteValue(kEnableGCFRendererByDefault, static_cast<DWORD>(1)); |
| 466 EXPECT_TRUE(IsGcfDefaultRenderer()); | 473 EXPECT_TRUE(IsGcfDefaultRenderer()); |
| 467 | 474 |
| 468 opt_for_host.DeleteValue(kTestFilter); // Just in case this exists | 475 opt_for_host.DeleteValue(kTestFilter); // Just in case this exists |
| 476 renderer_type_preferences_holder.ResetForTesting(); |
| 469 EXPECT_EQ(RENDERER_TYPE_CHROME_DEFAULT_RENDERER, | 477 EXPECT_EQ(RENDERER_TYPE_CHROME_DEFAULT_RENDERER, |
| 470 RendererTypeForUrl(kTestUrl)); | 478 RendererTypeForUrl(kTestUrl)); |
| 471 opt_for_host.WriteValue(kTestFilter, L""); | 479 opt_for_host.WriteValue(kTestFilter, L""); |
| 480 renderer_type_preferences_holder.ResetForTesting(); |
| 472 EXPECT_EQ(RENDERER_TYPE_UNDETERMINED, RendererTypeForUrl(kTestUrl)); | 481 EXPECT_EQ(RENDERER_TYPE_UNDETERMINED, RendererTypeForUrl(kTestUrl)); |
| 473 | 482 |
| 474 // Cleanup. | 483 // Cleanup. |
| 475 opt_for_gcf.DeleteValue(kTestFilter); | 484 opt_for_gcf.DeleteValue(kTestFilter); |
| 476 opt_for_host.DeleteValue(kTestFilter); | 485 opt_for_host.DeleteValue(kTestFilter); |
| 477 config_key.WriteValue(kEnableGCFRendererByDefault, saved_default_renderer); | 486 config_key.WriteValue(kEnableGCFRendererByDefault, saved_default_renderer); |
| 487 renderer_type_preferences_holder.ResetForTesting(); |
| 488 RendererTypeForUrl(L""); |
| 478 } | 489 } |
| 479 | 490 |
| 480 TEST_F(UtilTests, XUaCompatibleDirectiveTest) { | 491 TEST_F(UtilTests, XUaCompatibleDirectiveTest) { |
| 481 int all_versions[] = {0, 1, 2, 5, 6, 7, 8, 9, 10, 11, 99, 100, 101, 1000}; | 492 int all_versions[] = {0, 1, 2, 5, 6, 7, 8, 9, 10, 11, 99, 100, 101, 1000}; |
| 482 | 493 |
| 483 struct Cases { | 494 struct Cases { |
| 484 const char* header_value; | 495 const char* header_value; |
| 485 int max_version; | 496 int max_version; |
| 486 } test_cases[] = { | 497 } test_cases[] = { |
| 487 // Negative cases | 498 // Negative cases |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 | 546 |
| 536 ASSERT_EQ(expect_match, | 547 ASSERT_EQ(expect_match, |
| 537 CheckXUaCompatibleDirective(test.header_value, | 548 CheckXUaCompatibleDirective(test.header_value, |
| 538 all_versions[version_index])) | 549 all_versions[version_index])) |
| 539 << "Expect '" << test.header_value << "' to " | 550 << "Expect '" << test.header_value << "' to " |
| 540 << (expect_match ? "match" : "not match") << " IE major version " | 551 << (expect_match ? "match" : "not match") << " IE major version " |
| 541 << all_versions[version_index]; | 552 << all_versions[version_index]; |
| 542 } | 553 } |
| 543 } | 554 } |
| 544 } | 555 } |
| OLD | NEW |