Skip to content

Commit

Permalink
kiosk: Introduce GetApps in KioskController
Browse files Browse the repository at this point in the history
Expose GetApps from the kiosk app managers as a unified API through
KioskController.

This also migrates and simplifies the call-site in
KioskAppMenuController (this controls the "apps" button in the signin
screen).

  ash/shelf/login_shelf_view_unittest.cc \
  ash/login/ui/lock_contents_view_unittest.cc \
  chrome/browser/ash/login/app_mode/test/web_kiosk_browsertest.cc \
  chrome/browser/ash/login/app_mode/test/kiosk_browsertest.cc \
  chrome/browser/ash/login/error_screen_browsertest.cc

Bug: b:304509403, b:304981820
Test: tast run DUT "kiosk.Smoke.*"
Test: testing/xvfb.py tools/autotest.py -C out/Default --run_all \
Change-Id: I1cab614ca1cddcf2fc7c4838f1858f9ea26ef9d5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4946477
Reviewed-by: Jeroen Dhollander <jeroendh@google.com>
Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Edman Anjos <edman@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1215383}
  • Loading branch information
Edman Anjos authored and Chromium LUCI CQ committed Oct 26, 2023
1 parent 1c02a35 commit 17195a2
Show file tree
Hide file tree
Showing 18 changed files with 314 additions and 161 deletions.
7 changes: 7 additions & 0 deletions ash/login/login_screen_test_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "base/check.h"
#include "base/functional/callback.h"
#include "base/run_loop.h"
#include "components/account_id/account_id.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/test/ui_controls.h"
#include "ui/compositor/layer.h"
Expand Down Expand Up @@ -505,6 +506,12 @@ bool LoginScreenTestApi::LaunchApp(const std::string& app_id) {
return view && view->LaunchAppForTesting(app_id);
}

// static
bool LoginScreenTestApi::LaunchApp(const AccountId& account_id) {
LoginShelfView* view = GetLoginShelfView();
return view && view->LaunchAppForTesting(account_id);
}

