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 needs_background_networking_ = true; | |
240 mock_user_manager_.reset(new MockUserManager); | 241 mock_user_manager_.reset(new MockUserManager); |
241 ProfileHelper::SetAlwaysReturnPrimaryUserForTesting(true); | 242 ProfileHelper::SetAlwaysReturnPrimaryUserForTesting(true); |
242 AppLaunchController::SkipSplashWaitForTesting(); | 243 AppLaunchController::SkipSplashWaitForTesting(); |
243 AppLaunchController::SetNetworkWaitForTesting(kTestNetworkTimeoutSeconds); | 244 AppLaunchController::SetNetworkWaitForTesting(kTestNetworkTimeoutSeconds); |
244 | 245 |
245 OobeBaseTest::SetUp(); | 246 OobeBaseTest::SetUp(); |
246 } | 247 } |
247 | 248 |
248 virtual void TearDown() OVERRIDE { | 249 virtual void TearDown() OVERRIDE { |
249 ProfileHelper::SetAlwaysReturnPrimaryUserForTesting(false); | 250 ProfileHelper::SetAlwaysReturnPrimaryUserForTesting(false); |
(...skipping 18 matching lines...) Expand all Loading... | |
268 | 269 |
269 void LaunchApp(const std::string& app_id, bool diagnostic_mode) { | 270 void LaunchApp(const std::string& app_id, bool diagnostic_mode) { |
270 bool new_kiosk_ui = KioskAppMenuHandler::EnableNewKioskUI(); | 271 bool new_kiosk_ui = KioskAppMenuHandler::EnableNewKioskUI(); |
271 GetLoginUI()->CallJavascriptFunction(new_kiosk_ui ? | 272 GetLoginUI()->CallJavascriptFunction(new_kiosk_ui ? |
272 kLaunchAppForTestNewAPI : kLaunchAppForTestOldAPI, | 273 kLaunchAppForTestNewAPI : kLaunchAppForTestOldAPI, |
273 base::StringValue(app_id), | 274 base::StringValue(app_id), |
274 base::FundamentalValue(diagnostic_mode)); | 275 base::FundamentalValue(diagnostic_mode)); |
275 } | 276 } |
276 | 277 |
277 void ReloadKioskApps() { | 278 void ReloadKioskApps() { |
279 SetupTestAppUpdateCheck(); | |
280 | |
278 // Remove then add to ensure NOTIFICATION_KIOSK_APPS_LOADED fires. | 281 // Remove then add to ensure NOTIFICATION_KIOSK_APPS_LOADED fires. |
279 KioskAppManager::Get()->RemoveApp(test_app_id_); | 282 KioskAppManager::Get()->RemoveApp(test_app_id_); |
280 KioskAppManager::Get()->AddApp(test_app_id_); | 283 KioskAppManager::Get()->AddApp(test_app_id_); |
281 } | 284 } |
282 | 285 |
286 void SetupTestAppUpdateCheck() { | |
287 if (!test_app_version().empty()) { | |
288 fake_cws_->SetUpdateCrx( | |
289 test_app_id(), test_crx_file(), test_app_version()); | |
290 } | |
291 } | |
292 | |
283 void ReloadAutolaunchKioskApps() { | 293 void ReloadAutolaunchKioskApps() { |
294 set_test_app_version("1.0.0"); | |
295 set_test_crx_file(test_app_id() + ".crx"); | |
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. |
461 set_test_app_version("1.0.0"); | |
462 set_test_crx_file(test_app_id() + ".crx"); | |
468 StartAppLaunchFromLoginScreen(SimulateNetworkOfflineClosure()); | 463 StartAppLaunchFromLoginScreen(SimulateNetworkOfflineClosure()); |
469 OobeScreenWaiter splash_waiter(OobeDisplay::SCREEN_APP_LAUNCH_SPLASH); | 464 OobeScreenWaiter splash_waiter(OobeDisplay::SCREEN_APP_LAUNCH_SPLASH); |
470 splash_waiter.Wait(); | 465 splash_waiter.Wait(); |
471 WaitForAppLaunchNetworkTimeout(); | 466 WaitForAppLaunchNetworkTimeout(); |
472 | 467 |
473 // Configure network link should be visible. | 468 // Configure network link should be visible. |
474 JsExpect("$('splash-config-network').hidden == false"); | 469 JsExpect("$('splash-config-network').hidden == false"); |
475 | 470 |
476 // Set up fake user manager with an owner for the test. | 471 // Set up fake user manager with an owner for the test. |
477 static_cast<LoginDisplayHostImpl*>(LoginDisplayHostImpl::default_host()) | 472 static_cast<LoginDisplayHostImpl*>(LoginDisplayHostImpl::default_host()) |
(...skipping 24 matching lines...) Expand all Loading... | |
502 return chromeos::LoginDisplayHostImpl::default_host() | 497 return chromeos::LoginDisplayHostImpl::default_host() |
503 ->GetAppLaunchController(); | 498 ->GetAppLaunchController(); |
504 } | 499 } |
505 | 500 |
506 MockUserManager* mock_user_manager() { return mock_user_manager_.get(); } | 501 MockUserManager* mock_user_manager() { return mock_user_manager_.get(); } |
507 | 502 |
508 void set_test_app_id(const std::string& test_app_id) { | 503 void set_test_app_id(const std::string& test_app_id) { |
509 test_app_id_ = test_app_id; | 504 test_app_id_ = test_app_id; |
510 } | 505 } |
511 const std::string& test_app_id() const { return test_app_id_; } | 506 const std::string& test_app_id() const { return test_app_id_; } |
507 void set_test_app_version(const std::string& version) { | |
508 test_app_version_ = version; | |
509 } | |
510 const std::string& test_app_version() const { return test_app_version_; } | |
511 void set_test_crx_file(const std::string& filename) { | |
512 test_crx_file_ = filename; | |
513 } | |
514 const std::string& test_crx_file() const { return test_crx_file_; } | |
512 FakeCWS* fake_cws() { return fake_cws_.get(); } | 515 FakeCWS* fake_cws() { return fake_cws_.get(); } |
513 | 516 |
514 private: | 517 private: |
515 std::string test_app_id_; | 518 std::string test_app_id_; |
519 std::string test_app_version_; | |
520 std::string test_crx_file_; | |
516 scoped_ptr<FakeCWS> fake_cws_; | 521 scoped_ptr<FakeCWS> fake_cws_; |
517 scoped_ptr<MockUserManager> mock_user_manager_; | 522 scoped_ptr<MockUserManager> mock_user_manager_; |
518 | 523 |
519 DISALLOW_COPY_AND_ASSIGN(KioskTest); | 524 DISALLOW_COPY_AND_ASSIGN(KioskTest); |
520 }; | 525 }; |
521 | 526 |
522 IN_PROC_BROWSER_TEST_F(KioskTest, InstallAndLaunchApp) { | 527 IN_PROC_BROWSER_TEST_F(KioskTest, InstallAndLaunchApp) { |
528 set_test_app_version("1.0.0"); | |
529 set_test_crx_file(test_app_id() + ".crx"); | |
xiyuan
2014/07/14 18:20:55
Move this into a setup function?
jennyz
2014/07/14 22:33:00
Done.
| |
523 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure()); | 530 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure()); |
524 WaitForAppLaunchSuccess(); | 531 WaitForAppLaunchSuccess(); |
525 } | 532 } |
526 | 533 |
527 IN_PROC_BROWSER_TEST_F(KioskTest, NotSignedInWithGAIAAccount) { | 534 IN_PROC_BROWSER_TEST_F(KioskTest, NotSignedInWithGAIAAccount) { |
528 // Tests that the kiosk session is not considered to be logged in with a GAIA | 535 // Tests that the kiosk session is not considered to be logged in with a GAIA |
529 // account. | 536 // account. |
537 set_test_app_version("1.0.0"); | |
538 set_test_crx_file(test_app_id() + ".crx"); | |
530 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure()); | 539 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure()); |
531 WaitForAppLaunchSuccess(); | 540 WaitForAppLaunchSuccess(); |
532 | 541 |
533 Profile* app_profile = ProfileManager::GetPrimaryUserProfile(); | 542 Profile* app_profile = ProfileManager::GetPrimaryUserProfile(); |
534 ASSERT_TRUE(app_profile); | 543 ASSERT_TRUE(app_profile); |
535 EXPECT_FALSE(app_profile->GetPrefs()->HasPrefPath( | 544 EXPECT_FALSE(app_profile->GetPrefs()->HasPrefPath( |
536 prefs::kGoogleServicesUsername)); | 545 prefs::kGoogleServicesUsername)); |
537 } | 546 } |
538 | 547 |
539 IN_PROC_BROWSER_TEST_F(KioskTest, PRE_LaunchAppNetworkDown) { | 548 IN_PROC_BROWSER_TEST_F(KioskTest, PRE_LaunchAppNetworkDown) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
578 "})();")); | 587 "})();")); |
579 | 588 |
580 WaitForAppLaunchSuccess(); | 589 WaitForAppLaunchSuccess(); |
581 } | 590 } |
582 | 591 |
583 IN_PROC_BROWSER_TEST_F(KioskTest, LaunchAppNetworkDownConfigureNotAllowed) { | 592 IN_PROC_BROWSER_TEST_F(KioskTest, LaunchAppNetworkDownConfigureNotAllowed) { |
584 // Mock network could not be configured. | 593 // Mock network could not be configured. |
585 ScopedCanConfigureNetwork can_configure_network(false, true); | 594 ScopedCanConfigureNetwork can_configure_network(false, true); |
586 | 595 |
587 // Start app launch and wait for network connectivity timeout. | 596 // Start app launch and wait for network connectivity timeout. |
597 set_test_app_version("1.0.0"); | |
598 set_test_crx_file(test_app_id() + ".crx"); | |
588 StartAppLaunchFromLoginScreen(SimulateNetworkOfflineClosure()); | 599 StartAppLaunchFromLoginScreen(SimulateNetworkOfflineClosure()); |
589 OobeScreenWaiter splash_waiter(OobeDisplay::SCREEN_APP_LAUNCH_SPLASH); | 600 OobeScreenWaiter splash_waiter(OobeDisplay::SCREEN_APP_LAUNCH_SPLASH); |
590 splash_waiter.Wait(); | 601 splash_waiter.Wait(); |
591 WaitForAppLaunchNetworkTimeout(); | 602 WaitForAppLaunchNetworkTimeout(); |
592 | 603 |
593 // Configure network link should not be visible. | 604 // Configure network link should not be visible. |
594 JsExpect("$('splash-config-network').hidden == true"); | 605 JsExpect("$('splash-config-network').hidden == true"); |
595 | 606 |
596 // Network becomes online and app launch is resumed. | 607 // Network becomes online and app launch is resumed. |
597 SimulateNetworkOnline(); | 608 SimulateNetworkOnline(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
629 chrome::NOTIFICATION_APP_TERMINATING, | 640 chrome::NOTIFICATION_APP_TERMINATING, |
630 content::NotificationService::AllSources()); | 641 content::NotificationService::AllSources()); |
631 GetLoginUI()->CallJavascriptFunction("cr.ui.Oobe.handleAccelerator", | 642 GetLoginUI()->CallJavascriptFunction("cr.ui.Oobe.handleAccelerator", |
632 base::StringValue("app_launch_bailout")); | 643 base::StringValue("app_launch_bailout")); |
633 signal.Wait(); | 644 signal.Wait(); |
634 EXPECT_EQ(chromeos::KioskAppLaunchError::USER_CANCEL, | 645 EXPECT_EQ(chromeos::KioskAppLaunchError::USER_CANCEL, |
635 chromeos::KioskAppLaunchError::Get()); | 646 chromeos::KioskAppLaunchError::Get()); |
636 } | 647 } |
637 | 648 |
638 IN_PROC_BROWSER_TEST_F(KioskTest, LaunchInDiagnosticMode) { | 649 IN_PROC_BROWSER_TEST_F(KioskTest, LaunchInDiagnosticMode) { |
650 set_test_app_version("1.0.0"); | |
651 set_test_crx_file(test_app_id() + ".crx"); | |
639 PrepareAppLaunch(); | 652 PrepareAppLaunch(); |
640 SimulateNetworkOnline(); | 653 SimulateNetworkOnline(); |
641 | 654 |
642 LaunchApp(kTestKioskApp, true); | 655 LaunchApp(kTestKioskApp, true); |
643 | 656 |
644 content::WebContents* login_contents = GetLoginUI()->GetWebContents(); | 657 content::WebContents* login_contents = GetLoginUI()->GetWebContents(); |
645 | 658 |
646 bool new_kiosk_ui = KioskAppMenuHandler::EnableNewKioskUI(); | 659 bool new_kiosk_ui = KioskAppMenuHandler::EnableNewKioskUI(); |
647 JsConditionWaiter(login_contents, new_kiosk_ui ? | 660 JsConditionWaiter(login_contents, new_kiosk_ui ? |
648 kCheckDiagnosticModeNewAPI : kCheckDiagnosticModeOldAPI).Wait(); | 661 kCheckDiagnosticModeNewAPI : kCheckDiagnosticModeOldAPI).Wait(); |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
875 chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_VISIBLE, | 888 chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_VISIBLE, |
876 content::NotificationService::AllSources()).Wait(); | 889 content::NotificationService::AllSources()).Wait(); |
877 } | 890 } |
878 | 891 |
879 class KioskUpdateTest : public KioskTest { | 892 class KioskUpdateTest : public KioskTest { |
880 public: | 893 public: |
881 KioskUpdateTest() {} | 894 KioskUpdateTest() {} |
882 virtual ~KioskUpdateTest() {} | 895 virtual ~KioskUpdateTest() {} |
883 | 896 |
884 protected: | 897 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 { | 898 virtual void SetUpOnMainThread() OVERRIDE { |
892 KioskTest::SetUpOnMainThread(); | 899 KioskTest::SetUpOnMainThread(); |
893 } | 900 } |
894 | 901 |
902 void PreCacheApp(const std::string& app_id, | |
903 const std::string& version, | |
904 const std::string& crx_file) { | |
905 set_test_app_id(app_id); | |
906 set_test_app_version(version); | |
907 set_test_crx_file(crx_file); | |
908 | |
909 KioskAppManager* manager = KioskAppManager::Get(); | |
910 AppDataLoadWaiter waiter(manager, app_id, version); | |
911 ReloadKioskApps(); | |
912 waiter.Wait(); | |
913 EXPECT_TRUE(waiter.loaded()); | |
914 std::string cached_version; | |
915 base::FilePath file_path; | |
916 EXPECT_TRUE(manager->GetCachedCrx(app_id, &file_path, &cached_version)); | |
917 EXPECT_EQ(version, cached_version); | |
918 } | |
919 | |
920 void UpdateExternalCache(const std::string& version, | |
921 const std::string& crx_file) { | |
922 set_test_app_version(version); | |
923 set_test_crx_file(crx_file); | |
924 SetupTestAppUpdateCheck(); | |
925 | |
926 KioskAppManager* manager = KioskAppManager::Get(); | |
927 AppDataLoadWaiter waiter(manager, test_app_id(), version); | |
928 KioskAppManager::Get()->UpdateExternalCache(); | |
929 waiter.Wait(); | |
930 EXPECT_TRUE(waiter.loaded()); | |
931 std::string cached_version; | |
932 base::FilePath file_path; | |
933 EXPECT_TRUE( | |
934 manager->GetCachedCrx(test_app_id(), &file_path, &cached_version)); | |
935 EXPECT_EQ(version, cached_version); | |
936 } | |
937 | |
938 void PreCacheAndLaunchApp(const std::string& app_id, | |
939 const std::string& version, | |
940 const std::string& crx_file) { | |
941 set_test_app_id(app_id); | |
942 set_test_app_version(version); | |
943 set_test_crx_file(crx_file); | |
944 PrepareAppLaunch(); | |
945 SimulateNetworkOnline(); | |
946 LaunchApp(test_app_id(), false); | |
947 WaitForAppLaunchSuccess(); | |
948 EXPECT_EQ(version, GetInstalledAppVersion().GetString()); | |
949 } | |
950 | |
895 private: | 951 private: |
952 class AppDataLoadWaiter : public KioskAppManagerObserver { | |
953 public: | |
954 AppDataLoadWaiter(KioskAppManager* manager, | |
955 const std::string& app_id, | |
956 const std::string& version) | |
957 : runner_(NULL), | |
958 manager_(manager), | |
959 loaded_(false), | |
960 quit_(false), | |
961 app_id_(app_id), | |
962 version_(version) { | |
963 manager_->AddObserver(this); | |
964 } | |
965 | |
966 virtual ~AppDataLoadWaiter() { manager_->RemoveObserver(this); } | |
967 | |
968 void Wait() { | |
969 if (quit_) | |
970 return; | |
971 runner_ = new content::MessageLoopRunner; | |
972 runner_->Run(); | |
973 } | |
974 | |
975 bool loaded() const { return loaded_; } | |
976 | |
977 private: | |
978 // KioskAppManagerObserver overrides: | |
979 virtual void OnKioskAppDataChanged(const std::string& app_id) OVERRIDE { | |
980 std::string cached_version; | |
981 base::FilePath file_path; | |
982 if (!manager_->GetCachedCrx(app_id_, &file_path, &cached_version)) | |
983 return; | |
984 if (version_ != cached_version) | |
985 return; | |
986 loaded_ = true; | |
987 quit_ = true; | |
988 if (runner_) | |
989 runner_->Quit(); | |
990 } | |
991 | |
992 virtual void OnKioskAppDataLoadFailure(const std::string& app_id) OVERRIDE { | |
993 loaded_ = false; | |
994 quit_ = true; | |
995 if (runner_) | |
996 runner_->Quit(); | |
997 } | |
998 | |
999 scoped_refptr<content::MessageLoopRunner> runner_; | |
1000 KioskAppManager* manager_; | |
1001 bool loaded_; | |
1002 bool quit_; | |
1003 std::string app_id_; | |
1004 std::string version_; | |
1005 | |
1006 DISALLOW_COPY_AND_ASSIGN(AppDataLoadWaiter); | |
1007 }; | |
896 | 1008 |
897 DISALLOW_COPY_AND_ASSIGN(KioskUpdateTest); | 1009 DISALLOW_COPY_AND_ASSIGN(KioskUpdateTest); |
898 }; | 1010 }; |
899 | 1011 |
1012 IN_PROC_BROWSER_TEST_F(KioskUpdateTest, PRE_LaunchOfflineEnabledAppNoNetwork) { | |
1013 PreCacheAndLaunchApp(kTestOfflineEnabledKioskApp, | |
1014 "1.0.0", | |
1015 std::string(kTestOfflineEnabledKioskApp) + "_v1.crx"); | |
1016 } | |
1017 | |
900 IN_PROC_BROWSER_TEST_F(KioskUpdateTest, LaunchOfflineEnabledAppNoNetwork) { | 1018 IN_PROC_BROWSER_TEST_F(KioskUpdateTest, LaunchOfflineEnabledAppNoNetwork) { |
901 set_test_app_id(kTestOfflineEnabledKioskApp); | 1019 set_test_app_id(kTestOfflineEnabledKioskApp); |
902 | 1020 StartUIForAppLaunch(); |
903 PrepareAppLaunch(); | |
904 SimulateNetworkOffline(); | 1021 SimulateNetworkOffline(); |
905 SetupAppProfile("chromeos/app_mode/offline_enabled_app_profile"); | 1022 LaunchApp(test_app_id(), false); |
906 | 1023 WaitForAppLaunchSuccess(); |
907 LaunchApp(test_app_id(), false); | 1024 |
908 WaitForAppLaunchSuccess(); | 1025 EXPECT_EQ("1.0.0", GetInstalledAppVersion().GetString()); |
1026 } | |
1027 | |
1028 IN_PROC_BROWSER_TEST_F(KioskUpdateTest, | |
1029 PRE_LaunchCachedOfflineEnabledAppNoNetwork) { | |
1030 PreCacheApp(kTestOfflineEnabledKioskApp, | |
1031 "1.0.0", | |
1032 std::string(kTestOfflineEnabledKioskApp) + "_v1.crx"); | |
1033 } | |
1034 | |
1035 IN_PROC_BROWSER_TEST_F(KioskUpdateTest, | |
1036 LaunchCachedOfflineEnabledAppNoNetwork) { | |
1037 set_test_app_id(kTestOfflineEnabledKioskApp); | |
1038 EXPECT_TRUE( | |
1039 KioskAppManager::Get()->HasCachedCrx(kTestOfflineEnabledKioskApp)); | |
1040 StartUIForAppLaunch(); | |
1041 SimulateNetworkOffline(); | |
1042 LaunchApp(test_app_id(), false); | |
1043 WaitForAppLaunchSuccess(); | |
1044 | |
1045 EXPECT_EQ("1.0.0", GetInstalledAppVersion().GetString()); | |
1046 } | |
1047 | |
1048 // Network offline, app v1.0 has run before, has cached v2.0 crx and v2.0 should | |
1049 // be installed and launched during next launch. | |
1050 IN_PROC_BROWSER_TEST_F(KioskUpdateTest, | |
1051 PRE_LaunchCachedNewVersionOfflineEnabledAppNoNetwork) { | |
1052 // Install and launch v1 app. | |
1053 PreCacheAndLaunchApp(kTestOfflineEnabledKioskApp, | |
1054 "1.0.0", | |
1055 std::string(kTestOfflineEnabledKioskApp) + "_v1.crx"); | |
1056 // Update cache for v2 app. | |
1057 UpdateExternalCache("2.0.0", | |
1058 std::string(kTestOfflineEnabledKioskApp) + ".crx"); | |
1059 // The installed app is still in v1. | |
1060 EXPECT_EQ("1.0.0", GetInstalledAppVersion().GetString()); | |
1061 } | |
1062 | |
1063 IN_PROC_BROWSER_TEST_F(KioskUpdateTest, | |
1064 LaunchCachedNewVersionOfflineEnabledAppNoNetwork) { | |
1065 set_test_app_id(kTestOfflineEnabledKioskApp); | |
1066 EXPECT_TRUE(KioskAppManager::Get()->HasCachedCrx(test_app_id())); | |
1067 | |
1068 StartUIForAppLaunch(); | |
1069 SimulateNetworkOffline(); | |
1070 LaunchApp(test_app_id(), false); | |
1071 WaitForAppLaunchSuccess(); | |
1072 | |
1073 // v2 app should have been installed. | |
1074 EXPECT_EQ("2.0.0", GetInstalledAppVersion().GetString()); | |
1075 } | |
1076 | |
1077 IN_PROC_BROWSER_TEST_F(KioskUpdateTest, PRE_LaunchOfflineEnabledAppNoUpdate) { | |
1078 PreCacheAndLaunchApp(kTestOfflineEnabledKioskApp, | |
1079 "1.0.0", | |
1080 std::string(kTestOfflineEnabledKioskApp) + "_v1.crx"); | |
909 } | 1081 } |
910 | 1082 |
911 IN_PROC_BROWSER_TEST_F(KioskUpdateTest, LaunchOfflineEnabledAppNoUpdate) { | 1083 IN_PROC_BROWSER_TEST_F(KioskUpdateTest, LaunchOfflineEnabledAppNoUpdate) { |
912 set_test_app_id(kTestOfflineEnabledKioskApp); | 1084 set_test_app_id(kTestOfflineEnabledKioskApp); |
913 | |
914 fake_cws()->SetNoUpdate(test_app_id()); | 1085 fake_cws()->SetNoUpdate(test_app_id()); |
915 | 1086 |
916 PrepareAppLaunch(); | 1087 StartUIForAppLaunch(); |
917 SimulateNetworkOnline(); | 1088 SimulateNetworkOnline(); |
918 SetupAppProfile("chromeos/app_mode/offline_enabled_app_profile"); | 1089 LaunchApp(test_app_id(), false); |
919 | 1090 WaitForAppLaunchSuccess(); |
920 LaunchApp(test_app_id(), false); | 1091 |
921 WaitForAppLaunchSuccess(); | 1092 EXPECT_EQ("1.0.0", GetInstalledAppVersion().GetString()); |
922 | 1093 } |
923 EXPECT_EQ("1.0.0", GetInstalledAppVersion().GetString()); | 1094 |
1095 IN_PROC_BROWSER_TEST_F(KioskUpdateTest, PRE_LaunchOfflineEnabledAppHasUpdate) { | |
1096 PreCacheAndLaunchApp(kTestOfflineEnabledKioskApp, | |
1097 "1.0.0", | |
1098 std::string(kTestOfflineEnabledKioskApp) + "_v1.crx"); | |
924 } | 1099 } |
925 | 1100 |
926 IN_PROC_BROWSER_TEST_F(KioskUpdateTest, LaunchOfflineEnabledAppHasUpdate) { | 1101 IN_PROC_BROWSER_TEST_F(KioskUpdateTest, LaunchOfflineEnabledAppHasUpdate) { |
927 set_test_app_id(kTestOfflineEnabledKioskApp); | 1102 set_test_app_id(kTestOfflineEnabledKioskApp); |
928 | |
929 fake_cws()->SetUpdateCrx( | 1103 fake_cws()->SetUpdateCrx( |
930 test_app_id(), "ajoggoflpgplnnjkjamcmbepjdjdnpdp.crx", "2.0.0"); | 1104 test_app_id(), "ajoggoflpgplnnjkjamcmbepjdjdnpdp.crx", "2.0.0"); |
931 | 1105 |
932 PrepareAppLaunch(); | 1106 StartUIForAppLaunch(); |
933 SimulateNetworkOnline(); | 1107 SimulateNetworkOnline(); |
934 SetupAppProfile("chromeos/app_mode/offline_enabled_app_profile"); | |
935 | |
936 LaunchApp(test_app_id(), false); | 1108 LaunchApp(test_app_id(), false); |
937 WaitForAppLaunchSuccess(); | 1109 WaitForAppLaunchSuccess(); |
938 | 1110 |
939 EXPECT_EQ("2.0.0", GetInstalledAppVersion().GetString()); | 1111 EXPECT_EQ("2.0.0", GetInstalledAppVersion().GetString()); |
940 } | 1112 } |
941 | 1113 |
1114 IN_PROC_BROWSER_TEST_F(KioskUpdateTest, PRE_PermissionChange) { | |
1115 PreCacheAndLaunchApp(kTestOfflineEnabledKioskApp, | |
1116 "2.0.0", | |
1117 std::string(kTestOfflineEnabledKioskApp) + ".crx"); | |
1118 } | |
1119 | |
942 IN_PROC_BROWSER_TEST_F(KioskUpdateTest, PermissionChange) { | 1120 IN_PROC_BROWSER_TEST_F(KioskUpdateTest, PermissionChange) { |
943 set_test_app_id(kTestOfflineEnabledKioskApp); | 1121 set_test_app_id(kTestOfflineEnabledKioskApp); |
944 | 1122 set_test_app_version("2.0.0"); |
945 fake_cws()->SetUpdateCrx( | 1123 set_test_crx_file(test_app_id() + "_v2_permission_change.crx"); |
946 test_app_id(), | 1124 |
947 "ajoggoflpgplnnjkjamcmbepjdjdnpdp_v2_permission_change.crx", | 1125 StartUIForAppLaunch(); |
948 "2.0.0"); | |
949 | |
950 PrepareAppLaunch(); | |
951 SimulateNetworkOnline(); | 1126 SimulateNetworkOnline(); |
952 SetupAppProfile("chromeos/app_mode/offline_enabled_app_profile"); | 1127 LaunchApp(test_app_id(), false); |
953 | 1128 WaitForAppLaunchSuccess(); |
954 LaunchApp(test_app_id(), false); | 1129 |
955 WaitForAppLaunchSuccess(); | |
956 | |
957 EXPECT_EQ("2.0.0", GetInstalledAppVersion().GetString()); | 1130 EXPECT_EQ("2.0.0", GetInstalledAppVersion().GetString()); |
958 } | 1131 } |
959 | 1132 |
960 IN_PROC_BROWSER_TEST_F(KioskUpdateTest, PRE_PreserveLocalData) { | 1133 IN_PROC_BROWSER_TEST_F(KioskUpdateTest, PRE_PreserveLocalData) { |
961 // Installs v1 app and writes some local data. | 1134 // Installs v1 app and writes some local data. |
962 set_test_app_id(kTestLocalFsKioskApp); | 1135 set_test_app_id(kTestLocalFsKioskApp); |
1136 set_test_app_version("1.0.0"); | |
1137 set_test_crx_file(test_app_id() + ".crx"); | |
963 | 1138 |
964 ResultCatcher catcher; | 1139 ResultCatcher catcher; |
965 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure()); | 1140 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure()); |
966 WaitForAppLaunchSuccess(); | 1141 WaitForAppLaunchSuccess(); |
967 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 1142 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
968 } | 1143 } |
969 | 1144 |
970 IN_PROC_BROWSER_TEST_F(KioskUpdateTest, PreserveLocalData) { | 1145 IN_PROC_BROWSER_TEST_F(KioskUpdateTest, PreserveLocalData) { |
971 // Update existing v1 app installed in PRE_PreserveLocalData to v2 | 1146 // Update existing v1 app installed in PRE_PreserveLocalData to v2 |
972 // that reads and verifies the local data. | 1147 // that reads and verifies the local data. |
973 set_test_app_id(kTestLocalFsKioskApp); | 1148 set_test_app_id(kTestLocalFsKioskApp); |
974 | 1149 set_test_app_version("2.0.0"); |
975 fake_cws()->SetUpdateCrx( | 1150 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; | 1151 ResultCatcher catcher; |
981 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure()); | 1152 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure()); |
982 WaitForAppLaunchSuccess(); | 1153 WaitForAppLaunchSuccess(); |
983 | 1154 |
984 EXPECT_EQ("2.0.0", GetInstalledAppVersion().GetString()); | 1155 EXPECT_EQ("2.0.0", GetInstalledAppVersion().GetString()); |
985 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 1156 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
986 } | 1157 } |
987 | 1158 |
988 class KioskEnterpriseTest : public KioskTest { | 1159 class KioskEnterpriseTest : public KioskTest { |
989 protected: | 1160 protected: |
990 KioskEnterpriseTest() {} | 1161 KioskEnterpriseTest() {} |
991 | 1162 |
992 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 1163 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
993 device_policy_test_helper_.MarkAsEnterpriseOwned(); | 1164 device_policy_test_helper_.MarkAsEnterpriseOwned(); |
994 device_policy_test_helper_.InstallOwnerKey(); | 1165 device_policy_test_helper_.InstallOwnerKey(); |
995 | 1166 |
996 KioskTest::SetUpInProcessBrowserTestFixture(); | 1167 KioskTest::SetUpInProcessBrowserTestFixture(); |
997 } | 1168 } |
998 | 1169 |
999 virtual void SetUpOnMainThread() OVERRIDE { | 1170 virtual void SetUpOnMainThread() OVERRIDE { |
1171 set_test_app_id(kTestEnterpriseKioskApp); | |
1172 set_test_app_version("1.0.0"); | |
1173 set_test_crx_file(test_app_id() + ".crx"); | |
1174 SetupTestAppUpdateCheck(); | |
1175 | |
1000 KioskTest::SetUpOnMainThread(); | 1176 KioskTest::SetUpOnMainThread(); |
1001 // Configure kTestEnterpriseKioskApp in device policy. | 1177 // Configure kTestEnterpriseKioskApp in device policy. |
1002 em::DeviceLocalAccountsProto* accounts = | 1178 em::DeviceLocalAccountsProto* accounts = |
1003 device_policy_test_helper_.device_policy()->payload() | 1179 device_policy_test_helper_.device_policy()->payload() |
1004 .mutable_device_local_accounts(); | 1180 .mutable_device_local_accounts(); |
1005 em::DeviceLocalAccountInfoProto* account = accounts->add_account(); | 1181 em::DeviceLocalAccountInfoProto* account = accounts->add_account(); |
1006 account->set_account_id(kTestEnterpriseAccountId); | 1182 account->set_account_id(kTestEnterpriseAccountId); |
1007 account->set_type( | 1183 account->set_type( |
1008 em::DeviceLocalAccountInfoProto::ACCOUNT_TYPE_KIOSK_APP); | 1184 em::DeviceLocalAccountInfoProto::ACCOUNT_TYPE_KIOSK_APP); |
1009 account->mutable_kiosk_app()->set_app_id(kTestEnterpriseKioskApp); | 1185 account->mutable_kiosk_app()->set_app_id(kTestEnterpriseKioskApp); |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1193 content::WindowedNotificationObserver( | 1369 content::WindowedNotificationObserver( |
1194 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE, | 1370 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE, |
1195 content::NotificationService::AllSources()).Wait(); | 1371 content::NotificationService::AllSources()).Wait(); |
1196 | 1372 |
1197 // Wait for the wallpaper to load. | 1373 // Wait for the wallpaper to load. |
1198 WaitForWallpaper(); | 1374 WaitForWallpaper(); |
1199 EXPECT_TRUE(wallpaper_loaded()); | 1375 EXPECT_TRUE(wallpaper_loaded()); |
1200 } | 1376 } |
1201 | 1377 |
1202 } // namespace chromeos | 1378 } // namespace chromeos |
OLD | NEW |