File: chrome_app_deprecation_kiosk_browsertest.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (183 lines) | stat: -rw-r--r-- 6,684 bytes parent folder | download
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
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/public/cpp/login_accelerators.h"
#include "base/task/current_thread.h"
#include "base/test/metrics/histogram_tester.h"
#include "chrome/browser/apps/app_service/publishers/chrome_app_deprecation.h"
#include "chrome/browser/ash/app_mode/kiosk_app_launch_error.h"
#include "chrome/browser/ash/app_mode/kiosk_controller.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/login/app_mode/kiosk_launch_controller.h"
#include "chrome/browser/ui/ash/login/login_display_host.h"
#include "chrome/test/base/mixin_based_in_process_browser_test.h"
#include "content/public/test/browser_test.h"

namespace apps {

using ash::KioskAppLaunchError;
using ash::KioskMixin;
using ash::kiosk::test::LaunchAppManually;
using ash::kiosk::test::OfflineEnabledChromeAppV1;
using ash::kiosk::test::WaitKioskLaunched;

enum AllowChromeAppsFlag {
  kDefault,  // by default the flag is disabled.
  kEnabled,
};

template <AllowChromeAppsFlag flag>
class ChromeAppDeprecationKioskSessionBrowserTest
    : public MixinBasedInProcessBrowserTest {
 public:
  ChromeAppDeprecationKioskSessionBrowserTest() {
    switch (flag) {
      case kDefault:
        scoped_feature_list_.InitWithEmptyFeatureAndFieldTrialLists();
        break;
      case kEnabled:
        scoped_feature_list_.InitAndEnableFeature(
            chrome_app_deprecation::kAllowChromeAppsInKioskSessions);
        break;
    }
  }

  ChromeAppDeprecationKioskSessionBrowserTest(
      const ChromeAppDeprecationKioskSessionBrowserTest&) = delete;
  ChromeAppDeprecationKioskSessionBrowserTest& operator=(
      const ChromeAppDeprecationKioskSessionBrowserTest&) = delete;
  ~ChromeAppDeprecationKioskSessionBrowserTest() override = default;

  void WaitForChromeAppDeprecatedLaunchError() {
    ASSERT_TRUE(base::test::RunUntil([&]() {
      return KioskAppLaunchError::Get() ==
             KioskAppLaunchError::Error::kChromeAppDeprecated;
    }));
  }

  bool PressBailoutAccelerator() {
    return ash::LoginDisplayHost::default_host()->HandleAccelerator(
        ash::LoginAcceleratorAction::kAppLaunchBailout);
  }

  void VerifyUniqueKioskLaunchErrorMetric(KioskAppLaunchError::Error error) {
    histogram_.ExpectUniqueSample(ash::kKioskLaunchErrorHistogram, error,
                                  /*expected_bucket_count=*/1);
  }

 private:
  base::HistogramTester histogram_;

  KioskMixin kiosk_{
      &mixin_host_,
      /*cached_configuration=*/KioskMixin::Config{
          /*name=*/{},
          KioskMixin::AutoLaunchAccount{OfflineEnabledChromeAppV1().account_id},
          {OfflineEnabledChromeAppV1()}}};
  base::test::ScopedFeatureList scoped_feature_list_;
};

using ChromeAppDeprecationKioskDefaultFlagTest =
    ChromeAppDeprecationKioskSessionBrowserTest<AllowChromeAppsFlag::kDefault>;

IN_PROC_BROWSER_TEST_F(ChromeAppDeprecationKioskDefaultFlagTest,
                       StuckOnSplashScreen) {
  WaitForChromeAppDeprecatedLaunchError();

  base::RunLoop().RunUntilIdle();

  // Check kiosk is not started and user is stuck on the splash screen.
  EXPECT_EQ(ash::KioskController::Get().GetKioskSystemSession(), nullptr);
  EXPECT_TRUE(ash::KioskController::Get().IsSessionStarting());
}

// Bailout accelerator should work on the splash screen with the Chrome App
// deprecated message.
IN_PROC_BROWSER_TEST_F(ChromeAppDeprecationKioskDefaultFlagTest,
                       UserCancelled) {
  WaitForChromeAppDeprecatedLaunchError();
  EXPECT_TRUE(ash::KioskController::Get().IsSessionStarting());

  PressBailoutAccelerator();

  RunUntilBrowserProcessQuits();
  EXPECT_EQ(KioskAppLaunchError::Get(),
            KioskAppLaunchError::Error::kUserCancel);
  EXPECT_FALSE(ash::KioskController::Get().IsSessionStarting());
}

IN_PROC_BROWSER_TEST_F(ChromeAppDeprecationKioskDefaultFlagTest,
                       AllowlistedAppCanBeLaunched) {
  chrome_app_deprecation::AddAppToAllowlistForTesting(
      OfflineEnabledChromeAppV1().app_id);

  ASSERT_FALSE(base::FeatureList::IsEnabled(
      chrome_app_deprecation::kAllowChromeAppsInKioskSessions));

  ASSERT_TRUE(WaitKioskLaunched());
}

IN_PROC_BROWSER_TEST_F(ChromeAppDeprecationKioskDefaultFlagTest,
                       PRE_CheckMetric) {
  WaitForChromeAppDeprecatedLaunchError();
}

// Metrics are recorded on the next browser start.
IN_PROC_BROWSER_TEST_F(ChromeAppDeprecationKioskDefaultFlagTest, CheckMetric) {
  VerifyUniqueKioskLaunchErrorMetric(
      KioskAppLaunchError::Error::kChromeAppDeprecated);
}

IN_PROC_BROWSER_TEST_F(ChromeAppDeprecationKioskDefaultFlagTest,
                       PRE_CheckAutoLaunchWorks) {
  WaitForChromeAppDeprecatedLaunchError();
}

// When Chrome App is deprecated, the auto-launch after the browser restart
// should proceed and stuck on the same splash screen.
IN_PROC_BROWSER_TEST_F(ChromeAppDeprecationKioskDefaultFlagTest,
                       CheckAutoLaunchWorks) {
  WaitForChromeAppDeprecatedLaunchError();

  base::RunLoop().RunUntilIdle();

  // Check kiosk is not started and user is stuck on the splash screen.
  EXPECT_EQ(ash::KioskController::Get().GetKioskSystemSession(), nullptr);
  EXPECT_TRUE(ash::KioskController::Get().IsSessionStarting());
}

IN_PROC_BROWSER_TEST_F(ChromeAppDeprecationKioskDefaultFlagTest,
                       PRE_NoAutoLaunchAfterUserCancelled) {
  WaitForChromeAppDeprecatedLaunchError();
  EXPECT_TRUE(ash::KioskController::Get().IsSessionStarting());

  PressBailoutAccelerator();

  RunUntilBrowserProcessQuits();
  EXPECT_EQ(KioskAppLaunchError::Get(),
            KioskAppLaunchError::Error::kUserCancel);
  EXPECT_FALSE(ash::KioskController::Get().IsSessionStarting());
}

// Keep the existing behavior -- if user cancelled kiosk launch, app should not
// be auto-launched again.
IN_PROC_BROWSER_TEST_F(ChromeAppDeprecationKioskDefaultFlagTest,
                       NoAutoLaunchAfterUserCancelled) {
  base::RunLoop().RunUntilIdle();
  EXPECT_FALSE(ash::KioskController::Get().IsSessionStarting());
}

using ChromeAppDeprecationKioskEnabledFeatureFlagTest =
    ChromeAppDeprecationKioskSessionBrowserTest<AllowChromeAppsFlag::kEnabled>;

IN_PROC_BROWSER_TEST_F(ChromeAppDeprecationKioskEnabledFeatureFlagTest,
                       LaunchChromeApp) {
  ASSERT_TRUE(base::FeatureList::IsEnabled(
      chrome_app_deprecation::kAllowChromeAppsInKioskSessions));
  ASSERT_TRUE(WaitKioskLaunched());
}

}  // namespace apps