Commit f9178f09 authored by Maciek Kumorek's avatar Maciek Kumorek Committed by Commit Bot

Add a switch to simulate errors in the about page

Add --simulate-update-hresult and --simulate-update-error-code
switches. The first switch can take the HRESULT error code value,
the second one specifies a value that corresponds to the
GoolgeUpdateErrorCode enum. With these switches, when using
VersionUpdaterWin, one can simulate errors in the about page to debug
how the UI reflects certain errors conditions.

Bug: 1066529
Change-Id: I6500b81108c69d252087ebcdb1cba0ffba86dbed
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2131019
Commit-Queue: Maciek Kumorek <makumo@microsoft.com>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarSorin Jianu <sorin@chromium.org>
Reviewed-by: default avatarGreg Thompson <grt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#760218}
parent a68c16b3
......@@ -4082,6 +4082,8 @@ jumbo_static_library("browser") {
"google/google_update_policy_fetcher_win.h",
"google/google_update_win.cc",
"google/google_update_win.h",
"google/switches.cc",
"google/switches.h",
"win/conflicts/incompatible_applications_updater.cc",
"win/conflicts/incompatible_applications_updater.h",
"win/conflicts/installed_applications.cc",
......
This diff is collapsed.
......@@ -19,6 +19,7 @@
#include "base/path_service.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_command_line.h"
#include "base/test/scoped_path_override.h"
#include "base/test/test_reg_util_win.h"
#include "base/test/test_simple_task_runner.h"
......@@ -26,6 +27,7 @@
#include "base/version.h"
#include "base/win/atl.h"
#include "base/win/registry.h"
#include "chrome/browser/google/switches.h"
#include "chrome/common/chrome_version.h"
#include "chrome/install_static/test/scoped_install_details.h"
#include "chrome/installer/util/google_update_settings.h"
......@@ -35,6 +37,8 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/win/atl_module.h"
using ::testing::_;
using ::testing::AllOfArray;
using ::testing::DoAll;
using ::testing::HasSubstr;
using ::testing::InSequence;
......@@ -45,7 +49,6 @@ using ::testing::SetArgPointee;
using ::testing::StrEq;
using ::testing::StrictMock;
using ::testing::Values;
using ::testing::_;
namespace {
......@@ -1062,6 +1065,72 @@ TEST_P(GoogleUpdateWinTest, UpdateInstalledMultipleDelegates) {
EXPECT_EQ(GetLastUpdateState()->new_version, new_version_);
}
// Test the case where the GoogleUpdate class responds with error provided
// via the command line with specified hresult and GoogleUpdateErrorCode.
TEST_P(GoogleUpdateWinTest, SimulateHresultWithErrorCode) {
base::test::ScopedCommandLine commandline;
// Simulate GOOGLE_UPDATE_ONDEMAND_CLASS_NOT_FOUND (3).
commandline.GetProcessCommandLine()->AppendSwitchASCII(
switches::kSimulateUpdateErrorCode, "3");
// Simulate WININET_E_INCORRECT_HANDLE_TYPE (0x80072ef2).
commandline.GetProcessCommandLine()->AppendSwitchASCII(
switches::kSimulateUpdateHresult, "0x80072ef2");
// Expect the appropriate error when the on-demand class cannot be created.
EXPECT_CALL(mock_update_check_delegate_,
OnError(GOOGLE_UPDATE_ONDEMAND_CLASS_NOT_FOUND,
AllOfArray({HasSubstr(L"error code 3:"),
HasSubstr(L"0x80072EF2")}),
_));
BeginUpdateCheck(std::string(), false, 0,
mock_update_check_delegate_.AsWeakPtr());
task_runner_->RunUntilIdle();
ASSERT_TRUE(GetLastUpdateState());
EXPECT_EQ(GetLastUpdateState()->error_code,
GOOGLE_UPDATE_ONDEMAND_CLASS_NOT_FOUND);
}
// Test the case where the GoogleUpdate class responds with error provided
// via the command line with a specific hresult.
TEST_P(GoogleUpdateWinTest, SimulateHresultOnly) {
base::test::ScopedCommandLine commandline;
// Simulate WININET_E_INCORRECT_HANDLE_TYPE (0x80072ef2).
commandline.GetProcessCommandLine()->AppendSwitchASCII(
switches::kSimulateUpdateHresult, "0x80072ef2");
// Expect the appropriate error when the on-demand class cannot be created.
EXPECT_CALL(mock_update_check_delegate_,
OnError(GOOGLE_UPDATE_ERROR_UPDATING,
AllOfArray({HasSubstr(L"error code 7:"),
HasSubstr(L"0x80072EF2")}),
_));
BeginUpdateCheck(std::string(), false, 0,
mock_update_check_delegate_.AsWeakPtr());
task_runner_->RunUntilIdle();
ASSERT_TRUE(GetLastUpdateState());
EXPECT_EQ(GetLastUpdateState()->error_code, GOOGLE_UPDATE_ERROR_UPDATING);
}
// Test the case where the GoogleUpdate class responds with error provided
// via the command line without specific hresult.
TEST_P(GoogleUpdateWinTest, SimulateHresultDefault) {
base::test::ScopedCommandLine commandline;
commandline.GetProcessCommandLine()->AppendSwitch(
switches::kSimulateUpdateHresult);
// Expect the appropriate error when the on-demand class cannot be created.
EXPECT_CALL(mock_update_check_delegate_,
OnError(GOOGLE_UPDATE_ERROR_UPDATING,
AllOfArray({HasSubstr(L"error code 7:"),
HasSubstr(L"0x80004005")}),
_));
BeginUpdateCheck(std::string(), false, 0,
mock_update_check_delegate_.AsWeakPtr());
task_runner_->RunUntilIdle();
ASSERT_TRUE(GetLastUpdateState());
EXPECT_EQ(GetLastUpdateState()->error_code, GOOGLE_UPDATE_ERROR_UPDATING);
}
INSTANTIATE_TEST_SUITE_P(UserLevel, GoogleUpdateWinTest, Values(false));
INSTANTIATE_TEST_SUITE_P(SystemLevel, GoogleUpdateWinTest, Values(true));
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/google/switches.h"
namespace switches {
// Simulates a specific HRESULT error code returned by the update check.
// If the switch value is not specified (as hex) then it defaults to E_FAIL.
const char kSimulateUpdateHresult[] = "simulate-update-hresult";
// Simulates a GoogleUpdateErrorCode error by the update check.
// Must be supplied with |kSimulateUpdateHresult| switch.
const char kSimulateUpdateErrorCode[] = "simulate-update-error-code";
} // namespace switches
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_GOOGLE_SWITCHES_H_
#define CHROME_BROWSER_GOOGLE_SWITCHES_H_
namespace switches {
extern const char kSimulateUpdateHresult[];
extern const char kSimulateUpdateErrorCode[];
} // namespace switches
#endif // CHROME_BROWSER_GOOGLE_SWITCHES_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment