Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/prefs/pref_service.h" | 6 #include "base/prefs/pref_service.h" |
| 7 #include "base/timer/timer.h" | |
| 8 #include "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
| 10 #include "chrome/browser/chromeos/login/login_manager_test.h" | 9 #include "chrome/browser/chromeos/login/login_manager_test.h" |
| 11 #include "chrome/browser/chromeos/login/screenshot_tester.h" | 10 #include "chrome/browser/chromeos/login/screenshot_test.h" |
| 12 #include "chrome/browser/chromeos/login/startup_utils.h" | 11 #include "chrome/browser/chromeos/login/startup_utils.h" |
| 13 #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h" | 12 #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h" |
| 14 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" | 13 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" |
| 15 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
| 16 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/notification_observer.h" | 16 #include "content/public/browser/notification_observer.h" |
| 18 #include "content/public/browser/notification_registrar.h" | 17 #include "content/public/browser/notification_registrar.h" |
| 19 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
| 20 #include "content/public/browser/notification_types.h" | 19 #include "content/public/browser/notification_types.h" |
| 21 #include "ui/compositor/compositor_switches.h" | 20 #include "ui/compositor/compositor_switches.h" |
| 22 | 21 |
| 23 namespace chromeos { | 22 namespace chromeos { |
| 24 | 23 |
| 25 namespace { | 24 namespace { |
| 26 | 25 |
| 27 const char kTestUser1[] = "test-user1@gmail.com"; | 26 const char kTestUser1[] = "test-user1@gmail.com"; |
| 28 const char kTestUser2[] = "test-user2@gmail.com"; | 27 const char kTestUser2[] = "test-user2@gmail.com"; |
| 29 | 28 |
| 30 // A class that provides a way to wait until all the animation | 29 } // anonymous namespace |
| 31 // has loaded and is properly shown on the screen. | 30 |
| 32 class AnimationDelayHandler : public content::NotificationObserver { | 31 class LoginUITest : public chromeos::ScreenshotTest { |
| 33 public: | 32 public: |
| 34 AnimationDelayHandler(); | 33 virtual ~LoginUITest() {} |
| 35 | 34 |
| 36 // Should be run as early as possible on order not to miss notifications. | 35 // Override from ScreenshotTest |
| 37 // It seems though that it can't be moved to constructor(?). | 36 virtual void InitializeAnimationHandler() OVERRIDE; |
| 38 void Initialize(); | |
| 39 | 37 |
| 40 // Override from content::NotificationObserver. | 38 // Override from ScreenshotTest |
| 41 virtual void Observe(int type, | 39 virtual void Observe(int type, |
| 42 const content::NotificationSource& source, | 40 const content::NotificationSource& source, |
| 43 const content::NotificationDetails& details) OVERRIDE; | 41 const content::NotificationDetails& details) OVERRIDE; |
| 44 | 42 |
| 45 // This method checks if animation is loaded, and, if not, | 43 // Override from ScreenshotTest. |
| 46 // waits until it is loaded and properly shown on the screen. | 44 virtual bool IsAnimationLoaded() OVERRIDE; |
| 47 void WaitUntilAnimationLoads(); | |
| 48 | 45 |
| 49 private: | 46 private: |
| 50 void InitializeForWaiting(const base::Closure& quitter); | |
| 51 | |
| 52 // It turns out that it takes some more time for the animation | |
| 53 // to finish loading even after all the notifications have been sent. | |
| 54 // That happens due to some properties of compositor. | |
| 55 // This method should be used after getting all the necessary notifications | |
| 56 // to wait for the actual load of animation. | |
| 57 void SynchronizeAnimationLoadWithCompositor(); | |
| 58 | |
| 59 // This method exists only because of the current implementation of | |
| 60 // SynchronizeAnimationLoadWithCompositor. | |
| 61 void HandleAnimationLoad(); | |
| 62 | |
| 63 // Returns true if, according to the notificatons received, animation has | |
| 64 // finished loading by now. | |
| 65 bool IsAnimationLoaded(); | |
| 66 | |
| 67 base::OneShotTimer<AnimationDelayHandler> timer_; | |
| 68 bool waiter_loop_is_on_; | |
| 69 bool login_or_lock_webui_visible_; | 47 bool login_or_lock_webui_visible_; |
| 70 base::Closure animation_waiter_quitter_; | |
| 71 content::NotificationRegistrar registrar_; | |
| 72 }; | 48 }; |
| 73 | 49 |
| 74 } // anonymous namespace | 50 void LoginUITest::InitializeAnimationHandler() { |
| 75 | 51 login_or_lock_webui_visible_ = false; |
| 76 AnimationDelayHandler::AnimationDelayHandler() | |
| 77 : waiter_loop_is_on_(false), login_or_lock_webui_visible_(false) { | |
| 78 } | |
| 79 | |
| 80 void AnimationDelayHandler::Initialize() { | |
| 81 waiter_loop_is_on_ = false; | |
| 82 registrar_.Add(this, | 52 registrar_.Add(this, |
| 83 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, | 53 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, |
| 84 content::NotificationService::AllSources()); | 54 content::NotificationService::AllSources()); |
| 85 } | 55 } |
| 86 | 56 |
| 87 bool AnimationDelayHandler::IsAnimationLoaded() { | 57 bool LoginUITest::IsAnimationLoaded() { |
| 88 return login_or_lock_webui_visible_; | 58 return login_or_lock_webui_visible_; |
| 89 } | 59 } |
| 90 | 60 |
| 91 void AnimationDelayHandler::Observe( | 61 void LoginUITest::Observe(int type, |
| 92 int type, | 62 const content::NotificationSource& source, |
| 93 const content::NotificationSource& source, | 63 const content::NotificationDetails& details) { |
| 94 const content::NotificationDetails& details) { | |
| 95 if (chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE == type) { | 64 if (chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE == type) { |
| 96 login_or_lock_webui_visible_ = true; | 65 login_or_lock_webui_visible_ = true; |
| 97 registrar_.Remove(this, | 66 registrar_.Remove(this, |
| 98 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, | 67 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, |
| 99 content::NotificationService::AllSources()); | 68 content::NotificationService::AllSources()); |
| 100 } | 69 } |
| 101 if (waiter_loop_is_on_ && IsAnimationLoaded()) { | 70 if (waiter_loop_is_on_ && IsAnimationLoaded()) { |
| 102 content::BrowserThread::PostTask( | 71 content::BrowserThread::PostTask( |
| 103 content::BrowserThread::UI, FROM_HERE, animation_waiter_quitter_); | 72 content::BrowserThread::UI, FROM_HERE, animation_waiter_quitter_); |
| 104 } | 73 } |
| 105 } | 74 } |
| 106 | 75 |
| 107 void AnimationDelayHandler::InitializeForWaiting(const base::Closure& quitter) { | |
| 108 waiter_loop_is_on_ = true; | |
| 109 animation_waiter_quitter_ = quitter; | |
| 110 } | |
| 111 | |
| 112 void AnimationDelayHandler::HandleAnimationLoad() { | |
| 113 timer_.Stop(); | |
| 114 content::BrowserThread::PostTask( | |
| 115 content::BrowserThread::UI, FROM_HERE, animation_waiter_quitter_); | |
| 116 } | |
| 117 | |
| 118 // Current implementation is a mockup. | |
| 119 // It simply waits for 5 seconds, assuming that this time is enough for | |
| 120 // animation to load completely. | |
| 121 // TODO(elizavetai): Replace this temporary hack with getting a | |
| 122 // valid notification from compositor. | |
| 123 void AnimationDelayHandler::SynchronizeAnimationLoadWithCompositor() { | |
| 124 base::RunLoop waiter; | |
| 125 animation_waiter_quitter_ = waiter.QuitClosure(); | |
| 126 timer_.Start(FROM_HERE, | |
| 127 base::TimeDelta::FromSeconds(5), | |
| 128 this, | |
| 129 &AnimationDelayHandler::HandleAnimationLoad); | |
| 130 waiter.Run(); | |
| 131 } | |
| 132 | |
| 133 void AnimationDelayHandler::WaitUntilAnimationLoads() { | |
| 134 if (!IsAnimationLoaded()) { | |
| 135 base::RunLoop animation_waiter; | |
| 136 InitializeForWaiting(animation_waiter.QuitClosure()); | |
| 137 animation_waiter.Run(); | |
| 138 } | |
| 139 SynchronizeAnimationLoadWithCompositor(); | |
| 140 } | |
| 141 | |
| 142 class LoginUITest : public chromeos::LoginManagerTest { | |
| 143 public: | |
| 144 bool enable_test_screenshots_; | |
| 145 LoginUITest() : LoginManagerTest(false) {} | |
| 146 virtual ~LoginUITest() {} | |
| 147 virtual void SetUpOnMainThread() OVERRIDE { | |
| 148 enable_test_screenshots_ = screenshot_tester.TryInitialize(); | |
| 149 if (enable_test_screenshots_) { | |
| 150 animation_delay_handler.Initialize(); | |
| 151 } | |
| 152 LoginManagerTest::SetUpOnMainThread(); | |
| 153 } | |
| 154 | |
| 155 protected: | |
| 156 AnimationDelayHandler animation_delay_handler; | |
| 157 ScreenshotTester screenshot_tester; | |
| 158 }; | |
| 159 | 76 |
| 160 IN_PROC_BROWSER_TEST_F(LoginUITest, PRE_LoginUIVisible) { | 77 IN_PROC_BROWSER_TEST_F(LoginUITest, PRE_LoginUIVisible) { |
| 161 RegisterUser(kTestUser1); | 78 RegisterUser(kTestUser1); |
| 162 RegisterUser(kTestUser2); | 79 RegisterUser(kTestUser2); |
| 163 StartupUtils::MarkOobeCompleted(); | 80 StartupUtils::MarkOobeCompleted(); |
| 164 } | 81 } |
| 165 | 82 |
| 166 // Verifies basic login UI properties. | 83 // Verifies basic login UI properties. |
| 167 IN_PROC_BROWSER_TEST_F(LoginUITest, LoginUIVisible) { | 84 IN_PROC_BROWSER_TEST_F(LoginUITest, LoginUIVisible) { |
| 168 JSExpect("!!document.querySelector('#account-picker')"); | 85 JSExpect("!!document.querySelector('#account-picker')"); |
| 169 JSExpect("!!document.querySelector('#pod-row')"); | 86 JSExpect("!!document.querySelector('#pod-row')"); |
| 170 JSExpect( | 87 JSExpect( |
| 171 "document.querySelectorAll('.pod:not(#user-pod-template)').length == 2"); | 88 "document.querySelectorAll('.pod:not(#user-pod-template)').length == 2"); |
| 172 | 89 |
| 173 JSExpect("document.querySelectorAll('.pod:not(#user-pod-template)')[0]" | 90 JSExpect("document.querySelectorAll('.pod:not(#user-pod-template)')[0]" |
| 174 ".user.emailAddress == '" + std::string(kTestUser1) + "'"); | 91 ".user.emailAddress == '" + std::string(kTestUser1) + "'"); |
| 175 JSExpect("document.querySelectorAll('.pod:not(#user-pod-template)')[1]" | 92 JSExpect("document.querySelectorAll('.pod:not(#user-pod-template)')[1]" |
| 176 ".user.emailAddress == '" + std::string(kTestUser2) + "'"); | 93 ".user.emailAddress == '" + std::string(kTestUser2) + "'"); |
| 177 if (enable_test_screenshots_) { | 94 RunScreenshotTesting("LoginUITest-LoginUIVisible"); |
|
dzhioev (left Google)
2014/08/07 11:23:55
Note for future improvements: we can form test nam
| |
| 178 animation_delay_handler.WaitUntilAnimationLoads(); | |
| 179 screenshot_tester.Run("LoginUITest-LoginUIVisible"); | |
| 180 } | |
| 181 } | 95 } |
| 182 | 96 |
| 183 IN_PROC_BROWSER_TEST_F(LoginUITest, PRE_InterruptedAutoStartEnrollment) { | 97 IN_PROC_BROWSER_TEST_F(LoginUITest, PRE_InterruptedAutoStartEnrollment) { |
| 184 StartupUtils::MarkOobeCompleted(); | 98 StartupUtils::MarkOobeCompleted(); |
| 185 PrefService* prefs = g_browser_process->local_state(); | 99 PrefService* prefs = g_browser_process->local_state(); |
| 186 prefs->SetBoolean(prefs::kDeviceEnrollmentAutoStart, true); | 100 prefs->SetBoolean(prefs::kDeviceEnrollmentAutoStart, true); |
| 187 } | 101 } |
| 188 | 102 |
| 189 // Tests that the default first screen is the network screen after OOBE | 103 // Tests that the default first screen is the network screen after OOBE |
| 190 // when auto enrollment is enabled and device is not yet enrolled. | 104 // when auto enrollment is enabled and device is not yet enrolled. |
| 191 IN_PROC_BROWSER_TEST_F(LoginUITest, InterruptedAutoStartEnrollment) { | 105 IN_PROC_BROWSER_TEST_F(LoginUITest, InterruptedAutoStartEnrollment) { |
| 192 OobeScreenWaiter(OobeDisplay::SCREEN_OOBE_NETWORK).Wait(); | 106 OobeScreenWaiter(OobeDisplay::SCREEN_OOBE_NETWORK).Wait(); |
| 193 } | 107 } |
| 194 | 108 |
| 195 } // namespace chromeos | 109 } // namespace chromeos |
| OLD | NEW |