Commit 58105cd8 authored by Saurabh Nijhara's avatar Saurabh Nijhara Committed by Commit Bot

Updating API to fetch the End of life (Eol) status of the device

Updated API in update_required_screen to fetch the Eol status of the device. GetEolStatus has been deprecated and hence, now using GetEolInfo. Also, added a browser test for the same.

Bug: 1020616
Change-Id: I3e5ba906fb9c2fa88e75536b4a1017ae2f7bee79
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1910085
Commit-Queue: Saurabh Nijhara <snijhara@google.com>
Reviewed-by: default avatarDenis Kuznetsov [CET] <antrim@chromium.org>
Cr-Commit-Position: refs/heads/master@{#714866}
parent 68ab955f
......@@ -10,6 +10,7 @@
#include "ash/public/cpp/login_screen.h"
#include "ash/public/cpp/system_tray.h"
#include "base/bind.h"
#include "base/time/default_clock.h"
#include "chrome/browser/chromeos/login/error_screens_histogram_helper.h"
#include "chrome/browser/chromeos/login/helper.h"
#include "chrome/browser/chromeos/login/ui/login_display.h"
......@@ -42,7 +43,8 @@ UpdateRequiredScreen::UpdateRequiredScreen(UpdateRequiredView* view,
histogram_helper_(
std::make_unique<ErrorScreensHistogramHelper>("UpdateRequired")),
version_updater_(std::make_unique<VersionUpdater>(this)),
network_state_helper_(std::make_unique<login::NetworkStateHelper>()) {
network_state_helper_(std::make_unique<login::NetworkStateHelper>()),
clock_(base::DefaultClock::GetInstance()) {
if (view_)
view_->Bind(this);
}
......@@ -72,9 +74,19 @@ void UpdateRequiredScreen::Show() {
view_->Show();
}
}
version_updater_->GetEolInfo(base::BindOnce(
&UpdateRequiredScreen::OnGetEolInfo, weak_factory_.GetWeakPtr()));
}
// TODO(crbug/1020616): Get end-of-life information and update the UI based on
// that.
void UpdateRequiredScreen::OnGetEolInfo(
const chromeos::UpdateEngineClient::EolInfo& info) {
// TODO(crbug.com/1020616) : Handle if the device is left on this screen
// for long enough to reach Eol.
if (!info.eol_date.is_null() && info.eol_date <= clock_->Now()) {
EnsureScreenIsShown();
if (view_)
view_->SetUIState(UpdateRequiredView::EOL);
}
}
void UpdateRequiredScreen::Hide() {
......@@ -264,6 +276,10 @@ VersionUpdater* UpdateRequiredScreen::GetVersionUpdaterForTesting() {
return version_updater_.get();
}
void UpdateRequiredScreen::SetClockForTesting(base::Clock* clock) {
clock_ = clock;
}
void UpdateRequiredScreen::EnsureScreenIsShown() {
if (is_shown_ || !view_)
return;
......
......@@ -17,6 +17,10 @@
#include "chrome/browser/chromeos/login/screens/error_screen.h"
#include "chrome/browser/chromeos/login/version_updater/version_updater.h"
namespace base {
class Clock;
} // namespace base
namespace chromeos {
class ErrorScreensHistogramHelper;
......@@ -59,6 +63,9 @@ class UpdateRequiredScreen : public BaseScreen,
VersionUpdater* GetVersionUpdaterForTesting();
// Set a base clock (used to set current time) for testing EOL.
void SetClockForTesting(base::Clock* clock);
private:
void EnsureScreenIsShown();
......@@ -83,6 +90,8 @@ class UpdateRequiredScreen : public BaseScreen,
// The user requested an attempt to connect to the network should be made.
void OnConnectRequested();
void OnGetEolInfo(const chromeos::UpdateEngineClient::EolInfo& info);
void OnErrorScreenHidden();
// True if there was no notification about captive portal state for
......@@ -113,6 +122,9 @@ class UpdateRequiredScreen : public BaseScreen,
// instead.
base::OneShotTimer error_message_timer_;
// Overridden for testing EOL by setting the current time.
base::Clock* clock_;
ErrorScreen::ConnectRequestCallbackSubscription connect_request_subscription_;
base::WeakPtrFactory<UpdateRequiredScreen> weak_factory_{this};
......
// 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/chromeos/login/screens/update_required_screen.h"
#include <memory>
#include "base/bind_helpers.h"
#include "base/callback.h"
#include "base/optional.h"
#include "base/run_loop.h"
#include "base/test/simple_test_clock.h"
#include "base/test/simple_test_tick_clock.h"
#include "base/time/time.h"
#include "chrome/browser/chromeos/login/login_wizard.h"
#include "chrome/browser/chromeos/login/screens/error_screen.h"
#include "chrome/browser/chromeos/login/test/js_checker.h"
#include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h"
#include "chrome/browser/chromeos/login/ui/login_display_host.h"
#include "chrome/browser/chromeos/login/version_updater/version_updater.h"
#include "chrome/browser/ui/webui/chromeos/login/error_screen_handler.h"
#include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
#include "chrome/browser/ui/webui/chromeos/login/update_required_screen_handler.h"
#include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/test/base/mixin_based_in_process_browser_test.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/fake_update_engine_client.h"
namespace chromeos {
namespace {
chromeos::OobeUI* GetOobeUI() {
auto* host = chromeos::LoginDisplayHost::default_host();
return host ? host->GetOobeUI() : nullptr;
}
} // namespace
class UpdateRequiredScreenTest : public MixinBasedInProcessBrowserTest {
public:
UpdateRequiredScreenTest() = default;
~UpdateRequiredScreenTest() override = default;
UpdateRequiredScreenTest(const UpdateRequiredScreenTest&) = delete;
UpdateRequiredScreenTest& operator=(const UpdateRequiredScreenTest&) = delete;
// InProcessBrowserTest:
void SetUpInProcessBrowserTestFixture() override {
MixinBasedInProcessBrowserTest::SetUpInProcessBrowserTestFixture();
fake_update_engine_client_ = new FakeUpdateEngineClient();
chromeos::DBusThreadManager::GetSetterForTesting()->SetUpdateEngineClient(
std::unique_ptr<UpdateEngineClient>(fake_update_engine_client_));
}
void SetUpOnMainThread() override {
MixinBasedInProcessBrowserTest::SetUpOnMainThread();
ShowLoginWizard(OobeScreen::SCREEN_TEST_NO_WINDOW);
tick_clock_.Advance(base::TimeDelta::FromMinutes(1));
clock_ = std::make_unique<base::SimpleTestClock>();
error_screen_ = GetOobeUI()->GetErrorScreen();
update_required_screen_ = std::make_unique<UpdateRequiredScreen>(
GetOobeUI()->GetView<UpdateRequiredScreenHandler>(), error_screen_);
update_required_screen_->SetClockForTesting(clock_.get());
version_updater_ = update_required_screen_->GetVersionUpdaterForTesting();
version_updater_->set_tick_clock_for_testing(&tick_clock_);
}
void TearDownOnMainThread() override {
update_required_screen_.reset();
base::RunLoop run_loop;
LoginDisplayHost::default_host()->Finalize(run_loop.QuitClosure());
run_loop.Run();
MixinBasedInProcessBrowserTest::TearDownOnMainThread();
}
void SetEolDateUTC(const char* utc_date_string) {
base::Time utc_date;
ASSERT_TRUE(base::Time::FromUTCString(utc_date_string, &utc_date));
fake_update_engine_client_->set_eol_date(utc_date);
}
void SetCurrentTimeUTC(const char* utc_date_string) {
base::Time utc_time;
ASSERT_TRUE(base::Time::FromUTCString(utc_date_string, &utc_time));
clock_->SetNow(utc_time);
}
protected:
std::unique_ptr<UpdateRequiredScreen> update_required_screen_;
// Error screen - owned by OobeUI.
ErrorScreen* error_screen_ = nullptr;
// Fake update engine for testing
FakeUpdateEngineClient* fake_update_engine_client_ = nullptr; // Unowned.
// Version updater - owned by |update_required_screen_|.
VersionUpdater* version_updater_ = nullptr;
base::SimpleTestTickClock tick_clock_;
// Clock to set current time for testing EOL.
std::unique_ptr<base::SimpleTestClock> clock_;
};
IN_PROC_BROWSER_TEST_F(UpdateRequiredScreenTest, TestEolReached) {
SetEolDateUTC("1 January 2019");
SetCurrentTimeUTC("1 November 2019");
update_required_screen_->Show();
OobeScreenWaiter update_screen_waiter(UpdateRequiredView::kScreenId);
update_screen_waiter.set_assert_next_screen();
update_screen_waiter.Wait();
test::OobeJS().ExpectVisible("update-required-card");
test::OobeJS().ExpectVisiblePath({"update-required-card", "eol-dialog"});
test::OobeJS().ExpectHiddenPath(
{"update-required-card", "update-required-error-dialog"});
}
IN_PROC_BROWSER_TEST_F(UpdateRequiredScreenTest, TestEolNotReached) {
SetEolDateUTC("1 November 2019");
SetCurrentTimeUTC("1 January 2019");
update_required_screen_->Show();
OobeScreenWaiter update_screen_waiter(UpdateRequiredView::kScreenId);
update_screen_waiter.set_assert_next_screen();
update_screen_waiter.Wait();
test::OobeJS().ExpectVisible("update-required-card");
test::OobeJS().ExpectHiddenPath({"update-required-card", "eol-dialog"});
test::OobeJS().ExpectVisiblePath(
{"update-required-card", "update-required-error-dialog"});
}
} // namespace chromeos
......@@ -143,6 +143,22 @@ base::OneShotTimer* VersionUpdater::GetRebootTimerForTesting() {
return &reboot_timer_;
}
void VersionUpdater::GetEolInfo(EolInfoCallback callback) {
UpdateEngineClient* update_engine_client =
DBusThreadManager::Get()->GetUpdateEngineClient();
// Request the End of Life (Auto Update Expiration) status. Bind to a weak_ptr
// bound method rather than passing |callback| directly so that |callback|
// does not outlive |this|.
update_engine_client->GetEolInfo(
base::BindOnce(&VersionUpdater::OnGetEolInfo,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void VersionUpdater::OnGetEolInfo(EolInfoCallback callback,
UpdateEngineClient::EolInfo info) {
std::move(callback).Run(std::move(info));
}
void VersionUpdater::UpdateStatusChangedForTesting(
const update_engine::StatusResult& status) {
UpdateStatusChanged(status);
......
......@@ -95,6 +95,10 @@ class VersionUpdater : public UpdateEngineClient::Observer,
virtual void DelayErrorMessage() = 0;
};
// Callback type for |GetEOLInfo|
using EolInfoCallback =
base::OnceCallback<void(const UpdateEngineClient::EolInfo& eol_info)>;
explicit VersionUpdater(VersionUpdater::Delegate* delegate);
~VersionUpdater() override;
......@@ -112,6 +116,9 @@ class VersionUpdater : public UpdateEngineClient::Observer,
const UpdateInfo& update_info() { return update_info_; }
// Has the device already reached its End Of Life (Auto Update Expiration) ?
void GetEolInfo(EolInfoCallback callback);
void set_tick_clock_for_testing(const base::TickClock* tick_clock) {
tick_clock_ = tick_clock;
}
......@@ -127,6 +134,8 @@ class VersionUpdater : public UpdateEngineClient::Observer,
private:
void RequestUpdateCheck();
void OnGetEolInfo(EolInfoCallback cb, UpdateEngineClient::EolInfo info);
// UpdateEngineClient::Observer implementation:
void UpdateStatusChanged(const update_engine::StatusResult& status) override;
......
......@@ -18,7 +18,7 @@
<template>
<oobe-dialog has-buttons hidden="[[showOn_(ui_state,
'update-required-message',
'update-error')]]">
'update-error')]]" id="update-required-error-dialog">
<div slot="subtitle">
<div hidden="[[showOn_(ui_state, 'update-error')]]"
class="update-error">
......@@ -88,12 +88,20 @@
</oobe-dialog>
<oobe-dialog
hidden="[[showOn_(ui_state, 'update-completed-need-reboot', 'eol')]]">
hidden="[[showOn_(ui_state, 'update-completed-need-reboot')]]"
id="update-completed-dialog">
<div slot="subtitle">
<div hidden="[[showOn_(ui_state, 'update-completed-need-reboot')]]">
<div>
[[i18nDynamic(locale,'rebootNeededMessage')]]
</div>
<div hidden="[[showOn_(ui_state, 'eol')]]">
</div>
</oobe-dialog>
<oobe-dialog
hidden="[[showOn_(ui_state, 'eol')]]"
id="eol-dialog">
<div slot="subtitle">>
<div>
[[i18nDynamic(locale,'eolMessage')]]
</div>
</div>
......
......@@ -2189,6 +2189,7 @@ if (!is_android) {
"../browser/chromeos/login/screens/recommend_apps/scoped_test_recommend_apps_fetcher_factory.h",
"../browser/chromeos/login/screens/recommend_apps_screen_browsertest.cc",
"../browser/chromeos/login/screens/supervision_transition_screen_browsertest.cc",
"../browser/chromeos/login/screens/update_required_screen_browsertest.cc",
"../browser/chromeos/login/screens/update_screen_browsertest.cc",
"../browser/chromeos/login/screens/user_selection_screen_browsertest.cc",
"../browser/chromeos/login/screens/welcome_screen_browsertest.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