Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(227)

Side by Side Diff: chrome/browser/google/google_update_win_unittest.cc

Issue 1117263002: Switch on-demand update checks to the less-old GoogleUpdate3 API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sync to position 329622 Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/browser/google/google_update_win.h" 5 #include "chrome/browser/google/google_update_win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <atlbase.h> 8 #include <atlbase.h>
9 #include <atlcom.h> 9 #include <atlcom.h>
10 10
11 #include <queue> 11 #include <queue>
12 12
13 #include "base/base_paths.h" 13 #include "base/base_paths.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/path_service.h" 15 #include "base/path_service.h"
16 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
18 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
19 #include "base/test/scoped_path_override.h" 18 #include "base/test/scoped_path_override.h"
20 #include "base/test/test_reg_util_win.h" 19 #include "base/test/test_reg_util_win.h"
21 #include "base/test/test_simple_task_runner.h" 20 #include "base/test/test_simple_task_runner.h"
22 #include "base/thread_task_runner_handle.h" 21 #include "base/thread_task_runner_handle.h"
23 #include "base/version.h" 22 #include "base/version.h"
24 #include "base/win/registry.h" 23 #include "base/win/registry.h"
24 #include "base/win/scoped_comptr.h"
25 #include "chrome/installer/util/browser_distribution.h" 25 #include "chrome/installer/util/browser_distribution.h"
26 #include "chrome/installer/util/google_update_settings.h" 26 #include "chrome/installer/util/google_update_settings.h"
27 #include "chrome/installer/util/helper.h" 27 #include "chrome/installer/util/helper.h"
28 #include "google_update/google_update_idl.h" 28 #include "google_update/google_update_idl.h"
29 #include "testing/gmock/include/gmock/gmock.h" 29 #include "testing/gmock/include/gmock/gmock.h"
30 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
31 #include "ui/base/win/atl_module.h" 31 #include "ui/base/win/atl_module.h"
32 #include "version.h" 32 #include "version.h"
33 33
34 using ::testing::Assign;
34 using ::testing::DoAll; 35 using ::testing::DoAll;
36 using ::testing::DoubleEq;
37 using ::testing::HasSubstr;
38 using ::testing::InSequence;
35 using ::testing::Invoke; 39 using ::testing::Invoke;
36 using ::testing::IsEmpty; 40 using ::testing::IsEmpty;
37 using ::testing::Return; 41 using ::testing::Return;
42 using ::testing::Sequence;
38 using ::testing::SetArgPointee; 43 using ::testing::SetArgPointee;
39 using ::testing::StrEq; 44 using ::testing::StrEq;
40 using ::testing::Unused; 45 using ::testing::StrictMock;
41 using ::testing::Values; 46 using ::testing::Values;
42 using ::testing::_; 47 using ::testing::_;
43 48
44 namespace { 49 namespace {
45 50
46 class UpdateCheckCallbackReceiver { 51 class MockUpdateCheckDelegate : public UpdateCheckDelegate {
47 public: 52 public:
48 UpdateCheckCallbackReceiver() {} 53 MockUpdateCheckDelegate() : weak_ptr_factory_(this) {}
49 virtual ~UpdateCheckCallbackReceiver() {} 54
50 virtual void OnUpdateCheckCallback(GoogleUpdateUpgradeResult result, 55 base::WeakPtr<UpdateCheckDelegate> AsWeakPtr() {
51 GoogleUpdateErrorCode error_code, 56 return weak_ptr_factory_.GetWeakPtr();
52 const base::string16& error_message, 57 }
53 const base::string16& version) = 0; 58
54 UpdateCheckCallback GetCallback() { 59 MOCK_METHOD1(OnUpdateCheckComplete, void(const base::string16&));
55 return base::Bind(&UpdateCheckCallbackReceiver::UpdateCheckCallback, 60 MOCK_METHOD2(OnUpgradeProgress, void(int, const base::string16&));
56 base::Unretained(this)); 61 MOCK_METHOD1(OnUpgradeComplete, void(const base::string16&));
57 } 62 MOCK_METHOD3(OnError, void(GoogleUpdateErrorCode,
58 63 const base::string16&,
59 private: 64 const base::string16&));
60 void UpdateCheckCallback(GoogleUpdateUpgradeResult result, 65
61 GoogleUpdateErrorCode error_code, 66 private:
62 const base::string16& error_message, 67 base::WeakPtrFactory<UpdateCheckDelegate> weak_ptr_factory_;
63 const base::string16& version) { 68
64 OnUpdateCheckCallback(result, error_code, error_message, version); 69 DISALLOW_COPY_AND_ASSIGN(MockUpdateCheckDelegate);
65 } 70 };
66 71
67 DISALLOW_COPY_AND_ASSIGN(UpdateCheckCallbackReceiver); 72 // An interface that exposes a factory method for creating an IGoogleUpdate3Web
68 }; 73 // instance.
69
70 class MockUpdateCheckCallbackReceiver : public UpdateCheckCallbackReceiver {
71 public:
72 MockUpdateCheckCallbackReceiver() {}
73 MOCK_METHOD4(OnUpdateCheckCallback,
74 void(GoogleUpdateUpgradeResult,
75 GoogleUpdateErrorCode,
76 const base::string16&,
77 const base::string16&));
78
79 private:
80 DISALLOW_COPY_AND_ASSIGN(MockUpdateCheckCallbackReceiver);
81 };
82
83 class GoogleUpdateFactory { 74 class GoogleUpdateFactory {
84 public: 75 public:
85 virtual ~GoogleUpdateFactory() {} 76 virtual ~GoogleUpdateFactory() {}
86 virtual HRESULT Create(base::win::ScopedComPtr<IGoogleUpdate>* on_demand) = 0; 77 virtual HRESULT Create(
87 }; 78 base::win::ScopedComPtr<IGoogleUpdate3Web>* google_update) = 0;
88 79 };
80
81 // A mock factory for creating an IGoogleUpdate3Web instance.
89 class MockGoogleUpdateFactory : public GoogleUpdateFactory { 82 class MockGoogleUpdateFactory : public GoogleUpdateFactory {
90 public: 83 public:
91 MockGoogleUpdateFactory() {} 84 MockGoogleUpdateFactory() {}
92 MOCK_METHOD1(Create, HRESULT(base::win::ScopedComPtr<IGoogleUpdate>*)); 85 MOCK_METHOD1(Create, HRESULT(base::win::ScopedComPtr<IGoogleUpdate3Web>*));
93 86
94 private: 87 private:
95 DISALLOW_COPY_AND_ASSIGN(MockGoogleUpdateFactory); 88 DISALLOW_COPY_AND_ASSIGN(MockGoogleUpdateFactory);
96 }; 89 };
97 90
98 // A mock IGoogleUpdate on-demand update class that can run an IJobObserver 91 class MockCurrentState : public CComObjectRootEx<CComSingleThreadModel>,
99 // through a set of states. 92 public ICurrentState {
100 class MockOnDemand : public CComObjectRootEx<CComSingleThreadModel>, 93 public:
101 public IGoogleUpdate { 94 BEGIN_COM_MAP(MockCurrentState)
102 public: 95 COM_INTERFACE_ENTRY(ICurrentState)
103 BEGIN_COM_MAP(MockOnDemand)
104 COM_INTERFACE_ENTRY(IGoogleUpdate)
105 END_COM_MAP() 96 END_COM_MAP()
106 97
107 MockOnDemand() : task_runner_(base::ThreadTaskRunnerHandle::Get()) {} 98 MockCurrentState() {}
108 99
100 // Adds an expectation for get_completionMessage that will return the given
101 // message any number of times.
102 void ExpectCompletionMessage(const base::string16& completion_message) {
103 completion_message_ = completion_message;
104 EXPECT_CALL(*this, get_completionMessage(_))
105 .WillRepeatedly(
106 ::testing::Invoke(this, &MockCurrentState::GetCompletionMessage));
107 }
108
109 HRESULT GetCompletionMessage(BSTR* completion_message) {
110 *completion_message = SysAllocString(completion_message_.c_str());
111 return S_OK;
112 }
113
114 // Adds an expectation for get_availableVersion that will return the given
115 // version any number of times.
116 void ExpectAvailableVersion(const base::string16& available_version) {
117 available_version_ = available_version;
118 EXPECT_CALL(*this, get_availableVersion(_))
119 .WillRepeatedly(
120 ::testing::Invoke(this, &MockCurrentState::GetAvailableVersion));
121 }
122
123 HRESULT GetAvailableVersion(BSTR* available_version) {
124 *available_version = SysAllocString(available_version_.c_str());
125 return S_OK;
126 }
127
128 // ICurrentState:
129 MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE,
130 get_stateValue,
131 HRESULT(LONG *));
132 MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE,
133 get_availableVersion,
134 HRESULT(BSTR *));
135 MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE,
136 get_bytesDownloaded,
137 HRESULT(ULONG *));
138 MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE,
139 get_totalBytesToDownload,
140 HRESULT(ULONG *));
141 MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE,
142 get_downloadTimeRemainingMs,
143 HRESULT(LONG *));
144 MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE,
145 get_nextRetryTime,
146 HRESULT(ULONGLONG *));
147 MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE,
148 get_installProgress,
149 HRESULT(LONG *));
150 MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE,
151 get_installTimeRemainingMs,
152 HRESULT(LONG *));
153 MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE,
154 get_isCanceled,
155 HRESULT(VARIANT_BOOL *));
156 MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE,
157 get_errorCode,
158 HRESULT(LONG *));
159 MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE,
160 get_extraCode1,
161 HRESULT(LONG *));
162 MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE,
163 get_completionMessage,
164 HRESULT(BSTR *));
165 MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE,
166 get_installerResultCode,
167 HRESULT(LONG *));
168 MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE,
169 get_installerResultExtraCode1,
170 HRESULT(LONG *));
171 MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE,
172 get_postInstallLaunchCommandLine,
173 HRESULT(BSTR *));
174 MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE,
175 get_postInstallUrl,
176 HRESULT(BSTR *));
177 MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE,
178 get_postInstallAction,
179 HRESULT(LONG *));
180
181 // IDispatch:
182 MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE,
183 GetTypeInfoCount,
184 HRESULT(UINT *));
185 MOCK_METHOD3_WITH_CALLTYPE(STDMETHODCALLTYPE,
186 GetTypeInfo,
187 HRESULT(UINT, LCID, ITypeInfo **));
188 MOCK_METHOD5_WITH_CALLTYPE(STDMETHODCALLTYPE,
189 GetIDsOfNames,
190 HRESULT(REFIID, LPOLESTR *, UINT, LCID, DISPID *));
191 MOCK_METHOD8_WITH_CALLTYPE(STDMETHODCALLTYPE,
192 Invoke,
193 HRESULT(DISPID, REFIID, LCID, WORD, DISPPARAMS *,
194 VARIANT *, EXCEPINFO *, UINT *));
195
196 private:
197 base::string16 completion_message_;
198 base::string16 available_version_;
199
200 DISALLOW_COPY_AND_ASSIGN(MockCurrentState);
201 };
202
203 class MockApp : public CComObjectRootEx<CComSingleThreadModel>, public IAppWeb {
204 public:
205 BEGIN_COM_MAP(MockApp)
206 COM_INTERFACE_ENTRY(IAppWeb)
207 END_COM_MAP()
208
209 MockApp() {}
210
211 // IAppWeb:
212 MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE,
213 get_appId,
214 HRESULT(BSTR *));
215 MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE,
216 get_currentVersionWeb,
217 HRESULT(IDispatch **));
218 MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE,
219 get_nextVersionWeb,
220 HRESULT(IDispatch **));
109 MOCK_METHOD2_WITH_CALLTYPE(STDMETHODCALLTYPE, 221 MOCK_METHOD2_WITH_CALLTYPE(STDMETHODCALLTYPE,
110 CheckForUpdate, 222 get_command,
111 HRESULT(const wchar_t*, IJobObserver*)); 223 HRESULT(BSTR, IDispatch **));
224 MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE,
225 cancel,
226 HRESULT());
227 MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE,
228 get_currentState,
229 HRESULT(IDispatch **));
230 MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE,
231 launch,
232 HRESULT());
233 MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE,
234 uninstall,
235 HRESULT());
236
237 // IDispatch:
238 MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE,
239 GetTypeInfoCount,
240 HRESULT(UINT *));
241 MOCK_METHOD3_WITH_CALLTYPE(STDMETHODCALLTYPE,
242 GetTypeInfo,
243 HRESULT(UINT, LCID, ITypeInfo **));
244 MOCK_METHOD5_WITH_CALLTYPE(STDMETHODCALLTYPE,
245 GetIDsOfNames,
246 HRESULT(REFIID, LPOLESTR *, UINT, LCID, DISPID *));
247 MOCK_METHOD8_WITH_CALLTYPE(STDMETHODCALLTYPE,
248 Invoke,
249 HRESULT(DISPID, REFIID, LCID, WORD, DISPPARAMS *,
250 VARIANT *, EXCEPINFO *, UINT *));
251
252 private:
253 DISALLOW_COPY_AND_ASSIGN(MockApp);
254 };
255
256 class MockAppBundle : public CComObjectRootEx<CComSingleThreadModel>,
257 public IAppBundleWeb {
258 public:
259 BEGIN_COM_MAP(MockAppBundle)
260 COM_INTERFACE_ENTRY(IAppBundleWeb)
261 END_COM_MAP()
262
263 MockAppBundle() {}
264
265 // IAppBundleWeb:
266 MOCK_METHOD4_WITH_CALLTYPE(STDMETHODCALLTYPE,
267 createApp,
268 HRESULT(BSTR, BSTR, BSTR, BSTR));
269 MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE,
270 createInstalledApp,
271 HRESULT(BSTR));
272 MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE,
273 createAllInstalledApps,
274 HRESULT());
275 MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE,
276 get_displayLanguage,
277 HRESULT(BSTR *));
278 MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE,
279 put_displayLanguage,
280 HRESULT(BSTR));
281 MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE,
282 put_parentHWND,
283 HRESULT(ULONG_PTR));
284 MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE,
285 get_length,
286 HRESULT(int *));
112 MOCK_METHOD2_WITH_CALLTYPE(STDMETHODCALLTYPE, 287 MOCK_METHOD2_WITH_CALLTYPE(STDMETHODCALLTYPE,
113 Update, 288 get_appWeb,
114 HRESULT(const wchar_t*, IJobObserver*)); 289 HRESULT(int, IDispatch **));
115 290 MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE,
116 void OnCheckRunUpToDateSequence(const base::char16* app_guid) { 291 initialize,
117 EXPECT_CALL(*this, CheckForUpdate(StrEq(app_guid), _)) 292 HRESULT());
118 .WillOnce(DoAll(Invoke(this, &MockOnDemand::BeginUpToDateSequence), 293 MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE,
119 Return(S_OK))); 294 checkForUpdate,
120 } 295 HRESULT());
121 296 MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE,
122 void OnCheckRunUpdateAvailableSequence(const base::char16* app_guid, 297 download,
123 const base::string16& new_version) { 298 HRESULT());
124 new_version_ = new_version; 299 MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE,
125 EXPECT_CALL(*this, CheckForUpdate(StrEq(app_guid), _)) 300 install,
126 .WillOnce( 301 HRESULT());
127 DoAll(Invoke(this, &MockOnDemand::BeginUpdateAvailableSequence), 302 MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE,
128 Return(S_OK))); 303 pause,
129 } 304 HRESULT());
130 305 MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE,
131 void OnUpdateRunInstallUpdateSequence(const base::char16* app_guid, 306 resume,
132 const base::string16& new_version) { 307 HRESULT());
133 new_version_ = new_version; 308 MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE,
134 EXPECT_CALL(*this, Update(StrEq(app_guid), _)) 309 cancel,
135 .WillOnce(DoAll(Invoke(this, &MockOnDemand::BeginInstallUpdateSequence), 310 HRESULT());
136 Return(S_OK))); 311 MOCK_METHOD2_WITH_CALLTYPE(STDMETHODCALLTYPE,
137 } 312 downloadPackage,
138 313 HRESULT(BSTR, BSTR));
139 void OnUpdateRunUpdateErrorSequence(const base::char16* app_guid, 314 MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE,
140 const base::char16* error_text) { 315 get_currentState,
141 error_text_ = error_text; 316 HRESULT(VARIANT *));
142 EXPECT_CALL(*this, Update(StrEq(app_guid), _)) 317
143 .WillOnce(DoAll(Invoke(this, &MockOnDemand::BeginUpdateErrorSequence), 318 // IDispatch:
144 Return(S_OK))); 319 MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE,
145 } 320 GetTypeInfoCount,
146 321 HRESULT(UINT *));
147 private: 322 MOCK_METHOD3_WITH_CALLTYPE(STDMETHODCALLTYPE,
148 enum State { 323 GetTypeInfo,
149 STATE_CHECKING, 324 HRESULT(UINT, LCID, ITypeInfo **));
150 STATE_COMPLETE_SUCCESS, 325 MOCK_METHOD5_WITH_CALLTYPE(STDMETHODCALLTYPE,
151 STATE_UPDATE_AVAILABLE, 326 GetIDsOfNames,
152 STATE_WAITING_TO_DOWNLOAD, 327 HRESULT(REFIID, LPOLESTR *, UINT, LCID, DISPID *));
153 STATE_DOWNLOADING_25, 328 MOCK_METHOD8_WITH_CALLTYPE(STDMETHODCALLTYPE,
154 STATE_DOWNLOADING_100, 329 Invoke,
155 STATE_WAITING_TO_INSTALL, 330 HRESULT(DISPID, REFIID, LCID, WORD, DISPPARAMS *,
156 STATE_INSTALLING, 331 VARIANT *, EXCEPINFO *, UINT *));
157 STATE_COMPLETE_ERROR, 332
158 }; 333 private:
159 334 DISALLOW_COPY_AND_ASSIGN(MockAppBundle);
160 void BeginUpToDateSequence(Unused, IJobObserver* job_observer_ptr) { 335 };
161 job_observer_ = job_observer_ptr; 336
162 states_.push(STATE_CHECKING); 337 class MockGoogleUpdate : public CComObjectRootEx<CComSingleThreadModel>,
163 states_.push(STATE_COMPLETE_SUCCESS); 338 public IGoogleUpdate3Web {
164 task_runner_->PostTask( 339 public:
165 FROM_HERE, base::Bind(&MockOnDemand::Advance, base::Unretained(this))); 340 BEGIN_COM_MAP(MockGoogleUpdate)
166 } 341 COM_INTERFACE_ENTRY(IGoogleUpdate3Web)
167 342 END_COM_MAP()
168 void BeginUpdateAvailableSequence(Unused, IJobObserver* job_observer_ptr) { 343
169 job_observer_ = job_observer_ptr; 344 MockGoogleUpdate() {}
170 states_.push(STATE_CHECKING); 345
171 states_.push(STATE_UPDATE_AVAILABLE); 346 // IGoogleUpdate3Web:
172 states_.push(STATE_COMPLETE_SUCCESS); 347 MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE,
173 task_runner_->PostTask( 348 createAppBundleWeb,
174 FROM_HERE, base::Bind(&MockOnDemand::Advance, base::Unretained(this))); 349 HRESULT(IDispatch**));
175 } 350
176 351 // IDispatch:
177 void BeginInstallUpdateSequence(Unused, IJobObserver* job_observer_ptr) { 352 MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE,
178 job_observer_ = job_observer_ptr; 353 GetTypeInfoCount,
179 states_.push(STATE_CHECKING); 354 HRESULT(UINT *));
180 states_.push(STATE_UPDATE_AVAILABLE); 355 MOCK_METHOD3_WITH_CALLTYPE(STDMETHODCALLTYPE,
181 states_.push(STATE_WAITING_TO_DOWNLOAD); 356 GetTypeInfo,
182 states_.push(STATE_DOWNLOADING_25); 357 HRESULT(UINT, LCID, ITypeInfo **));
183 states_.push(STATE_DOWNLOADING_100); 358 MOCK_METHOD5_WITH_CALLTYPE(STDMETHODCALLTYPE,
184 states_.push(STATE_WAITING_TO_INSTALL); 359 GetIDsOfNames,
185 states_.push(STATE_INSTALLING); 360 HRESULT(REFIID, LPOLESTR *, UINT, LCID, DISPID *));
186 states_.push(STATE_COMPLETE_SUCCESS); 361 MOCK_METHOD8_WITH_CALLTYPE(STDMETHODCALLTYPE,
187 task_runner_->PostTask( 362 Invoke,
188 FROM_HERE, base::Bind(&MockOnDemand::Advance, base::Unretained(this))); 363 HRESULT(DISPID, REFIID, LCID, WORD, DISPPARAMS *,
189 } 364 VARIANT *, EXCEPINFO *, UINT *));
190 365
191 void BeginUpdateErrorSequence(Unused, IJobObserver* job_observer_ptr) { 366 DISALLOW_COPY_AND_ASSIGN(MockGoogleUpdate);
192 job_observer_ = job_observer_ptr;
193 states_.push(STATE_CHECKING);
194 states_.push(STATE_UPDATE_AVAILABLE);
195 states_.push(STATE_WAITING_TO_DOWNLOAD);
196 states_.push(STATE_DOWNLOADING_25);
197 states_.push(STATE_DOWNLOADING_100);
198 states_.push(STATE_WAITING_TO_INSTALL);
199 states_.push(STATE_INSTALLING);
200 states_.push(STATE_COMPLETE_ERROR);
201 task_runner_->PostTask(
202 FROM_HERE, base::Bind(&MockOnDemand::Advance, base::Unretained(this)));
203 }
204
205 // Advance to the next state. If this state is non-terminal, a task is posted
206 // to advance to the next state a bit later.
207 void Advance() {
208 ASSERT_FALSE(states_.empty());
209 switch (states_.front()) {
210 case STATE_CHECKING:
211 EXPECT_EQ(S_OK, job_observer_->OnCheckingForUpdate());
212 break;
213 case STATE_COMPLETE_SUCCESS:
214 EXPECT_EQ(S_OK,
215 job_observer_->OnComplete(COMPLETION_CODE_SUCCESS, nullptr));
216 break;
217 case STATE_UPDATE_AVAILABLE:
218 EXPECT_EQ(S_OK, job_observer_->OnUpdateAvailable(new_version_.c_str()));
219 break;
220 case STATE_WAITING_TO_DOWNLOAD:
221 EXPECT_EQ(S_OK, job_observer_->OnWaitingToDownload());
222 break;
223 case STATE_DOWNLOADING_25:
224 EXPECT_EQ(S_OK, job_observer_->OnDownloading(47, 25));
225 break;
226 case STATE_DOWNLOADING_100:
227 EXPECT_EQ(S_OK, job_observer_->OnDownloading(42, 100));
228 break;
229 case STATE_WAITING_TO_INSTALL:
230 EXPECT_EQ(S_OK, job_observer_->OnWaitingToInstall());
231 break;
232 case STATE_INSTALLING:
233 EXPECT_EQ(S_OK, job_observer_->OnInstalling());
234 break;
235 case STATE_COMPLETE_ERROR:
236 EXPECT_EQ(S_OK, job_observer_->OnComplete(COMPLETION_CODE_ERROR,
237 error_text_.c_str()));
238 break;
239 }
240 states_.pop();
241 if (states_.empty()) {
242 // Drop the reference to the observer when the terminal state is reached.
243 job_observer_ = nullptr;
244 } else {
245 task_runner_->PostTask(FROM_HERE, base::Bind(&MockOnDemand::Advance,
246 base::Unretained(this)));
247 }
248 }
249
250 // The task runner on which the state machine runs.
251 scoped_refptr<base::TaskRunner> task_runner_;
252
253 // The new version for a successful update check or update.
254 base::string16 new_version_;
255
256 // Error text to be supplied for an unsuccessful update check or update.
257 base::string16 error_text_;
258
259 // The set of states to be run on an IJobObserver.
260 std::queue<State> states_;
261
262 // The IJobObserver given to either CheckForUpdate() or Update() that is being
263 // driven through the desired state transitions.
264 base::win::ScopedComPtr<IJobObserver> job_observer_;
265
266 DISALLOW_COPY_AND_ASSIGN(MockOnDemand);
267 }; 367 };
268 368
269 } // namespace 369 } // namespace
270 370
371 // A test fixture that can simulate the IGoogleUpdate3Web API via Google Mock.
372 // Individual tests must wire up the factories by a call to one of the
373 // PrepareSimulator methods. The family of Push*State methods are then used to
374 // configure the set of states to be simulated.
271 class GoogleUpdateWinTest : public ::testing::TestWithParam<bool> { 375 class GoogleUpdateWinTest : public ::testing::TestWithParam<bool> {
272 public: 376 public:
273 static void SetUpTestCase() { ui::win::CreateATLModuleIfNeeded(); } 377 static void SetUpTestCase() {
378 ui::win::CreateATLModuleIfNeeded();
379 // Configure all mock functions that return HRESULT to return failure.
380 ::testing::DefaultValue<HRESULT>::Set(E_FAIL);
381 }
382
383 static void TearDownTestCase() { ::testing::DefaultValue<HRESULT>::Clear(); }
274 384
275 protected: 385 protected:
276 GoogleUpdateWinTest() 386 GoogleUpdateWinTest()
277 : task_runner_(new base::TestSimpleTaskRunner()), 387 : task_runner_(new base::TestSimpleTaskRunner()),
278 task_runner_handle_(task_runner_), 388 task_runner_handle_(task_runner_),
279 system_level_(GetParam()), 389 system_level_install_(GetParam()),
280 mock_on_demand_(nullptr) {} 390 mock_app_(nullptr),
391 mock_app_bundle_(nullptr) {}
281 392
282 void SetUp() override { 393 void SetUp() override {
283 ::testing::TestWithParam<bool>::SetUp(); 394 ::testing::TestWithParam<bool>::SetUp();
284 395
285 // Override FILE_EXE so that it looks like the test is running from the 396 // Override FILE_EXE so that it looks like the test is running from the
286 // standard install location for this mode (system-level or user-level). 397 // standard install location for this mode (system-level or user-level).
287 base::FilePath file_exe; 398 base::FilePath file_exe;
288 ASSERT_TRUE(PathService::Get(base::FILE_EXE, &file_exe)); 399 ASSERT_TRUE(PathService::Get(base::FILE_EXE, &file_exe));
289 base::FilePath install_dir(installer::GetChromeInstallPath( 400 base::FilePath install_dir(installer::GetChromeInstallPath(
290 system_level_, BrowserDistribution::GetDistribution())); 401 system_level_install_, BrowserDistribution::GetDistribution()));
291 file_exe_override_.reset(new base::ScopedPathOverride( 402 file_exe_override_.reset(new base::ScopedPathOverride(
292 base::FILE_EXE, install_dir.Append(file_exe.BaseName()), 403 base::FILE_EXE, install_dir.Append(file_exe.BaseName()),
293 true /* is_absolute */, false /* create */)); 404 true /* is_absolute */, false /* create */));
294 405
295 // Override these paths so that they can be found after the registry 406 // Override these paths so that they can be found after the registry
296 // override manager is in place. 407 // override manager is in place.
297 base::FilePath temp; 408 base::FilePath temp;
298 PathService::Get(base::DIR_PROGRAM_FILES, &temp); 409 PathService::Get(base::DIR_PROGRAM_FILES, &temp);
299 program_files_override_.reset( 410 program_files_override_.reset(
300 new base::ScopedPathOverride(base::DIR_PROGRAM_FILES, temp)); 411 new base::ScopedPathOverride(base::DIR_PROGRAM_FILES, temp));
301 PathService::Get(base::DIR_PROGRAM_FILESX86, &temp); 412 PathService::Get(base::DIR_PROGRAM_FILESX86, &temp);
302 program_files_x86_override_.reset( 413 program_files_x86_override_.reset(
303 new base::ScopedPathOverride(base::DIR_PROGRAM_FILESX86, temp)); 414 new base::ScopedPathOverride(base::DIR_PROGRAM_FILESX86, temp));
304 PathService::Get(base::DIR_LOCAL_APP_DATA, &temp); 415 PathService::Get(base::DIR_LOCAL_APP_DATA, &temp);
305 local_app_data_override_.reset( 416 local_app_data_override_.reset(
306 new base::ScopedPathOverride(base::DIR_LOCAL_APP_DATA, temp)); 417 new base::ScopedPathOverride(base::DIR_LOCAL_APP_DATA, temp));
307 418
308 // Override the registry so that tests can freely push state to it. 419 // Override the registry so that tests can freely push state to it.
309 registry_override_manager_.OverrideRegistry(HKEY_CURRENT_USER); 420 registry_override_manager_.OverrideRegistry(HKEY_CURRENT_USER);
310 registry_override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE); 421 registry_override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE);
311 422
312 // Chrome is installed as multi-install. 423 // Chrome is installed as multi-install.
313 const HKEY root = system_level_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; 424 const HKEY root =
425 system_level_install_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
314 base::win::RegKey key(root, kClients, KEY_WRITE | KEY_WOW64_32KEY); 426 base::win::RegKey key(root, kClients, KEY_WRITE | KEY_WOW64_32KEY);
315 ASSERT_EQ(ERROR_SUCCESS, 427 ASSERT_EQ(ERROR_SUCCESS,
316 key.CreateKey(kChromeGuid, KEY_WRITE | KEY_WOW64_32KEY)); 428 key.CreateKey(kChromeGuid, KEY_WRITE | KEY_WOW64_32KEY));
317 ASSERT_EQ(ERROR_SUCCESS, 429 ASSERT_EQ(ERROR_SUCCESS,
318 key.WriteValue( 430 key.WriteValue(
319 L"pv", base::ASCIIToUTF16(CHROME_VERSION_STRING).c_str())); 431 L"pv", base::ASCIIToUTF16(CHROME_VERSION_STRING).c_str()));
320 ASSERT_EQ(ERROR_SUCCESS, 432 ASSERT_EQ(ERROR_SUCCESS,
321 key.Create(root, kClientState, KEY_WRITE | KEY_WOW64_32KEY)); 433 key.Create(root, kClientState, KEY_WRITE | KEY_WOW64_32KEY));
322 ASSERT_EQ(ERROR_SUCCESS, 434 ASSERT_EQ(ERROR_SUCCESS,
323 key.CreateKey(kChromeGuid, KEY_WRITE | KEY_WOW64_32KEY)); 435 key.CreateKey(kChromeGuid, KEY_WRITE | KEY_WOW64_32KEY));
324 ASSERT_EQ(ERROR_SUCCESS, 436 ASSERT_EQ(ERROR_SUCCESS,
325 key.WriteValue(L"UninstallArguments", 437 key.WriteValue(L"UninstallArguments",
326 L"--uninstall --multi-install --chrome")); 438 L"--uninstall --multi-install --chrome"));
327 439
328 // Provide an IGoogleUpdate on-demand update class factory so that this test 440 // Provide an IGoogleUpdate3Web class factory so that this test can provide
329 // can provide a mocked-out instance. 441 // a mocked-out instance.
330 SetGoogleUpdateFactoryForTesting( 442 SetGoogleUpdateFactoryForTesting(
331 base::Bind(&GoogleUpdateFactory::Create, 443 base::Bind(&GoogleUpdateFactory::Create,
332 base::Unretained(&mock_google_update_factory_))); 444 base::Unretained(&mock_google_update_factory_)));
333 // Configure the factory to return a generic failure by default.
334 ON_CALL(mock_google_update_factory_, Create(_))
335 .WillByDefault(Return(E_FAIL));
336
337 // Create a mock IGoogleUpdate on-demand update class
338 ASSERT_EQ(S_OK, CComObject<MockOnDemand>::CreateInstance(&mock_on_demand_));
339 on_demand_holder_ = mock_on_demand_;
340 // Configure the mock to return a generic failure by default.
341 ON_CALL(*mock_on_demand_, CheckForUpdate(_, _))
342 .WillByDefault(Return(E_FAIL));
343 ON_CALL(*mock_on_demand_, Update(_, _)).WillByDefault(Return(E_FAIL));
344 445
345 // Compute a newer version. 446 // Compute a newer version.
346 base::Version current_version(CHROME_VERSION_STRING); 447 base::Version current_version(CHROME_VERSION_STRING);
347 new_version_ = base::StringPrintf(L"%u.%u.%u.%u", 448 new_version_ = base::StringPrintf(L"%u.%u.%u.%u",
348 current_version.components()[0], 449 current_version.components()[0],
349 current_version.components()[1], 450 current_version.components()[1],
350 current_version.components()[2] + 1, 451 current_version.components()[2] + 1,
351 current_version.components()[3]); 452 current_version.components()[3]);
352 } 453 }
353 454
354 void TearDown() override { 455 void TearDown() override {
456 ASSERT_EQ(nullptr, mock_app_);
457 ASSERT_EQ(nullptr, mock_app_bundle_);
458 ASSERT_TRUE(states_.empty());
355 // Remove the test's IGoogleUpdate on-demand update class factory. 459 // Remove the test's IGoogleUpdate on-demand update class factory.
356 SetGoogleUpdateFactoryForTesting(OnDemandAppsClassFactory()); 460 SetGoogleUpdateFactoryForTesting(GoogleUpdate3ClassFactory());
461 ::testing::TestWithParam<bool>::TearDown();
357 } 462 }
358 463
359 // Set the default update policy in the registry. 464 // Prepares the IGoogleUpdate3Web simulator.
360 void SetDefaultUpdatePolicy(GoogleUpdateSettings::UpdatePolicy policy) const { 465 void PrepareSimulator(const base::char16* app_guid) {
361 base::win::RegKey policy_key(HKEY_LOCAL_MACHINE, kPoliciesKey, 466 // Make the installed app and configure it to call the test fixture's
362 KEY_SET_VALUE); 467 // GetNextState method.
363 ASSERT_EQ(ERROR_SUCCESS, policy_key.WriteValue(kUpdateDefault, policy)); 468 ASSERT_EQ(S_OK, CComObject<MockApp>::CreateInstance(&mock_app_));
469 ON_CALL(*mock_app_, get_currentState(_))
470 .WillByDefault(Invoke(this, &GoogleUpdateWinTest::GetNextState));
471
472 // Make the app bundle containing the app.
473 ASSERT_EQ(S_OK,
474 CComObject<MockAppBundle>::CreateInstance(&mock_app_bundle_));
475 EXPECT_CALL(*mock_app_bundle_, initialize())
476 .WillOnce(Return(S_OK));
477 // The bundle will be called on to create the installed app.
478 EXPECT_CALL(*mock_app_bundle_, createInstalledApp(StrEq(app_guid)))
479 .WillOnce(Return(S_OK));
480 // Give mock_app_bundle a ref to the app which it will return when asked.
481 mock_app_->AddRef();
482 EXPECT_CALL(*mock_app_bundle_, get_appWeb(0, _))
483 .WillOnce(DoAll(SetArgPointee<1>(mock_app_),
484 Assign(&mock_app_, nullptr),
485 Return(S_OK)));
486
487 // Make the updater which will return the app bundle above.
488 CComObject<MockGoogleUpdate>* mock_google_update = nullptr;
489 ASSERT_EQ(S_OK, CComObject<MockGoogleUpdate>::CreateInstance(
490 &mock_google_update));
491 // Give mock_google_update a ref to the bundle which it will return when
492 // created.
493 mock_app_bundle_->AddRef();
494 EXPECT_CALL(*mock_google_update, createAppBundleWeb(_))
495 .WillOnce(DoAll(SetArgPointee<0>(mock_app_bundle_),
496 Assign(&mock_app_bundle_, nullptr),
497 Return(S_OK)));
498
499 // Give the factory this updater. Do not add a ref, as the factory will add
500 // one when it hands out its instance.
501 EXPECT_CALL(mock_google_update_factory_, Create(_))
502 .WillOnce(DoAll(SetArgPointee<0>(mock_google_update), Return(S_OK)));
364 } 503 }
365 504
366 // Stuffs |policy| in the registry for the app identified by |app_guid|. 505 // Prepares the IGoogleUpdate3Web simulator to process an update check.
367 void SetAppUpdatePolicy(const base::char16* app_guid, 506 void PrepareSimulatorForUpdateCheck(const base::char16* app_guid) {
368 GoogleUpdateSettings::UpdatePolicy policy) const { 507 PrepareSimulator(app_guid);
369 base::string16 value_name(L"Update"); 508 // Expect the bundle to be called on to start the update.
370 value_name += app_guid; 509 EXPECT_CALL(*mock_app_bundle_, checkForUpdate())
371 base::win::RegKey policy_key(HKEY_LOCAL_MACHINE, kPoliciesKey, 510 .WillOnce(Return(S_OK));
372 KEY_SET_VALUE);
373 ASSERT_EQ(ERROR_SUCCESS, policy_key.WriteValue(value_name.c_str(), policy));
374 } 511 }
375 512
376 static const base::char16 kPoliciesKey[]; 513 // Prepares the IGoogleUpdate3Web simulator to process an upgrade.
377 static const base::char16 kUpdateDefault[]; 514 void PrepareSimulatorForUpgrade(const base::char16* app_guid) {
515 PrepareSimulatorForUpdateCheck(app_guid);
516 // Expect the bundle to be called on to start the install.
517 EXPECT_CALL(*mock_app_bundle_, install())
518 .WillOnce(Return(S_OK));
519 }
520
521 // Adds a MockCurrentState to the back of the sequence to be returned by the
522 // mock IAppWeb.
523 void PushState(CurrentState state) {
524 MakeNextState(state);
525 }
526
527 // Adds a MockCurrentState to the back of the sequence to be returned by the
528 // mock IAppWeb for an ERROR state.
529 void PushErrorState(LONG error_code,
530 const base::string16& completion_message,
531 LONG installer_result_code) {
532 CComObject<MockCurrentState>* mock_state = MakeNextState(STATE_ERROR);
533 EXPECT_CALL(*mock_state, get_errorCode(_))
534 .WillRepeatedly(DoAll(SetArgPointee<0>(error_code), Return(S_OK)));
535 mock_state->ExpectCompletionMessage(completion_message);
536 if (installer_result_code != -1) {
537 EXPECT_CALL(*mock_state, get_installerResultCode(_))
538 .WillRepeatedly(DoAll(SetArgPointee<0>(installer_result_code),
539 Return(S_OK)));
540 }
541 }
542
543 // Adds a MockCurrentState to the back of the sequence to be returned by the
544 // mock IAppWeb for an UPDATE_AVAILABLE state.
545 void PushUpdateAvailableState(const base::string16& new_version) {
546 MakeNextState(STATE_UPDATE_AVAILABLE)->ExpectAvailableVersion(new_version);
547 }
548
549 // Adds a MockCurrentState to the back of the sequence to be returned by the
550 // mock IAppWeb for a DOWNLOADING or INSTALLING state.
551 void PushProgressiveState(CurrentState state, int progress) {
552 CComObject<MockCurrentState>* mock_state = MakeNextState(state);
553 if (state == STATE_DOWNLOADING) {
554 const ULONG kTotalBytes = 1024;
555 ULONG bytes_down = static_cast<double>(kTotalBytes) * progress / 100.0;
556 EXPECT_CALL(*mock_state, get_totalBytesToDownload(_))
557 .WillRepeatedly(DoAll(SetArgPointee<0>(kTotalBytes), Return(S_OK)));
558 EXPECT_CALL(*mock_state, get_bytesDownloaded(_))
559 .WillRepeatedly(DoAll(SetArgPointee<0>(bytes_down), Return(S_OK)));
560 } else if (state == STATE_INSTALLING) {
561 EXPECT_CALL(*mock_state, get_installProgress(_))
562 .WillRepeatedly(DoAll(SetArgPointee<0>(progress), Return(S_OK)));
563 } else {
564 ADD_FAILURE() << "unsupported state " << state;
565 }
566 }
567
378 static const base::char16 kClients[]; 568 static const base::char16 kClients[];
379 static const base::char16 kClientState[]; 569 static const base::char16 kClientState[];
380 static const base::char16 kChromeGuid[]; 570 static const base::char16 kChromeGuid[];
381 static const base::char16 kChromeBinariesGuid[]; 571 static const base::char16 kChromeBinariesGuid[];
382 572
383 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; 573 scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
384 base::ThreadTaskRunnerHandle task_runner_handle_; 574 base::ThreadTaskRunnerHandle task_runner_handle_;
385 bool system_level_; 575 bool system_level_install_;
386 scoped_ptr<base::ScopedPathOverride> file_exe_override_; 576 scoped_ptr<base::ScopedPathOverride> file_exe_override_;
387 scoped_ptr<base::ScopedPathOverride> program_files_override_; 577 scoped_ptr<base::ScopedPathOverride> program_files_override_;
388 scoped_ptr<base::ScopedPathOverride> program_files_x86_override_; 578 scoped_ptr<base::ScopedPathOverride> program_files_x86_override_;
389 scoped_ptr<base::ScopedPathOverride> local_app_data_override_; 579 scoped_ptr<base::ScopedPathOverride> local_app_data_override_;
390 registry_util::RegistryOverrideManager registry_override_manager_; 580 registry_util::RegistryOverrideManager registry_override_manager_;
391 MockUpdateCheckCallbackReceiver callback_receiver_; 581
392 MockGoogleUpdateFactory mock_google_update_factory_; 582 // A mock object, the OnUpdateCheckCallback method of which will be invoked
393 CComObject<MockOnDemand>* mock_on_demand_; 583 // each time the update check machinery invokes the given UpdateCheckCallback.
394 base::win::ScopedComPtr<IGoogleUpdate> on_demand_holder_; 584 StrictMock<MockUpdateCheckDelegate> mock_update_check_delegate_;
585
586 // A mock object that provides a GoogleUpdate3ClassFactory by which the test
587 // fixture's IGoogleUpdate3Web simulator is provided to the update check
588 // machinery.
589 StrictMock<MockGoogleUpdateFactory> mock_google_update_factory_;
590
591 // The mock objects that simulate the IGoogleUpdate3Web API.
592 CComObject<MockApp>* mock_app_;
593 CComObject<MockAppBundle>* mock_app_bundle_;
594
595 // A gmock sequence under which expectations on the MockApp are evaluated.
596 Sequence state_sequence_;
597
598 // The states returned by the MockApp when probed.
599 std::queue<CComObject<MockCurrentState>*> states_;
600
601 // The new version that the fixture will pretend is available.
395 base::string16 new_version_; 602 base::string16 new_version_;
396 603
604 private:
605 // Returns a new MockCurrentState that will be returned by the mock IAppWeb's
606 // get_currentState method.
607 CComObject<MockCurrentState>* MakeNextState(CurrentState state) {
608 CComObject<MockCurrentState>* mock_state = nullptr;
609 // The new object's refcount is held at zero until it is released from the
610 // simulator in GetNextState.
611 EXPECT_EQ(S_OK, CComObject<MockCurrentState>::CreateInstance(&mock_state));
612 EXPECT_CALL(*mock_state, get_stateValue(_))
613 .WillRepeatedly(DoAll(SetArgPointee<0>(state), Return(S_OK)));
614 states_.push(mock_state);
615 // Tell the app to expect this state.
616 EXPECT_CALL(*mock_app_, get_currentState(_))
617 .InSequence(state_sequence_);
618 return mock_state;
619 }
620
621 // An implementation of IAppWeb::get_currentState that advances the
622 // IGoogleUpdate3Web simulator through a series of states.
623 HRESULT GetNextState(IDispatch** current_state) {
624 EXPECT_FALSE(states_.empty());
625 *current_state = states_.front();
626 // Give a reference to the caller.
627 (*current_state)->AddRef();
628 states_.pop();
629 return S_OK;
630 }
631
397 DISALLOW_COPY_AND_ASSIGN(GoogleUpdateWinTest); 632 DISALLOW_COPY_AND_ASSIGN(GoogleUpdateWinTest);
398 }; 633 };
399 634
400 // static 635 // static
401 const base::char16 GoogleUpdateWinTest::kPoliciesKey[] =
402 L"SOFTWARE\\Policies\\Google\\Update";
403 const base::char16 GoogleUpdateWinTest::kUpdateDefault[] = L"UpdateDefault";
404 const base::char16 GoogleUpdateWinTest::kClients[] = 636 const base::char16 GoogleUpdateWinTest::kClients[] =
405 L"Software\\Google\\Update\\Clients"; 637 L"Software\\Google\\Update\\Clients";
406 const base::char16 GoogleUpdateWinTest::kClientState[] = 638 const base::char16 GoogleUpdateWinTest::kClientState[] =
407 L"Software\\Google\\Update\\ClientState"; 639 L"Software\\Google\\Update\\ClientState";
408 const base::char16 GoogleUpdateWinTest::kChromeGuid[] = 640 const base::char16 GoogleUpdateWinTest::kChromeGuid[] =
409 L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; 641 L"{8A69D345-D564-463c-AFF1-A69D9E530F96}";
410 const base::char16 GoogleUpdateWinTest::kChromeBinariesGuid[] = 642 const base::char16 GoogleUpdateWinTest::kChromeBinariesGuid[] =
411 L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}"; 643 L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}";
412 644
413 // Test that an update check fails with the proper error code if Chrome isn't in 645 // Test that an update check fails with the proper error code if Chrome isn't in
414 // one of the expected install directories. 646 // one of the expected install directories.
415 TEST_P(GoogleUpdateWinTest, InvalidInstallDirectory) { 647 TEST_P(GoogleUpdateWinTest, InvalidInstallDirectory) {
416 // Override FILE_EXE so that it looks like the test is running from a 648 // Override FILE_EXE so that it looks like the test is running from a
417 // non-standard location. 649 // non-standard location.
418 base::FilePath file_exe; 650 base::FilePath file_exe;
419 base::FilePath dir_temp; 651 base::FilePath dir_temp;
420 ASSERT_TRUE(PathService::Get(base::FILE_EXE, &file_exe)); 652 ASSERT_TRUE(PathService::Get(base::FILE_EXE, &file_exe));
421 ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &dir_temp)); 653 ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &dir_temp));
422 file_exe_override_.reset(); 654 file_exe_override_.reset();
423 file_exe_override_.reset(new base::ScopedPathOverride( 655 file_exe_override_.reset(new base::ScopedPathOverride(
424 base::FILE_EXE, dir_temp.Append(file_exe.BaseName()), 656 base::FILE_EXE, dir_temp.Append(file_exe.BaseName()),
425 true /* is_absolute */, false /* create */)); 657 true /* is_absolute */, false /* create */));
426 658
427 EXPECT_CALL( 659 EXPECT_CALL(mock_update_check_delegate_,
428 callback_receiver_, 660 OnError(CANNOT_UPGRADE_CHROME_IN_THIS_DIRECTORY, _, _));
429 OnUpdateCheckCallback(UPGRADE_ERROR, 661 BeginUpdateCheck(task_runner_, std::string(), false, 0,
430 CANNOT_UPGRADE_CHROME_IN_THIS_DIRECTORY, _, _)); 662 mock_update_check_delegate_.AsWeakPtr());
431 BeginUpdateCheck(task_runner_, false, 0, callback_receiver_.GetCallback());
432 task_runner_->RunUntilIdle(); 663 task_runner_->RunUntilIdle();
433 } 664 }
434 665
435 #if defined(GOOGLE_CHROME_BUILD) 666 #if defined(GOOGLE_CHROME_BUILD)
436 667
437 TEST_P(GoogleUpdateWinTest, AllUpdatesDisabledByPolicy) { 668 // Test the case where the GoogleUpdate class can't be created for an update
438 // Disable updates altogether. 669 // check.
439 SetDefaultUpdatePolicy(GoogleUpdateSettings::UPDATES_DISABLED);
440
441 EXPECT_CALL(callback_receiver_,
442 OnUpdateCheckCallback(UPGRADE_ERROR,
443 GOOGLE_UPDATE_DISABLED_BY_POLICY, _, _));
444 BeginUpdateCheck(task_runner_, false, 0, callback_receiver_.GetCallback());
445 task_runner_->RunUntilIdle();
446 }
447
448 TEST_P(GoogleUpdateWinTest, MultiUpdatesDisabledByPolicy) {
449 // Disable updates altogether.
450 SetAppUpdatePolicy(kChromeBinariesGuid,
451 GoogleUpdateSettings::UPDATES_DISABLED);
452
453 EXPECT_CALL(callback_receiver_,
454 OnUpdateCheckCallback(UPGRADE_ERROR,
455 GOOGLE_UPDATE_DISABLED_BY_POLICY, _, _));
456 BeginUpdateCheck(task_runner_, false, 0, callback_receiver_.GetCallback());
457 task_runner_->RunUntilIdle();
458 }
459
460 TEST_P(GoogleUpdateWinTest, AllManualUpdatesDisabledByPolicy) {
461 // Disable updates altogether.
462 SetDefaultUpdatePolicy(GoogleUpdateSettings::AUTO_UPDATES_ONLY);
463
464 EXPECT_CALL(
465 callback_receiver_,
466 OnUpdateCheckCallback(UPGRADE_ERROR,
467 GOOGLE_UPDATE_DISABLED_BY_POLICY_AUTO_ONLY, _, _));
468 BeginUpdateCheck(task_runner_, false, 0, callback_receiver_.GetCallback());
469 task_runner_->RunUntilIdle();
470 }
471
472 TEST_P(GoogleUpdateWinTest, MultiManualUpdatesDisabledByPolicy) {
473 // Disable updates altogether.
474 SetAppUpdatePolicy(kChromeBinariesGuid,
475 GoogleUpdateSettings::AUTO_UPDATES_ONLY);
476
477 EXPECT_CALL(
478 callback_receiver_,
479 OnUpdateCheckCallback(UPGRADE_ERROR,
480 GOOGLE_UPDATE_DISABLED_BY_POLICY_AUTO_ONLY, _, _));
481 BeginUpdateCheck(task_runner_, false, 0, callback_receiver_.GetCallback());
482 task_runner_->RunUntilIdle();
483 }
484
485 TEST_P(GoogleUpdateWinTest, NoGoogleUpdateForCheck) { 670 TEST_P(GoogleUpdateWinTest, NoGoogleUpdateForCheck) {
486 // The factory should be called upon: let it fail. 671 // The factory should be called upon: let it fail.
487 EXPECT_CALL(mock_google_update_factory_, Create(_)); 672 EXPECT_CALL(mock_google_update_factory_, Create(_));
488 673
489 // Expect the appropriate error when the on-demand class cannot be created. 674 // Expect the appropriate error when the on-demand class cannot be created.
490 EXPECT_CALL(callback_receiver_, 675 EXPECT_CALL(mock_update_check_delegate_,
491 OnUpdateCheckCallback( 676 OnError(GOOGLE_UPDATE_ONDEMAND_CLASS_NOT_FOUND, _, _));
492 UPGRADE_ERROR, GOOGLE_UPDATE_ONDEMAND_CLASS_NOT_FOUND, _, _)); 677 BeginUpdateCheck(task_runner_, std::string(), false, 0,
493 BeginUpdateCheck(task_runner_, false, 0, callback_receiver_.GetCallback()); 678 mock_update_check_delegate_.AsWeakPtr());
494 task_runner_->RunUntilIdle(); 679 task_runner_->RunUntilIdle();
495 } 680 }
496 681
682 // Test the case where the GoogleUpdate class can't be created for an upgrade.
497 TEST_P(GoogleUpdateWinTest, NoGoogleUpdateForUpgrade) { 683 TEST_P(GoogleUpdateWinTest, NoGoogleUpdateForUpgrade) {
498 // The factory should be called upon: let it fail. 684 // The factory should be called upon: let it fail.
499 EXPECT_CALL(mock_google_update_factory_, Create(_)); 685 EXPECT_CALL(mock_google_update_factory_, Create(_));
500 686
501 // Expect the appropriate error when the on-demand class cannot be created. 687 // Expect the appropriate error when the on-demand class cannot be created.
502 EXPECT_CALL(callback_receiver_, 688 EXPECT_CALL(mock_update_check_delegate_,
503 OnUpdateCheckCallback( 689 OnError(GOOGLE_UPDATE_ONDEMAND_CLASS_NOT_FOUND, _, _));
504 UPGRADE_ERROR, GOOGLE_UPDATE_ONDEMAND_CLASS_NOT_FOUND, _, _)); 690 BeginUpdateCheck(task_runner_, std::string(), true, 0,
505 BeginUpdateCheck(task_runner_, true, 0, callback_receiver_.GetCallback()); 691 mock_update_check_delegate_.AsWeakPtr());
506 task_runner_->RunUntilIdle(); 692 task_runner_->RunUntilIdle();
507 } 693 }
508 694
695 // Test the case where the GoogleUpdate class returns an error when an update
696 // check is started.
509 TEST_P(GoogleUpdateWinTest, FailUpdateCheck) { 697 TEST_P(GoogleUpdateWinTest, FailUpdateCheck) {
510 // The factory should be called upon: let it return the mock on-demand class. 698 // The factory should be called upon: let it return the mock on-demand class.
511 EXPECT_CALL(mock_google_update_factory_, Create(_)) 699 PrepareSimulator(kChromeBinariesGuid);
512 .WillOnce(DoAll(SetArgPointee<0>(mock_on_demand_), Return(S_OK))); 700 // checkForUpdate will fail.
513 // The mock on-demand class should be called. 701 EXPECT_CALL(*mock_app_bundle_, checkForUpdate())
514 EXPECT_CALL(*mock_on_demand_, CheckForUpdate(StrEq(kChromeBinariesGuid), _)); 702 .WillOnce(Return(E_FAIL));
515 703
516 EXPECT_CALL( 704 EXPECT_CALL(mock_update_check_delegate_,
517 callback_receiver_, 705 OnError(GOOGLE_UPDATE_ONDEMAND_CLASS_REPORTED_ERROR, _, _));
518 OnUpdateCheckCallback(UPGRADE_ERROR, 706 BeginUpdateCheck(task_runner_, std::string(), false, 0,
519 GOOGLE_UPDATE_ONDEMAND_CLASS_REPORTED_ERROR, _, _)); 707 mock_update_check_delegate_.AsWeakPtr());
520 BeginUpdateCheck(task_runner_, false, 0, callback_receiver_.GetCallback());
521 task_runner_->RunUntilIdle(); 708 task_runner_->RunUntilIdle();
522 } 709 }
523 710
524 TEST_P(GoogleUpdateWinTest, UpdateCheckNoUpdate) { 711 // Test the case where the GoogleUpdate class reports that updates are disabled
525 EXPECT_CALL(mock_google_update_factory_, Create(_)) 712 // by Group Policy.
526 .WillOnce(DoAll(SetArgPointee<0>(mock_on_demand_), Return(S_OK))); 713 TEST_P(GoogleUpdateWinTest, UpdatesDisabledByPolicy) {
527 mock_on_demand_->OnCheckRunUpToDateSequence(kChromeBinariesGuid); 714 static const HRESULT GOOPDATE_E_APP_UPDATE_DISABLED_BY_POLICY = 0x80040813;
715 PrepareSimulatorForUpdateCheck(kChromeBinariesGuid);
716 PushState(STATE_INIT);
717 PushState(STATE_CHECKING_FOR_UPDATE);
718 PushErrorState(GOOPDATE_E_APP_UPDATE_DISABLED_BY_POLICY,
719 L"disabled by policy", -1);
528 720
529 EXPECT_CALL(callback_receiver_, 721 EXPECT_CALL(mock_update_check_delegate_,
530 OnUpdateCheckCallback(UPGRADE_ALREADY_UP_TO_DATE, 722 OnError(GOOGLE_UPDATE_DISABLED_BY_POLICY, _, _));
531 GOOGLE_UPDATE_NO_ERROR, IsEmpty(), _)); 723 BeginUpdateCheck(task_runner_, std::string(), false, 0,
532 BeginUpdateCheck(task_runner_, false, 0, callback_receiver_.GetCallback()); 724 mock_update_check_delegate_.AsWeakPtr());
533 task_runner_->RunUntilIdle(); 725 task_runner_->RunUntilIdle();
534 } 726 }
535 727
536 TEST_P(GoogleUpdateWinTest, UpdateCheckUpdateAvailable) { 728 // Test an update check where no update is available.
537 EXPECT_CALL(mock_google_update_factory_, Create(_)) 729 TEST_P(GoogleUpdateWinTest, UpdateCheckNoUpdate) {
538 .WillOnce(DoAll(SetArgPointee<0>(mock_on_demand_), Return(S_OK))); 730 PrepareSimulatorForUpdateCheck(kChromeBinariesGuid);
539 mock_on_demand_->OnCheckRunUpdateAvailableSequence(kChromeBinariesGuid, 731 PushState(STATE_INIT);
540 new_version_); 732 PushState(STATE_CHECKING_FOR_UPDATE);
733 PushState(STATE_NO_UPDATE);
541 734
542 EXPECT_CALL( 735 EXPECT_CALL(mock_update_check_delegate_,
543 callback_receiver_, 736 OnUpdateCheckComplete(IsEmpty())); // new_version
544 OnUpdateCheckCallback(UPGRADE_IS_AVAILABLE, GOOGLE_UPDATE_NO_ERROR, 737 BeginUpdateCheck(task_runner_, std::string(), false, 0,
545 IsEmpty(), StrEq(new_version_))); 738 mock_update_check_delegate_.AsWeakPtr());
546 BeginUpdateCheck(task_runner_, false, 0, callback_receiver_.GetCallback());
547 task_runner_->RunUntilIdle(); 739 task_runner_->RunUntilIdle();
548 } 740 }
549 741
550 TEST_P(GoogleUpdateWinTest, UpdateInstalled) { 742 // Test an update check where an update is available.
551 EXPECT_CALL(mock_google_update_factory_, Create(_)) 743 TEST_P(GoogleUpdateWinTest, UpdateCheckUpdateAvailable) {
552 .WillOnce(DoAll(SetArgPointee<0>(mock_on_demand_), Return(S_OK))); 744 PrepareSimulatorForUpdateCheck(kChromeBinariesGuid);
553 mock_on_demand_->OnUpdateRunInstallUpdateSequence(kChromeBinariesGuid, 745 PushState(STATE_INIT);
554 new_version_); 746 PushState(STATE_CHECKING_FOR_UPDATE);
747 PushUpdateAvailableState(new_version_);
555 748
556 EXPECT_CALL(callback_receiver_, 749 EXPECT_CALL(mock_update_check_delegate_,
557 OnUpdateCheckCallback(UPGRADE_SUCCESSFUL, GOOGLE_UPDATE_NO_ERROR, 750 OnUpdateCheckComplete(StrEq(new_version_)));
558 IsEmpty(), StrEq(new_version_))); 751 BeginUpdateCheck(task_runner_, std::string(), false, 0,
559 BeginUpdateCheck(task_runner_, true, 0, callback_receiver_.GetCallback()); 752 mock_update_check_delegate_.AsWeakPtr());
560 task_runner_->RunUntilIdle(); 753 task_runner_->RunUntilIdle();
561 } 754 }
562 755
563 TEST_P(GoogleUpdateWinTest, UpdateFailed) { 756 // Test a successful upgrade.
564 static const base::char16 kError[] = L"It didn't work."; 757 TEST_P(GoogleUpdateWinTest, UpdateInstalled) {
565 EXPECT_CALL(mock_google_update_factory_, Create(_)) 758 PrepareSimulatorForUpgrade(kChromeBinariesGuid);
566 .WillOnce(DoAll(SetArgPointee<0>(mock_on_demand_), Return(S_OK))); 759 PushState(STATE_INIT);
567 mock_on_demand_->OnUpdateRunUpdateErrorSequence(kChromeBinariesGuid, kError); 760 PushState(STATE_CHECKING_FOR_UPDATE);
761 PushUpdateAvailableState(new_version_);
762 PushState(STATE_WAITING_TO_DOWNLOAD);
763 PushProgressiveState(STATE_DOWNLOADING, 0);
764 PushProgressiveState(STATE_DOWNLOADING, 25);
765 PushProgressiveState(STATE_DOWNLOADING, 25);
766 PushProgressiveState(STATE_DOWNLOADING, 75);
767 PushState(STATE_WAITING_TO_INSTALL);
768 PushProgressiveState(STATE_INSTALLING, 50);
769 PushState(STATE_INSTALL_COMPLETE);
568 770
569 EXPECT_CALL(callback_receiver_, 771 {
570 OnUpdateCheckCallback(UPGRADE_ERROR, GOOGLE_UPDATE_ERROR_UPDATING, 772 InSequence callback_sequence;
571 StrEq(kError), IsEmpty())); 773 EXPECT_CALL(mock_update_check_delegate_,
572 BeginUpdateCheck(task_runner_, true, 0, callback_receiver_.GetCallback()); 774 OnUpgradeProgress(0, StrEq(new_version_)));
775 EXPECT_CALL(mock_update_check_delegate_,
776 OnUpgradeProgress(12, StrEq(new_version_)));
777 EXPECT_CALL(mock_update_check_delegate_,
778 OnUpgradeProgress(37, StrEq(new_version_)));
779 EXPECT_CALL(mock_update_check_delegate_,
780 OnUpgradeProgress(50, StrEq(new_version_)));
781 EXPECT_CALL(mock_update_check_delegate_,
782 OnUpgradeProgress(75, StrEq(new_version_)));
783 EXPECT_CALL(mock_update_check_delegate_,
784 OnUpgradeComplete(StrEq(new_version_)));
785 }
786 BeginUpdateCheck(task_runner_, std::string(), true, 0,
787 mock_update_check_delegate_.AsWeakPtr());
573 task_runner_->RunUntilIdle(); 788 task_runner_->RunUntilIdle();
574 } 789 }
575 790
791 // Test a failed upgrade where Google Update reports that the installer failed.
792 TEST_P(GoogleUpdateWinTest, UpdateFailed) {
793 const base::string16 error(L"It didn't work.");
794 static const HRESULT GOOPDATEINSTALL_E_INSTALLER_FAILED = 0x80040902;
795 static const int kInstallerError = 12;
796
797 PrepareSimulatorForUpgrade(kChromeBinariesGuid);
798 PushState(STATE_INIT);
799 PushState(STATE_CHECKING_FOR_UPDATE);
800 PushUpdateAvailableState(new_version_);
801 PushState(STATE_WAITING_TO_DOWNLOAD);
802 PushProgressiveState(STATE_DOWNLOADING, 0);
803 PushProgressiveState(STATE_DOWNLOADING, 25);
804 PushProgressiveState(STATE_DOWNLOADING, 25);
805 PushProgressiveState(STATE_DOWNLOADING, 75);
806 PushState(STATE_WAITING_TO_INSTALL);
807 PushProgressiveState(STATE_INSTALLING, 50);
808 PushErrorState(GOOPDATEINSTALL_E_INSTALLER_FAILED, error, kInstallerError);
809
810 {
811 InSequence callback_sequence;
812 EXPECT_CALL(mock_update_check_delegate_,
813 OnUpgradeProgress(0, StrEq(new_version_)));
814 EXPECT_CALL(mock_update_check_delegate_,
815 OnUpgradeProgress(12, StrEq(new_version_)));
816 EXPECT_CALL(mock_update_check_delegate_,
817 OnUpgradeProgress(37, StrEq(new_version_)));
818 EXPECT_CALL(mock_update_check_delegate_,
819 OnUpgradeProgress(50, StrEq(new_version_)));
820 EXPECT_CALL(mock_update_check_delegate_,
821 OnUpgradeProgress(75, StrEq(new_version_)));
822 EXPECT_CALL(mock_update_check_delegate_,
823 OnError(GOOGLE_UPDATE_ERROR_UPDATING, HasSubstr(error),
824 StrEq(new_version_)));
825 }
826 BeginUpdateCheck(task_runner_, std::string(), true, 0,
827 mock_update_check_delegate_.AsWeakPtr());
828 task_runner_->RunUntilIdle();
829 }
830
576 #endif // defined(GOOGLE_CHROME_BUILD) 831 #endif // defined(GOOGLE_CHROME_BUILD)
577 832
578 INSTANTIATE_TEST_CASE_P(UserLevel, GoogleUpdateWinTest, Values(false)); 833 INSTANTIATE_TEST_CASE_P(UserLevel, GoogleUpdateWinTest, Values(false));
579 834
580 INSTANTIATE_TEST_CASE_P(SystemLevel, GoogleUpdateWinTest, Values(true)); 835 INSTANTIATE_TEST_CASE_P(SystemLevel, GoogleUpdateWinTest, Values(true));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698