kiosk_browsertest.cc revision d0247b1b59f9c528cb6df88b4f2b9afaf80d181e
1// Copyright (c) 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "base/command_line.h"
6#include "base/memory/scoped_ptr.h"
7#include "base/message_loop/message_loop.h"
8#include "base/path_service.h"
9#include "chrome/browser/browser_process.h"
10#include "chrome/browser/chrome_browser_main.h"
11#include "chrome/browser/chrome_browser_main_extra_parts.h"
12#include "chrome/browser/chrome_content_browser_client.h"
13#include "chrome/browser/chrome_notification_types.h"
14#include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h"
15#include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
16#include "chrome/browser/chromeos/login/app_launch_controller.h"
17#include "chrome/browser/chromeos/login/app_launch_signin_screen.h"
18#include "chrome/browser/chromeos/login/existing_user_controller.h"
19#include "chrome/browser/chromeos/login/login_display_host_impl.h"
20#include "chrome/browser/chromeos/login/mock_user_manager.h"
21#include "chrome/browser/chromeos/login/webui_login_display.h"
22#include "chrome/browser/chromeos/login/wizard_controller.h"
23#include "chrome/browser/chromeos/settings/cros_settings.h"
24#include "chrome/browser/chromeos/settings/cros_settings_names.h"
25#include "chrome/browser/extensions/extension_service.h"
26#include "chrome/browser/extensions/extension_system.h"
27#include "chrome/browser/extensions/extension_test_message_listener.h"
28#include "chrome/browser/lifetime/application_lifetime.h"
29#include "chrome/browser/prefs/scoped_user_pref_update.h"
30#include "chrome/browser/profiles/profile_manager.h"
31#include "chrome/browser/ui/browser.h"
32#include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
33#include "chrome/common/chrome_paths.h"
34#include "chrome/common/chrome_switches.h"
35#include "chrome/common/extensions/extension.h"
36#include "chrome/test/base/in_process_browser_test.h"
37#include "chrome/test/base/interactive_test_utils.h"
38#include "chrome/test/base/ui_test_utils.h"
39#include "chromeos/chromeos_switches.h"
40#include "content/public/browser/notification_observer.h"
41#include "content/public/browser/notification_registrar.h"
42#include "content/public/browser/notification_service.h"
43#include "content/public/test/test_utils.h"
44#include "google_apis/gaia/fake_gaia.h"
45#include "google_apis/gaia/gaia_switches.h"
46#include "net/base/network_change_notifier.h"
47#include "net/test/embedded_test_server/embedded_test_server.h"
48#include "net/test/embedded_test_server/http_request.h"
49#include "net/test/embedded_test_server/http_response.h"
50#include "testing/gmock/include/gmock/gmock.h"
51#include "testing/gtest/include/gtest/gtest.h"
52
53
54namespace chromeos {
55
56namespace {
57
58// Webstore data json is in
59//   chrome/test/data/chromeos/app_mode/webstore/inlineinstall/
60//       detail/ggbflgnkafappblpkiflbgpmkfdpnhhe
61const char kTestKioskApp[] = "ggbflgnkafappblpkiflbgpmkfdpnhhe";
62
63// Timeout while waiting for network connectivity during tests.
64const int kTestNetworkTimeoutSeconds = 1;
65
66// Email of owner account for test.
67const char kTestOwnerEmail[] = "owner@example.com";
68
69// Helper function for GetConsumerKioskModeStatusCallback.
70void ConsumerKioskModeStatusCheck(
71    KioskAppManager::ConsumerKioskModeStatus* out_status,
72    const base::Closure& runner_quit_task,
73    KioskAppManager::ConsumerKioskModeStatus in_status) {
74  LOG(INFO) << "KioskAppManager::ConsumerKioskModeStatus = " << in_status;
75  *out_status = in_status;
76  runner_quit_task.Run();
77}
78
79// Helper KioskAppManager::EnableKioskModeCallback implementation.
80void ConsumerKioskModeLockCheck(
81    bool* out_locked,
82    const base::Closure& runner_quit_task,
83    bool in_locked) {
84  LOG(INFO) << "kiosk locked  = " << in_locked;
85  *out_locked = in_locked;
86  runner_quit_task.Run();
87}
88
89// Helper function for WaitForNetworkTimeOut.
90void OnNetworkWaitTimedOut(const base::Closure& runner_quit_task) {
91  runner_quit_task.Run();
92}
93
94}  // namespace
95
96// Fake NetworkChangeNotifier used to simulate network connectivity.
97class FakeNetworkChangeNotifier : public net::NetworkChangeNotifier {
98 public:
99  FakeNetworkChangeNotifier() : connection_type_(CONNECTION_NONE) {}
100
101  virtual ConnectionType GetCurrentConnectionType() const OVERRIDE {
102    return connection_type_;
103  }
104
105  void GoOnline() {
106    SetConnectionType(net::NetworkChangeNotifier::CONNECTION_ETHERNET);
107  }
108
109  void GoOffline() {
110    SetConnectionType(net::NetworkChangeNotifier::CONNECTION_NONE);
111  }
112
113  void SetConnectionType(ConnectionType type) {
114    connection_type_ = type;
115    NotifyObserversOfNetworkChange(type);
116    base::RunLoop().RunUntilIdle();
117  }
118
119  virtual ~FakeNetworkChangeNotifier() {}
120
121 private:
122  ConnectionType connection_type_;
123  DISALLOW_COPY_AND_ASSIGN(FakeNetworkChangeNotifier);
124};
125
126// A waiter that blocks until the expected oobe screen is reached.
127class OobeScreenWaiter : public OobeUI::Observer {
128 public:
129  explicit OobeScreenWaiter(OobeDisplay::Screen expected_screen)
130      : waiting_for_screen_(false),
131        expected_screen_(expected_screen) {
132  }
133
134  virtual ~OobeScreenWaiter() {
135    if (waiting_for_screen_) {
136      GetOobeUI()->RemoveObserver(this);
137    }
138  }
139
140  void Wait() {
141    if (GetOobeUI()->current_screen() == expected_screen_) {
142      return;
143    }
144
145    waiting_for_screen_ = true;
146    GetOobeUI()->AddObserver(this);
147
148    runner_ = new content::MessageLoopRunner;
149    runner_->Run();
150    ASSERT_EQ(expected_screen_, GetOobeUI()->current_screen());
151    ASSERT_FALSE(waiting_for_screen_);
152  }
153
154  // OobeUI::Observer implementation:
155  virtual void OnCurrentScreenChanged(
156        OobeDisplay::Screen current_screen,
157        OobeDisplay::Screen new_screen) OVERRIDE {
158    if (waiting_for_screen_ && new_screen == expected_screen_) {
159      runner_->Quit();
160      waiting_for_screen_ = false;
161      GetOobeUI()->RemoveObserver(this);
162    }
163  }
164
165  OobeUI* GetOobeUI() {
166    OobeUI* oobe_ui = static_cast<chromeos::LoginDisplayHostImpl*>(
167        chromeos::LoginDisplayHostImpl::default_host())->GetOobeUI();
168    CHECK(oobe_ui);
169    return oobe_ui;
170  }
171
172 private:
173  bool waiting_for_screen_;
174  OobeDisplay::Screen expected_screen_;
175  scoped_refptr<content::MessageLoopRunner> runner_;
176};
177
178class KioskTest : public InProcessBrowserTest,
179                  // Param defining is multi-profiles enabled.
180                  public testing::WithParamInterface<bool> {
181 public:
182  KioskTest() {
183    set_exit_when_last_browser_closes(false);
184  }
185
186  virtual ~KioskTest() {}
187
188 protected:
189  virtual void SetUp() OVERRIDE {
190    base::FilePath test_data_dir;
191    PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir);
192    embedded_test_server()->ServeFilesFromDirectory(test_data_dir);
193    embedded_test_server()->RegisterRequestHandler(
194        base::Bind(&FakeGaia::HandleRequest, base::Unretained(&fake_gaia_)));
195    ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
196
197    mock_user_manager_.reset(new MockUserManager);
198    AppLaunchController::SkipSplashWaitForTesting();
199    AppLaunchController::SetNetworkWaitForTesting(kTestNetworkTimeoutSeconds);
200
201    InProcessBrowserTest::SetUp();
202  }
203
204  virtual void CleanUpOnMainThread() OVERRIDE {
205    // We need to clean up these objects in this specific order.
206    fake_network_notifier_.reset(NULL);
207    disable_network_notifier_.reset(NULL);
208
209    AppLaunchController::SetNetworkTimeoutCallbackForTesting(NULL);
210    AppLaunchController::SetUserManagerForTesting(NULL);
211
212    // If the login display is still showing, exit gracefully.
213    if (LoginDisplayHostImpl::default_host()) {
214      base::MessageLoop::current()->PostTask(FROM_HERE,
215                                             base::Bind(&chrome::AttemptExit));
216      content::RunMessageLoop();
217    }
218
219    // Clean up while main thread still runs.
220    // See http://crbug.com/176659.
221    KioskAppManager::Get()->CleanUp();
222  }
223
224  virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
225    if (GetParam())
226      command_line->AppendSwitch(::switches::kMultiProfiles);
227
228    command_line->AppendSwitch(chromeos::switches::kLoginManager);
229    command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests);
230    command_line->AppendSwitch(
231        chromeos::switches::kDisableChromeCaptivePortalDetector);
232    command_line->AppendSwitch(::switches::kDisableBackgroundNetworking);
233    command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user");
234
235    const GURL& server_url = embedded_test_server()->base_url();
236    command_line->AppendSwitchASCII(::switches::kGaiaUrl, server_url.spec());
237    command_line->AppendSwitchASCII(::switches::kLsoUrl, server_url.spec());
238    command_line->AppendSwitchASCII(::switches::kGoogleApisUrl,
239                                    server_url.spec());
240    command_line->AppendSwitchASCII(
241        ::switches::kAppsGalleryURL,
242        server_url.Resolve("/chromeos/app_mode/webstore").spec());
243    command_line->AppendSwitchASCII(
244        ::switches::kAppsGalleryDownloadURL,
245        server_url.Resolve(
246            "/chromeos/app_mode/webstore/downloads/%s.crx").spec());
247  }
248
249  void ReloadKioskApps() {
250    KioskAppManager::Get()->AddApp(kTestKioskApp);
251  }
252
253  void ReloadAutolaunchKioskApps() {
254    KioskAppManager::Get()->AddApp(kTestKioskApp);
255    KioskAppManager::Get()->SetAutoLaunchApp(kTestKioskApp);
256  }
257
258  void StartAppLaunchFromLoginScreen(bool has_connectivity) {
259    EnableConsumerKioskMode();
260
261    // Start UI, find menu entry for this app and launch it.
262    content::WindowedNotificationObserver login_signal(
263      chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
264      content::NotificationService::AllSources());
265    chromeos::WizardController::SkipPostLoginScreensForTesting();
266    chromeos::WizardController* wizard_controller =
267        chromeos::WizardController::default_controller();
268    CHECK(wizard_controller);
269    wizard_controller->SkipToLoginForTesting();
270    login_signal.Wait();
271
272    // Wait for the Kiosk App configuration to reload, then launch the app.
273    content::WindowedNotificationObserver apps_loaded_signal(
274        chrome::NOTIFICATION_KIOSK_APPS_LOADED,
275        content::NotificationService::AllSources());
276    ReloadKioskApps();
277    apps_loaded_signal.Wait();
278
279    if (!has_connectivity)
280      SimulateNetworkOffline();
281
282    GetLoginUI()->CallJavascriptFunction(
283        "login.AppsMenuButton.runAppForTesting",
284        base::StringValue(kTestKioskApp));
285  }
286
287  void WaitForAppLaunchSuccess() {
288    SimulateNetworkOnline();
289
290    ExtensionTestMessageListener
291        launch_data_check_listener("launchData.isKioskSession = true", false);
292
293    // Wait for the Kiosk App to launch.
294    content::WindowedNotificationObserver(
295        chrome::NOTIFICATION_KIOSK_APP_LAUNCHED,
296        content::NotificationService::AllSources()).Wait();
297
298    // Check installer status.
299    EXPECT_EQ(chromeos::KioskAppLaunchError::NONE,
300              chromeos::KioskAppLaunchError::Get());
301
302    // Check if the kiosk webapp is really installed for the default profile.
303    ASSERT_TRUE(ProfileManager::GetDefaultProfile());
304    const extensions::Extension* app =
305        extensions::ExtensionSystem::Get(ProfileManager::GetDefaultProfile())->
306        extension_service()->GetInstalledExtension(kTestKioskApp);
307    EXPECT_TRUE(app);
308
309    // Wait until the app terminates.
310    content::RunMessageLoop();
311
312    // Check that the app had been informed that it is running in a kiosk
313    // session.
314    EXPECT_TRUE(launch_data_check_listener.was_satisfied());
315  }
316
317  void SimulateNetworkOffline() {
318    disable_network_notifier_.reset(
319        new net::NetworkChangeNotifier::DisableForTest);
320
321    fake_network_notifier_.reset(new FakeNetworkChangeNotifier);
322  }
323
324  void SimulateNetworkOnline() {
325    if (fake_network_notifier_.get())
326      fake_network_notifier_->GoOnline();
327  }
328
329  void WaitForAppLaunchNetworkTimeout() {
330    if (GetAppLaunchController()->network_wait_timedout())
331      return;
332
333    scoped_refptr<content::MessageLoopRunner> runner =
334        new content::MessageLoopRunner;
335
336    base::Closure callback = base::Bind(
337        &OnNetworkWaitTimedOut, runner->QuitClosure());
338    AppLaunchController::SetNetworkTimeoutCallbackForTesting(&callback);
339
340    runner->Run();
341
342    CHECK(GetAppLaunchController()->network_wait_timedout());
343    AppLaunchController::SetNetworkTimeoutCallbackForTesting(NULL);
344  }
345
346  void EnableConsumerKioskMode() {
347    scoped_ptr<bool> locked(new bool(false));
348    scoped_refptr<content::MessageLoopRunner> runner =
349        new content::MessageLoopRunner;
350    KioskAppManager::Get()->EnableConsumerModeKiosk(
351        base::Bind(&ConsumerKioskModeLockCheck,
352                   locked.get(),
353                   runner->QuitClosure()));
354    runner->Run();
355    EXPECT_TRUE(*locked.get());
356  }
357
358  KioskAppManager::ConsumerKioskModeStatus GetConsumerKioskModeStatus() {
359    KioskAppManager::ConsumerKioskModeStatus status =
360        static_cast<KioskAppManager::ConsumerKioskModeStatus>(-1);
361    scoped_refptr<content::MessageLoopRunner> runner =
362        new content::MessageLoopRunner;
363    KioskAppManager::Get()->GetConsumerKioskModeStatus(
364        base::Bind(&ConsumerKioskModeStatusCheck,
365                   &status,
366                   runner->QuitClosure()));
367    runner->Run();
368    CHECK_NE(status, static_cast<KioskAppManager::ConsumerKioskModeStatus>(-1));
369    return status;
370  }
371
372  content::WebUI* GetLoginUI() {
373    return static_cast<chromeos::LoginDisplayHostImpl*>(
374        chromeos::LoginDisplayHostImpl::default_host())->GetOobeUI()->web_ui();
375  }
376
377  AppLaunchController* GetAppLaunchController() {
378    return chromeos::LoginDisplayHostImpl::default_host()
379        ->GetAppLaunchController();
380  }
381
382  FakeGaia fake_gaia_;
383  scoped_ptr<net::NetworkChangeNotifier::DisableForTest>
384      disable_network_notifier_;
385  scoped_ptr<FakeNetworkChangeNotifier> fake_network_notifier_;
386  scoped_ptr<MockUserManager> mock_user_manager_;
387 };
388
389IN_PROC_BROWSER_TEST_P(KioskTest, InstallAndLaunchApp) {
390  StartAppLaunchFromLoginScreen(true);
391  WaitForAppLaunchSuccess();
392}
393
394IN_PROC_BROWSER_TEST_P(KioskTest, LaunchAppNetworkDown) {
395  // Start app launch and wait for network connectivity timeout.
396  StartAppLaunchFromLoginScreen(false);
397  OobeScreenWaiter splash_waiter(OobeDisplay::SCREEN_APP_LAUNCH_SPLASH);
398  splash_waiter.Wait();
399  WaitForAppLaunchNetworkTimeout();
400
401  // Set up fake user manager with an owner for the test.
402  mock_user_manager_->SetActiveUser(kTestOwnerEmail);
403  AppLaunchController::SetUserManagerForTesting(mock_user_manager_.get());
404  static_cast<LoginDisplayHostImpl*>(LoginDisplayHostImpl::default_host())
405      ->GetOobeUI()->ShowOobeUI(false);
406
407  // Configure network should bring up lock screen for owner.
408  OobeScreenWaiter lock_screen_waiter(OobeDisplay::SCREEN_ACCOUNT_PICKER);
409  static_cast<AppLaunchSplashScreenActor::Delegate*>(GetAppLaunchController())
410    ->OnConfigureNetwork();
411  lock_screen_waiter.Wait();
412
413  // A network error screen should be shown after authenticating.
414  OobeScreenWaiter error_screen_waiter(OobeDisplay::SCREEN_ERROR_MESSAGE);
415  static_cast<AppLaunchSigninScreen::Delegate*>(GetAppLaunchController())
416    ->OnOwnerSigninSuccess();
417  error_screen_waiter.Wait();
418
419  ASSERT_TRUE(GetAppLaunchController()->showing_network_dialog());
420
421  WaitForAppLaunchSuccess();
422}
423
424IN_PROC_BROWSER_TEST_P(KioskTest, LaunchAppUserCancel) {
425  StartAppLaunchFromLoginScreen(false);
426  OobeScreenWaiter splash_waiter(OobeDisplay::SCREEN_APP_LAUNCH_SPLASH);
427  splash_waiter.Wait();
428
429  CrosSettings::Get()->SetBoolean(
430      kAccountsPrefDeviceLocalAccountAutoLoginBailoutEnabled, true);
431  content::WindowedNotificationObserver signal(
432      chrome::NOTIFICATION_APP_TERMINATING,
433      content::NotificationService::AllSources());
434  GetLoginUI()->CallJavascriptFunction("cr.ui.Oobe.handleAccelerator",
435                                       base::StringValue("app_launch_bailout"));
436  signal.Wait();
437  EXPECT_EQ(chromeos::KioskAppLaunchError::USER_CANCEL,
438            chromeos::KioskAppLaunchError::Get());
439}
440
441IN_PROC_BROWSER_TEST_P(KioskTest, AutolaunchWarningCancel) {
442  EnableConsumerKioskMode();
443  // Start UI, find menu entry for this app and launch it.
444  chromeos::WizardController::SkipPostLoginScreensForTesting();
445  chromeos::WizardController* wizard_controller =
446      chromeos::WizardController::default_controller();
447  CHECK(wizard_controller);
448  ReloadAutolaunchKioskApps();
449  wizard_controller->SkipToLoginForTesting();
450
451  EXPECT_FALSE(KioskAppManager::Get()->GetAutoLaunchApp().empty());
452  EXPECT_FALSE(KioskAppManager::Get()->IsAutoLaunchEnabled());
453
454  // Wait for the auto launch warning come up.
455  content::WindowedNotificationObserver(
456      chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE,
457      content::NotificationService::AllSources()).Wait();
458  GetLoginUI()->CallJavascriptFunction(
459      "login.AutolaunchScreen.confirmAutoLaunchForTesting",
460      base::FundamentalValue(false));
461
462  // Wait for the auto launch warning to go away.
463  content::WindowedNotificationObserver(
464      chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_COMPLETED,
465      content::NotificationService::AllSources()).Wait();
466
467  EXPECT_FALSE(KioskAppManager::Get()->IsAutoLaunchEnabled());
468}
469
470IN_PROC_BROWSER_TEST_P(KioskTest, AutolaunchWarningConfirm) {
471  EnableConsumerKioskMode();
472  // Start UI, find menu entry for this app and launch it.
473  chromeos::WizardController::SkipPostLoginScreensForTesting();
474  chromeos::WizardController* wizard_controller =
475      chromeos::WizardController::default_controller();
476  CHECK(wizard_controller);
477  wizard_controller->SkipToLoginForTesting();
478
479  ReloadAutolaunchKioskApps();
480  EXPECT_FALSE(KioskAppManager::Get()->GetAutoLaunchApp().empty());
481  EXPECT_FALSE(KioskAppManager::Get()->IsAutoLaunchEnabled());
482
483  // Wait for the auto launch warning come up.
484  content::WindowedNotificationObserver(
485      chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE,
486      content::NotificationService::AllSources()).Wait();
487  GetLoginUI()->CallJavascriptFunction(
488      "login.AutolaunchScreen.confirmAutoLaunchForTesting",
489      base::FundamentalValue(true));
490
491  // Wait for the auto launch warning to go away.
492  content::WindowedNotificationObserver(
493      chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_COMPLETED,
494      content::NotificationService::AllSources()).Wait();
495
496  EXPECT_FALSE(KioskAppManager::Get()->GetAutoLaunchApp().empty());
497  EXPECT_TRUE(KioskAppManager::Get()->IsAutoLaunchEnabled());
498
499  // Wait for the Kiosk App to launch.
500  content::WindowedNotificationObserver(
501      chrome::NOTIFICATION_KIOSK_APP_LAUNCHED,
502      content::NotificationService::AllSources()).Wait();
503
504  // Check installer status.
505  EXPECT_EQ(chromeos::KioskAppLaunchError::NONE,
506            chromeos::KioskAppLaunchError::Get());
507
508  // Check if the kiosk webapp is really installed for the default profile.
509  ASSERT_TRUE(ProfileManager::GetDefaultProfile());
510  const extensions::Extension* app =
511      extensions::ExtensionSystem::Get(ProfileManager::GetDefaultProfile())->
512      extension_service()->GetInstalledExtension(kTestKioskApp);
513  EXPECT_TRUE(app);
514
515  // Wait until the app terminates.
516  content::RunMessageLoop();
517}
518
519IN_PROC_BROWSER_TEST_P(KioskTest, KioskEnableCancel) {
520  chromeos::WizardController::SkipPostLoginScreensForTesting();
521  chromeos::WizardController* wizard_controller =
522      chromeos::WizardController::default_controller();
523  CHECK(wizard_controller);
524
525  // Check Kiosk mode status.
526  EXPECT_EQ(KioskAppManager::CONSUMER_KIOSK_MODE_CONFIGURABLE,
527            GetConsumerKioskModeStatus());
528
529  // Wait for the login UI to come up and switch to the kiosk_enable screen.
530  wizard_controller->SkipToLoginForTesting();
531  content::WindowedNotificationObserver(
532      chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
533      content::NotificationService::AllSources()).Wait();
534  GetLoginUI()->CallJavascriptFunction("cr.ui.Oobe.handleAccelerator",
535                                       base::StringValue("kiosk_enable"));
536
537  // Wait for the kiosk_enable screen to show and cancel the screen.
538  content::WindowedNotificationObserver(
539      chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_VISIBLE,
540      content::NotificationService::AllSources()).Wait();
541  GetLoginUI()->CallJavascriptFunction(
542      "login.KioskEnableScreen.enableKioskForTesting",
543      base::FundamentalValue(false));
544
545  // Wait for the kiosk_enable screen to disappear.
546  content::WindowedNotificationObserver(
547      chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_COMPLETED,
548      content::NotificationService::AllSources()).Wait();
549
550  // Check that the status still says configurable.
551  EXPECT_EQ(KioskAppManager::CONSUMER_KIOSK_MODE_CONFIGURABLE,
552            GetConsumerKioskModeStatus());
553}
554
555IN_PROC_BROWSER_TEST_P(KioskTest, KioskEnableConfirmed) {
556  // Start UI, find menu entry for this app and launch it.
557  chromeos::WizardController::SkipPostLoginScreensForTesting();
558  chromeos::WizardController* wizard_controller =
559      chromeos::WizardController::default_controller();
560  CHECK(wizard_controller);
561
562  // Check Kiosk mode status.
563  EXPECT_EQ(KioskAppManager::CONSUMER_KIOSK_MODE_CONFIGURABLE,
564            GetConsumerKioskModeStatus());
565  wizard_controller->SkipToLoginForTesting();
566
567  // Wait for the login UI to come up and switch to the kiosk_enable screen.
568  wizard_controller->SkipToLoginForTesting();
569  content::WindowedNotificationObserver(
570      chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
571      content::NotificationService::AllSources()).Wait();
572  GetLoginUI()->CallJavascriptFunction("cr.ui.Oobe.handleAccelerator",
573                                       base::StringValue("kiosk_enable"));
574
575  // Wait for the kiosk_enable screen to show and cancel the screen.
576  content::WindowedNotificationObserver(
577      chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_VISIBLE,
578      content::NotificationService::AllSources()).Wait();
579  GetLoginUI()->CallJavascriptFunction(
580      "login.KioskEnableScreen.enableKioskForTesting",
581      base::FundamentalValue(true));
582
583  // Wait for the signal that indicates Kiosk Mode is enabled.
584  content::WindowedNotificationObserver(
585      chrome::NOTIFICATION_KIOSK_ENABLED,
586      content::NotificationService::AllSources()).Wait();
587  EXPECT_EQ(KioskAppManager::CONSUMER_KIOSK_MODE_ENABLED,
588            GetConsumerKioskModeStatus());
589}
590
591INSTANTIATE_TEST_CASE_P(KioskTestInstantiation, KioskTest, testing::Bool());
592
593}  // namespace chromeos
594