// static
bool LoginScreenTestApi::ClickAppsButton() {
return SimulateButtonPressedForTesting(LoginShelfView::kApps);
Expand Down
23 changes: 14 additions & 9 deletions ash/login/ui/lock_contents_view_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3358,7 +3358,7 @@ TEST_F(LockContentsViewUnitTest, LoginExtensionUiWithNoUsers) {
}

class LockContentsViewWithKioskLicenseTest : public LoginTestBase {
protected:
public:
LockContentsViewWithKioskLicenseTest() {
scoped_feature_list_.InitAndEnableFeature(
ash::features::kCryptohomeRecovery);
Expand All @@ -3376,8 +3376,13 @@ class LockContentsViewWithKioskLicenseTest : public LoginTestBase {
NotifySessionStateChanged(session_manager::SessionState::OOBE);
}

void SetNumberOfKioskApps(int number_apps) {
std::vector<KioskAppMenuEntry> kiosk_apps(number_apps);
void SetNFakeKioskApps(int n) {
std::vector<KioskAppMenuEntry> kiosk_apps(
n, KioskAppMenuEntry(KioskAppMenuEntry::AppType::kChromeApp,
AccountId::FromUserEmail("fake@email.com"),
/*chrome_app_id=*/"abc123chromeappid",
/*name=*/u"Fake App",
/*icon=*/gfx::ImageSkia()));
login_shelf_view_->SetKioskApps(kiosk_apps);
}

Expand Down Expand Up @@ -3409,7 +3414,7 @@ TEST_F(LockContentsViewWithKioskLicenseTest,
SetWidget(CreateWidgetWithContent(lock_contents_view));

NotifySessionStateChanged(session_manager::SessionState::LOGIN_PRIMARY);
SetNumberOfKioskApps(1);
SetNFakeKioskApps(1);

EXPECT_TRUE(test_api.kiosk_default_message());
EXPECT_FALSE(test_api.kiosk_default_message()->GetVisible());
Expand All @@ -3431,7 +3436,7 @@ TEST_F(LockContentsViewWithKioskLicenseTest, ShouldHideKioskDefaultMessage) {
SetWidget(CreateWidgetWithContent(lock_contents_view));

NotifySessionStateChanged(session_manager::SessionState::LOGIN_PRIMARY);
SetNumberOfKioskApps(0);
SetNFakeKioskApps(0);

EXPECT_FALSE(test_api.kiosk_default_message());
}
Expand All @@ -3453,7 +3458,7 @@ TEST_F(LockContentsViewWithKioskLicenseTest,
SetWidget(CreateWidgetWithContent(lock_contents_view));

NotifySessionStateChanged(session_manager::SessionState::LOGIN_PRIMARY);
SetNumberOfKioskApps(0);
SetNFakeKioskApps(0);

EXPECT_TRUE(test_api.kiosk_default_message());
EXPECT_TRUE(test_api.kiosk_default_message()->GetVisible());
Expand All @@ -3476,7 +3481,7 @@ TEST_F(LockContentsViewWithKioskLicenseTest,
SetWidget(CreateWidgetWithContent(lock_contents_view));

NotifySessionStateChanged(session_manager::SessionState::LOGIN_PRIMARY);
SetNumberOfKioskApps(0);
SetNFakeKioskApps(0);

EXPECT_TRUE(test_api.kiosk_default_message());
EXPECT_TRUE(test_api.kiosk_default_message()->GetVisible());
Expand All @@ -3500,12 +3505,12 @@ TEST_F(LockContentsViewWithKioskLicenseTest,
SetWidget(CreateWidgetWithContent(lock_contents_view));

NotifySessionStateChanged(session_manager::SessionState::LOGIN_PRIMARY);
SetNumberOfKioskApps(0);
SetNFakeKioskApps(0);

EXPECT_TRUE(test_api.kiosk_default_message());
EXPECT_TRUE(test_api.kiosk_default_message()->GetVisible());

SetNumberOfKioskApps(1);
SetNFakeKioskApps(1);

EXPECT_TRUE(test_api.kiosk_default_message());
EXPECT_FALSE(test_api.kiosk_default_message()->GetVisible());
Expand Down
11 changes: 7 additions & 4 deletions ash/login/ui/lock_debug_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@
#include "base/memory/raw_ptr.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "components/account_id/account_id.h"
#include "components/user_manager/known_user.h"
#include "components/user_manager/multi_user/multi_user_sign_in_policy.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "ui/base/ime/ash/ime_keyboard.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/views/controls/button/md_text_button.h"
#include "ui/views/controls/scroll_view.h"
#include "ui/views/controls/scrollbar/overlay_scroll_bar.h"
Expand Down Expand Up @@ -69,6 +71,8 @@ constexpr const char kDebugEnterpriseInfo[] = "Asset ID: 1111";
constexpr const char kDebugBluetoothName[] = "Bluetooth adapter";

constexpr const char kDebugKioskAppId[] = "asdf1234";
const AccountId kDebugKioskAppAccountId =
AccountId::FromUserEmail("fake@email.com");
constexpr const char16_t kDebugKioskAppName[] = u"Test App Name";

constexpr const char kDebugDefaultLocaleCode[] = "en-GB";
Expand Down Expand Up @@ -521,10 +525,9 @@ class LockDebugView::DebugDataDispatcherTransformer
}

void AddKioskApp(ShelfWidget* shelf_widget) {
KioskAppMenuEntry menu_item;
menu_item.app_id = kDebugKioskAppId;
menu_item.name = kDebugKioskAppName;
kiosk_apps_.push_back(std::move(menu_item));
kiosk_apps_.emplace_back(KioskAppMenuEntry::AppType::kChromeApp,
kDebugKioskAppAccountId, kDebugKioskAppId,
kDebugKioskAppName, gfx::ImageSkia());
shelf_widget->GetLoginShelfView()->SetKioskApps(kiosk_apps_);
}

Expand Down
21 changes: 19 additions & 2 deletions ash/public/cpp/kiosk_app_menu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,32 @@

#include "ash/public/cpp/kiosk_app_menu.h"

#include "base/check.h"
#include "base/check_op.h"
#include "third_party/abseil-cpp/absl/types/optional.h"

namespace ash {

namespace {

KioskAppMenu* g_instance = nullptr;
}

KioskAppMenuEntry::KioskAppMenuEntry() = default;
} // namespace

KioskAppMenuEntry::KioskAppMenuEntry(
AppType type,
const AccountId& account_id,
const absl::optional<std::string>& chrome_app_id,
std::u16string name,
gfx::ImageSkia icon)
: type(type),
account_id(account_id),
chrome_app_id(chrome_app_id),
name(std::move(name)),
icon(icon) {
bool should_have_chrome_app_id = type == AppType::kChromeApp;
CHECK_EQ(should_have_chrome_app_id, chrome_app_id.has_value());
}
KioskAppMenuEntry::KioskAppMenuEntry(const KioskAppMenuEntry& other) = default;
KioskAppMenuEntry::KioskAppMenuEntry(KioskAppMenuEntry&& other) = default;
KioskAppMenuEntry::~KioskAppMenuEntry() = default;
Expand Down
23 changes: 16 additions & 7 deletions ash/public/cpp/kiosk_app_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,36 @@
#include "ash/public/cpp/ash_public_export.h"
#include "base/functional/callback_forward.h"
#include "components/account_id/account_id.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "ui/gfx/image/image_skia.h"

namespace ash {

// Metadata about a kiosk app. Used for display in the kiosk app menu in the
// login screen shelf.
// Metadata used to populate the Kiosk apps menu in the login screen shelf.
struct ASH_PUBLIC_EXPORT KioskAppMenuEntry {
KioskAppMenuEntry();
// Mirrors `KioskAppType`.
enum class AppType { kArcApp, kChromeApp, kWebApp };

KioskAppMenuEntry(AppType type,
const AccountId& account_id,
const absl::optional<std::string>& chrome_app_id,
std::u16string name,
gfx::ImageSkia icon);
KioskAppMenuEntry(const KioskAppMenuEntry& other);
KioskAppMenuEntry(KioskAppMenuEntry&& other);
~KioskAppMenuEntry();

KioskAppMenuEntry& operator=(KioskAppMenuEntry&& other);
KioskAppMenuEntry& operator=(const KioskAppMenuEntry& other);

// For Chrome kiosk apps only, the extension app id.
std::string app_id;
~KioskAppMenuEntry();

AppType type;

// For ARC kiosk apps only, the account id for the app.
AccountId account_id;

// Only present in Chrome apps, `nullopt` in other types.
absl::optional<std::string> chrome_app_id;

std::u16string name;

gfx::ImageSkia icon;
Expand Down
1 change: 1 addition & 0 deletions ash/public/cpp/login_screen_test_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class ASH_PUBLIC_EXPORT LoginScreenTestApi {
static void ClickChallengeResponseButton(const AccountId& account_id);
static int64_t GetUiUpdateCount();
static bool LaunchApp(const std::string& app_id);
static bool LaunchApp(const AccountId& account_id);
static bool ClickAppsButton();
static bool ClickAddUserButton();
static bool ClickCancelButton();
Expand Down
25 changes: 20 additions & 5 deletions ash/shelf/kiosk_apps_button.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/shelf/login_shelf_button.h"
#include "ash/shell.h"
#include "base/check.h"
#include "base/functional/callback.h"
#include "chromeos/strings/grit/chromeos_strings.h"
#include "skia/ext/image_operations.h"
Expand All @@ -36,10 +37,20 @@ class KioskAppsButton::KioskAppsMenuModel
bool IsLaunchEnabled() const { return is_launch_enabled_; }
void SetLaunchEnabled(bool enabled) { is_launch_enabled_ = enabled; }

bool LaunchApp(const std::string& app_id) {
bool LaunchApp(const std::string& chrome_app_id) {
for (size_t i = 0; i < kiosk_apps_.size(); ++i) {
if (kiosk_apps_[i].app_id == app_id) {
ExecuteCommand(i, 0);
if (kiosk_apps_[i].chrome_app_id == chrome_app_id) {
ExecuteCommand(/*command_id=*/i, /*event_flags=*/0);
return true;
}
}
return false;
}

bool LaunchApp(const AccountId& account_id) {
for (size_t i = 0; i < kiosk_apps_.size(); ++i) {
if (kiosk_apps_[i].account_id == account_id) {
ExecuteCommand(/*command_id=*/i, /*event_flags=*/0);
return true;
}
}
Expand Down Expand Up @@ -123,8 +134,12 @@ KioskAppsButton::KioskAppsButton()

KioskAppsButton::~KioskAppsButton() = default;

bool KioskAppsButton::LaunchAppForTesting(const std::string& app_id) {
return menu_model_->LaunchApp(app_id);
bool KioskAppsButton::LaunchAppForTesting(const std::string& chrome_app_id) {
return menu_model_->LaunchApp(chrome_app_id);
}

bool KioskAppsButton::LaunchAppForTesting(const AccountId& account_id) {
return menu_model_->LaunchApp(account_id);
}

void KioskAppsButton::SetApps(
Expand Down
2 changes: 2 additions & 0 deletions ash/shelf/kiosk_apps_button.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "ash/public/cpp/kiosk_app_menu.h"
#include "ash/shelf/login_shelf_button.h"
#include "base/memory/raw_ptr.h"
#include "components/account_id/account_id.h"
#include "ui/base/models/simple_menu_model.h"
#include "ui/views/controls/button/menu_button_controller.h"
#include "ui/views/controls/menu/menu_runner.h"
Expand All @@ -31,6 +32,7 @@ class ASH_EXPORT KioskAppsButton : public LoginShelfButton {

// Launch app based on the app_id.
bool LaunchAppForTesting(const std::string& app_id);
bool LaunchAppForTesting(const AccountId& account_id);

// Replace the existing items list with a new list of kiosk app menu items.
void SetApps(const std::vector<KioskAppMenuEntry>& kiosk_apps);
Expand Down

0 comments on commit 17195a2

Please sign in to comment.