kiosk_browsertest.cc revision 5e3f23d412006dc4db4e659864679f29341e113f
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/path_service.h" 7#include "base/strings/stringprintf.h" 8#include "chrome/browser/browser_process.h" 9#include "chrome/browser/chrome_browser_main.h" 10#include "chrome/browser/chrome_browser_main_extra_parts.h" 11#include "chrome/browser/chrome_content_browser_client.h" 12#include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h" 13#include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" 14#include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h" 15#include "chrome/browser/chromeos/login/existing_user_controller.h" 16#include "chrome/browser/chromeos/login/login_display_host_impl.h" 17#include "chrome/browser/chromeos/login/webui_login_display.h" 18#include "chrome/browser/chromeos/login/wizard_controller.h" 19#include "chrome/browser/extensions/extension_service.h" 20#include "chrome/browser/extensions/extension_system.h" 21#include "chrome/browser/lifetime/application_lifetime.h" 22#include "chrome/browser/prefs/scoped_user_pref_update.h" 23#include "chrome/browser/profiles/profile_manager.h" 24#include "chrome/browser/ui/browser.h" 25#include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" 26#include "chrome/common/chrome_notification_types.h" 27#include "chrome/common/chrome_paths.h" 28#include "chrome/common/chrome_switches.h" 29#include "chrome/common/extensions/extension.h" 30#include "chrome/test/base/in_process_browser_test.h" 31#include "chrome/test/base/interactive_test_utils.h" 32#include "chrome/test/base/ui_test_utils.h" 33#include "chromeos/chromeos_switches.h" 34#include "content/public/browser/notification_observer.h" 35#include "content/public/browser/notification_registrar.h" 36#include "content/public/browser/notification_service.h" 37#include "content/public/test/test_utils.h" 38#include "google_apis/gaia/gaia_switches.h" 39#include "net/base/host_port_pair.h" 40#include "net/dns/mock_host_resolver.h" 41#include "net/test/embedded_test_server/embedded_test_server.h" 42#include "net/test/embedded_test_server/http_request.h" 43#include "net/test/embedded_test_server/http_response.h" 44#include "testing/gmock/include/gmock/gmock.h" 45#include "testing/gtest/include/gtest/gtest.h" 46 47using namespace net::test_server; 48 49namespace chromeos { 50 51namespace { 52 53const char kWebstoreDomain[] = "cws.com"; 54const base::FilePath kServiceLogin("chromeos/service_login.html"); 55 56// Webstore data json is in 57// chrome/test/data/chromeos/app_mode/webstore/inlineinstall/ 58// detail/ggbflgnkafappblpkiflbgpmkfdpnhhe 59const char kTestKioskApp[] = "ggbflgnkafappblpkiflbgpmkfdpnhhe"; 60 61class TestBrowserMainExtraParts 62 : public ChromeBrowserMainExtraParts, 63 public content::NotificationObserver { 64 public: 65 TestBrowserMainExtraParts() {} 66 virtual ~TestBrowserMainExtraParts() {} 67 68 void set_quit_task(const base::Closure& quit_task) { quit_task_ = quit_task; } 69 void set_gaia_url(const GURL& url) { gaia_url_ = url; } 70 71 void SetupSigninScreen() { 72 chromeos::ExistingUserController* controller = 73 chromeos::ExistingUserController::current_controller(); 74 CHECK(controller); 75 chromeos::WebUILoginDisplay* webui_login_display = 76 static_cast<chromeos::WebUILoginDisplay*>( 77 controller->login_display()); 78 CHECK(webui_login_display); 79 webui_login_display->SetGaiaUrlForTesting(gaia_url_); 80 webui_login_display->ShowSigninScreenForCreds("username", "password"); 81 } 82 83 protected: 84 content::NotificationRegistrar registrar_; 85 base::Closure quit_task_; 86 GURL gaia_url_; 87 88 DISALLOW_COPY_AND_ASSIGN(TestBrowserMainExtraParts); 89}; 90 91// Used to add an observer to NotificationService after it's created. 92class KioskAppLaunchScenarioHandler : public TestBrowserMainExtraParts { 93 public: 94 KioskAppLaunchScenarioHandler() {} 95 96 virtual ~KioskAppLaunchScenarioHandler() {} 97 98 private: 99 // ChromeBrowserMainExtraParts implementation. 100 virtual void PreEarlyInitialization() OVERRIDE { 101 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE, 102 content::NotificationService::AllSources()); 103 registrar_.Add(this, chrome::NOTIFICATION_KIOSK_APPS_LOADED, 104 content::NotificationService::AllSources()); 105 registrar_.Add(this, chrome::NOTIFICATION_KIOSK_APP_LAUNCHED, 106 content::NotificationService::AllSources()); 107 } 108 109 // Overridden from content::NotificationObserver: 110 virtual void Observe(int type, 111 const content::NotificationSource& source, 112 const content::NotificationDetails& details) OVERRIDE { 113 if (type == chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE) { 114 LOG(INFO) << "NOTIFICATION_LOGIN_WEBUI_VISIBLE"; 115 SetupSigninScreen(); 116 } else if (type == chrome::NOTIFICATION_KIOSK_APPS_LOADED) { 117 LOG(INFO) << "chrome::NOTIFICATION_KIOSK_APPS_LOADED"; 118 content::WebUI* web_ui = static_cast<chromeos::LoginDisplayHostImpl*>( 119 chromeos::LoginDisplayHostImpl::default_host())-> 120 GetOobeUI()->web_ui(); 121 web_ui->CallJavascriptFunction("login.AppsMenuButton.runAppForTesting", 122 base::StringValue(kTestKioskApp)); 123 } else if (type == chrome::NOTIFICATION_KIOSK_APP_LAUNCHED) { 124 LOG(INFO) << "chrome::NOTIFICATION_KIOSK_APP_LAUNCHED"; 125 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, 126 content::NotificationService::AllSources()); 127 quit_task_.Run(); 128 } else if (type == content::NOTIFICATION_RENDERER_PROCESS_CLOSED) { 129 LOG(INFO) << "content::NOTIFICATION_RENDERER_PROCESS_CLOSED"; 130 quit_task_.Run(); 131 } else { 132 NOTREACHED(); 133 } 134 } 135 136 DISALLOW_COPY_AND_ASSIGN(KioskAppLaunchScenarioHandler); 137}; 138 139class AutostartWarningCancelScenarioHandler : public TestBrowserMainExtraParts { 140 public: 141 AutostartWarningCancelScenarioHandler() { 142 } 143 144 virtual ~AutostartWarningCancelScenarioHandler() {} 145 146 private: 147 // ChromeBrowserMainExtraParts implementation. 148 virtual void PreEarlyInitialization() OVERRIDE { 149 registrar_.Add(this, chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE, 150 content::NotificationService::AllSources()); 151 registrar_.Add(this, 152 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_COMPLETED, 153 content::NotificationService::AllSources()); 154 registrar_.Add(this, chrome::NOTIFICATION_KIOSK_APP_LAUNCHED, 155 content::NotificationService::AllSources()); 156 } 157 158 // Overridden from content::NotificationObserver: 159 virtual void Observe(int type, 160 const content::NotificationSource& source, 161 const content::NotificationDetails& details) OVERRIDE { 162 switch (type) { 163 case chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE: { 164 LOG(INFO) << "chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE"; 165 content::WebUI* web_ui = static_cast<chromeos::LoginDisplayHostImpl*>( 166 chromeos::LoginDisplayHostImpl::default_host())-> 167 GetOobeUI()->web_ui(); 168 web_ui->CallJavascriptFunction( 169 "login.AutolaunchScreen.confirmAutoLaunchForTesting", 170 base::FundamentalValue(false)); 171 break; 172 } 173 case chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_COMPLETED: { 174 LOG(INFO) << "chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_COMPLETED"; 175 quit_task_.Run(); 176 break; 177 } 178 case chrome::NOTIFICATION_KIOSK_APP_LAUNCHED: { 179 LOG(FATAL) << "chrome::NOTIFICATION_KIOSK_APP_LAUNCHED"; 180 break; 181 } 182 default: { 183 NOTREACHED(); 184 } 185 } 186 } 187 188 DISALLOW_COPY_AND_ASSIGN(AutostartWarningCancelScenarioHandler); 189}; 190 191class AutostartWarningConfirmScenarioHandler 192 : public TestBrowserMainExtraParts { 193 public: 194 AutostartWarningConfirmScenarioHandler() : first_pass_(true) { 195 } 196 197 virtual ~AutostartWarningConfirmScenarioHandler() {} 198 199 private: 200 // ChromeBrowserMainExtraParts implementation. 201 virtual void PreEarlyInitialization() OVERRIDE { 202 registrar_.Add(this, chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE, 203 content::NotificationService::AllSources()); 204 registrar_.Add(this, 205 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_COMPLETED, 206 content::NotificationService::AllSources()); 207 registrar_.Add(this, chrome::NOTIFICATION_KIOSK_APP_LAUNCHED, 208 content::NotificationService::AllSources()); 209 } 210 211 // Overridden from content::NotificationObserver: 212 virtual void Observe(int type, 213 const content::NotificationSource& source, 214 const content::NotificationDetails& details) OVERRIDE { 215 switch (type) { 216 case chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE: { 217 LOG(INFO) << "chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE"; 218 if (!first_pass_) 219 break; 220 221 content::WebUI* web_ui = static_cast<chromeos::LoginDisplayHostImpl*>( 222 chromeos::LoginDisplayHostImpl::default_host())-> 223 GetOobeUI()->web_ui(); 224 web_ui->CallJavascriptFunction( 225 "login.AutolaunchScreen.confirmAutoLaunchForTesting", 226 base::FundamentalValue(true)); 227 } 228 case chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_COMPLETED: { 229 LOG(INFO) << "chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_COMPLETED"; 230 first_pass_ = false; 231 break; 232 } 233 case chrome::NOTIFICATION_KIOSK_APP_LAUNCHED: 234 LOG(INFO) << "chrome::NOTIFICATION_KIOSK_APP_LAUNCHED"; 235 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, 236 content::NotificationService::AllSources()); 237 quit_task_.Run(); 238 break; 239 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { 240 LOG(INFO) << "chrome::NOTIFICATION_RENDERER_PROCESS_CLOSED"; 241 quit_task_.Run(); 242 break; 243 } 244 default: { 245 NOTREACHED(); 246 } 247 } 248 } 249 250 bool first_pass_; 251 252 DISALLOW_COPY_AND_ASSIGN(AutostartWarningConfirmScenarioHandler); 253}; 254 255class TestContentBrowserClient : public chrome::ChromeContentBrowserClient { 256 public: 257 enum LaunchEventSequence { 258 KioskAppLaunch, 259 AutostartWarningCanceled, 260 AutostartWarningConfirmed, 261 }; 262 263 explicit TestContentBrowserClient(LaunchEventSequence sequence) 264 : browser_main_extra_parts_(NULL), sequence_(sequence) { 265 } 266 267 virtual ~TestContentBrowserClient() {} 268 269 virtual content::BrowserMainParts* CreateBrowserMainParts( 270 const content::MainFunctionParams& parameters) OVERRIDE { 271 ChromeBrowserMainParts* main_parts = static_cast<ChromeBrowserMainParts*>( 272 ChromeContentBrowserClient::CreateBrowserMainParts(parameters)); 273 274 switch (sequence_) { 275 case KioskAppLaunch: 276 browser_main_extra_parts_ = new KioskAppLaunchScenarioHandler(); 277 break; 278 case AutostartWarningCanceled: 279 browser_main_extra_parts_ = new AutostartWarningCancelScenarioHandler(); 280 break; 281 case AutostartWarningConfirmed: 282 browser_main_extra_parts_ = 283 new AutostartWarningConfirmScenarioHandler(); 284 break; 285 } 286 287 main_parts->AddParts(browser_main_extra_parts_); 288 return main_parts; 289 } 290 291 TestBrowserMainExtraParts* browser_main_extra_parts_; 292 293 private: 294 LaunchEventSequence sequence_; 295 296 DISALLOW_COPY_AND_ASSIGN(TestContentBrowserClient); 297}; 298 299} // namespace 300 301 302class KioskTest : public chromeos::CrosInProcessBrowserTest, 303 // Param defining is multi-profiles enabled. 304 public testing::WithParamInterface<bool> { 305 public: 306 KioskTest() 307 : chromeos::CrosInProcessBrowserTest(), 308 original_content_browser_client_(NULL), 309 test_server_(NULL) { 310 SetExitWhenLastBrowserCloses(false); 311 } 312 313 virtual ~KioskTest() {} 314 315 protected: 316 virtual void InitializeKioskTest() = 0; 317 318 virtual void SetUpOnMainThread() OVERRIDE { 319 test_server_ = new EmbeddedTestServer( 320 content::BrowserThread::GetMessageLoopProxyForThread( 321 content::BrowserThread::IO)); 322 CHECK(test_server_->InitializeAndWaitUntilReady()); 323 test_server_->RegisterRequestHandler( 324 base::Bind(&KioskTest::HandleRequest, base::Unretained(this))); 325 LOG(INFO) << "Set up http server at " << test_server_->base_url(); 326 327 const GURL gaia_url("http://localhost:" + test_server_->base_url().port()); 328 content_browser_client_->browser_main_extra_parts_->set_gaia_url(gaia_url); 329 } 330 331 virtual void CleanUpOnMainThread() OVERRIDE { 332 // Clean up while main thread still runs. 333 // See http://crbug.com/176659. 334 chromeos::KioskAppManager::Get()->CleanUp(); 335 336 LOG(INFO) << "Stopping the http server."; 337 EXPECT_TRUE(test_server_->ShutdownAndWaitUntilComplete()); 338 delete test_server_; // Destructor wants UI thread. 339 } 340 341 scoped_ptr<HttpResponse> HandleRequest(const HttpRequest& request) { 342 GURL url = test_server_->GetURL(request.relative_url); 343 LOG(INFO) << "Http request: " << url.spec(); 344 345 scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse()); 346 if (url.path() == "/ServiceLogin") { 347 http_response->set_code(net::test_server::SUCCESS); 348 http_response->set_content(service_login_response_); 349 http_response->set_content_type("text/html"); 350 } else if (url.path() == "/ServiceLoginAuth") { 351 LOG(INFO) << "Params: " << request.content; 352 static const char kContinueParam[] = "continue="; 353 int continue_arg_begin = request.content.find(kContinueParam) + 354 arraysize(kContinueParam) - 1; 355 int continue_arg_end = request.content.find("&", continue_arg_begin); 356 const std::string continue_url = request.content.substr( 357 continue_arg_begin, continue_arg_end - continue_arg_begin); 358 http_response->set_code(net::test_server::SUCCESS); 359 const std::string redirect_js = 360 "document.location.href = unescape('" + continue_url + "');"; 361 http_response->set_content( 362 "<HTML><HEAD><SCRIPT>\n" + redirect_js + "\n</SCRIPT></HEAD></HTML>"); 363 http_response->set_content_type("text/html"); 364 } else { 365 LOG(ERROR) << "Unsupported url: " << url.path(); 366 } 367 return http_response.PassAs<HttpResponse>(); 368 } 369 370 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 371 if (GetParam()) { 372 command_line->AppendSwitch(::switches::kMultiProfiles); 373 } 374 command_line->AppendSwitch(chromeos::switches::kLoginManager); 375 command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests); 376 command_line->AppendSwitch( 377 chromeos::switches::kDisableChromeCaptivePortalDetector); 378 command_line->AppendSwitch(::switches::kDisableBackgroundNetworking); 379 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user"); 380 381 ASSERT_TRUE(test_server()->Start()); 382 net::HostPortPair host_port = test_server()->host_port_pair(); 383 std::string test_gallery_url = base::StringPrintf( 384 "http://%s:%d/files/chromeos/app_mode/webstore", 385 kWebstoreDomain, host_port.port()); 386 command_line->AppendSwitchASCII( 387 ::switches::kAppsGalleryURL, test_gallery_url); 388 389 std::string test_gallery_download_url = test_gallery_url; 390 test_gallery_download_url.append("/downloads/%s.crx"); 391 command_line->AppendSwitchASCII( 392 ::switches::kAppsGalleryDownloadURL, test_gallery_download_url); 393 } 394 395 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { 396 InitializeKioskTest(); 397 original_content_browser_client_ = content::SetBrowserClientForTesting( 398 content_browser_client_.get()); 399 400 base::FilePath test_data_dir; 401 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); 402 CHECK(file_util::ReadFileToString(test_data_dir.Append(kServiceLogin), 403 &service_login_response_)); 404 405 host_resolver()->AddRule(kWebstoreDomain, "127.0.0.1"); 406 } 407 408 void ReloadKioskApps() { 409 chromeos::KioskAppManager::Get()->AddApp(kTestKioskApp); 410 } 411 412 void ReloadAutolaunchKioskApps() { 413 chromeos::KioskAppManager::Get()->AddApp(kTestKioskApp); 414 chromeos::KioskAppManager::Get()->SetAutoLaunchApp(kTestKioskApp); 415 } 416 417 scoped_ptr<TestContentBrowserClient> content_browser_client_; 418 content::ContentBrowserClient* original_content_browser_client_; 419 std::string service_login_response_; 420 EmbeddedTestServer* test_server_; // cant use scoped_ptr because destructor 421 // needs UI thread. 422 }; 423 424class KioskLaunchTest : public KioskTest { 425 public: 426 KioskLaunchTest() : KioskTest() {} 427 virtual ~KioskLaunchTest() {} 428 429 // KioskTest overrides. 430 virtual void InitializeKioskTest() OVERRIDE { 431 content_browser_client_.reset( 432 new TestContentBrowserClient(TestContentBrowserClient::KioskAppLaunch)); 433 } 434}; 435 436IN_PROC_BROWSER_TEST_P(KioskLaunchTest, InstallAndLaunchApp) { 437 // Start UI, find menu entry for this app and launch it. 438 chromeos::WizardController::SkipPostLoginScreensForTesting(); 439 chromeos::WizardController* wizard_controller = 440 chromeos::WizardController::default_controller(); 441 CHECK(wizard_controller); 442 wizard_controller->SkipToLoginForTesting(); 443 444 ReloadKioskApps(); 445 446 // The first loop exits after we receive NOTIFICATION_KIOSK_APP_LAUNCHED 447 // notification - right at app launch. 448 scoped_refptr<content::MessageLoopRunner> runner = 449 new content::MessageLoopRunner; 450 content_browser_client_->browser_main_extra_parts_->set_quit_task( 451 runner->QuitClosure()); 452 runner->Run(); 453 454 // Check installer status. 455 EXPECT_EQ(chromeos::KioskAppLaunchError::NONE, 456 chromeos::KioskAppLaunchError::Get()); 457 458 // Check if the kiosk webapp is really installed for the default profile. 459 ASSERT_TRUE(ProfileManager::GetDefaultProfile()); 460 const extensions::Extension* app = 461 extensions::ExtensionSystem::Get(ProfileManager::GetDefaultProfile())-> 462 extension_service()->GetInstalledExtension(kTestKioskApp); 463 EXPECT_TRUE(app); 464 465 // The second loop exits when kiosk app terminates and we receive 466 // NOTIFICATION_RENDERER_PROCESS_CLOSED. 467 scoped_refptr<content::MessageLoopRunner> runner2 = 468 new content::MessageLoopRunner; 469 content_browser_client_->browser_main_extra_parts_->set_quit_task( 470 runner2->QuitClosure()); 471 runner2->Run(); 472} 473 474class KioskAutolaunchCancelTest : public KioskTest { 475 public: 476 KioskAutolaunchCancelTest() : KioskTest(), login_display_host_(NULL) {} 477 virtual ~KioskAutolaunchCancelTest() {} 478 479 private: 480 // Overrides from KioskTest. 481 virtual void InitializeKioskTest() OVERRIDE { 482 content_browser_client_.reset(new TestContentBrowserClient( 483 TestContentBrowserClient::AutostartWarningCanceled)); 484 } 485 486 virtual void SetUpOnMainThread() OVERRIDE { 487 login_display_host_ = LoginDisplayHostImpl::default_host(); 488 KioskTest::SetUpOnMainThread(); 489 } 490 491 virtual void CleanUpOnMainThread() OVERRIDE { 492 // LoginDisplayHost owns controllers and all windows. 493 base::MessageLoopForUI::current()->DeleteSoon(FROM_HERE, 494 login_display_host_); 495 KioskTest::CleanUpOnMainThread(); 496 } 497 498 LoginDisplayHost* login_display_host_; 499}; 500 501IN_PROC_BROWSER_TEST_P(KioskAutolaunchCancelTest, AutolaunchWarningCancel) { 502 // Start UI, find menu entry for this app and launch it. 503 chromeos::WizardController::SkipPostLoginScreensForTesting(); 504 chromeos::WizardController* wizard_controller = 505 chromeos::WizardController::default_controller(); 506 CHECK(wizard_controller); 507 ReloadAutolaunchKioskApps(); 508 wizard_controller->SkipToLoginForTesting(); 509 510 EXPECT_FALSE( 511 chromeos::KioskAppManager::Get()->GetAutoLaunchApp().empty()); 512 EXPECT_FALSE( 513 chromeos::KioskAppManager::Get()->IsAutoLaunchEnabled()); 514 515 // The loop exits after we receive 516 // NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_COMPLETED after 517 // NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE notification - right after 518 // auto launch is canceled. 519 scoped_refptr<content::MessageLoopRunner> runner = 520 new content::MessageLoopRunner; 521 content_browser_client_->browser_main_extra_parts_->set_quit_task( 522 runner->QuitClosure()); 523 runner->Run(); 524 525 EXPECT_FALSE( 526 chromeos::KioskAppManager::Get()->IsAutoLaunchEnabled()); 527} 528 529class KioskAutolaunchConfirmTest : public KioskTest { 530 public: 531 KioskAutolaunchConfirmTest() : KioskTest() {} 532 virtual ~KioskAutolaunchConfirmTest() {} 533 534 private: 535 // Overrides from KioskTest. 536 virtual void InitializeKioskTest() OVERRIDE { 537 content_browser_client_.reset(new TestContentBrowserClient( 538 TestContentBrowserClient::AutostartWarningConfirmed)); 539 } 540}; 541 542IN_PROC_BROWSER_TEST_P(KioskAutolaunchConfirmTest, AutolaunchWarningConfirm) { 543 // Start UI, find menu entry for this app and launch it. 544 chromeos::WizardController::SkipPostLoginScreensForTesting(); 545 chromeos::WizardController* wizard_controller = 546 chromeos::WizardController::default_controller(); 547 CHECK(wizard_controller); 548 wizard_controller->SkipToLoginForTesting(); 549 550 ReloadAutolaunchKioskApps(); 551 EXPECT_FALSE( 552 chromeos::KioskAppManager::Get()->GetAutoLaunchApp().empty()); 553 EXPECT_FALSE( 554 chromeos::KioskAppManager::Get()->IsAutoLaunchEnabled()); 555 556 // The loop exits after we receive NOTIFICATION_KIOSK_APP_LAUNCHED 557 // notification - right at app launch. 558 scoped_refptr<content::MessageLoopRunner> runner = 559 new content::MessageLoopRunner; 560 content_browser_client_->browser_main_extra_parts_->set_quit_task( 561 runner->QuitClosure()); 562 runner->Run(); 563 564 EXPECT_FALSE( 565 chromeos::KioskAppManager::Get()->GetAutoLaunchApp().empty()); 566 EXPECT_TRUE( 567 chromeos::KioskAppManager::Get()->IsAutoLaunchEnabled()); 568 569 // Check installer status. 570 EXPECT_EQ(chromeos::KioskAppLaunchError::NONE, 571 chromeos::KioskAppLaunchError::Get()); 572 573 // Check if the kiosk webapp is really installed for the default profile. 574 ASSERT_TRUE(ProfileManager::GetDefaultProfile()); 575 const extensions::Extension* app = 576 extensions::ExtensionSystem::Get(ProfileManager::GetDefaultProfile())-> 577 extension_service()->GetInstalledExtension(kTestKioskApp); 578 EXPECT_TRUE(app); 579 580 // The second loop exits when kiosk app terminates and we receive 581 // NOTIFICATION_RENDERER_PROCESS_CLOSED. 582 scoped_refptr<content::MessageLoopRunner> runner2 = 583 new content::MessageLoopRunner; 584 content_browser_client_->browser_main_extra_parts_->set_quit_task( 585 runner2->QuitClosure()); 586 runner2->Run(); 587} 588 589INSTANTIATE_TEST_CASE_P(KioskLaunchTestInstantiation, 590 KioskLaunchTest, 591 testing::Bool()); 592 593INSTANTIATE_TEST_CASE_P(KioskAutolaunchCancelTestInstantiation, 594 KioskAutolaunchCancelTest, 595 testing::Bool()); 596 597INSTANTIATE_TEST_CASE_P(KioskAutolaunchConfirmTestInstantiation, 598 KioskAutolaunchConfirmTest, 599 testing::Bool()); 600} // namespace chromeos 601