OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/installer/setup/update_active_setup_version_work_item.h" | 5 #include "chrome/installer/setup/update_active_setup_version_work_item.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include <ostream> | 9 #include <ostream> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
13 #include "base/test/test_reg_util_win.h" | 13 #include "base/test/test_reg_util_win.h" |
14 #include "base/win/registry.h" | 14 #include "base/win/registry.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 | 16 |
17 using testing::ValuesIn; | 17 using testing::ValuesIn; |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 const HKEY kActiveSetupRoot = HKEY_LOCAL_MACHINE; | 21 const HKEY kActiveSetupRoot = HKEY_LOCAL_MACHINE; |
22 const base::char16 kActiveSetupPath[] = L"Active Setup\\test"; | 22 const base::char16 kActiveSetupPath[] = L"Active Setup\\test"; |
23 | 23 |
24 struct UpdateActiveSetupVersionWorkItemTestCase { | 24 struct UpdateActiveSetupVersionWorkItemTestCase { |
25 // The initial value to be set in the registry prior to executing the | 25 // The initial value to be set in the registry prior to executing the |
26 // UpdateActiveSetupVersionWorkItem. No value will be set if this null. | 26 // UpdateActiveSetupVersionWorkItem. No value will be set if this null. |
27 const wchar_t* initial_value; | 27 const wchar_t* initial_value; |
28 | 28 |
29 // Whether to ask the UpdateActiveSetupVersionWorkItem to bump the OS_UPGRADES | 29 // Whether to ask the UpdateActiveSetupVersionWorkItem to bump the |
30 // component of the Active Setup version. | 30 // SELECTIVE_TRIGGER component of the Active Setup version. |
31 bool bump_os_upgrades_component; | 31 bool bump_selective_trigger; |
32 | 32 |
33 // The expected value after executing the UpdateActiveSetupVersionWorkItem. | 33 // The expected value after executing the UpdateActiveSetupVersionWorkItem. |
34 const wchar_t* expected_result; | 34 const wchar_t* expected_result; |
35 } const kUpdateActiveSetupVersionWorkItemTestCases[] = { | 35 } const kUpdateActiveSetupVersionWorkItemTestCases[] = { |
36 // Initial install. | 36 // Initial install. |
37 {nullptr, false, L"43,0,0,0"}, | 37 {nullptr, false, L"43,0,0,0"}, |
38 // No-op update. | 38 // No-op update. |
39 {L"43.0.0.0", false, L"43,0,0,0"}, | 39 {L"43,0,0,0", false, L"43,0,0,0"}, |
40 // Update only major component. | 40 // Update only major component. |
41 {L"24,1,2,3", false, L"43,1,2,3"}, | 41 {L"24,1,2,3", false, L"43,0,0,0"}, |
42 // Reset from bogus value. | 42 // Reset from bogus value. |
43 {L"zzz", false, L"43,0,0,0"}, | 43 {L"zzz", false, L"43,0,0,0"}, |
44 // Reset from invalid version (too few components). | 44 // Reset from invalid version (too few components). |
45 {L"1,2", false, L"43,0,0,0"}, | 45 {L"1,2", false, L"43,0,0,0"}, |
46 // Reset from invalid version (too many components). | 46 // Reset from invalid version (too many components). |
47 {L"43,1,2,3,10", false, L"43,0,0,0"}, | 47 {L"43,1,2,3,10", false, L"43,1,2,3"}, |
48 // Reset from empty string. | 48 // Reset from empty string. |
49 {L"", false, L"43,0,0,0"}, | 49 {L"", false, L"43,0,0,0"}, |
50 | 50 |
51 // Same tests with an OS_UPGRADES component bump. | 51 // Same tests with a SELECTIVE_TRIGGER component bump. |
52 {nullptr, true, L"43,0,1,0"}, | 52 {nullptr, true, L"43,0,0,0"}, |
53 {L"43.0.0.0", true, L"43,0,1,0"}, | 53 {L"43,0,0,0", true, L"43,0,1,0"}, |
54 {L"24,1,2,3", true, L"43,1,3,3"}, | 54 {L"43,0,46,0", true, L"43,0,47,0"}, |
55 {L"zzz", true, L"43,0,1,0"}, | 55 {L"24,1,2,3", true, L"43,0,0,0"}, |
56 {L"1,2", true, L"43,0,1,0"}, | 56 {L"zzz", true, L"43,0,0,0"}, |
57 {L"43,1,2,3,10", true, L"43,0,1,0"}, | 57 {L"1,2", true, L"43,0,0,0"}, |
58 {L"", true, L"43,0,1,0"}, | 58 {L"43,1,2,3,10", true, L"43,1,3,3"}, |
59 // Bumping a negative OS upgrade component should result in it being | 59 {L"", true, L"43,0,0,0"}, |
60 // reset and subsequently bumped to 1 as usual. | 60 // Bumping a negative selective trigger component should result in it being |
| 61 // reset and subsequently bumped to 1. |
61 {L"43,11,-123,33", true, L"43,11,1,33"}, | 62 {L"43,11,-123,33", true, L"43,11,1,33"}, |
62 }; | 63 }; |
63 | 64 |
64 // Implements PrintTo in order for gtest to be able to print the problematic | 65 // Implements PrintTo in order for gtest to be able to print the problematic |
65 // UpdateActiveSetupVersionWorkItemTestCase on failure. | 66 // UpdateActiveSetupVersionWorkItemTestCase on failure. |
66 void PrintTo(const UpdateActiveSetupVersionWorkItemTestCase& test_case, | 67 void PrintTo(const UpdateActiveSetupVersionWorkItemTestCase& test_case, |
67 ::std::ostream* os) { | 68 ::std::ostream* os) { |
68 *os << "Initial value: " | 69 *os << "Initial value: " |
69 << (test_case.initial_value ? test_case.initial_value : L"(empty)") | 70 << (test_case.initial_value ? test_case.initial_value : L"(empty)") |
70 << ", bump_os_upgrades_component: " | 71 << ", bump_selective_trigger: " << test_case.bump_selective_trigger |
71 << test_case.bump_os_upgrades_component | |
72 << ", expected result: " << test_case.expected_result; | 72 << ", expected result: " << test_case.expected_result; |
73 } | 73 } |
74 | 74 |
75 } // namespace | 75 } // namespace |
76 | 76 |
77 class UpdateActiveSetupVersionWorkItemTest | 77 class UpdateActiveSetupVersionWorkItemTest |
78 : public testing::TestWithParam<UpdateActiveSetupVersionWorkItemTestCase> { | 78 : public testing::TestWithParam<UpdateActiveSetupVersionWorkItemTestCase> { |
79 public: | 79 public: |
80 UpdateActiveSetupVersionWorkItemTest() {} | 80 UpdateActiveSetupVersionWorkItemTest() {} |
81 | 81 |
82 void SetUp() override { | 82 void SetUp() override { |
83 ASSERT_NO_FATAL_FAILURE( | 83 ASSERT_NO_FATAL_FAILURE( |
84 registry_override_manager_.OverrideRegistry(kActiveSetupRoot)); | 84 registry_override_manager_.OverrideRegistry(kActiveSetupRoot)); |
85 } | 85 } |
86 | 86 |
87 private: | 87 private: |
88 registry_util::RegistryOverrideManager registry_override_manager_; | 88 registry_util::RegistryOverrideManager registry_override_manager_; |
89 | 89 |
90 DISALLOW_COPY_AND_ASSIGN(UpdateActiveSetupVersionWorkItemTest); | 90 DISALLOW_COPY_AND_ASSIGN(UpdateActiveSetupVersionWorkItemTest); |
91 }; | 91 }; |
92 | 92 |
93 TEST_P(UpdateActiveSetupVersionWorkItemTest, Execute) { | 93 TEST_P(UpdateActiveSetupVersionWorkItemTest, Execute) { |
94 // Get the parametrized |test_case| which defines 5 steps: | 94 // Get the parametrized |test_case| which defines 5 steps: |
95 // 1) Maybe set an initial Active Setup version in the registry according to | 95 // 1) Maybe set an initial Active Setup version in the registry according to |
96 // |test_case.initial_value|. | 96 // |test_case.initial_value|. |
97 // 2) Declare the work to be done by the UpdateActiveSetupVersionWorkItem | 97 // 2) Declare the work to be done by the UpdateActiveSetupVersionWorkItem |
98 // based on |test_case.bump_os_upgrades_component|. | 98 // based on |test_case.bump_selective_trigger|. |
99 // 3) Unconditionally execute the Active Setup work items. | 99 // 3) Unconditionally execute the Active Setup work items. |
100 // 4) Verify that the updated Active Setup version is as expected by | 100 // 4) Verify that the updated Active Setup version is as expected by |
101 // |test_case.expected_result|. | 101 // |test_case.expected_result|. |
102 // 5) Rollback and verify that |test_case.initial_value| is back. | 102 // 5) Rollback and verify that |test_case.initial_value| is back. |
103 const UpdateActiveSetupVersionWorkItemTestCase& test_case = GetParam(); | 103 const UpdateActiveSetupVersionWorkItemTestCase& test_case = GetParam(); |
104 | 104 |
105 base::win::RegKey test_key; | 105 base::win::RegKey test_key; |
106 | 106 |
107 ASSERT_EQ(ERROR_FILE_NOT_FOUND, | 107 ASSERT_EQ(ERROR_FILE_NOT_FOUND, |
108 test_key.Open(kActiveSetupRoot, kActiveSetupPath, KEY_READ)); | 108 test_key.Open(kActiveSetupRoot, kActiveSetupPath, KEY_READ)); |
109 | 109 |
110 UpdateActiveSetupVersionWorkItem active_setup_work_item( | 110 UpdateActiveSetupVersionWorkItem active_setup_work_item( |
111 kActiveSetupPath, test_case.bump_os_upgrades_component | 111 kActiveSetupPath, |
112 ? UpdateActiveSetupVersionWorkItem:: | 112 test_case.bump_selective_trigger |
113 UPDATE_AND_BUMP_OS_UPGRADES_COMPONENT | 113 ? UpdateActiveSetupVersionWorkItem::UPDATE_AND_BUMP_SELECTIVE_TRIGGER |
114 : UpdateActiveSetupVersionWorkItem::UPDATE); | 114 : UpdateActiveSetupVersionWorkItem::UPDATE); |
115 | 115 |
116 // Create the key and set the |initial_value| *after* the WorkItem to confirm | 116 // Create the key and set the |initial_value| *after* the WorkItem to confirm |
117 // that all of the work is done when executing the item, not when creating it. | 117 // that all of the work is done when executing the item, not when creating it. |
118 ASSERT_EQ(ERROR_SUCCESS, | 118 ASSERT_EQ(ERROR_SUCCESS, |
119 test_key.Create(kActiveSetupRoot, kActiveSetupPath, KEY_SET_VALUE)); | 119 test_key.Create(kActiveSetupRoot, kActiveSetupPath, KEY_SET_VALUE)); |
120 if (test_case.initial_value) { | 120 if (test_case.initial_value) { |
121 ASSERT_EQ(ERROR_SUCCESS, | 121 ASSERT_EQ(ERROR_SUCCESS, |
122 test_key.WriteValue(L"Version", test_case.initial_value)); | 122 test_key.WriteValue(L"Version", test_case.initial_value)); |
123 } | 123 } |
124 | 124 |
(...skipping 20 matching lines...) Expand all Loading... |
145 EXPECT_EQ(test_case.initial_value, version_out); | 145 EXPECT_EQ(test_case.initial_value, version_out); |
146 } else { | 146 } else { |
147 EXPECT_EQ(ERROR_FILE_NOT_FOUND, read_result); | 147 EXPECT_EQ(ERROR_FILE_NOT_FOUND, read_result); |
148 } | 148 } |
149 } | 149 } |
150 } | 150 } |
151 | 151 |
152 INSTANTIATE_TEST_CASE_P(UpdateActiveSetupVersionWorkItemTestInstance, | 152 INSTANTIATE_TEST_CASE_P(UpdateActiveSetupVersionWorkItemTestInstance, |
153 UpdateActiveSetupVersionWorkItemTest, | 153 UpdateActiveSetupVersionWorkItemTest, |
154 ValuesIn(kUpdateActiveSetupVersionWorkItemTestCases)); | 154 ValuesIn(kUpdateActiveSetupVersionWorkItemTestCases)); |
OLD | NEW |