Make castv2 performance test work.
[chromium-blink-merge.git] / chrome / browser / google / google_update_win_unittest.cc
blob97498e4b03e2b81fd87f3b732953d65a82833789
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
3 // found in the LICENSE file.
5 #include "chrome/browser/google/google_update_win.h"
7 #include <windows.h>
8 #include <atlbase.h>
9 #include <atlcom.h>
11 #include <queue>
13 #include "base/base_paths.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/path_service.h"
16 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/stringprintf.h"
18 #include "base/strings/utf_string_conversions.h"
19 #include "base/test/scoped_path_override.h"
20 #include "base/test/test_reg_util_win.h"
21 #include "base/test/test_simple_task_runner.h"
22 #include "base/thread_task_runner_handle.h"
23 #include "base/version.h"
24 #include "base/win/registry.h"
25 #include "chrome/installer/util/browser_distribution.h"
26 #include "chrome/installer/util/google_update_settings.h"
27 #include "chrome/installer/util/helper.h"
28 #include "google_update/google_update_idl.h"
29 #include "testing/gmock/include/gmock/gmock.h"
30 #include "testing/gtest/include/gtest/gtest.h"
31 #include "ui/base/win/atl_module.h"
32 #include "version.h"
34 using ::testing::DoAll;
35 using ::testing::Invoke;
36 using ::testing::IsEmpty;
37 using ::testing::Return;
38 using ::testing::SetArgPointee;
39 using ::testing::StrEq;
40 using ::testing::Unused;
41 using ::testing::Values;
42 using ::testing::_;
44 namespace {
46 class UpdateCheckCallbackReceiver {
47 public:
48 UpdateCheckCallbackReceiver() {}
49 virtual ~UpdateCheckCallbackReceiver() {}
50 virtual void OnUpdateCheckCallback(GoogleUpdateUpgradeResult result,
51 GoogleUpdateErrorCode error_code,
52 const base::string16& error_message,
53 const base::string16& version) = 0;
54 UpdateCheckCallback GetCallback() {
55 return base::Bind(&UpdateCheckCallbackReceiver::UpdateCheckCallback,
56 base::Unretained(this));
59 private:
60 void UpdateCheckCallback(GoogleUpdateUpgradeResult result,
61 GoogleUpdateErrorCode error_code,
62 const base::string16& error_message,
63 const base::string16& version) {
64 OnUpdateCheckCallback(result, error_code, error_message, version);
67 DISALLOW_COPY_AND_ASSIGN(UpdateCheckCallbackReceiver);
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&));
79 private:
80 DISALLOW_COPY_AND_ASSIGN(MockUpdateCheckCallbackReceiver);
83 class GoogleUpdateFactory {
84 public:
85 virtual ~GoogleUpdateFactory() {}
86 virtual HRESULT Create(base::win::ScopedComPtr<IGoogleUpdate>* on_demand) = 0;
89 class MockGoogleUpdateFactory : public GoogleUpdateFactory {
90 public:
91 MockGoogleUpdateFactory() {}
92 MOCK_METHOD1(Create, HRESULT(base::win::ScopedComPtr<IGoogleUpdate>*));
94 private:
95 DISALLOW_COPY_AND_ASSIGN(MockGoogleUpdateFactory);
98 // A mock IGoogleUpdate on-demand update class that can run an IJobObserver
99 // through a set of states.
100 class MockOnDemand : public CComObjectRootEx<CComSingleThreadModel>,
101 public IGoogleUpdate {
102 public:
103 BEGIN_COM_MAP(MockOnDemand)
104 COM_INTERFACE_ENTRY(IGoogleUpdate)
105 END_COM_MAP()
107 MockOnDemand() : task_runner_(base::ThreadTaskRunnerHandle::Get()) {}
109 MOCK_METHOD2_WITH_CALLTYPE(STDMETHODCALLTYPE,
110 CheckForUpdate,
111 HRESULT(const wchar_t*, IJobObserver*));
112 MOCK_METHOD2_WITH_CALLTYPE(STDMETHODCALLTYPE,
113 Update,
114 HRESULT(const wchar_t*, IJobObserver*));
116 void OnCheckRunUpToDateSequence(const base::char16* app_guid) {
117 EXPECT_CALL(*this, CheckForUpdate(StrEq(app_guid), _))
118 .WillOnce(DoAll(Invoke(this, &MockOnDemand::BeginUpToDateSequence),
119 Return(S_OK)));
122 void OnCheckRunUpdateAvailableSequence(const base::char16* app_guid,
123 const base::string16& new_version) {
124 new_version_ = new_version;
125 EXPECT_CALL(*this, CheckForUpdate(StrEq(app_guid), _))
126 .WillOnce(
127 DoAll(Invoke(this, &MockOnDemand::BeginUpdateAvailableSequence),
128 Return(S_OK)));
131 void OnUpdateRunInstallUpdateSequence(const base::char16* app_guid,
132 const base::string16& new_version) {
133 new_version_ = new_version;
134 EXPECT_CALL(*this, Update(StrEq(app_guid), _))
135 .WillOnce(DoAll(Invoke(this, &MockOnDemand::BeginInstallUpdateSequence),
136 Return(S_OK)));
139 void OnUpdateRunUpdateErrorSequence(const base::char16* app_guid,
140 const base::char16* error_text) {
141 error_text_ = error_text;
142 EXPECT_CALL(*this, Update(StrEq(app_guid), _))
143 .WillOnce(DoAll(Invoke(this, &MockOnDemand::BeginUpdateErrorSequence),
144 Return(S_OK)));
147 private:
148 enum State {
149 STATE_CHECKING,
150 STATE_COMPLETE_SUCCESS,
151 STATE_UPDATE_AVAILABLE,
152 STATE_WAITING_TO_DOWNLOAD,
153 STATE_DOWNLOADING_25,
154 STATE_DOWNLOADING_100,
155 STATE_WAITING_TO_INSTALL,
156 STATE_INSTALLING,
157 STATE_COMPLETE_ERROR,
160 void BeginUpToDateSequence(Unused, IJobObserver* job_observer_ptr) {
161 job_observer_ = job_observer_ptr;
162 states_.push(STATE_CHECKING);
163 states_.push(STATE_COMPLETE_SUCCESS);
164 task_runner_->PostTask(
165 FROM_HERE, base::Bind(&MockOnDemand::Advance, base::Unretained(this)));
168 void BeginUpdateAvailableSequence(Unused, IJobObserver* job_observer_ptr) {
169 job_observer_ = job_observer_ptr;
170 states_.push(STATE_CHECKING);
171 states_.push(STATE_UPDATE_AVAILABLE);
172 states_.push(STATE_COMPLETE_SUCCESS);
173 task_runner_->PostTask(
174 FROM_HERE, base::Bind(&MockOnDemand::Advance, base::Unretained(this)));
177 void BeginInstallUpdateSequence(Unused, IJobObserver* job_observer_ptr) {
178 job_observer_ = job_observer_ptr;
179 states_.push(STATE_CHECKING);
180 states_.push(STATE_UPDATE_AVAILABLE);
181 states_.push(STATE_WAITING_TO_DOWNLOAD);
182 states_.push(STATE_DOWNLOADING_25);
183 states_.push(STATE_DOWNLOADING_100);
184 states_.push(STATE_WAITING_TO_INSTALL);
185 states_.push(STATE_INSTALLING);
186 states_.push(STATE_COMPLETE_SUCCESS);
187 task_runner_->PostTask(
188 FROM_HERE, base::Bind(&MockOnDemand::Advance, base::Unretained(this)));
191 void BeginUpdateErrorSequence(Unused, IJobObserver* job_observer_ptr) {
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)));
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;
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)));
250 // The task runner on which the state machine runs.
251 scoped_refptr<base::TaskRunner> task_runner_;
253 // The new version for a successful update check or update.
254 base::string16 new_version_;
256 // Error text to be supplied for an unsuccessful update check or update.
257 base::string16 error_text_;
259 // The set of states to be run on an IJobObserver.
260 std::queue<State> states_;
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_;
266 DISALLOW_COPY_AND_ASSIGN(MockOnDemand);
269 } // namespace
271 class GoogleUpdateWinTest : public ::testing::TestWithParam<bool> {
272 public:
273 static void SetUpTestCase() { ui::win::CreateATLModuleIfNeeded(); }
275 protected:
276 GoogleUpdateWinTest()
277 : task_runner_(new base::TestSimpleTaskRunner()),
278 task_runner_handle_(task_runner_),
279 system_level_(GetParam()),
280 mock_on_demand_(nullptr) {}
282 void SetUp() override {
283 ::testing::TestWithParam<bool>::SetUp();
285 // 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).
287 base::FilePath file_exe;
288 ASSERT_TRUE(PathService::Get(base::FILE_EXE, &file_exe));
289 base::FilePath install_dir(installer::GetChromeInstallPath(
290 system_level_, BrowserDistribution::GetDistribution()));
291 file_exe_override_.reset(new base::ScopedPathOverride(
292 base::FILE_EXE, install_dir.Append(file_exe.BaseName()),
293 true /* is_absolute */, false /* create */));
295 // Override these paths so that they can be found after the registry
296 // override manager is in place.
297 base::FilePath temp;
298 PathService::Get(base::DIR_PROGRAM_FILES, &temp);
299 program_files_override_.reset(
300 new base::ScopedPathOverride(base::DIR_PROGRAM_FILES, temp));
301 PathService::Get(base::DIR_PROGRAM_FILESX86, &temp);
302 program_files_x86_override_.reset(
303 new base::ScopedPathOverride(base::DIR_PROGRAM_FILESX86, temp));
304 PathService::Get(base::DIR_LOCAL_APP_DATA, &temp);
305 local_app_data_override_.reset(
306 new base::ScopedPathOverride(base::DIR_LOCAL_APP_DATA, temp));
308 // Override the registry so that tests can freely push state to it.
309 registry_override_manager_.OverrideRegistry(HKEY_CURRENT_USER);
310 registry_override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE);
312 // Chrome is installed as multi-install.
313 const HKEY root = system_level_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
314 base::win::RegKey key(root, kClients, KEY_WRITE | KEY_WOW64_32KEY);
315 ASSERT_EQ(ERROR_SUCCESS,
316 key.CreateKey(kChromeGuid, KEY_WRITE | KEY_WOW64_32KEY));
317 ASSERT_EQ(ERROR_SUCCESS,
318 key.WriteValue(
319 L"pv", base::ASCIIToUTF16(CHROME_VERSION_STRING).c_str()));
320 ASSERT_EQ(ERROR_SUCCESS,
321 key.Create(root, kClientState, KEY_WRITE | KEY_WOW64_32KEY));
322 ASSERT_EQ(ERROR_SUCCESS,
323 key.CreateKey(kChromeGuid, KEY_WRITE | KEY_WOW64_32KEY));
324 ASSERT_EQ(ERROR_SUCCESS,
325 key.WriteValue(L"UninstallArguments",
326 L"--uninstall --multi-install --chrome"));
328 // Provide an IGoogleUpdate on-demand update class factory so that this test
329 // can provide a mocked-out instance.
330 SetGoogleUpdateFactoryForTesting(
331 base::Bind(&GoogleUpdateFactory::Create,
332 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));
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));
345 // Compute a newer version.
346 base::Version current_version(CHROME_VERSION_STRING);
347 new_version_ = base::StringPrintf(L"%u.%u.%u.%u",
348 current_version.components()[0],
349 current_version.components()[1],
350 current_version.components()[2] + 1,
351 current_version.components()[3]);
354 void TearDown() override {
355 // Remove the test's IGoogleUpdate on-demand update class factory.
356 SetGoogleUpdateFactoryForTesting(OnDemandAppsClassFactory());
359 // Set the default update policy in the registry.
360 void SetDefaultUpdatePolicy(GoogleUpdateSettings::UpdatePolicy policy) const {
361 base::win::RegKey policy_key(HKEY_LOCAL_MACHINE, kPoliciesKey,
362 KEY_SET_VALUE);
363 ASSERT_EQ(ERROR_SUCCESS, policy_key.WriteValue(kUpdateDefault, policy));
366 // Stuffs |policy| in the registry for the app identified by |app_guid|.
367 void SetAppUpdatePolicy(const base::char16* app_guid,
368 GoogleUpdateSettings::UpdatePolicy policy) const {
369 base::string16 value_name(L"Update");
370 value_name += app_guid;
371 base::win::RegKey policy_key(HKEY_LOCAL_MACHINE, kPoliciesKey,
372 KEY_SET_VALUE);
373 ASSERT_EQ(ERROR_SUCCESS, policy_key.WriteValue(value_name.c_str(), policy));
376 static const base::char16 kPoliciesKey[];
377 static const base::char16 kUpdateDefault[];
378 static const base::char16 kClients[];
379 static const base::char16 kClientState[];
380 static const base::char16 kChromeGuid[];
381 static const base::char16 kChromeBinariesGuid[];
383 scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
384 base::ThreadTaskRunnerHandle task_runner_handle_;
385 bool system_level_;
386 scoped_ptr<base::ScopedPathOverride> file_exe_override_;
387 scoped_ptr<base::ScopedPathOverride> program_files_override_;
388 scoped_ptr<base::ScopedPathOverride> program_files_x86_override_;
389 scoped_ptr<base::ScopedPathOverride> local_app_data_override_;
390 registry_util::RegistryOverrideManager registry_override_manager_;
391 MockUpdateCheckCallbackReceiver callback_receiver_;
392 MockGoogleUpdateFactory mock_google_update_factory_;
393 CComObject<MockOnDemand>* mock_on_demand_;
394 base::win::ScopedComPtr<IGoogleUpdate> on_demand_holder_;
395 base::string16 new_version_;
397 DISALLOW_COPY_AND_ASSIGN(GoogleUpdateWinTest);
400 // 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[] =
405 L"Software\\Google\\Update\\Clients";
406 const base::char16 GoogleUpdateWinTest::kClientState[] =
407 L"Software\\Google\\Update\\ClientState";
408 const base::char16 GoogleUpdateWinTest::kChromeGuid[] =
409 L"{8A69D345-D564-463c-AFF1-A69D9E530F96}";
410 const base::char16 GoogleUpdateWinTest::kChromeBinariesGuid[] =
411 L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}";
413 // Test that an update check fails with the proper error code if Chrome isn't in
414 // one of the expected install directories.
415 TEST_P(GoogleUpdateWinTest, InvalidInstallDirectory) {
416 // Override FILE_EXE so that it looks like the test is running from a
417 // non-standard location.
418 base::FilePath file_exe;
419 base::FilePath dir_temp;
420 ASSERT_TRUE(PathService::Get(base::FILE_EXE, &file_exe));
421 ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &dir_temp));
422 file_exe_override_.reset();
423 file_exe_override_.reset(new base::ScopedPathOverride(
424 base::FILE_EXE, dir_temp.Append(file_exe.BaseName()),
425 true /* is_absolute */, false /* create */));
427 EXPECT_CALL(
428 callback_receiver_,
429 OnUpdateCheckCallback(UPGRADE_ERROR,
430 CANNOT_UPGRADE_CHROME_IN_THIS_DIRECTORY, _, _));
431 BeginUpdateCheck(task_runner_, false, 0, callback_receiver_.GetCallback());
432 task_runner_->RunUntilIdle();
435 #if defined(GOOGLE_CHROME_BUILD)
437 TEST_P(GoogleUpdateWinTest, AllUpdatesDisabledByPolicy) {
438 // Disable updates altogether.
439 SetDefaultUpdatePolicy(GoogleUpdateSettings::UPDATES_DISABLED);
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();
448 TEST_P(GoogleUpdateWinTest, MultiUpdatesDisabledByPolicy) {
449 // Disable updates altogether.
450 SetAppUpdatePolicy(kChromeBinariesGuid,
451 GoogleUpdateSettings::UPDATES_DISABLED);
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();
460 TEST_P(GoogleUpdateWinTest, AllManualUpdatesDisabledByPolicy) {
461 // Disable updates altogether.
462 SetDefaultUpdatePolicy(GoogleUpdateSettings::AUTO_UPDATES_ONLY);
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();
472 TEST_P(GoogleUpdateWinTest, MultiManualUpdatesDisabledByPolicy) {
473 // Disable updates altogether.
474 SetAppUpdatePolicy(kChromeBinariesGuid,
475 GoogleUpdateSettings::AUTO_UPDATES_ONLY);
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();
485 TEST_P(GoogleUpdateWinTest, NoGoogleUpdateForCheck) {
486 // The factory should be called upon: let it fail.
487 EXPECT_CALL(mock_google_update_factory_, Create(_));
489 // Expect the appropriate error when the on-demand class cannot be created.
490 EXPECT_CALL(callback_receiver_,
491 OnUpdateCheckCallback(
492 UPGRADE_ERROR, GOOGLE_UPDATE_ONDEMAND_CLASS_NOT_FOUND, _, _));
493 BeginUpdateCheck(task_runner_, false, 0, callback_receiver_.GetCallback());
494 task_runner_->RunUntilIdle();
497 TEST_P(GoogleUpdateWinTest, NoGoogleUpdateForUpgrade) {
498 // The factory should be called upon: let it fail.
499 EXPECT_CALL(mock_google_update_factory_, Create(_));
501 // Expect the appropriate error when the on-demand class cannot be created.
502 EXPECT_CALL(callback_receiver_,
503 OnUpdateCheckCallback(
504 UPGRADE_ERROR, GOOGLE_UPDATE_ONDEMAND_CLASS_NOT_FOUND, _, _));
505 BeginUpdateCheck(task_runner_, true, 0, callback_receiver_.GetCallback());
506 task_runner_->RunUntilIdle();
509 TEST_P(GoogleUpdateWinTest, FailUpdateCheck) {
510 // The factory should be called upon: let it return the mock on-demand class.
511 EXPECT_CALL(mock_google_update_factory_, Create(_))
512 .WillOnce(DoAll(SetArgPointee<0>(mock_on_demand_), Return(S_OK)));
513 // The mock on-demand class should be called.
514 EXPECT_CALL(*mock_on_demand_, CheckForUpdate(StrEq(kChromeBinariesGuid), _));
516 EXPECT_CALL(
517 callback_receiver_,
518 OnUpdateCheckCallback(UPGRADE_ERROR,
519 GOOGLE_UPDATE_ONDEMAND_CLASS_REPORTED_ERROR, _, _));
520 BeginUpdateCheck(task_runner_, false, 0, callback_receiver_.GetCallback());
521 task_runner_->RunUntilIdle();
524 TEST_P(GoogleUpdateWinTest, UpdateCheckNoUpdate) {
525 EXPECT_CALL(mock_google_update_factory_, Create(_))
526 .WillOnce(DoAll(SetArgPointee<0>(mock_on_demand_), Return(S_OK)));
527 mock_on_demand_->OnCheckRunUpToDateSequence(kChromeBinariesGuid);
529 EXPECT_CALL(callback_receiver_,
530 OnUpdateCheckCallback(UPGRADE_ALREADY_UP_TO_DATE,
531 GOOGLE_UPDATE_NO_ERROR, IsEmpty(), _));
532 BeginUpdateCheck(task_runner_, false, 0, callback_receiver_.GetCallback());
533 task_runner_->RunUntilIdle();
536 TEST_P(GoogleUpdateWinTest, UpdateCheckUpdateAvailable) {
537 EXPECT_CALL(mock_google_update_factory_, Create(_))
538 .WillOnce(DoAll(SetArgPointee<0>(mock_on_demand_), Return(S_OK)));
539 mock_on_demand_->OnCheckRunUpdateAvailableSequence(kChromeBinariesGuid,
540 new_version_);
542 EXPECT_CALL(
543 callback_receiver_,
544 OnUpdateCheckCallback(UPGRADE_IS_AVAILABLE, GOOGLE_UPDATE_NO_ERROR,
545 IsEmpty(), StrEq(new_version_)));
546 BeginUpdateCheck(task_runner_, false, 0, callback_receiver_.GetCallback());
547 task_runner_->RunUntilIdle();
550 TEST_P(GoogleUpdateWinTest, UpdateInstalled) {
551 EXPECT_CALL(mock_google_update_factory_, Create(_))
552 .WillOnce(DoAll(SetArgPointee<0>(mock_on_demand_), Return(S_OK)));
553 mock_on_demand_->OnUpdateRunInstallUpdateSequence(kChromeBinariesGuid,
554 new_version_);
556 EXPECT_CALL(callback_receiver_,
557 OnUpdateCheckCallback(UPGRADE_SUCCESSFUL, GOOGLE_UPDATE_NO_ERROR,
558 IsEmpty(), StrEq(new_version_)));
559 BeginUpdateCheck(task_runner_, true, 0, callback_receiver_.GetCallback());
560 task_runner_->RunUntilIdle();
563 TEST_P(GoogleUpdateWinTest, UpdateFailed) {
564 static const base::char16 kError[] = L"It didn't work.";
565 EXPECT_CALL(mock_google_update_factory_, Create(_))
566 .WillOnce(DoAll(SetArgPointee<0>(mock_on_demand_), Return(S_OK)));
567 mock_on_demand_->OnUpdateRunUpdateErrorSequence(kChromeBinariesGuid, kError);
569 EXPECT_CALL(callback_receiver_,
570 OnUpdateCheckCallback(UPGRADE_ERROR, GOOGLE_UPDATE_ERROR_UPDATING,
571 StrEq(kError), IsEmpty()));
572 BeginUpdateCheck(task_runner_, true, 0, callback_receiver_.GetCallback());
573 task_runner_->RunUntilIdle();
576 #endif // defined(GOOGLE_CHROME_BUILD)
578 INSTANTIATE_TEST_CASE_P(UserLevel, GoogleUpdateWinTest, Values(false));
580 INSTANTIATE_TEST_CASE_P(SystemLevel, GoogleUpdateWinTest, Values(true));