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/prefs/pref_service.h" | 6 #include "base/prefs/pref_service.h" |
| 7 #include "base/timer/timer.h" |
6 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/chrome_notification_types.h" |
7 #include "chrome/browser/chromeos/login/login_manager_test.h" | 10 #include "chrome/browser/chromeos/login/login_manager_test.h" |
| 11 #include "chrome/browser/chromeos/login/screenshot_tester.h" |
8 #include "chrome/browser/chromeos/login/startup_utils.h" | 12 #include "chrome/browser/chromeos/login/startup_utils.h" |
9 #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h" | 13 #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h" |
| 14 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" |
10 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
| 16 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/notification_observer.h" |
| 18 #include "content/public/browser/notification_registrar.h" |
| 19 #include "content/public/browser/notification_service.h" |
| 20 #include "content/public/browser/notification_types.h" |
| 21 #include "ui/compositor/compositor_switches.h" |
11 | 22 |
12 namespace chromeos { | 23 namespace chromeos { |
13 | 24 |
14 namespace { | 25 namespace { |
15 | 26 |
16 const char kTestUser1[] = "test-user1@gmail.com"; | 27 const char kTestUser1[] = "test-user1@gmail.com"; |
17 const char kTestUser2[] = "test-user2@gmail.com"; | 28 const char kTestUser2[] = "test-user2@gmail.com"; |
18 | 29 |
| 30 // A class that provides a way to wait until all the animation |
| 31 // has loaded and is properly shown on the screen. |
| 32 class AnimationDelayHandler : public content::NotificationObserver { |
| 33 public: |
| 34 AnimationDelayHandler(); |
| 35 |
| 36 // Should be run as early as possible on order not to miss notifications. |
| 37 // It seems though that it can't be moved to constructor(?). |
| 38 void Initialize(); |
| 39 |
| 40 // Override from content::NotificationObserver. |
| 41 virtual void Observe(int type, |
| 42 const content::NotificationSource& source, |
| 43 const content::NotificationDetails& details) OVERRIDE; |
| 44 |
| 45 // This method checks if animation is loaded, and, if not, |
| 46 // waits until it is loaded and properly shown on the screen. |
| 47 void WaitUntilAnimationLoads(); |
| 48 |
| 49 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_; |
| 70 base::Closure animation_waiter_quitter_; |
| 71 content::NotificationRegistrar registrar_; |
| 72 }; |
| 73 |
19 } // anonymous namespace | 74 } // anonymous namespace |
20 | 75 |
| 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, |
| 83 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, |
| 84 content::NotificationService::AllSources()); |
| 85 } |
| 86 |
| 87 bool AnimationDelayHandler::IsAnimationLoaded() { |
| 88 return login_or_lock_webui_visible_; |
| 89 } |
| 90 |
| 91 void AnimationDelayHandler::Observe( |
| 92 int type, |
| 93 const content::NotificationSource& source, |
| 94 const content::NotificationDetails& details) { |
| 95 if (chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE == type) { |
| 96 login_or_lock_webui_visible_ = true; |
| 97 registrar_.Remove(this, |
| 98 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, |
| 99 content::NotificationService::AllSources()); |
| 100 } |
| 101 if (waiter_loop_is_on_ && IsAnimationLoaded()) { |
| 102 content::BrowserThread::PostTask( |
| 103 content::BrowserThread::UI, FROM_HERE, animation_waiter_quitter_); |
| 104 } |
| 105 } |
| 106 |
| 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 |
21 class LoginUITest : public chromeos::LoginManagerTest { | 142 class LoginUITest : public chromeos::LoginManagerTest { |
22 public: | 143 public: |
| 144 bool enable_test_screenshots_; |
23 LoginUITest() : LoginManagerTest(false) {} | 145 LoginUITest() : LoginManagerTest(false) {} |
24 virtual ~LoginUITest() {} | 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 } else { |
| 152 LOG(WARNING) << "Screenshots will not be taken"; |
| 153 } |
| 154 LoginManagerTest::SetUpOnMainThread(); |
| 155 } |
| 156 |
| 157 protected: |
| 158 AnimationDelayHandler animation_delay_handler; |
| 159 ScreenshotTester screenshot_tester; |
25 }; | 160 }; |
26 | 161 |
27 IN_PROC_BROWSER_TEST_F(LoginUITest, PRE_LoginUIVisible) { | 162 IN_PROC_BROWSER_TEST_F(LoginUITest, PRE_LoginUIVisible) { |
28 RegisterUser(kTestUser1); | 163 RegisterUser(kTestUser1); |
29 RegisterUser(kTestUser2); | 164 RegisterUser(kTestUser2); |
30 StartupUtils::MarkOobeCompleted(); | 165 StartupUtils::MarkOobeCompleted(); |
31 } | 166 } |
32 | 167 |
33 // Verifies basic login UI properties. | 168 // Verifies basic login UI properties. |
34 IN_PROC_BROWSER_TEST_F(LoginUITest, LoginUIVisible) { | 169 IN_PROC_BROWSER_TEST_F(LoginUITest, LoginUIVisible) { |
35 JSExpect("!!document.querySelector('#account-picker')"); | 170 JSExpect("!!document.querySelector('#account-picker')"); |
36 JSExpect("!!document.querySelector('#pod-row')"); | 171 JSExpect("!!document.querySelector('#pod-row')"); |
37 JSExpect( | 172 JSExpect( |
38 "document.querySelectorAll('.pod:not(#user-pod-template)').length == 2"); | 173 "document.querySelectorAll('.pod:not(#user-pod-template)').length == 2"); |
39 | 174 |
40 JSExpect("document.querySelectorAll('.pod:not(#user-pod-template)')[0]" | 175 JSExpect("document.querySelectorAll('.pod:not(#user-pod-template)')[0]" |
41 ".user.emailAddress == '" + std::string(kTestUser1) + "'"); | 176 ".user.emailAddress == '" + std::string(kTestUser1) + "'"); |
42 JSExpect("document.querySelectorAll('.pod:not(#user-pod-template)')[1]" | 177 JSExpect("document.querySelectorAll('.pod:not(#user-pod-template)')[1]" |
43 ".user.emailAddress == '" + std::string(kTestUser2) + "'"); | 178 ".user.emailAddress == '" + std::string(kTestUser2) + "'"); |
| 179 if (enable_test_screenshots_) { |
| 180 animation_delay_handler.WaitUntilAnimationLoads(); |
| 181 screenshot_tester.Run("LoginUITest-LoginUIVisible"); |
| 182 } |
44 } | 183 } |
45 | 184 |
46 IN_PROC_BROWSER_TEST_F(LoginUITest, PRE_InterruptedAutoStartEnrollment) { | 185 IN_PROC_BROWSER_TEST_F(LoginUITest, PRE_InterruptedAutoStartEnrollment) { |
47 StartupUtils::MarkOobeCompleted(); | 186 StartupUtils::MarkOobeCompleted(); |
48 | |
49 PrefService* prefs = g_browser_process->local_state(); | 187 PrefService* prefs = g_browser_process->local_state(); |
50 prefs->SetBoolean(prefs::kDeviceEnrollmentAutoStart, true); | 188 prefs->SetBoolean(prefs::kDeviceEnrollmentAutoStart, true); |
51 } | 189 } |
52 | 190 |
53 // Tests that the default first screen is the network screen after OOBE | 191 // Tests that the default first screen is the network screen after OOBE |
54 // when auto enrollment is enabled and device is not yet enrolled. | 192 // when auto enrollment is enabled and device is not yet enrolled. |
55 IN_PROC_BROWSER_TEST_F(LoginUITest, InterruptedAutoStartEnrollment) { | 193 IN_PROC_BROWSER_TEST_F(LoginUITest, InterruptedAutoStartEnrollment) { |
56 OobeScreenWaiter(OobeDisplay::SCREEN_OOBE_NETWORK).Wait(); | 194 OobeScreenWaiter(OobeDisplay::SCREEN_OOBE_NETWORK).Wait(); |
57 } | 195 } |
58 | 196 |
59 } // namespace chromeos | 197 } // namespace chromeos |
OLD | NEW |