| 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 <memory> |
| 5 #include <vector> | 6 #include <vector> |
| 6 | 7 |
| 7 #include "ash/desktop_background/desktop_background_controller.h" | 8 #include "ash/desktop_background/desktop_background_controller.h" |
| 8 #include "ash/desktop_background/desktop_background_controller_observer.h" | 9 #include "ash/desktop_background/desktop_background_controller_observer.h" |
| 9 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 10 #include "base/bind.h" | 11 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 12 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
| 13 #include "base/location.h" | 14 #include "base/location.h" |
| 14 #include "base/macros.h" | 15 #include "base/macros.h" |
| 15 #include "base/memory/scoped_ptr.h" | |
| 16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
| 17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
| 19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
| 20 #include "base/synchronization/lock.h" | 20 #include "base/synchronization/lock.h" |
| 21 #include "chrome/browser/chrome_notification_types.h" | 21 #include "chrome/browser/chrome_notification_types.h" |
| 22 #include "chrome/browser/chromeos/app_mode/fake_cws.h" | 22 #include "chrome/browser/chromeos/app_mode/fake_cws.h" |
| 23 #include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h" | 23 #include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h" |
| 24 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" | 24 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" |
| 25 #include "chrome/browser/chromeos/file_manager/fake_disk_mount_manager.h" | 25 #include "chrome/browser/chromeos/file_manager/fake_disk_mount_manager.h" |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 *out_locked = in_locked; | 222 *out_locked = in_locked; |
| 223 runner_quit_task.Run(); | 223 runner_quit_task.Run(); |
| 224 } | 224 } |
| 225 | 225 |
| 226 // Helper function for WaitForNetworkTimeOut. | 226 // Helper function for WaitForNetworkTimeOut. |
| 227 void OnNetworkWaitTimedOut(const base::Closure& runner_quit_task) { | 227 void OnNetworkWaitTimedOut(const base::Closure& runner_quit_task) { |
| 228 runner_quit_task.Run(); | 228 runner_quit_task.Run(); |
| 229 } | 229 } |
| 230 | 230 |
| 231 // Helper function for LockFileThread. | 231 // Helper function for LockFileThread. |
| 232 void LockAndUnlock(scoped_ptr<base::Lock> lock) { | 232 void LockAndUnlock(std::unique_ptr<base::Lock> lock) { |
| 233 lock->Acquire(); | 233 lock->Acquire(); |
| 234 lock->Release(); | 234 lock->Release(); |
| 235 } | 235 } |
| 236 | 236 |
| 237 bool IsAppInstalled(const std::string& app_id, const std::string& version) { | 237 bool IsAppInstalled(const std::string& app_id, const std::string& version) { |
| 238 Profile* app_profile = ProfileManager::GetPrimaryUserProfile(); | 238 Profile* app_profile = ProfileManager::GetPrimaryUserProfile(); |
| 239 DCHECK(app_profile); | 239 DCHECK(app_profile); |
| 240 const extensions::Extension* app = | 240 const extensions::Extension* app = |
| 241 extensions::ExtensionSystem::Get(app_profile) | 241 extensions::ExtensionSystem::Get(app_profile) |
| 242 ->extension_service() | 242 ->extension_service() |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 &OnNetworkWaitTimedOut, runner->QuitClosure()); | 714 &OnNetworkWaitTimedOut, runner->QuitClosure()); |
| 715 AppLaunchController::SetNetworkTimeoutCallbackForTesting(&callback); | 715 AppLaunchController::SetNetworkTimeoutCallbackForTesting(&callback); |
| 716 | 716 |
| 717 runner->Run(); | 717 runner->Run(); |
| 718 | 718 |
| 719 CHECK(GetAppLaunchController()->network_wait_timedout()); | 719 CHECK(GetAppLaunchController()->network_wait_timedout()); |
| 720 AppLaunchController::SetNetworkTimeoutCallbackForTesting(NULL); | 720 AppLaunchController::SetNetworkTimeoutCallbackForTesting(NULL); |
| 721 } | 721 } |
| 722 | 722 |
| 723 void EnableConsumerKioskMode() { | 723 void EnableConsumerKioskMode() { |
| 724 scoped_ptr<bool> locked(new bool(false)); | 724 std::unique_ptr<bool> locked(new bool(false)); |
| 725 scoped_refptr<content::MessageLoopRunner> runner = | 725 scoped_refptr<content::MessageLoopRunner> runner = |
| 726 new content::MessageLoopRunner; | 726 new content::MessageLoopRunner; |
| 727 KioskAppManager::Get()->EnableConsumerKioskAutoLaunch( | 727 KioskAppManager::Get()->EnableConsumerKioskAutoLaunch( |
| 728 base::Bind(&ConsumerKioskModeAutoStartLockCheck, | 728 base::Bind(&ConsumerKioskModeAutoStartLockCheck, |
| 729 locked.get(), | 729 locked.get(), |
| 730 runner->QuitClosure())); | 730 runner->QuitClosure())); |
| 731 runner->Run(); | 731 runner->Run(); |
| 732 EXPECT_TRUE(*locked.get()); | 732 EXPECT_TRUE(*locked.get()); |
| 733 } | 733 } |
| 734 | 734 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 return LoginDisplayHost::default_host()->GetAppLaunchController(); | 792 return LoginDisplayHost::default_host()->GetAppLaunchController(); |
| 793 } | 793 } |
| 794 | 794 |
| 795 // Returns a lock that is holding a task on the FILE thread. Any tasks posted | 795 // Returns a lock that is holding a task on the FILE thread. Any tasks posted |
| 796 // to the FILE thread after this call will be blocked until the returned | 796 // to the FILE thread after this call will be blocked until the returned |
| 797 // lock is released. | 797 // lock is released. |
| 798 // This can be used to prevent app installation from completing until some | 798 // This can be used to prevent app installation from completing until some |
| 799 // other conditions are checked and triggered. For example, this can be used | 799 // other conditions are checked and triggered. For example, this can be used |
| 800 // to trigger the network screen during app launch without racing with the | 800 // to trigger the network screen during app launch without racing with the |
| 801 // app launching process itself. | 801 // app launching process itself. |
| 802 scoped_ptr<base::AutoLock> LockFileThread() { | 802 std::unique_ptr<base::AutoLock> LockFileThread() { |
| 803 scoped_ptr<base::Lock> lock(new base::Lock); | 803 std::unique_ptr<base::Lock> lock(new base::Lock); |
| 804 scoped_ptr<base::AutoLock> auto_lock(new base::AutoLock(*lock)); | 804 std::unique_ptr<base::AutoLock> auto_lock(new base::AutoLock(*lock)); |
| 805 content::BrowserThread::PostTask( | 805 content::BrowserThread::PostTask( |
| 806 content::BrowserThread::FILE, FROM_HERE, | 806 content::BrowserThread::FILE, FROM_HERE, |
| 807 base::Bind(&LockAndUnlock, base::Passed(&lock))); | 807 base::Bind(&LockAndUnlock, base::Passed(&lock))); |
| 808 return auto_lock; | 808 return auto_lock; |
| 809 } | 809 } |
| 810 | 810 |
| 811 MockUserManager* mock_user_manager() { return mock_user_manager_.get(); } | 811 MockUserManager* mock_user_manager() { return mock_user_manager_.get(); } |
| 812 | 812 |
| 813 void set_test_app_id(const std::string& test_app_id) { | 813 void set_test_app_id(const std::string& test_app_id) { |
| 814 test_app_id_ = test_app_id; | 814 test_app_id_ = test_app_id; |
| 815 } | 815 } |
| 816 const std::string& test_app_id() const { return test_app_id_; } | 816 const std::string& test_app_id() const { return test_app_id_; } |
| 817 void set_test_app_version(const std::string& version) { | 817 void set_test_app_version(const std::string& version) { |
| 818 test_app_version_ = version; | 818 test_app_version_ = version; |
| 819 } | 819 } |
| 820 const std::string& test_app_version() const { return test_app_version_; } | 820 const std::string& test_app_version() const { return test_app_version_; } |
| 821 void set_test_crx_file(const std::string& filename) { | 821 void set_test_crx_file(const std::string& filename) { |
| 822 test_crx_file_ = filename; | 822 test_crx_file_ = filename; |
| 823 } | 823 } |
| 824 const std::string& test_crx_file() const { return test_crx_file_; } | 824 const std::string& test_crx_file() const { return test_crx_file_; } |
| 825 FakeCWS* fake_cws() { return fake_cws_.get(); } | 825 FakeCWS* fake_cws() { return fake_cws_.get(); } |
| 826 | 826 |
| 827 void set_use_consumer_kiosk_mode(bool use) { | 827 void set_use_consumer_kiosk_mode(bool use) { |
| 828 use_consumer_kiosk_mode_ = use; | 828 use_consumer_kiosk_mode_ = use; |
| 829 } | 829 } |
| 830 | 830 |
| 831 ScopedCrosSettingsTestHelper settings_helper_; | 831 ScopedCrosSettingsTestHelper settings_helper_; |
| 832 scoped_ptr<FakeOwnerSettingsService> owner_settings_service_; | 832 std::unique_ptr<FakeOwnerSettingsService> owner_settings_service_; |
| 833 | 833 |
| 834 const AccountId test_owner_account_id_ = | 834 const AccountId test_owner_account_id_ = |
| 835 AccountId::FromUserEmail(kTestOwnerEmail); | 835 AccountId::FromUserEmail(kTestOwnerEmail); |
| 836 | 836 |
| 837 private: | 837 private: |
| 838 bool use_consumer_kiosk_mode_ = true; | 838 bool use_consumer_kiosk_mode_ = true; |
| 839 std::string test_app_id_; | 839 std::string test_app_id_; |
| 840 std::string test_app_version_; | 840 std::string test_app_version_; |
| 841 std::string test_crx_file_; | 841 std::string test_crx_file_; |
| 842 scoped_ptr<FakeCWS> fake_cws_; | 842 std::unique_ptr<FakeCWS> fake_cws_; |
| 843 scoped_ptr<MockUserManager> mock_user_manager_; | 843 std::unique_ptr<MockUserManager> mock_user_manager_; |
| 844 | 844 |
| 845 DISALLOW_COPY_AND_ASSIGN(KioskTest); | 845 DISALLOW_COPY_AND_ASSIGN(KioskTest); |
| 846 }; | 846 }; |
| 847 | 847 |
| 848 IN_PROC_BROWSER_TEST_F(KioskTest, InstallAndLaunchApp) { | 848 IN_PROC_BROWSER_TEST_F(KioskTest, InstallAndLaunchApp) { |
| 849 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure()); | 849 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure()); |
| 850 WaitForAppLaunchSuccess(); | 850 WaitForAppLaunchSuccess(); |
| 851 KioskAppManager::App app; | 851 KioskAppManager::App app; |
| 852 ASSERT_TRUE(KioskAppManager::Get()->GetApp(test_app_id(), &app)); | 852 ASSERT_TRUE(KioskAppManager::Get()->GetApp(test_app_id(), &app)); |
| 853 EXPECT_FALSE(app.was_auto_launched_with_zero_delay); | 853 EXPECT_FALSE(app.was_auto_launched_with_zero_delay); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 942 IN_PROC_BROWSER_TEST_F(KioskTest, LaunchAppNetworkDown) { | 942 IN_PROC_BROWSER_TEST_F(KioskTest, LaunchAppNetworkDown) { |
| 943 // Tests the network down case for launching an existing app that is | 943 // Tests the network down case for launching an existing app that is |
| 944 // installed in PRE_LaunchAppNetworkDown. | 944 // installed in PRE_LaunchAppNetworkDown. |
| 945 RunAppLaunchNetworkDownTest(); | 945 RunAppLaunchNetworkDownTest(); |
| 946 } | 946 } |
| 947 | 947 |
| 948 IN_PROC_BROWSER_TEST_F(KioskTest, LaunchAppWithNetworkConfigAccelerator) { | 948 IN_PROC_BROWSER_TEST_F(KioskTest, LaunchAppWithNetworkConfigAccelerator) { |
| 949 ScopedCanConfigureNetwork can_configure_network(true, false); | 949 ScopedCanConfigureNetwork can_configure_network(true, false); |
| 950 | 950 |
| 951 // Block app loading until the network screen is shown. | 951 // Block app loading until the network screen is shown. |
| 952 scoped_ptr<base::AutoLock> lock = LockFileThread(); | 952 std::unique_ptr<base::AutoLock> lock = LockFileThread(); |
| 953 | 953 |
| 954 // Start app launch and wait for network connectivity timeout. | 954 // Start app launch and wait for network connectivity timeout. |
| 955 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure()); | 955 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure()); |
| 956 OobeScreenWaiter splash_waiter(OobeScreen::SCREEN_APP_LAUNCH_SPLASH); | 956 OobeScreenWaiter splash_waiter(OobeScreen::SCREEN_APP_LAUNCH_SPLASH); |
| 957 splash_waiter.Wait(); | 957 splash_waiter.Wait(); |
| 958 | 958 |
| 959 // A network error screen should be shown after authenticating. | 959 // A network error screen should be shown after authenticating. |
| 960 OobeScreenWaiter error_screen_waiter(OobeScreen::SCREEN_ERROR_MESSAGE); | 960 OobeScreenWaiter error_screen_waiter(OobeScreen::SCREEN_ERROR_MESSAGE); |
| 961 // Simulate Ctrl+Alt+N accelerator. | 961 // Simulate Ctrl+Alt+N accelerator. |
| 962 GetLoginUI()->CallJavascriptFunction( | 962 GetLoginUI()->CallJavascriptFunction( |
| (...skipping 1348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2311 content::WindowedNotificationObserver( | 2311 content::WindowedNotificationObserver( |
| 2312 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE, | 2312 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE, |
| 2313 content::NotificationService::AllSources()).Wait(); | 2313 content::NotificationService::AllSources()).Wait(); |
| 2314 | 2314 |
| 2315 // Wait for the wallpaper to load. | 2315 // Wait for the wallpaper to load. |
| 2316 WaitForWallpaper(); | 2316 WaitForWallpaper(); |
| 2317 EXPECT_TRUE(wallpaper_loaded()); | 2317 EXPECT_TRUE(wallpaper_loaded()); |
| 2318 } | 2318 } |
| 2319 | 2319 |
| 2320 } // namespace chromeos | 2320 } // namespace chromeos |
| OLD | NEW |