1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974
|
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ash/eol/eol_notification.h"
#include <memory>
#include <string>
#include "ash/constants/ash_features.h"
#include "ash/constants/ash_switches.h"
#include "ash/public/cpp/ash_view_ids.h"
#include "ash/public/cpp/system_tray_test_api.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/simple_test_clock.h"
#include "chrome/browser/ash/login/session/user_session_manager.h"
#include "chrome/browser/ash/login/test/device_state_mixin.h"
#include "chrome/browser/ash/login/test/guest_session_mixin.h"
#include "chrome/browser/ash/login/test/logged_in_user_mixin.h"
#include "chrome/browser/ash/login/test/session_manager_state_waiter.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/notifications/notification_display_service_tester.h"
#include "chrome/browser/notifications/notification_test_util.h"
#include "chrome/browser/notifications/notification_ui_manager.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profile_manager_observer.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/mixin_based_in_process_browser_test.h"
#include "chromeos/ash/components/browser_context_helper/browser_context_helper.h"
#include "chromeos/ash/components/dbus/update_engine/fake_update_engine_client.h"
#include "chromeos/ash/components/dbus/update_engine/update_engine_client.h"
#include "components/session_manager/core/session_manager.h"
#include "components/user_manager/user_manager.h"
#include "content/public/test/browser_test.h"
namespace ash {
namespace {
constexpr char kEolNotificationId[] = "chrome://product_eol";
enum class TestCase {
kIncentivesDisabled,
kIncentivesWithoutOffer,
kIncentivesWithOffer,
kIncentivesWithOfferAndAUEWarning,
};
// Returns the "incentive_type" feature param to be used for a test case.
std::string GetTestFeatureParamString(TestCase test_case) {
switch (test_case) {
case TestCase::kIncentivesDisabled:
NOTREACHED();
case TestCase::kIncentivesWithoutOffer:
return "no_offer";
case TestCase::kIncentivesWithOffer:
return "offer";
case TestCase::kIncentivesWithOfferAndAUEWarning:
return "offer_with_warning";
}
}
// Sets up a test's scoped feature list to run enable the provided test case.
void SetUpScopedFeatureListForTestCase(
TestCase test_case,
base::test::ScopedFeatureList* scoped_feature_list) {
if (test_case == TestCase::kIncentivesDisabled) {
scoped_feature_list->InitAndDisableFeature(features::kEolIncentive);
} else {
scoped_feature_list->InitAndEnableFeatureWithParameters(
features::kEolIncentive,
{{"incentive_type", GetTestFeatureParamString(test_case)}});
}
}
// Possible results for `EolStatusMixin::SetUpTime()`.
enum class TimeSetupResult {
kSuccess,
kInvalidNow,
kInvalidEol,
kInvalidProfileCreation
};
// A mixin that injects a stub notification display service that tracks set of
// notifications for the primary profile. Expected to be used with test that go
// through login flow, and the primary user profile is different than the
// browser test profile (`browser()->profile()`).
class NotificationDisplayServiceMixin : public InProcessBrowserTestMixin,
public ProfileManagerObserver {
public:
explicit NotificationDisplayServiceMixin(
InProcessBrowserTestMixinHost* mixin_host)
: InProcessBrowserTestMixin(mixin_host) {}
NotificationDisplayServiceMixin(const NotificationDisplayServiceMixin&) =
delete;
NotificationDisplayServiceMixin& operator=(
const NotificationDisplayServiceMixin&) = delete;
~NotificationDisplayServiceMixin() override = default;
// InProcessBrowserTestMixin:
void SetUpOnMainThread() override {
// The mixin observes profile manager, and initializes the test notification
// service when the primary user profile gets added. If primary user (and
// profile) have already been created at this point, the mixin will not be
// able to detect profile addition.
ASSERT_FALSE(user_manager::UserManager::Get()->GetPrimaryUser());
profile_waiter_ = std::make_unique<base::RunLoop>();
profile_manager_observer_.Observe(g_browser_process->profile_manager());
}
void TearDownOnMainThread() override {
profile_manager_observer_.Reset();
profile_waiter_.reset();
display_service_.reset();
}
// ProfileManagerObserver:
void OnProfileAdded(Profile* profile) override {
if (!user_manager::UserManager::Get()->IsPrimaryUser(
BrowserContextHelper::Get()->GetUserByBrowserContext(profile))) {
return;
}
profile_manager_observer_.Reset();
display_service_ =
std::make_unique<NotificationDisplayServiceTester>(profile);
profile_waiter_->Quit();
}
NotificationDisplayServiceTester* WaitForDisplayService() {
if (!display_service_ && !profile_manager_observer_.IsObserving()) {
return nullptr;
}
profile_waiter_->Run();
return display_service_.get();
}
private:
base::ScopedObservation<ProfileManager, ProfileManagerObserver>
profile_manager_observer_{this};
std::unique_ptr<NotificationDisplayServiceTester> display_service_;
std::unique_ptr<base::RunLoop> profile_waiter_;
};
// Mixin that sets up session state to indicate certain EOL status:
// It can override EOL date provided returned by update engine, the current time
// used by EOL notification handler, and profile creation time.
class EolStatusMixin : public InProcessBrowserTestMixin {
public:
explicit EolStatusMixin(InProcessBrowserTestMixinHost* mixin_host)
: InProcessBrowserTestMixin(mixin_host) {}
EolStatusMixin(const EolStatusMixin&) = delete;
EolStatusMixin& operator=(const EolStatusMixin&) = delete;
~EolStatusMixin() override = default;
// InProcessBrowserTestMixin:
void SetUpInProcessBrowserTestFixture() override {
InProcessBrowserTestMixin::SetUpInProcessBrowserTestFixture();
update_engine_client_ = UpdateEngineClient::InitializeFakeForTest();
}
void SetUpOnMainThread() override {
InProcessBrowserTestMixin::SetUpOnMainThread();
UserSessionManager::GetInstance()
->SetEolNotificationHandlerFactoryForTesting(
base::BindRepeating(&EolStatusMixin::CreateEolNotificationHandler,
base::Unretained(this)));
}
void TearDownOnMainThread() override {
UserSessionManager::GetInstance()
->SetEolNotificationHandlerFactoryForTesting(
UserSessionManager::EolNotificationHandlerFactoryCallback());
InProcessBrowserTestMixin::TearDownOnMainThread();
}
// Sets up times relevant to calculating EOL notification status.
// `now_string` - The time used by EOL notification handler.
// `eol_string` - The time reportted by fake update engine as device EOL.
// `profile_creation_string` - The time used to override user profile creation
// when EOL notification handler gets created.
// Callers should verify that the method returned kSuccess.
[[nodiscard]] TimeSetupResult SetUpTime(const char* now_string,
const char* eol_string,
const char* profile_creation_string) {
base::Time now;
if (!base::Time::FromUTCString(now_string, &now)) {
return TimeSetupResult::kInvalidNow;
}
base::Time eol;
if (!base::Time::FromUTCString(eol_string, &eol)) {
return TimeSetupResult::kInvalidEol;
}
if (!base::Time::FromUTCString(profile_creation_string,
&profile_creation_time_)) {
return TimeSetupResult::kInvalidProfileCreation;
}
clock_.SetNow(now);
update_engine_client_->set_eol_date(eol);
return TimeSetupResult::kSuccess;
}
private:
std::unique_ptr<EolNotification> CreateEolNotificationHandler(
Profile* profile) {
auto eol_notification = std::make_unique<EolNotification>(profile);
eol_notification->OverrideClockForTesting(&clock_);
if (!profile_creation_time_.is_null()) {
profile->SetCreationTimeForTesting(profile_creation_time_);
}
return eol_notification;
}
raw_ptr<FakeUpdateEngineClient, DanglingUntriaged> update_engine_client_ =
nullptr;
base::SimpleTestClock clock_;
base::Time profile_creation_time_;
};
} // namespace
// Tests that verify EOL notifications for regular users on non-managed devices.
class EolNotificationTest : public MixinBasedInProcessBrowserTest,
public ::testing::WithParamInterface<TestCase> {
public:
EolNotificationTest() {
SetUpScopedFeatureListForTestCase(GetParam(), &scoped_feature_list_);
}
bool NotificationHasClaimButton() {
return GetParam() != TestCase::kIncentivesDisabled;
}
std::u16string GetEolApproachingNotificationTitle(
const std::u16string& eol_month) const {
switch (GetParam()) {
case TestCase::kIncentivesDisabled:
return u"Updates end " + eol_month;
case TestCase::kIncentivesWithoutOffer:
return u"Security updates end soon. Upgrade to a new Chromebook.";
case TestCase::kIncentivesWithOffer:
return u"Save $50 or more on a new Chromebook, when you upgrade today";
case TestCase::kIncentivesWithOfferAndAUEWarning:
return u"Security updates end soon. Save $50 or more on a new "
u"Chromebook.";
}
}
std::u16string GetEolApproachingNotificationMessage(
const std::string& eol_month) const {
switch (GetParam()) {
case TestCase::kIncentivesDisabled:
return u"You'll still be able to use this Chrome device after that "
u"time, but it will no longer get automatic software and "
u"security updates";
case TestCase::kIncentivesWithoutOffer:
return base::UTF8ToUTF16(base::StringPrintf(
"You will stop getting security and software updates for this "
"Chromebook in %s. Upgrade your Chromebook for the best "
"experience.",
eol_month.c_str()));
case TestCase::kIncentivesWithOffer:
case TestCase::kIncentivesWithOfferAndAUEWarning:
return base::UTF8ToUTF16(
base::StringPrintf("You will stop getting security updates for "
"this Chromebook in %s. Time to upgrade for "
"the latest security and software. Offer "
"terms apply.",
eol_month.c_str()));
}
}
std::u16string GetRecentEolNotificationTitle() const {
switch (GetParam()) {
case TestCase::kIncentivesDisabled:
return u"Final software update";
case TestCase::kIncentivesWithoutOffer:
return u"Security updates have ended. Upgrade to a new Chromebook.";
case TestCase::kIncentivesWithOffer:
return u"Save $50 or more on a new Chromebook, when you upgrade today";
case TestCase::kIncentivesWithOfferAndAUEWarning:
return u"Security updates have ended. Save $50 or more on a new "
u"Chromebook.";
}
}
std::u16string GetRecentEolNotificationMessage() const {
switch (GetParam()) {
case TestCase::kIncentivesDisabled:
return u"This is the last automatic software and security update for "
u"this Chrome device. To get future updates, upgrade to a "
u"newer model.";
case TestCase::kIncentivesWithoutOffer:
return u"Your Chromebook is no longer receiving security and software "
u"updates. Upgrade your Chromebook for the best experience.";
case TestCase::kIncentivesWithOffer:
case TestCase::kIncentivesWithOfferAndAUEWarning:
return u"Your Chromebook is no longer receiving security updates. "
u"Time to upgrade for the latest security and software. "
u"Offer terms apply.";
}
}
bool ShowsNotificationWithOffer() const {
switch (GetParam()) {
case TestCase::kIncentivesDisabled:
case TestCase::kIncentivesWithoutOffer:
return false;
case TestCase::kIncentivesWithOffer:
case TestCase::kIncentivesWithOfferAndAUEWarning:
return true;
}
}
protected:
EolStatusMixin eol_status_mixin_{&mixin_host_};
NotificationDisplayServiceMixin notifications_mixin_{&mixin_host_};
ash::LoggedInUserMixin logged_in_user_mixin_{
&mixin_host_, /*test_base=*/this, embedded_test_server(),
LoggedInUserMixin::LogInType::kConsumer};
private:
base::test::ScopedFeatureList scoped_feature_list_;
};
INSTANTIATE_TEST_SUITE_P(
All,
EolNotificationTest,
::testing::Values(TestCase::kIncentivesDisabled,
TestCase::kIncentivesWithoutOffer,
TestCase::kIncentivesWithOffer,
TestCase::kIncentivesWithOfferAndAUEWarning));
// Tests that verify EOL notifications are not shown on managed devices.
class ManagedDeviceEolNotificationTest
: public MixinBasedInProcessBrowserTest,
public ::testing::WithParamInterface<TestCase> {
public:
ManagedDeviceEolNotificationTest() {
SetUpScopedFeatureListForTestCase(GetParam(), &scoped_feature_list_);
}
protected:
EolStatusMixin eol_status_mixin_{&mixin_host_};
NotificationDisplayServiceMixin notifications_mixin_{&mixin_host_};
ash::DeviceStateMixin device_state_{
&mixin_host_,
ash::DeviceStateMixin::State::OOBE_COMPLETED_CLOUD_ENROLLED};
ash::LoggedInUserMixin logged_in_user_mixin_{
&mixin_host_, /*test_base=*/this, embedded_test_server(),
LoggedInUserMixin::LogInType::kManaged};
private:
base::test::ScopedFeatureList scoped_feature_list_;
};
INSTANTIATE_TEST_SUITE_P(
All,
ManagedDeviceEolNotificationTest,
::testing::Values(TestCase::kIncentivesDisabled,
TestCase::kIncentivesWithoutOffer,
TestCase::kIncentivesWithOffer,
TestCase::kIncentivesWithOfferAndAUEWarning));
// Tests that verify EOL notifications with incentives are not shown for child
// users.
class ChildUserEolNotificationTest
: public MixinBasedInProcessBrowserTest,
public ::testing::WithParamInterface<TestCase> {
public:
ChildUserEolNotificationTest() {
SetUpScopedFeatureListForTestCase(GetParam(), &scoped_feature_list_);
}
protected:
EolStatusMixin eol_status_mixin_{&mixin_host_};
NotificationDisplayServiceMixin notifications_mixin_{&mixin_host_};
ash::LoggedInUserMixin logged_in_user_mixin_{
&mixin_host_, /*test_base=*/this, embedded_test_server(),
LoggedInUserMixin::LogInType::kChild};
private:
base::test::ScopedFeatureList scoped_feature_list_;
};
INSTANTIATE_TEST_SUITE_P(
All,
ChildUserEolNotificationTest,
::testing::Values(TestCase::kIncentivesDisabled,
TestCase::kIncentivesWithoutOffer,
TestCase::kIncentivesWithOffer,
TestCase::kIncentivesWithOfferAndAUEWarning));
class SuppressedNotificationTest : public MixinBasedInProcessBrowserTest {
protected:
EolStatusMixin eol_status_mixin_{&mixin_host_};
NotificationDisplayServiceMixin notifications_mixin_{&mixin_host_};
ash::LoggedInUserMixin logged_in_user_mixin_{
&mixin_host_, /*test_base=*/this, embedded_test_server(),
LoggedInUserMixin::LogInType::kConsumer};
};
IN_PROC_BROWSER_TEST_P(EolNotificationTest, ShowNotificationForEolApproaching) {
ASSERT_EQ(TimeSetupResult::kSuccess,
eol_status_mixin_.SetUpTime(
/*now_string=*/"12 May 2023", /*eol_string=*/"01 June 2023",
/*profile_creation_string=*/"05 December 2021"));
logged_in_user_mixin_.LogInUser();
NotificationDisplayServiceTester* notification_display_service =
notifications_mixin_.WaitForDisplayService();
ASSERT_TRUE(notification_display_service);
base::RunLoop().RunUntilIdle();
std::optional<message_center::Notification> notification =
notification_display_service->GetNotification(kEolNotificationId);
ASSERT_TRUE(notification);
EXPECT_EQ(GetEolApproachingNotificationTitle(u"June 2023"),
notification->title());
EXPECT_EQ(GetEolApproachingNotificationMessage("June 2023"),
notification->message());
if (NotificationHasClaimButton()) {
notification_display_service->SimulateClick(
NotificationHandler::Type::TRANSIENT, notification->id(),
/*action_index=*/0, /*reply=*/std::nullopt);
content::WebContents* active_contents =
chrome::FindLastActive()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(active_contents);
EXPECT_EQ(ShowsNotificationWithOffer()
? chrome::kEolIncentiveNotificationOfferURL
: chrome::kEolIncentiveNotificationNoOfferURL,
active_contents->GetVisibleURL());
}
}
IN_PROC_BROWSER_TEST_P(EolNotificationTest, NoTrayNoticeWhenEolApproaches) {
ASSERT_EQ(TimeSetupResult::kSuccess,
eol_status_mixin_.SetUpTime(
/*now_string=*/"12 May 2023", /*eol_string=*/"01 June 2023",
/*profile_creation_string=*/"05 December 2021"));
logged_in_user_mixin_.LogInUser();
base::RunLoop().RunUntilIdle();
EXPECT_FALSE(SystemTrayTestApi().IsBubbleViewVisible(
VIEW_ID_QS_EOL_NOTICE_BUTTON, /*open_tray=*/true));
}
IN_PROC_BROWSER_TEST_P(EolNotificationTest,
PRE_EolApproachingNotificationNotReshown) {
ASSERT_EQ(TimeSetupResult::kSuccess,
eol_status_mixin_.SetUpTime(
/*now_string=*/"12 May 2023", /*eol_string=*/"01 June 2023",
/*profile_creation_string=*/"05 December 2021"));
logged_in_user_mixin_.LogInUser();
NotificationDisplayServiceTester* notification_display_service =
notifications_mixin_.WaitForDisplayService();
ASSERT_TRUE(notification_display_service);
base::RunLoop().RunUntilIdle();
std::optional<message_center::Notification> notification =
notification_display_service->GetNotification(kEolNotificationId);
ASSERT_TRUE(notification);
notification_display_service->SimulateClick(
NotificationHandler::Type::TRANSIENT, notification->id(),
/*action_index=*/0, /*reply=*/std::nullopt);
}
IN_PROC_BROWSER_TEST_P(EolNotificationTest,
EolApproachingNotificationNotReshown) {
ASSERT_EQ(TimeSetupResult::kSuccess,
eol_status_mixin_.SetUpTime(
/*now_string=*/"12 May 2023", /*eol_string=*/"01 June 2023",
/*profile_creation_string=*/"05 December 2021"));
logged_in_user_mixin_.LogInUser();
NotificationDisplayServiceTester* notification_display_service =
notifications_mixin_.WaitForDisplayService();
ASSERT_TRUE(notification_display_service);
base::RunLoop().RunUntilIdle();
std::optional<message_center::Notification> notification =
notification_display_service->GetNotification(kEolNotificationId);
EXPECT_FALSE(notification);
}
IN_PROC_BROWSER_TEST_P(EolNotificationTest,
ShowEolApproachingNotificationForNewUsers) {
ASSERT_EQ(
TimeSetupResult::kSuccess,
eol_status_mixin_.SetUpTime(/*now_string=*/"12 May 2023",
/*eol_string=*/"01 June 2023",
/*profile_creation_string=*/"01 April 2023"));
logged_in_user_mixin_.LogInUser();
NotificationDisplayServiceTester* notification_display_service =
notifications_mixin_.WaitForDisplayService();
ASSERT_TRUE(notification_display_service);
base::RunLoop().RunUntilIdle();
std::optional<message_center::Notification> notification =
notification_display_service->GetNotification(kEolNotificationId);
ASSERT_TRUE(notification);
// Users that were created recently are not eligible for incentive
// notifications.
EXPECT_EQ(u"Updates end June 2023", notification->title());
notification_display_service->SimulateClick(
NotificationHandler::Type::TRANSIENT, notification->id(),
/*action_index=*/0, /*reply=*/std::nullopt);
content::WebContents* active_contents =
chrome::FindLastActive()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(active_contents);
EXPECT_EQ(GURL(chrome::kAutoUpdatePolicyURL),
active_contents->GetVisibleURL());
}
IN_PROC_BROWSER_TEST_P(EolNotificationTest, ShowRecentEolNotification) {
ASSERT_EQ(TimeSetupResult::kSuccess,
eol_status_mixin_.SetUpTime(
/*now_string=*/"03 June 2023", /*eol_string=*/"01 June 2023",
/*profile_creation_string=*/"05 December 2021"));
logged_in_user_mixin_.LogInUser();
NotificationDisplayServiceTester* notification_display_service =
notifications_mixin_.WaitForDisplayService();
ASSERT_TRUE(notification_display_service);
base::RunLoop().RunUntilIdle();
std::optional<message_center::Notification> notification =
notification_display_service->GetNotification(kEolNotificationId);
ASSERT_TRUE(notification);
EXPECT_EQ(GetRecentEolNotificationTitle(), notification->title());
EXPECT_EQ(GetRecentEolNotificationMessage(), notification->message());
if (NotificationHasClaimButton()) {
notification_display_service->SimulateClick(
NotificationHandler::Type::TRANSIENT, notification->id(),
/*action_index=*/0, /*reply=*/std::nullopt);
content::WebContents* active_contents =
chrome::FindLastActive()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(active_contents);
EXPECT_EQ(ShowsNotificationWithOffer()
? chrome::kEolIncentiveNotificationOfferURL
: chrome::kEolIncentiveNotificationNoOfferURL,
active_contents->GetVisibleURL());
}
}
IN_PROC_BROWSER_TEST_P(EolNotificationTest,
PRE_RecentEolNotificationNotReshown) {
ASSERT_EQ(TimeSetupResult::kSuccess,
eol_status_mixin_.SetUpTime(
/*now_string=*/"03 June 2023", /*eol_string=*/"01 June 2023",
/*profile_creation_string=*/"05 December 2021"));
logged_in_user_mixin_.LogInUser();
NotificationDisplayServiceTester* notification_display_service =
notifications_mixin_.WaitForDisplayService();
ASSERT_TRUE(notification_display_service);
base::RunLoop().RunUntilIdle();
std::optional<message_center::Notification> notification =
notification_display_service->GetNotification(kEolNotificationId);
ASSERT_TRUE(notification);
notification_display_service->SimulateClick(
NotificationHandler::Type::TRANSIENT, notification->id(),
/*action_index=*/0, /*reply=*/std::nullopt);
// Verify quick settings notice still shows.
EXPECT_EQ(
GetParam() != TestCase::kIncentivesDisabled,
SystemTrayTestApi().IsBubbleViewVisible(VIEW_ID_QS_EOL_NOTICE_BUTTON,
/*open_tray=*/true));
}
IN_PROC_BROWSER_TEST_P(EolNotificationTest, RecentEolNotificationNotReshown) {
ASSERT_EQ(TimeSetupResult::kSuccess,
eol_status_mixin_.SetUpTime(
/*now_string=*/"03 June 2023", /*eol_string=*/"01 June 2023",
/*profile_creation_string=*/"05 December 2021"));
logged_in_user_mixin_.LogInUser();
NotificationDisplayServiceTester* notification_display_service =
notifications_mixin_.WaitForDisplayService();
ASSERT_TRUE(notification_display_service);
base::RunLoop().RunUntilIdle();
std::optional<message_center::Notification> notification =
notification_display_service->GetNotification(kEolNotificationId);
EXPECT_EQ(GetParam() == TestCase::kIncentivesDisabled, !!notification);
}
IN_PROC_BROWSER_TEST_P(EolNotificationTest, PRE_ShowTrayNoticeSoonAfterEol) {
ASSERT_EQ(TimeSetupResult::kSuccess,
eol_status_mixin_.SetUpTime(
/*now_string=*/"03 June 2023", /*eol_string=*/"01 June 2023",
/*profile_creation_string=*/"05 December 2021"));
logged_in_user_mixin_.LogInUser();
base::RunLoop().RunUntilIdle();
const bool incentives_enabled = GetParam() != TestCase::kIncentivesDisabled;
SystemTrayTestApi tray_test_api;
ASSERT_EQ(incentives_enabled,
tray_test_api.IsBubbleViewVisible(VIEW_ID_QS_EOL_NOTICE_BUTTON,
/*open_tray=*/true));
if (!incentives_enabled) {
return;
}
tray_test_api.ClickBubbleView(VIEW_ID_QS_EOL_NOTICE_BUTTON);
content::WebContents* active_contents =
chrome::FindLastActive()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(active_contents);
EXPECT_EQ(ShowsNotificationWithOffer()
? chrome::kEolIncentiveNotificationOfferURL
: chrome::kEolIncentiveNotificationNoOfferURL,
active_contents->GetVisibleURL());
}
IN_PROC_BROWSER_TEST_P(EolNotificationTest, ShowTrayNoticeSoonAfterEol) {
ASSERT_EQ(TimeSetupResult::kSuccess,
eol_status_mixin_.SetUpTime(
/*now_string=*/"03 June 2023", /*eol_string=*/"01 June 2023",
/*profile_creation_string=*/"05 December 2021"));
logged_in_user_mixin_.LogInUser();
base::RunLoop().RunUntilIdle();
SystemTrayTestApi tray_test_api;
EXPECT_EQ(GetParam() != TestCase::kIncentivesDisabled,
tray_test_api.IsBubbleViewVisible(VIEW_ID_QS_EOL_NOTICE_BUTTON,
/*open_tray=*/true));
}
IN_PROC_BROWSER_TEST_P(EolNotificationTest, NoTrayNoticeOnLockScreen) {
ASSERT_EQ(TimeSetupResult::kSuccess,
eol_status_mixin_.SetUpTime(
/*now_string=*/"03 June 2023", /*eol_string=*/"01 June 2023",
/*profile_creation_string=*/"05 December 2021"));
logged_in_user_mixin_.LogInUser();
base::RunLoop().RunUntilIdle();
SessionManagerClient::Get()->RequestLockScreen();
SessionStateWaiter(session_manager::SessionState::LOCKED).Wait();
SystemTrayTestApi tray_test_api;
EXPECT_FALSE(tray_test_api.IsBubbleViewVisible(VIEW_ID_QS_EOL_NOTICE_BUTTON,
/*open_tray=*/true));
}
IN_PROC_BROWSER_TEST_P(EolNotificationTest, NoTrayNoticeBeforeLogin) {
ASSERT_EQ(TimeSetupResult::kSuccess,
eol_status_mixin_.SetUpTime(
/*now_string=*/"03 June 2023", /*eol_string=*/"01 June 2023",
/*profile_creation_string=*/"05 December 2021"));
base::RunLoop().RunUntilIdle();
SystemTrayTestApi tray_test_api;
EXPECT_FALSE(tray_test_api.IsBubbleViewVisible(VIEW_ID_QS_EOL_NOTICE_BUTTON,
/*open_tray=*/true));
}
IN_PROC_BROWSER_TEST_P(EolNotificationTest, NoTrayNoticeForNewUsers) {
ASSERT_EQ(TimeSetupResult::kSuccess,
eol_status_mixin_.SetUpTime(
/*now_string=*/"03 June 2023", /*eol_string=*/"01 June 2023",
/*profile_creation_string=*/"05 May 2023"));
logged_in_user_mixin_.LogInUser();
base::RunLoop().RunUntilIdle();
SystemTrayTestApi tray_test_api;
EXPECT_FALSE(tray_test_api.IsBubbleViewVisible(VIEW_ID_QS_EOL_NOTICE_BUTTON,
/*open_tray=*/true));
}
IN_PROC_BROWSER_TEST_P(EolNotificationTest,
ShowRecentEolNotificationForNewUsers) {
ASSERT_EQ(
TimeSetupResult::kSuccess,
eol_status_mixin_.SetUpTime(/*now_string=*/"03 June 2023",
/*eol_string=*/"01 June 2023",
/*profile_creation_string=*/"05 May 2023"));
logged_in_user_mixin_.LogInUser();
NotificationDisplayServiceTester* notification_display_service =
notifications_mixin_.WaitForDisplayService();
ASSERT_TRUE(notification_display_service);
base::RunLoop().RunUntilIdle();
std::optional<message_center::Notification> notification =
notification_display_service->GetNotification(kEolNotificationId);
ASSERT_TRUE(notification);
// Recently created users are not eligible for incentives notifications.
EXPECT_EQ(u"Final software update", notification->title());
notification_display_service->SimulateClick(
NotificationHandler::Type::TRANSIENT, notification->id(),
/*action_index=*/0, /*reply=*/std::nullopt);
content::WebContents* active_contents =
chrome::FindLastActive()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(active_contents);
EXPECT_EQ(GURL(chrome::kEolNotificationURL),
active_contents->GetVisibleURL());
}
IN_PROC_BROWSER_TEST_P(EolNotificationTest, ShowNonRecentEolNotification) {
ASSERT_EQ(
TimeSetupResult::kSuccess,
eol_status_mixin_.SetUpTime(/*now_string=*/"03 July 2023",
/*eol_string=*/"01 June 2023",
/*profile_creation_string=*/"05 May 2020"));
logged_in_user_mixin_.LogInUser();
NotificationDisplayServiceTester* notification_display_service =
notifications_mixin_.WaitForDisplayService();
ASSERT_TRUE(notification_display_service);
base::RunLoop().RunUntilIdle();
std::optional<message_center::Notification> notification =
notification_display_service->GetNotification(kEolNotificationId);
ASSERT_TRUE(notification);
// Users should not see incentivized notification if they log in long after
// EOL.
EXPECT_EQ(u"Final software update", notification->title());
notification_display_service->SimulateClick(
NotificationHandler::Type::TRANSIENT, notification->id(),
/*action_index=*/0, /*reply=*/std::nullopt);
content::WebContents* active_contents =
chrome::FindLastActive()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(active_contents);
EXPECT_EQ(GURL(chrome::kEolNotificationURL),
active_contents->GetVisibleURL());
}
IN_PROC_BROWSER_TEST_P(EolNotificationTest, PRE_ShowTrayNoticeLongAfterEol) {
ASSERT_EQ(TimeSetupResult::kSuccess,
eol_status_mixin_.SetUpTime(
/*now_string=*/"03 August 2023", /*eol_string=*/"01 June 2023",
/*profile_creation_string=*/"05 December 2021"));
logged_in_user_mixin_.LogInUser();
base::RunLoop().RunUntilIdle();
const bool incentives_enabled = GetParam() != TestCase::kIncentivesDisabled;
SystemTrayTestApi tray_test_api;
ASSERT_EQ(incentives_enabled,
tray_test_api.IsBubbleViewVisible(VIEW_ID_QS_EOL_NOTICE_BUTTON,
/*open_tray=*/true));
if (!incentives_enabled) {
return;
}
tray_test_api.ClickBubbleView(VIEW_ID_QS_EOL_NOTICE_BUTTON);
content::WebContents* active_contents =
chrome::FindLastActive()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(active_contents);
EXPECT_EQ(chrome::kEolIncentiveNotificationNoOfferURL,
active_contents->GetVisibleURL());
}
IN_PROC_BROWSER_TEST_P(EolNotificationTest, ShowTrayNoticeLongAfterEol) {
ASSERT_EQ(TimeSetupResult::kSuccess,
eol_status_mixin_.SetUpTime(
/*now_string=*/"03 August 2023", /*eol_string=*/"01 June 2023",
/*profile_creation_string=*/"05 December 2021"));
logged_in_user_mixin_.LogInUser();
base::RunLoop().RunUntilIdle();
SystemTrayTestApi tray_test_api;
EXPECT_EQ(GetParam() != TestCase::kIncentivesDisabled,
tray_test_api.IsBubbleViewVisible(VIEW_ID_QS_EOL_NOTICE_BUTTON,
/*open_tray=*/true));
}
IN_PROC_BROWSER_TEST_P(ManagedDeviceEolNotificationTest,
NoEolApproachingNotification) {
ASSERT_EQ(TimeSetupResult::kSuccess,
eol_status_mixin_.SetUpTime(
/*now_string=*/"12 May 2023", /*eol_string=*/"01 June 2023",
/*profile_creation_string=*/"05 December 2021"));
logged_in_user_mixin_.LogInUser();
NotificationDisplayServiceTester* notification_display_service =
notifications_mixin_.WaitForDisplayService();
ASSERT_TRUE(notification_display_service);
base::RunLoop().RunUntilIdle();
std::optional<message_center::Notification> notification =
notification_display_service->GetNotification(kEolNotificationId);
EXPECT_FALSE(notification);
}
IN_PROC_BROWSER_TEST_P(ManagedDeviceEolNotificationTest,
NoEolPassedNotification) {
ASSERT_EQ(TimeSetupResult::kSuccess,
eol_status_mixin_.SetUpTime(
/*now_string=*/"03 June 2023", /*eol_string=*/"01 June 2023",
/*profile_creation_string=*/"05 December 2021"));
logged_in_user_mixin_.LogInUser();
NotificationDisplayServiceTester* notification_display_service =
notifications_mixin_.WaitForDisplayService();
ASSERT_TRUE(notification_display_service);
base::RunLoop().RunUntilIdle();
std::optional<message_center::Notification> notification =
notification_display_service->GetNotification(kEolNotificationId);
EXPECT_FALSE(notification);
}
IN_PROC_BROWSER_TEST_P(ManagedDeviceEolNotificationTest, NoTrayNotice) {
ASSERT_EQ(TimeSetupResult::kSuccess,
eol_status_mixin_.SetUpTime(
/*now_string=*/"03 June 2023", /*eol_string=*/"01 June 2023",
/*profile_creation_string=*/"05 December 2021"));
logged_in_user_mixin_.LogInUser();
base::RunLoop().RunUntilIdle();
EXPECT_FALSE(SystemTrayTestApi().IsBubbleViewVisible(
VIEW_ID_QS_EOL_NOTICE_BUTTON, /*open_tray=*/true));
}
IN_PROC_BROWSER_TEST_P(ChildUserEolNotificationTest,
NoEolApproachingNotification) {
ASSERT_EQ(TimeSetupResult::kSuccess,
eol_status_mixin_.SetUpTime(
/*now_string=*/"12 May 2023", /*eol_string=*/"01 June 2023",
/*profile_creation_string=*/"05 December 2021"));
logged_in_user_mixin_.LogInUser();
NotificationDisplayServiceTester* notification_display_service =
notifications_mixin_.WaitForDisplayService();
ASSERT_TRUE(notification_display_service);
base::RunLoop().RunUntilIdle();
std::optional<message_center::Notification> notification =
notification_display_service->GetNotification(kEolNotificationId);
ASSERT_TRUE(notification);
EXPECT_EQ(u"Updates end June 2023", notification->title());
}
IN_PROC_BROWSER_TEST_P(ChildUserEolNotificationTest, NoEolPassedNotification) {
ASSERT_EQ(TimeSetupResult::kSuccess,
eol_status_mixin_.SetUpTime(
/*now_string=*/"03 June 2023", /*eol_string=*/"01 June 2023",
/*profile_creation_string=*/"05 December 2021"));
logged_in_user_mixin_.LogInUser();
NotificationDisplayServiceTester* notification_display_service =
notifications_mixin_.WaitForDisplayService();
ASSERT_TRUE(notification_display_service);
base::RunLoop().RunUntilIdle();
std::optional<message_center::Notification> notification =
notification_display_service->GetNotification(kEolNotificationId);
ASSERT_TRUE(notification);
EXPECT_EQ(u"Final software update", notification->title());
}
IN_PROC_BROWSER_TEST_P(ChildUserEolNotificationTest, NoTrayNotice) {
ASSERT_EQ(TimeSetupResult::kSuccess,
eol_status_mixin_.SetUpTime(
/*now_string=*/"03 June 2023", /*eol_string=*/"01 June 2023",
/*profile_creation_string=*/"05 December 2021"));
logged_in_user_mixin_.LogInUser();
base::RunLoop().RunUntilIdle();
EXPECT_FALSE(SystemTrayTestApi().IsBubbleViewVisible(
VIEW_ID_QS_EOL_NOTICE_BUTTON, /*open_tray=*/true));
}
// Test that the eol notification is not shown when just within 180 days, when
// first eol warning is suppressed.
IN_PROC_BROWSER_TEST_F(SuppressedNotificationTest,
EolNotificationSupressed180DaysBefore) {
// Set eol date to be 173 days in the future.
ASSERT_EQ(TimeSetupResult::kSuccess,
eol_status_mixin_.SetUpTime(
/*now_string=*/"12 May 2023", /*eol_string=*/"1 November 2023",
/*profile_creation_string=*/"05 December 2021"));
logged_in_user_mixin_.LogInUser();
NotificationDisplayServiceTester* notification_display_service =
notifications_mixin_.WaitForDisplayService();
ASSERT_TRUE(notification_display_service);
base::RunLoop().RunUntilIdle();
std::optional<message_center::Notification> notification =
notification_display_service->GetNotification(kEolNotificationId);
ASSERT_TRUE(!notification);
}
// Test that the eol notification is shown when just within 90 days.
IN_PROC_BROWSER_TEST_F(SuppressedNotificationTest,
EolNotificationShown90DaysBefore) {
// Set eol date to be 83 days in the future.
ASSERT_EQ(TimeSetupResult::kSuccess,
eol_status_mixin_.SetUpTime(
/*now_string=*/"12 May 2023", /*eol_string=*/"3 August 2023",
/*profile_creation_string=*/"05 December 2021"));
logged_in_user_mixin_.LogInUser();
NotificationDisplayServiceTester* notification_display_service =
notifications_mixin_.WaitForDisplayService();
ASSERT_TRUE(notification_display_service);
base::RunLoop().RunUntilIdle();
std::optional<message_center::Notification> notification =
notification_display_service->GetNotification(kEolNotificationId);
EXPECT_TRUE(notification);
}
} // namespace ash
|