Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "apps/app_window.h" | 5 #include "apps/app_window.h" |
| 6 #include "apps/app_window_registry.h" | 6 #include "apps/app_window_registry.h" |
| 7 #include "apps/ui/native_app_window.h" | 7 #include "apps/ui/native_app_window.h" |
| 8 #include "ash/desktop_background/desktop_background_controller.h" | 8 #include "ash/desktop_background/desktop_background_controller.h" |
| 9 #include "ash/desktop_background/desktop_background_controller_observer.h" | 9 #include "ash/desktop_background/desktop_background_controller_observer.h" |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 public: | 230 public: |
| 231 KioskTest() : fake_cws_(new FakeCWS) { | 231 KioskTest() : fake_cws_(new FakeCWS) { |
| 232 set_exit_when_last_browser_closes(false); | 232 set_exit_when_last_browser_closes(false); |
| 233 } | 233 } |
| 234 | 234 |
| 235 virtual ~KioskTest() {} | 235 virtual ~KioskTest() {} |
| 236 | 236 |
| 237 protected: | 237 protected: |
| 238 virtual void SetUp() OVERRIDE { | 238 virtual void SetUp() OVERRIDE { |
| 239 test_app_id_ = kTestKioskApp; | 239 test_app_id_ = kTestKioskApp; |
| 240 set_test_app_version("1.0.0"); | |
| 241 set_test_crx_file(test_app_id() + ".crx"); | |
| 242 needs_background_networking_ = true; | |
| 240 mock_user_manager_.reset(new MockUserManager); | 243 mock_user_manager_.reset(new MockUserManager); |
| 241 ProfileHelper::SetAlwaysReturnPrimaryUserForTesting(true); | 244 ProfileHelper::SetAlwaysReturnPrimaryUserForTesting(true); |
| 242 AppLaunchController::SkipSplashWaitForTesting(); | 245 AppLaunchController::SkipSplashWaitForTesting(); |
| 243 AppLaunchController::SetNetworkWaitForTesting(kTestNetworkTimeoutSeconds); | 246 AppLaunchController::SetNetworkWaitForTesting(kTestNetworkTimeoutSeconds); |
| 244 | 247 |
| 245 OobeBaseTest::SetUp(); | 248 OobeBaseTest::SetUp(); |
| 246 } | 249 } |
| 247 | 250 |
| 248 virtual void TearDown() OVERRIDE { | 251 virtual void TearDown() OVERRIDE { |
| 249 ProfileHelper::SetAlwaysReturnPrimaryUserForTesting(false); | 252 ProfileHelper::SetAlwaysReturnPrimaryUserForTesting(false); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 268 | 271 |
| 269 void LaunchApp(const std::string& app_id, bool diagnostic_mode) { | 272 void LaunchApp(const std::string& app_id, bool diagnostic_mode) { |
| 270 bool new_kiosk_ui = KioskAppMenuHandler::EnableNewKioskUI(); | 273 bool new_kiosk_ui = KioskAppMenuHandler::EnableNewKioskUI(); |
| 271 GetLoginUI()->CallJavascriptFunction(new_kiosk_ui ? | 274 GetLoginUI()->CallJavascriptFunction(new_kiosk_ui ? |
| 272 kLaunchAppForTestNewAPI : kLaunchAppForTestOldAPI, | 275 kLaunchAppForTestNewAPI : kLaunchAppForTestOldAPI, |
| 273 base::StringValue(app_id), | 276 base::StringValue(app_id), |
| 274 base::FundamentalValue(diagnostic_mode)); | 277 base::FundamentalValue(diagnostic_mode)); |
| 275 } | 278 } |
| 276 | 279 |
| 277 void ReloadKioskApps() { | 280 void ReloadKioskApps() { |
| 281 SetupTestAppUpdateCheck(); | |
| 282 | |
| 278 // Remove then add to ensure NOTIFICATION_KIOSK_APPS_LOADED fires. | 283 // Remove then add to ensure NOTIFICATION_KIOSK_APPS_LOADED fires. |
| 279 KioskAppManager::Get()->RemoveApp(test_app_id_); | 284 KioskAppManager::Get()->RemoveApp(test_app_id_); |
| 280 KioskAppManager::Get()->AddApp(test_app_id_); | 285 KioskAppManager::Get()->AddApp(test_app_id_); |
| 281 } | 286 } |
| 282 | 287 |
| 288 void SetupTestAppUpdateCheck() { | |
| 289 if (!test_app_version().empty()) { | |
| 290 fake_cws_->SetUpdateCrx( | |
| 291 test_app_id(), test_crx_file(), test_app_version()); | |
| 292 } | |
| 293 } | |
| 294 | |
| 283 void ReloadAutolaunchKioskApps() { | 295 void ReloadAutolaunchKioskApps() { |
| 296 SetupTestAppUpdateCheck(); | |
| 297 | |
| 284 KioskAppManager::Get()->AddApp(test_app_id_); | 298 KioskAppManager::Get()->AddApp(test_app_id_); |
| 285 KioskAppManager::Get()->SetAutoLaunchApp(test_app_id_); | 299 KioskAppManager::Get()->SetAutoLaunchApp(test_app_id_); |
| 286 } | 300 } |
| 287 | 301 |
| 288 void PrepareAppLaunch() { | 302 void StartUIForAppLaunch() { |
| 289 EnableConsumerKioskMode(); | 303 EnableConsumerKioskMode(); |
| 290 | 304 |
| 291 // Start UI | 305 // Start UI |
| 292 content::WindowedNotificationObserver login_signal( | 306 content::WindowedNotificationObserver login_signal( |
| 293 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, | 307 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, |
| 294 content::NotificationService::AllSources()); | 308 content::NotificationService::AllSources()); |
| 295 chromeos::WizardController::SkipPostLoginScreensForTesting(); | 309 chromeos::WizardController::SkipPostLoginScreensForTesting(); |
| 296 chromeos::WizardController* wizard_controller = | 310 chromeos::WizardController* wizard_controller = |
| 297 chromeos::WizardController::default_controller(); | 311 chromeos::WizardController::default_controller(); |
| 298 if (wizard_controller) { | 312 if (wizard_controller) { |
| 299 wizard_controller->SkipToLoginForTesting(LoginScreenContext()); | 313 wizard_controller->SkipToLoginForTesting(LoginScreenContext()); |
| 300 login_signal.Wait(); | 314 login_signal.Wait(); |
| 301 } else { | 315 } else { |
| 302 // No wizard and running with an existing profile and it should land | 316 // No wizard and running with an existing profile and it should land |
| 303 // on account picker when new kiosk UI is enabled. Otherwise, just | 317 // on account picker when new kiosk UI is enabled. Otherwise, just |
| 304 // wait for the login signal from Gaia. | 318 // wait for the login signal from Gaia. |
| 305 if (KioskAppMenuHandler::EnableNewKioskUI()) | 319 if (KioskAppMenuHandler::EnableNewKioskUI()) |
| 306 OobeScreenWaiter(OobeDisplay::SCREEN_ACCOUNT_PICKER).Wait(); | 320 OobeScreenWaiter(OobeDisplay::SCREEN_ACCOUNT_PICKER).Wait(); |
| 307 else | 321 else |
| 308 login_signal.Wait(); | 322 login_signal.Wait(); |
| 309 } | 323 } |
| 324 } | |
| 325 | |
| 326 void PrepareAppLaunch() { | |
| 327 // Start UI | |
| 328 StartUIForAppLaunch(); | |
| 310 | 329 |
| 311 // Wait for the Kiosk App configuration to reload. | 330 // Wait for the Kiosk App configuration to reload. |
| 312 content::WindowedNotificationObserver apps_loaded_signal( | 331 content::WindowedNotificationObserver apps_loaded_signal( |
| 313 chrome::NOTIFICATION_KIOSK_APPS_LOADED, | 332 chrome::NOTIFICATION_KIOSK_APPS_LOADED, |
| 314 content::NotificationService::AllSources()); | 333 content::NotificationService::AllSources()); |
| 315 ReloadKioskApps(); | 334 ReloadKioskApps(); |
| 316 apps_loaded_signal.Wait(); | 335 apps_loaded_signal.Wait(); |
| 317 } | 336 } |
| 318 | 337 |
| 319 void StartAppLaunchFromLoginScreen(const base::Closure& network_setup_cb) { | 338 void StartAppLaunchFromLoginScreen(const base::Closure& network_setup_cb) { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 424 KioskAppManager::Get()->GetConsumerKioskAutoLaunchStatus( | 443 KioskAppManager::Get()->GetConsumerKioskAutoLaunchStatus( |
| 425 base::Bind(&ConsumerKioskAutoLaunchStatusCheck, | 444 base::Bind(&ConsumerKioskAutoLaunchStatusCheck, |
| 426 &status, | 445 &status, |
| 427 runner->QuitClosure())); | 446 runner->QuitClosure())); |
| 428 runner->Run(); | 447 runner->Run(); |
| 429 CHECK_NE(status, | 448 CHECK_NE(status, |
| 430 static_cast<KioskAppManager::ConsumerKioskAutoLaunchStatus>(-1)); | 449 static_cast<KioskAppManager::ConsumerKioskAutoLaunchStatus>(-1)); |
| 431 return status; | 450 return status; |
| 432 } | 451 } |
| 433 | 452 |
| 434 // Copies the app profile from |relative_app_profile_dir| from test directory | |
| 435 // to the app profile directory (assuming "user") under testing profile. This | |
| 436 // is for that needs to have a kiosk app already installed from a previous | |
| 437 // run. Note this must be called before app profile is loaded. | |
| 438 void SetupAppProfile(const std::string& relative_app_profile_dir) { | |
| 439 base::FilePath app_profile_dir; | |
| 440 KioskAppManager::App app_data; | |
| 441 CHECK(KioskAppManager::Get()->GetApp(test_app_id(), &app_data)); | |
| 442 std::string app_user_id_hash = | |
| 443 CryptohomeClient::GetStubSanitizedUsername(app_data.user_id); | |
| 444 app_profile_dir = | |
| 445 ProfileHelper::GetProfilePathByUserIdHash(app_user_id_hash); | |
| 446 ASSERT_TRUE(base::CreateDirectory(app_profile_dir)); | |
| 447 | |
| 448 base::FilePath test_data_dir; | |
| 449 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)); | |
| 450 test_data_dir = test_data_dir.AppendASCII(relative_app_profile_dir); | |
| 451 ASSERT_TRUE( | |
| 452 base::CopyFile(test_data_dir.Append(chrome::kPreferencesFilename), | |
| 453 app_profile_dir.Append(chrome::kPreferencesFilename))); | |
| 454 ASSERT_TRUE( | |
| 455 base::CopyDirectory(test_data_dir.AppendASCII("Extensions"), | |
| 456 app_profile_dir, | |
| 457 true)); | |
| 458 } | |
| 459 | |
| 460 void RunAppLaunchNetworkDownTest() { | 453 void RunAppLaunchNetworkDownTest() { |
| 461 mock_user_manager()->SetActiveUser(kTestOwnerEmail); | 454 mock_user_manager()->SetActiveUser(kTestOwnerEmail); |
| 462 AppLaunchSigninScreen::SetUserManagerForTesting(mock_user_manager()); | 455 AppLaunchSigninScreen::SetUserManagerForTesting(mock_user_manager()); |
| 463 | 456 |
| 464 // Mock network could be configured with owner's password. | 457 // Mock network could be configured with owner's password. |
| 465 ScopedCanConfigureNetwork can_configure_network(true, true); | 458 ScopedCanConfigureNetwork can_configure_network(true, true); |
| 466 | 459 |
| 467 // Start app launch and wait for network connectivity timeout. | 460 // Start app launch and wait for network connectivity timeout. |
| 468 StartAppLaunchFromLoginScreen(SimulateNetworkOfflineClosure()); | 461 StartAppLaunchFromLoginScreen(SimulateNetworkOfflineClosure()); |
| 469 OobeScreenWaiter splash_waiter(OobeDisplay::SCREEN_APP_LAUNCH_SPLASH); | 462 OobeScreenWaiter splash_waiter(OobeDisplay::SCREEN_APP_LAUNCH_SPLASH); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 502 return chromeos::LoginDisplayHostImpl::default_host() | 495 return chromeos::LoginDisplayHostImpl::default_host() |
| 503 ->GetAppLaunchController(); | 496 ->GetAppLaunchController(); |
| 504 } | 497 } |
| 505 | 498 |
| 506 MockUserManager* mock_user_manager() { return mock_user_manager_.get(); } | 499 MockUserManager* mock_user_manager() { return mock_user_manager_.get(); } |
| 507 | 500 |
| 508 void set_test_app_id(const std::string& test_app_id) { | 501 void set_test_app_id(const std::string& test_app_id) { |
| 509 test_app_id_ = test_app_id; | 502 test_app_id_ = test_app_id; |
| 510 } | 503 } |
| 511 const std::string& test_app_id() const { return test_app_id_; } | 504 const std::string& test_app_id() const { return test_app_id_; } |
| 505 void set_test_app_version(const std::string& version) { | |
| 506 test_app_version_ = version; | |
| 507 } | |
| 508 const std::string& test_app_version() const { return test_app_version_; } | |
| 509 void set_test_crx_file(const std::string& filename) { | |
| 510 test_crx_file_ = filename; | |
| 511 } | |
| 512 const std::string& test_crx_file() const { return test_crx_file_; } | |
| 512 FakeCWS* fake_cws() { return fake_cws_.get(); } | 513 FakeCWS* fake_cws() { return fake_cws_.get(); } |
| 513 | 514 |
| 514 private: | 515 private: |
| 515 std::string test_app_id_; | 516 std::string test_app_id_; |
| 517 std::string test_app_version_; | |
| 518 std::string test_crx_file_; | |
| 516 scoped_ptr<FakeCWS> fake_cws_; | 519 scoped_ptr<FakeCWS> fake_cws_; |
| 517 scoped_ptr<MockUserManager> mock_user_manager_; | 520 scoped_ptr<MockUserManager> mock_user_manager_; |
| 518 | 521 |
| 519 DISALLOW_COPY_AND_ASSIGN(KioskTest); | 522 DISALLOW_COPY_AND_ASSIGN(KioskTest); |
| 520 }; | 523 }; |
| 521 | 524 |
| 522 IN_PROC_BROWSER_TEST_F(KioskTest, InstallAndLaunchApp) { | 525 IN_PROC_BROWSER_TEST_F(KioskTest, InstallAndLaunchApp) { |
| 523 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure()); | 526 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure()); |
| 524 WaitForAppLaunchSuccess(); | 527 WaitForAppLaunchSuccess(); |
| 525 } | 528 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 578 "})();")); | 581 "})();")); |
| 579 | 582 |
| 580 WaitForAppLaunchSuccess(); | 583 WaitForAppLaunchSuccess(); |
| 581 } | 584 } |
| 582 | 585 |
| 583 IN_PROC_BROWSER_TEST_F(KioskTest, LaunchAppNetworkDownConfigureNotAllowed) { | 586 IN_PROC_BROWSER_TEST_F(KioskTest, LaunchAppNetworkDownConfigureNotAllowed) { |
| 584 // Mock network could not be configured. | 587 // Mock network could not be configured. |
| 585 ScopedCanConfigureNetwork can_configure_network(false, true); | 588 ScopedCanConfigureNetwork can_configure_network(false, true); |
| 586 | 589 |
| 587 // Start app launch and wait for network connectivity timeout. | 590 // Start app launch and wait for network connectivity timeout. |
| 591 set_test_app_version("1.0.0"); | |
| 592 set_test_crx_file(test_app_id() + ".crx"); | |
|
xiyuan
2014/07/15 02:32:51
Are these two lines necessary?
jennyz
2014/07/15 16:36:41
woops, removed.
| |
| 588 StartAppLaunchFromLoginScreen(SimulateNetworkOfflineClosure()); | 593 StartAppLaunchFromLoginScreen(SimulateNetworkOfflineClosure()); |
| 589 OobeScreenWaiter splash_waiter(OobeDisplay::SCREEN_APP_LAUNCH_SPLASH); | 594 OobeScreenWaiter splash_waiter(OobeDisplay::SCREEN_APP_LAUNCH_SPLASH); |
| 590 splash_waiter.Wait(); | 595 splash_waiter.Wait(); |
| 591 WaitForAppLaunchNetworkTimeout(); | 596 WaitForAppLaunchNetworkTimeout(); |
| 592 | 597 |
| 593 // Configure network link should not be visible. | 598 // Configure network link should not be visible. |
| 594 JsExpect("$('splash-config-network').hidden == true"); | 599 JsExpect("$('splash-config-network').hidden == true"); |
| 595 | 600 |
| 596 // Network becomes online and app launch is resumed. | 601 // Network becomes online and app launch is resumed. |
| 597 SimulateNetworkOnline(); | 602 SimulateNetworkOnline(); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 612 // Network error should show up automatically since this test does not | 617 // Network error should show up automatically since this test does not |
| 613 // require owner auth to configure network. | 618 // require owner auth to configure network. |
| 614 OobeScreenWaiter(OobeDisplay::SCREEN_ERROR_MESSAGE).Wait(); | 619 OobeScreenWaiter(OobeDisplay::SCREEN_ERROR_MESSAGE).Wait(); |
| 615 | 620 |
| 616 ASSERT_TRUE(GetAppLaunchController()->showing_network_dialog()); | 621 ASSERT_TRUE(GetAppLaunchController()->showing_network_dialog()); |
| 617 SimulateNetworkOnline(); | 622 SimulateNetworkOnline(); |
| 618 WaitForAppLaunchSuccess(); | 623 WaitForAppLaunchSuccess(); |
| 619 } | 624 } |
| 620 | 625 |
| 621 IN_PROC_BROWSER_TEST_F(KioskTest, LaunchAppUserCancel) { | 626 IN_PROC_BROWSER_TEST_F(KioskTest, LaunchAppUserCancel) { |
| 627 // Make fake_cws_ return empty update response. | |
| 628 set_test_app_version(""); | |
| 622 StartAppLaunchFromLoginScreen(SimulateNetworkOfflineClosure()); | 629 StartAppLaunchFromLoginScreen(SimulateNetworkOfflineClosure()); |
| 623 OobeScreenWaiter splash_waiter(OobeDisplay::SCREEN_APP_LAUNCH_SPLASH); | 630 OobeScreenWaiter splash_waiter(OobeDisplay::SCREEN_APP_LAUNCH_SPLASH); |
| 624 splash_waiter.Wait(); | 631 splash_waiter.Wait(); |
| 625 | 632 |
| 626 CrosSettings::Get()->SetBoolean( | 633 CrosSettings::Get()->SetBoolean( |
| 627 kAccountsPrefDeviceLocalAccountAutoLoginBailoutEnabled, true); | 634 kAccountsPrefDeviceLocalAccountAutoLoginBailoutEnabled, true); |
| 628 content::WindowedNotificationObserver signal( | 635 content::WindowedNotificationObserver signal( |
| 629 chrome::NOTIFICATION_APP_TERMINATING, | 636 chrome::NOTIFICATION_APP_TERMINATING, |
| 630 content::NotificationService::AllSources()); | 637 content::NotificationService::AllSources()); |
| 631 GetLoginUI()->CallJavascriptFunction("cr.ui.Oobe.handleAccelerator", | 638 GetLoginUI()->CallJavascriptFunction("cr.ui.Oobe.handleAccelerator", |
| 632 base::StringValue("app_launch_bailout")); | 639 base::StringValue("app_launch_bailout")); |
| 633 signal.Wait(); | 640 signal.Wait(); |
| 634 EXPECT_EQ(chromeos::KioskAppLaunchError::USER_CANCEL, | 641 EXPECT_EQ(chromeos::KioskAppLaunchError::USER_CANCEL, |
| 635 chromeos::KioskAppLaunchError::Get()); | 642 chromeos::KioskAppLaunchError::Get()); |
| 636 } | 643 } |
| 637 | 644 |
| 638 IN_PROC_BROWSER_TEST_F(KioskTest, LaunchInDiagnosticMode) { | 645 IN_PROC_BROWSER_TEST_F(KioskTest, LaunchInDiagnosticMode) { |
| 646 set_test_app_version("1.0.0"); | |
| 647 set_test_crx_file(test_app_id() + ".crx"); | |
|
xiyuan
2014/07/15 02:32:51
Are these two lines necessary?
jennyz
2014/07/15 16:36:41
Done.
| |
| 639 PrepareAppLaunch(); | 648 PrepareAppLaunch(); |
| 640 SimulateNetworkOnline(); | 649 SimulateNetworkOnline(); |
| 641 | 650 |
| 642 LaunchApp(kTestKioskApp, true); | 651 LaunchApp(kTestKioskApp, true); |
| 643 | 652 |
| 644 content::WebContents* login_contents = GetLoginUI()->GetWebContents(); | 653 content::WebContents* login_contents = GetLoginUI()->GetWebContents(); |
| 645 | 654 |
| 646 bool new_kiosk_ui = KioskAppMenuHandler::EnableNewKioskUI(); | 655 bool new_kiosk_ui = KioskAppMenuHandler::EnableNewKioskUI(); |
| 647 JsConditionWaiter(login_contents, new_kiosk_ui ? | 656 JsConditionWaiter(login_contents, new_kiosk_ui ? |
| 648 kCheckDiagnosticModeNewAPI : kCheckDiagnosticModeOldAPI).Wait(); | 657 kCheckDiagnosticModeNewAPI : kCheckDiagnosticModeOldAPI).Wait(); |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 875 chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_VISIBLE, | 884 chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_VISIBLE, |
| 876 content::NotificationService::AllSources()).Wait(); | 885 content::NotificationService::AllSources()).Wait(); |
| 877 } | 886 } |
| 878 | 887 |
| 879 class KioskUpdateTest : public KioskTest { | 888 class KioskUpdateTest : public KioskTest { |
| 880 public: | 889 public: |
| 881 KioskUpdateTest() {} | 890 KioskUpdateTest() {} |
| 882 virtual ~KioskUpdateTest() {} | 891 virtual ~KioskUpdateTest() {} |
| 883 | 892 |
| 884 protected: | 893 protected: |
| 885 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | |
| 886 // Needs background networking so that ExtensionDownloader works. | |
| 887 needs_background_networking_ = true; | |
| 888 KioskTest::SetUpCommandLine(command_line); | |
| 889 } | |
| 890 | |
| 891 virtual void SetUpOnMainThread() OVERRIDE { | 894 virtual void SetUpOnMainThread() OVERRIDE { |
| 892 KioskTest::SetUpOnMainThread(); | 895 KioskTest::SetUpOnMainThread(); |
| 893 } | 896 } |
| 894 | 897 |
| 898 void PreCacheApp(const std::string& app_id, | |
| 899 const std::string& version, | |
| 900 const std::string& crx_file) { | |
| 901 set_test_app_id(app_id); | |
| 902 set_test_app_version(version); | |
| 903 set_test_crx_file(crx_file); | |
| 904 | |
| 905 KioskAppManager* manager = KioskAppManager::Get(); | |
| 906 AppDataLoadWaiter waiter(manager, app_id, version); | |
| 907 ReloadKioskApps(); | |
| 908 waiter.Wait(); | |
| 909 EXPECT_TRUE(waiter.loaded()); | |
| 910 std::string cached_version; | |
| 911 base::FilePath file_path; | |
| 912 EXPECT_TRUE(manager->GetCachedCrx(app_id, &file_path, &cached_version)); | |
| 913 EXPECT_EQ(version, cached_version); | |
| 914 } | |
| 915 | |
| 916 void UpdateExternalCache(const std::string& version, | |
| 917 const std::string& crx_file) { | |
| 918 set_test_app_version(version); | |
| 919 set_test_crx_file(crx_file); | |
| 920 SetupTestAppUpdateCheck(); | |
| 921 | |
| 922 KioskAppManager* manager = KioskAppManager::Get(); | |
| 923 AppDataLoadWaiter waiter(manager, test_app_id(), version); | |
| 924 KioskAppManager::Get()->UpdateExternalCache(); | |
| 925 waiter.Wait(); | |
| 926 EXPECT_TRUE(waiter.loaded()); | |
| 927 std::string cached_version; | |
| 928 base::FilePath file_path; | |
| 929 EXPECT_TRUE( | |
| 930 manager->GetCachedCrx(test_app_id(), &file_path, &cached_version)); | |
| 931 EXPECT_EQ(version, cached_version); | |
| 932 } | |
| 933 | |
| 934 void PreCacheAndLaunchApp(const std::string& app_id, | |
| 935 const std::string& version, | |
| 936 const std::string& crx_file) { | |
| 937 set_test_app_id(app_id); | |
| 938 set_test_app_version(version); | |
| 939 set_test_crx_file(crx_file); | |
| 940 PrepareAppLaunch(); | |
| 941 SimulateNetworkOnline(); | |
| 942 LaunchApp(test_app_id(), false); | |
| 943 WaitForAppLaunchSuccess(); | |
| 944 EXPECT_EQ(version, GetInstalledAppVersion().GetString()); | |
| 945 } | |
| 946 | |
| 895 private: | 947 private: |
| 948 class AppDataLoadWaiter : public KioskAppManagerObserver { | |
| 949 public: | |
| 950 AppDataLoadWaiter(KioskAppManager* manager, | |
| 951 const std::string& app_id, | |
| 952 const std::string& version) | |
| 953 : runner_(NULL), | |
| 954 manager_(manager), | |
| 955 loaded_(false), | |
| 956 quit_(false), | |
| 957 app_id_(app_id), | |
| 958 version_(version) { | |
| 959 manager_->AddObserver(this); | |
| 960 } | |
| 961 | |
| 962 virtual ~AppDataLoadWaiter() { manager_->RemoveObserver(this); } | |
| 963 | |
| 964 void Wait() { | |
| 965 if (quit_) | |
| 966 return; | |
| 967 runner_ = new content::MessageLoopRunner; | |
| 968 runner_->Run(); | |
| 969 } | |
| 970 | |
| 971 bool loaded() const { return loaded_; } | |
| 972 | |
| 973 private: | |
| 974 // KioskAppManagerObserver overrides: | |
| 975 virtual void OnKioskExtensionLoadedInCache( | |
| 976 const std::string& app_id) OVERRIDE { | |
| 977 std::string cached_version; | |
| 978 base::FilePath file_path; | |
| 979 if (!manager_->GetCachedCrx(app_id_, &file_path, &cached_version)) | |
| 980 return; | |
| 981 if (version_ != cached_version) | |
| 982 return; | |
| 983 loaded_ = true; | |
| 984 quit_ = true; | |
| 985 if (runner_) | |
| 986 runner_->Quit(); | |
| 987 } | |
| 988 | |
| 989 virtual void OnKioskExtensionDownloadFailed( | |
| 990 const std::string& app_id) OVERRIDE { | |
| 991 loaded_ = false; | |
| 992 quit_ = true; | |
| 993 if (runner_) | |
| 994 runner_->Quit(); | |
| 995 } | |
| 996 | |
| 997 scoped_refptr<content::MessageLoopRunner> runner_; | |
| 998 KioskAppManager* manager_; | |
| 999 bool loaded_; | |
| 1000 bool quit_; | |
| 1001 std::string app_id_; | |
| 1002 std::string version_; | |
| 1003 | |
| 1004 DISALLOW_COPY_AND_ASSIGN(AppDataLoadWaiter); | |
| 1005 }; | |
| 896 | 1006 |
| 897 DISALLOW_COPY_AND_ASSIGN(KioskUpdateTest); | 1007 DISALLOW_COPY_AND_ASSIGN(KioskUpdateTest); |
| 898 }; | 1008 }; |
| 899 | 1009 |
| 1010 IN_PROC_BROWSER_TEST_F(KioskUpdateTest, PRE_LaunchOfflineEnabledAppNoNetwork) { | |
| 1011 PreCacheAndLaunchApp(kTestOfflineEnabledKioskApp, | |
| 1012 "1.0.0", | |
| 1013 std::string(kTestOfflineEnabledKioskApp) + "_v1.crx"); | |
| 1014 } | |
| 1015 | |
| 900 IN_PROC_BROWSER_TEST_F(KioskUpdateTest, LaunchOfflineEnabledAppNoNetwork) { | 1016 IN_PROC_BROWSER_TEST_F(KioskUpdateTest, LaunchOfflineEnabledAppNoNetwork) { |
| 901 set_test_app_id(kTestOfflineEnabledKioskApp); | 1017 set_test_app_id(kTestOfflineEnabledKioskApp); |
| 902 | 1018 StartUIForAppLaunch(); |
| 903 PrepareAppLaunch(); | |
| 904 SimulateNetworkOffline(); | 1019 SimulateNetworkOffline(); |
| 905 SetupAppProfile("chromeos/app_mode/offline_enabled_app_profile"); | 1020 LaunchApp(test_app_id(), false); |
| 906 | 1021 WaitForAppLaunchSuccess(); |
| 907 LaunchApp(test_app_id(), false); | 1022 |
| 908 WaitForAppLaunchSuccess(); | 1023 EXPECT_EQ("1.0.0", GetInstalledAppVersion().GetString()); |
| 1024 } | |
| 1025 | |
| 1026 IN_PROC_BROWSER_TEST_F(KioskUpdateTest, | |
| 1027 PRE_LaunchCachedOfflineEnabledAppNoNetwork) { | |
| 1028 PreCacheApp(kTestOfflineEnabledKioskApp, | |
| 1029 "1.0.0", | |
| 1030 std::string(kTestOfflineEnabledKioskApp) + "_v1.crx"); | |
| 1031 } | |
| 1032 | |
| 1033 IN_PROC_BROWSER_TEST_F(KioskUpdateTest, | |
| 1034 LaunchCachedOfflineEnabledAppNoNetwork) { | |
| 1035 set_test_app_id(kTestOfflineEnabledKioskApp); | |
| 1036 EXPECT_TRUE( | |
| 1037 KioskAppManager::Get()->HasCachedCrx(kTestOfflineEnabledKioskApp)); | |
| 1038 StartUIForAppLaunch(); | |
| 1039 SimulateNetworkOffline(); | |
| 1040 LaunchApp(test_app_id(), false); | |
| 1041 WaitForAppLaunchSuccess(); | |
| 1042 | |
| 1043 EXPECT_EQ("1.0.0", GetInstalledAppVersion().GetString()); | |
| 1044 } | |
| 1045 | |
| 1046 // Network offline, app v1.0 has run before, has cached v2.0 crx and v2.0 should | |
| 1047 // be installed and launched during next launch. | |
| 1048 IN_PROC_BROWSER_TEST_F(KioskUpdateTest, | |
| 1049 PRE_LaunchCachedNewVersionOfflineEnabledAppNoNetwork) { | |
| 1050 // Install and launch v1 app. | |
| 1051 PreCacheAndLaunchApp(kTestOfflineEnabledKioskApp, | |
| 1052 "1.0.0", | |
| 1053 std::string(kTestOfflineEnabledKioskApp) + "_v1.crx"); | |
| 1054 // Update cache for v2 app. | |
| 1055 UpdateExternalCache("2.0.0", | |
| 1056 std::string(kTestOfflineEnabledKioskApp) + ".crx"); | |
| 1057 // The installed app is still in v1. | |
| 1058 EXPECT_EQ("1.0.0", GetInstalledAppVersion().GetString()); | |
| 1059 } | |
| 1060 | |
| 1061 IN_PROC_BROWSER_TEST_F(KioskUpdateTest, | |
| 1062 LaunchCachedNewVersionOfflineEnabledAppNoNetwork) { | |
| 1063 set_test_app_id(kTestOfflineEnabledKioskApp); | |
| 1064 EXPECT_TRUE(KioskAppManager::Get()->HasCachedCrx(test_app_id())); | |
| 1065 | |
| 1066 StartUIForAppLaunch(); | |
| 1067 SimulateNetworkOffline(); | |
| 1068 LaunchApp(test_app_id(), false); | |
| 1069 WaitForAppLaunchSuccess(); | |
| 1070 | |
| 1071 // v2 app should have been installed. | |
| 1072 EXPECT_EQ("2.0.0", GetInstalledAppVersion().GetString()); | |
| 1073 } | |
| 1074 | |
| 1075 IN_PROC_BROWSER_TEST_F(KioskUpdateTest, PRE_LaunchOfflineEnabledAppNoUpdate) { | |
| 1076 PreCacheAndLaunchApp(kTestOfflineEnabledKioskApp, | |
| 1077 "1.0.0", | |
| 1078 std::string(kTestOfflineEnabledKioskApp) + "_v1.crx"); | |
| 909 } | 1079 } |
| 910 | 1080 |
| 911 IN_PROC_BROWSER_TEST_F(KioskUpdateTest, LaunchOfflineEnabledAppNoUpdate) { | 1081 IN_PROC_BROWSER_TEST_F(KioskUpdateTest, LaunchOfflineEnabledAppNoUpdate) { |
| 912 set_test_app_id(kTestOfflineEnabledKioskApp); | 1082 set_test_app_id(kTestOfflineEnabledKioskApp); |
| 913 | |
| 914 fake_cws()->SetNoUpdate(test_app_id()); | 1083 fake_cws()->SetNoUpdate(test_app_id()); |
| 915 | 1084 |
| 916 PrepareAppLaunch(); | 1085 StartUIForAppLaunch(); |
| 917 SimulateNetworkOnline(); | 1086 SimulateNetworkOnline(); |
| 918 SetupAppProfile("chromeos/app_mode/offline_enabled_app_profile"); | 1087 LaunchApp(test_app_id(), false); |
|
xiyuan
2014/07/15 02:32:51
We can delete chrome/test/data/chromeos/app_mode/o
jennyz
2014/07/15 18:34:24
Done.
| |
| 919 | 1088 WaitForAppLaunchSuccess(); |
| 920 LaunchApp(test_app_id(), false); | 1089 |
| 921 WaitForAppLaunchSuccess(); | 1090 EXPECT_EQ("1.0.0", GetInstalledAppVersion().GetString()); |
| 922 | 1091 } |
| 923 EXPECT_EQ("1.0.0", GetInstalledAppVersion().GetString()); | 1092 |
| 1093 IN_PROC_BROWSER_TEST_F(KioskUpdateTest, PRE_LaunchOfflineEnabledAppHasUpdate) { | |
| 1094 PreCacheAndLaunchApp(kTestOfflineEnabledKioskApp, | |
| 1095 "1.0.0", | |
| 1096 std::string(kTestOfflineEnabledKioskApp) + "_v1.crx"); | |
| 924 } | 1097 } |
| 925 | 1098 |
| 926 IN_PROC_BROWSER_TEST_F(KioskUpdateTest, LaunchOfflineEnabledAppHasUpdate) { | 1099 IN_PROC_BROWSER_TEST_F(KioskUpdateTest, LaunchOfflineEnabledAppHasUpdate) { |
| 927 set_test_app_id(kTestOfflineEnabledKioskApp); | 1100 set_test_app_id(kTestOfflineEnabledKioskApp); |
| 928 | |
| 929 fake_cws()->SetUpdateCrx( | 1101 fake_cws()->SetUpdateCrx( |
| 930 test_app_id(), "ajoggoflpgplnnjkjamcmbepjdjdnpdp.crx", "2.0.0"); | 1102 test_app_id(), "ajoggoflpgplnnjkjamcmbepjdjdnpdp.crx", "2.0.0"); |
| 931 | 1103 |
| 932 PrepareAppLaunch(); | 1104 StartUIForAppLaunch(); |
| 933 SimulateNetworkOnline(); | 1105 SimulateNetworkOnline(); |
| 934 SetupAppProfile("chromeos/app_mode/offline_enabled_app_profile"); | |
| 935 | |
| 936 LaunchApp(test_app_id(), false); | 1106 LaunchApp(test_app_id(), false); |
| 937 WaitForAppLaunchSuccess(); | 1107 WaitForAppLaunchSuccess(); |
| 938 | 1108 |
| 939 EXPECT_EQ("2.0.0", GetInstalledAppVersion().GetString()); | 1109 EXPECT_EQ("2.0.0", GetInstalledAppVersion().GetString()); |
| 940 } | 1110 } |
| 941 | 1111 |
| 1112 IN_PROC_BROWSER_TEST_F(KioskUpdateTest, PRE_PermissionChange) { | |
| 1113 PreCacheAndLaunchApp(kTestOfflineEnabledKioskApp, | |
| 1114 "2.0.0", | |
| 1115 std::string(kTestOfflineEnabledKioskApp) + ".crx"); | |
| 1116 } | |
| 1117 | |
| 942 IN_PROC_BROWSER_TEST_F(KioskUpdateTest, PermissionChange) { | 1118 IN_PROC_BROWSER_TEST_F(KioskUpdateTest, PermissionChange) { |
| 943 set_test_app_id(kTestOfflineEnabledKioskApp); | 1119 set_test_app_id(kTestOfflineEnabledKioskApp); |
| 944 | 1120 set_test_app_version("2.0.0"); |
| 945 fake_cws()->SetUpdateCrx( | 1121 set_test_crx_file(test_app_id() + "_v2_permission_change.crx"); |
| 946 test_app_id(), | 1122 |
| 947 "ajoggoflpgplnnjkjamcmbepjdjdnpdp_v2_permission_change.crx", | 1123 StartUIForAppLaunch(); |
| 948 "2.0.0"); | |
| 949 | |
| 950 PrepareAppLaunch(); | |
| 951 SimulateNetworkOnline(); | 1124 SimulateNetworkOnline(); |
| 952 SetupAppProfile("chromeos/app_mode/offline_enabled_app_profile"); | 1125 LaunchApp(test_app_id(), false); |
| 953 | 1126 WaitForAppLaunchSuccess(); |
| 954 LaunchApp(test_app_id(), false); | 1127 |
| 955 WaitForAppLaunchSuccess(); | |
| 956 | |
| 957 EXPECT_EQ("2.0.0", GetInstalledAppVersion().GetString()); | 1128 EXPECT_EQ("2.0.0", GetInstalledAppVersion().GetString()); |
| 958 } | 1129 } |
| 959 | 1130 |
| 960 IN_PROC_BROWSER_TEST_F(KioskUpdateTest, PRE_PreserveLocalData) { | 1131 IN_PROC_BROWSER_TEST_F(KioskUpdateTest, PRE_PreserveLocalData) { |
| 961 // Installs v1 app and writes some local data. | 1132 // Installs v1 app and writes some local data. |
| 962 set_test_app_id(kTestLocalFsKioskApp); | 1133 set_test_app_id(kTestLocalFsKioskApp); |
| 1134 set_test_app_version("1.0.0"); | |
| 1135 set_test_crx_file(test_app_id() + ".crx"); | |
| 963 | 1136 |
| 964 ResultCatcher catcher; | 1137 ResultCatcher catcher; |
| 965 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure()); | 1138 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure()); |
| 966 WaitForAppLaunchSuccess(); | 1139 WaitForAppLaunchSuccess(); |
| 967 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 1140 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 968 } | 1141 } |
| 969 | 1142 |
| 970 IN_PROC_BROWSER_TEST_F(KioskUpdateTest, PreserveLocalData) { | 1143 IN_PROC_BROWSER_TEST_F(KioskUpdateTest, PreserveLocalData) { |
| 971 // Update existing v1 app installed in PRE_PreserveLocalData to v2 | 1144 // Update existing v1 app installed in PRE_PreserveLocalData to v2 |
| 972 // that reads and verifies the local data. | 1145 // that reads and verifies the local data. |
| 973 set_test_app_id(kTestLocalFsKioskApp); | 1146 set_test_app_id(kTestLocalFsKioskApp); |
| 974 | 1147 set_test_app_version("2.0.0"); |
| 975 fake_cws()->SetUpdateCrx( | 1148 set_test_crx_file(test_app_id() + "_v2_read_and_verify_data.crx"); |
| 976 test_app_id(), | |
| 977 "bmbpicmpniaclbbpdkfglgipkkebnbjf_v2_read_and_verify_data.crx", | |
| 978 "2.0.0"); | |
| 979 | |
| 980 ResultCatcher catcher; | 1149 ResultCatcher catcher; |
| 981 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure()); | 1150 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure()); |
| 982 WaitForAppLaunchSuccess(); | 1151 WaitForAppLaunchSuccess(); |
| 983 | 1152 |
| 984 EXPECT_EQ("2.0.0", GetInstalledAppVersion().GetString()); | 1153 EXPECT_EQ("2.0.0", GetInstalledAppVersion().GetString()); |
| 985 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 1154 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 986 } | 1155 } |
| 987 | 1156 |
| 988 class KioskEnterpriseTest : public KioskTest { | 1157 class KioskEnterpriseTest : public KioskTest { |
| 989 protected: | 1158 protected: |
| 990 KioskEnterpriseTest() {} | 1159 KioskEnterpriseTest() {} |
| 991 | 1160 |
| 992 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 1161 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 993 device_policy_test_helper_.MarkAsEnterpriseOwned(); | 1162 device_policy_test_helper_.MarkAsEnterpriseOwned(); |
| 994 device_policy_test_helper_.InstallOwnerKey(); | 1163 device_policy_test_helper_.InstallOwnerKey(); |
| 995 | 1164 |
| 996 KioskTest::SetUpInProcessBrowserTestFixture(); | 1165 KioskTest::SetUpInProcessBrowserTestFixture(); |
| 997 } | 1166 } |
| 998 | 1167 |
| 999 virtual void SetUpOnMainThread() OVERRIDE { | 1168 virtual void SetUpOnMainThread() OVERRIDE { |
| 1169 set_test_app_id(kTestEnterpriseKioskApp); | |
| 1170 set_test_app_version("1.0.0"); | |
| 1171 set_test_crx_file(test_app_id() + ".crx"); | |
| 1172 SetupTestAppUpdateCheck(); | |
| 1173 | |
| 1000 KioskTest::SetUpOnMainThread(); | 1174 KioskTest::SetUpOnMainThread(); |
| 1001 // Configure kTestEnterpriseKioskApp in device policy. | 1175 // Configure kTestEnterpriseKioskApp in device policy. |
| 1002 em::DeviceLocalAccountsProto* accounts = | 1176 em::DeviceLocalAccountsProto* accounts = |
| 1003 device_policy_test_helper_.device_policy()->payload() | 1177 device_policy_test_helper_.device_policy()->payload() |
| 1004 .mutable_device_local_accounts(); | 1178 .mutable_device_local_accounts(); |
| 1005 em::DeviceLocalAccountInfoProto* account = accounts->add_account(); | 1179 em::DeviceLocalAccountInfoProto* account = accounts->add_account(); |
| 1006 account->set_account_id(kTestEnterpriseAccountId); | 1180 account->set_account_id(kTestEnterpriseAccountId); |
| 1007 account->set_type( | 1181 account->set_type( |
| 1008 em::DeviceLocalAccountInfoProto::ACCOUNT_TYPE_KIOSK_APP); | 1182 em::DeviceLocalAccountInfoProto::ACCOUNT_TYPE_KIOSK_APP); |
| 1009 account->mutable_kiosk_app()->set_app_id(kTestEnterpriseKioskApp); | 1183 account->mutable_kiosk_app()->set_app_id(kTestEnterpriseKioskApp); |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1193 content::WindowedNotificationObserver( | 1367 content::WindowedNotificationObserver( |
| 1194 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE, | 1368 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE, |
| 1195 content::NotificationService::AllSources()).Wait(); | 1369 content::NotificationService::AllSources()).Wait(); |
| 1196 | 1370 |
| 1197 // Wait for the wallpaper to load. | 1371 // Wait for the wallpaper to load. |
| 1198 WaitForWallpaper(); | 1372 WaitForWallpaper(); |
| 1199 EXPECT_TRUE(wallpaper_loaded()); | 1373 EXPECT_TRUE(wallpaper_loaded()); |
| 1200 } | 1374 } |
| 1201 | 1375 |
| 1202 } // namespace chromeos | 1376 } // namespace chromeos |
| OLD | NEW |