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
|
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <cstddef>
#include <optional>
#include <string>
#include <vector>
#include "ash/public/cpp/shelf_config.h"
#include "ash/public/cpp/shelf_test_api.h"
#include "ash/shell.h"
#include "base/check_deref.h"
#include "base/test/gtest_tags.h"
#include "base/time/time.h"
#include "chrome/browser/ash/app_mode/kiosk_app.h"
#include "chrome/browser/ash/app_mode/kiosk_app_types.h"
#include "chrome/browser/ash/app_mode/kiosk_controller.h"
#include "chrome/browser/ash/app_mode/kiosk_system_session.h"
#include "chrome/browser/ash/app_mode/test/fake_cws_chrome_apps.h"
#include "chrome/browser/ash/app_mode/test/kiosk_mixin.h"
#include "chrome/browser/ash/app_mode/test/kiosk_test_utils.h"
#include "chrome/browser/ash/app_mode/test/network_state_mixin.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/ui/ash/login/login_display_host.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/test/test_browser_closed_waiter.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/mixin_based_in_process_browser_test.h"
#include "components/signin/public/base/consent_level.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "content/public/test/browser_test.h"
#include "extensions/browser/app_window/app_window.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/events/test/event_generator.h"
#include "ui/gfx/native_widget_types.h"
namespace ash {
using kiosk::test::AutoLaunchKioskApp;
using kiosk::test::CloseAppWindow;
using kiosk::test::CurrentProfile;
using kiosk::test::IsAppInstalled;
using kiosk::test::LaunchAppManually;
using kiosk::test::OfflineEnabledChromeAppV1;
using kiosk::test::OpenA11ySettings;
using kiosk::test::TheKioskApp;
using kiosk::test::WaitKioskLaunched;
namespace {
void AddKioskLaunchTagIdToTestResult(KioskAppType app_type) {
// Workflow COM_KIOSK_CUJ3_TASK4_WF1.
constexpr char kLaunchChromeAppTag[] =
"screenplay-5e6b8c54-2eab-4ac0-a484-b9738466bb9b";
// Workflow COM_KIOSK_CUJ3_TASK5_WF1.
constexpr char kLaunchWebAppTag[] =
"screenplay-d93db63f-372e-4c3b-a1ca-3f23587dbac4";
switch (app_type) {
case KioskAppType::kChromeApp:
base::AddFeatureIdTagToTestResult(kLaunchChromeAppTag);
break;
case KioskAppType::kWebApp:
base::AddFeatureIdTagToTestResult(kLaunchWebAppTag);
break;
case KioskAppType::kIsolatedWebApp:
case KioskAppType::kArcvmApp:
break;
}
}
void SimulateSwipeUpGesture() {
auto& root_window = CHECK_DEREF(Shell::Get()->GetPrimaryRootWindow());
auto display_bounds = root_window.bounds();
const gfx::Point start_point(
display_bounds.width() / 4,
display_bounds.bottom() - ShelfConfig::Get()->shelf_size() / 2);
gfx::Point end_point(start_point.x(), start_point.y() - 80);
ui::test::EventGenerator(&root_window)
.GestureScrollSequence(start_point, end_point,
/*duration=*/base::Milliseconds(300), /*steps=*/4);
}
} // namespace
// Verifies generic Kiosk behavior.
class KioskTest : public MixinBasedInProcessBrowserTest,
public testing::WithParamInterface<KioskMixin::Config> {
public:
KioskTest() = default;
KioskTest(const KioskTest&) = delete;
KioskTest& operator=(const KioskTest&) = delete;
~KioskTest() override = default;
void SetUpOnMainThread() override {
MixinBasedInProcessBrowserTest::SetUpOnMainThread();
ASSERT_TRUE(WaitKioskLaunched());
}
KioskMixin kiosk_{&mixin_host_,
/*cached_configuration=*/GetParam()};
};
IN_PROC_BROWSER_TEST_P(KioskTest, LaunchesAndInstallsApp) {
AddKioskLaunchTagIdToTestResult(AutoLaunchKioskApp().id().type);
ASSERT_TRUE(IsAppInstalled(CurrentProfile(), AutoLaunchKioskApp()));
}
IN_PROC_BROWSER_TEST_P(KioskTest, HidesShelf) {
EXPECT_FALSE(ShelfTestApi().IsVisible());
SimulateSwipeUpGesture();
EXPECT_FALSE(ShelfTestApi().IsVisible());
}
IN_PROC_BROWSER_TEST_P(KioskTest, CanOpenA11ySettings) {
Browser* settings = OpenA11ySettings(CurrentProfile());
ASSERT_NE(settings, nullptr);
EXPECT_TRUE(settings->window()->IsActive());
EXPECT_TRUE(settings->window()->IsVisible());
}
IN_PROC_BROWSER_TEST_P(KioskTest, ExitsIfOnlySettingsWindowRemainsOpen) {
Browser& settings = CHECK_DEREF(OpenA11ySettings(CurrentProfile()));
EXPECT_GT(BrowserList::GetInstance()->size(), 0u);
// Close the app window and verify the settings browser gets closed too.
CloseAppWindow(AutoLaunchKioskApp());
ASSERT_TRUE(TestBrowserClosedWaiter(&settings).WaitUntilClosed());
EXPECT_EQ(BrowserList::GetInstance()->size(), 0u);
auto& session = CHECK_DEREF(KioskController::Get().GetKioskSystemSession());
EXPECT_TRUE(session.is_shutting_down());
}
IN_PROC_BROWSER_TEST_P(KioskTest, DoesNotExitWhenSettingsWindowCloses) {
Browser& settings = CHECK_DEREF(OpenA11ySettings(CurrentProfile()));
EXPECT_EQ(BrowserList::GetInstance()->GetLastActive(), &settings);
settings.window()->Close();
ASSERT_TRUE(TestBrowserClosedWaiter(&settings).WaitUntilClosed());
auto& session = CHECK_DEREF(KioskController::Get().GetKioskSystemSession());
EXPECT_FALSE(session.is_shutting_down());
}
IN_PROC_BROWSER_TEST_P(KioskTest, DoesNotSignInWithGaiaAccount) {
const auto& manager =
CHECK_DEREF(IdentityManagerFactory::GetForProfile(&CurrentProfile()));
EXPECT_FALSE(manager.HasPrimaryAccount(signin::ConsentLevel::kSignin));
}
INSTANTIATE_TEST_SUITE_P(
All,
KioskTest,
testing::ValuesIn(KioskMixin::ConfigsToAutoLaunchEachAppType()),
KioskMixin::ConfigName);
// Verifies generic online/offline related behavior in Kiosk.
class OfflineKioskTest
: public MixinBasedInProcessBrowserTest,
public testing::WithParamInterface<KioskMixin::Config> {
public:
OfflineKioskTest() = default;
OfflineKioskTest(const OfflineKioskTest&) = delete;
OfflineKioskTest& operator=(const OfflineKioskTest&) = delete;
~OfflineKioskTest() override = default;
static std::vector<KioskMixin::Config> Configs() {
// TODO(crbug.com/379633748): Add IWA.
return {
KioskMixin::Config{/*name=*/"WebApp",
/*auto_launch_account_id=*/{},
{KioskMixin::SimpleWebAppOption()}},
KioskMixin::Config{/*name=*/"ChromeApp",
/*auto_launch_account_id=*/{},
// The Chrome app needs to be offline enabled because
// some tests will launch it while offline.
{OfflineEnabledChromeAppV1()}}};
}
NetworkStateMixin network_state_{&mixin_host_};
KioskMixin kiosk_{&mixin_host_,
/*cached_configuration=*/GetParam()};
};
IN_PROC_BROWSER_TEST_P(OfflineKioskTest, OfflineLaunchWorksOnceItComesOnline) {
network_state_.SimulateOffline();
ASSERT_TRUE(LaunchAppManually(TheKioskApp()));
network_state_.SimulateOnline();
ASSERT_TRUE(WaitKioskLaunched());
ASSERT_TRUE((IsAppInstalled(CurrentProfile(), TheKioskApp())));
}
IN_PROC_BROWSER_TEST_P(OfflineKioskTest, PRE_LaunchesInstalledAppOffline) {
network_state_.SimulateOnline();
ASSERT_TRUE(LaunchAppManually(TheKioskApp()));
ASSERT_TRUE(WaitKioskLaunched());
ASSERT_TRUE((IsAppInstalled(CurrentProfile(), TheKioskApp())));
}
IN_PROC_BROWSER_TEST_P(OfflineKioskTest, LaunchesInstalledAppOffline) {
network_state_.SimulateOffline();
ASSERT_TRUE(LaunchAppManually(TheKioskApp()));
ASSERT_TRUE(WaitKioskLaunched());
}
INSTANTIATE_TEST_SUITE_P(All,
OfflineKioskTest,
testing::ValuesIn(OfflineKioskTest::Configs()),
KioskMixin::ConfigName);
} // namespace ash
|