Commit 51c9e47c authored by Andrey Zaytsev's avatar Andrey Zaytsev Committed by Commit Bot

Created skeleton code for checking browser safety and implemented an update check as part of it.

Bug: 1015841
Change-Id: Iacec36c6666d855d113e074148a101b21ab0e76d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1856846
Commit-Queue: Andrey Zaytsev <andzaytsev@google.com>
Reviewed-by: default avatarDan Beam <dbeam@chromium.org>
Reviewed-by: default avatarFlorian Uunk <feuunk@chromium.org>
Reviewed-by: default avatarMartin Šrámek <msramek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709015}
parent 6236efae
...@@ -1296,6 +1296,8 @@ jumbo_static_library("ui") { ...@@ -1296,6 +1296,8 @@ jumbo_static_library("ui") {
"webui/settings/protocol_handlers_handler.h", "webui/settings/protocol_handlers_handler.h",
"webui/settings/reset_settings_handler.cc", "webui/settings/reset_settings_handler.cc",
"webui/settings/reset_settings_handler.h", "webui/settings/reset_settings_handler.h",
"webui/settings/safety_check_handler.cc",
"webui/settings/safety_check_handler.h",
"webui/settings/search_engines_handler.cc", "webui/settings/search_engines_handler.cc",
"webui/settings/search_engines_handler.h", "webui/settings/search_engines_handler.h",
"webui/settings/settings_clear_browsing_data_handler.cc", "webui/settings/settings_clear_browsing_data_handler.cc",
...@@ -4137,6 +4139,8 @@ static_library("test_support") { ...@@ -4137,6 +4139,8 @@ static_library("test_support") {
"tabs/tab_ukm_test_helper.h", "tabs/tab_ukm_test_helper.h",
"test/test_confirm_bubble_model.cc", "test/test_confirm_bubble_model.cc",
"test/test_confirm_bubble_model.h", "test/test_confirm_bubble_model.h",
"webui/help/test_version_updater.cc",
"webui/help/test_version_updater.h",
] ]
deps += [ deps += [
"//chrome/test:test_support_ui", "//chrome/test:test_support_ui",
...@@ -4161,7 +4165,10 @@ static_library("test_support") { ...@@ -4161,7 +4165,10 @@ static_library("test_support") {
"ash/test_wallpaper_controller.cc", "ash/test_wallpaper_controller.cc",
"ash/test_wallpaper_controller.h", "ash/test_wallpaper_controller.h",
] ]
deps += [ "//ash/public/cpp" ] deps += [
"//ash/public/cpp",
"//chromeos/dbus",
]
} }
if (enable_extensions) { if (enable_extensions) {
......
// Copyright 2019 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/ui/webui/help/test_version_updater.h"
TestVersionUpdater::TestVersionUpdater() = default;
TestVersionUpdater::~TestVersionUpdater() = default;
void TestVersionUpdater::CheckForUpdate(const StatusCallback& callback,
const PromoteCallback&) {
callback.Run(status_, progress_, rollback_, version_, update_size_, message_);
}
// Copyright 2019 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_UI_WEBUI_HELP_TEST_VERSION_UPDATER_H_
#define CHROME_BROWSER_UI_WEBUI_HELP_TEST_VERSION_UPDATER_H_
#include "base/macros.h"
#include "build/build_config.h"
#include "chrome/browser/ui/webui/help/version_updater.h"
// A very simple VersionUpdater implementation that immediately invokes the
// StatusCallback with predefined parameters. Since this is only used for
// testing, only the parts of the interface that are needed for testing have
// been implemented.
class TestVersionUpdater : public VersionUpdater {
public:
TestVersionUpdater();
~TestVersionUpdater() override;
void CheckForUpdate(const StatusCallback& callback,
const PromoteCallback&) override;
void SetReturnedStatus(Status status) { status_ = status; }
// VersionUpdater implementation:
#if defined(OS_MACOSX)
void PromoteUpdater() const override {}
#endif
#if defined(OS_CHROMEOS)
void SetChannel(const std::string& channel,
bool is_powerwash_allowed) override {}
void GetChannel(bool get_current_channel,
const ChannelCallback& callback) override {}
void GetEolInfo(EolInfoCallback callback) override {}
void SetUpdateOverCellularOneTimePermission(const StatusCallback& callback,
const std::string& update_version,
int64_t update_size) override {}
#endif
private:
Status status_ = Status::UPDATED;
int progress_ = 0;
bool rollback_ = false;
std::string version_;
int64_t update_size_ = 0;
base::string16 message_;
DISALLOW_COPY_AND_ASSIGN(TestVersionUpdater);
};
#endif // CHROME_BROWSER_UI_WEBUI_HELP_TEST_VERSION_UPDATER_H_
// Copyright 2019 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/ui/webui/settings/safety_check_handler.h"
#include "base/bind.h"
SafetyCheckHandler::SafetyCheckHandler() = default;
SafetyCheckHandler::~SafetyCheckHandler() = default;
void SafetyCheckHandler::PerformSafetyCheck() {
version_updater_.reset(VersionUpdater::Create(web_ui()->GetWebContents()));
CheckUpdates(version_updater_.get(),
base::Bind(&SafetyCheckHandler::OnUpdateCheckResult,
base::Unretained(this)));
}
void SafetyCheckHandler::CheckUpdates(
VersionUpdater* version_updater,
const VersionUpdater::StatusCallback& update_callback) {
version_updater->CheckForUpdate(update_callback,
VersionUpdater::PromoteCallback());
}
void SafetyCheckHandler::OnUpdateCheckResult(VersionUpdater::Status status,
int progress,
bool rollback,
const std::string& version,
int64_t update_size,
const base::string16& message) {
NOTIMPLEMENTED();
}
// Copyright 2019 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_UI_WEBUI_SETTINGS_SAFETY_CHECK_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_SETTINGS_SAFETY_CHECK_HANDLER_H_
#include <stdint.h>
#include <memory>
#include <string>
#include "base/callback_forward.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/ui/webui/help/version_updater.h"
#include "chrome/browser/ui/webui/settings/settings_page_ui_handler.h"
// Settings page UI handler that checks four areas of browser safety: browser
// updates, password leaks, malicious extensions, and unwanted software.
class SafetyCheckHandler : public settings::SettingsPageUIHandler {
public:
SafetyCheckHandler();
~SafetyCheckHandler() override;
// Triggers all four of the browser safety checks.
// Note: since the checks deal with sensitive user information, this method
// should only be called as a result of an explicit user action.
void PerformSafetyCheck();
// Each triggers a corresponding check and calls the provided callback on
// completion.
void CheckUpdates(VersionUpdater* updater,
const VersionUpdater::StatusCallback& update_callback);
private:
// SettingsPageUIHandler implementation.
void OnJavascriptAllowed() override {}
void OnJavascriptDisallowed() override {}
// WebUIMessageHandler implementation.
void RegisterMessages() override {}
// Callbacks that get triggered when each check completes.
void OnUpdateCheckResult(VersionUpdater::Status status,
int progress,
bool rollback,
const std::string& version,
int64_t update_size,
const base::string16& message);
std::unique_ptr<VersionUpdater> version_updater_;
DISALLOW_COPY_AND_ASSIGN(SafetyCheckHandler);
};
#endif // CHROME_BROWSER_UI_WEBUI_SETTINGS_SAFETY_CHECK_HANDLER_H_
// Copyright 2019 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/ui/webui/settings/safety_check_handler.h"
#include "base/bind.h"
#include "chrome/browser/ui/webui/help/test_version_updater.h"
#include "testing/gtest/include/gtest/gtest.h"
class SafetyCheckHandlerTest : public ::testing::Test {
public:
void Callback(VersionUpdater::Status status,
int progress,
bool rollback,
const std::string& version,
int64_t update_size,
const base::string16& message) {
callback_invoked_ = true;
result_ = status;
}
protected:
bool callback_invoked_ = false;
VersionUpdater::Status result_;
TestVersionUpdater version_updater_;
SafetyCheckHandler safety_check_;
};
TEST_F(SafetyCheckHandlerTest, CheckUpdatesUpdated) {
version_updater_.SetReturnedStatus(VersionUpdater::Status::UPDATED);
safety_check_.CheckUpdates(
&version_updater_,
base::Bind(&SafetyCheckHandlerTest::Callback, base::Unretained(this)));
ASSERT_TRUE(callback_invoked_);
EXPECT_EQ(VersionUpdater::Status::UPDATED, result_);
}
TEST_F(SafetyCheckHandlerTest, CheckUpdatesNotUpdated) {
version_updater_.SetReturnedStatus(VersionUpdater::Status::DISABLED);
safety_check_.CheckUpdates(
&version_updater_,
base::Bind(&SafetyCheckHandlerTest::Callback, base::Unretained(this)));
ASSERT_TRUE(callback_invoked_);
EXPECT_EQ(VersionUpdater::Status::DISABLED, result_);
}
...@@ -3917,6 +3917,7 @@ test("unit_tests") { ...@@ -3917,6 +3917,7 @@ test("unit_tests") {
"../browser/ui/webui/settings/people_handler_unittest.cc", "../browser/ui/webui/settings/people_handler_unittest.cc",
"../browser/ui/webui/settings/profile_info_handler_unittest.cc", "../browser/ui/webui/settings/profile_info_handler_unittest.cc",
"../browser/ui/webui/settings/reset_settings_handler_unittest.cc", "../browser/ui/webui/settings/reset_settings_handler_unittest.cc",
"../browser/ui/webui/settings/safety_check_handler_unittest.cc",
"../browser/ui/webui/settings/settings_cookies_view_handler_unittest.cc", "../browser/ui/webui/settings/settings_cookies_view_handler_unittest.cc",
"../browser/ui/webui/settings/settings_manage_profile_handler_unittest.cc", "../browser/ui/webui/settings/settings_manage_profile_handler_unittest.cc",
"../browser/ui/webui/settings/site_settings_handler_unittest.cc", "../browser/ui/webui/settings/site_settings_handler_unittest.cc",
......
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