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" | 7 #include "base/timer/timer.h" |
8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
10 #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" | 11 #include "chrome/browser/chromeos/login/screenshot_testing_mixin.h" |
12 #include "chrome/browser/chromeos/login/startup_utils.h" | 12 #include "chrome/browser/chromeos/login/startup_utils.h" |
13 #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" | 14 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" |
15 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
17 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
18 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
19 #include "content/public/browser/notification_service.h" | 19 #include "content/public/browser/notification_service.h" |
20 #include "content/public/browser/notification_types.h" | 20 #include "content/public/browser/notification_types.h" |
21 #include "ui/compositor/compositor_switches.h" | 21 #include "ui/compositor/compositor_switches.h" |
22 | 22 |
23 namespace chromeos { | 23 namespace chromeos { |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
27 const char kTestUser1[] = "test-user1@gmail.com"; | 27 const char kTestUser1[] = "test-user1@gmail.com"; |
28 const char kTestUser2[] = "test-user2@gmail.com"; | 28 const char kTestUser2[] = "test-user2@gmail.com"; |
29 | 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 | |
74 } // anonymous namespace | |
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 } | 30 } |
141 | 31 |
142 class LoginUITest : public chromeos::LoginManagerTest { | 32 class LoginUITest : public chromeos::LoginManagerTest { |
143 public: | 33 public: |
144 bool enable_test_screenshots_; | 34 bool enable_test_screenshots_; |
145 LoginUITest() : LoginManagerTest(false) {} | 35 LoginUITest() : LoginManagerTest(false) { |
| 36 screenshot_testing_ = new ScreenshotTestingMixin; |
| 37 AddMixin(screenshot_testing_); |
| 38 } |
146 virtual ~LoginUITest() {} | 39 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 | 40 |
155 protected: | 41 protected: |
156 AnimationDelayHandler animation_delay_handler; | 42 ScreenshotTestingMixin* screenshot_testing_; |
157 ScreenshotTester screenshot_tester; | |
158 }; | 43 }; |
159 | 44 |
160 IN_PROC_BROWSER_TEST_F(LoginUITest, PRE_LoginUIVisible) { | 45 IN_PROC_BROWSER_TEST_F(LoginUITest, PRE_LoginUIVisible) { |
161 RegisterUser(kTestUser1); | 46 RegisterUser(kTestUser1); |
162 RegisterUser(kTestUser2); | 47 RegisterUser(kTestUser2); |
163 StartupUtils::MarkOobeCompleted(); | 48 StartupUtils::MarkOobeCompleted(); |
164 } | 49 } |
165 | 50 |
166 // Verifies basic login UI properties. | 51 // Verifies basic login UI properties. |
167 IN_PROC_BROWSER_TEST_F(LoginUITest, LoginUIVisible) { | 52 IN_PROC_BROWSER_TEST_F(LoginUITest, LoginUIVisible) { |
168 JSExpect("!!document.querySelector('#account-picker')"); | 53 JSExpect("!!document.querySelector('#account-picker')"); |
169 JSExpect("!!document.querySelector('#pod-row')"); | 54 JSExpect("!!document.querySelector('#pod-row')"); |
170 JSExpect( | 55 JSExpect( |
171 "document.querySelectorAll('.pod:not(#user-pod-template)').length == 2"); | 56 "document.querySelectorAll('.pod:not(#user-pod-template)').length == 2"); |
172 | 57 |
173 JSExpect("document.querySelectorAll('.pod:not(#user-pod-template)')[0]" | 58 JSExpect("document.querySelectorAll('.pod:not(#user-pod-template)')[0]" |
174 ".user.emailAddress == '" + std::string(kTestUser1) + "'"); | 59 ".user.emailAddress == '" + std::string(kTestUser1) + "'"); |
175 JSExpect("document.querySelectorAll('.pod:not(#user-pod-template)')[1]" | 60 JSExpect("document.querySelectorAll('.pod:not(#user-pod-template)')[1]" |
176 ".user.emailAddress == '" + std::string(kTestUser2) + "'"); | 61 ".user.emailAddress == '" + std::string(kTestUser2) + "'"); |
177 if (enable_test_screenshots_) { | 62 screenshot_testing_->RunScreenshotTesting("LoginUITest-LoginUIVisible"); |
178 animation_delay_handler.WaitUntilAnimationLoads(); | |
179 screenshot_tester.Run("LoginUITest-LoginUIVisible"); | |
180 } | |
181 } | 63 } |
182 | 64 |
183 IN_PROC_BROWSER_TEST_F(LoginUITest, PRE_InterruptedAutoStartEnrollment) { | 65 IN_PROC_BROWSER_TEST_F(LoginUITest, PRE_InterruptedAutoStartEnrollment) { |
184 StartupUtils::MarkOobeCompleted(); | 66 StartupUtils::MarkOobeCompleted(); |
185 PrefService* prefs = g_browser_process->local_state(); | 67 PrefService* prefs = g_browser_process->local_state(); |
186 prefs->SetBoolean(prefs::kDeviceEnrollmentAutoStart, true); | 68 prefs->SetBoolean(prefs::kDeviceEnrollmentAutoStart, true); |
187 } | 69 } |
188 | 70 |
189 // Tests that the default first screen is the network screen after OOBE | 71 // Tests that the default first screen is the network screen after OOBE |
190 // when auto enrollment is enabled and device is not yet enrolled. | 72 // when auto enrollment is enabled and device is not yet enrolled. |
191 IN_PROC_BROWSER_TEST_F(LoginUITest, InterruptedAutoStartEnrollment) { | 73 IN_PROC_BROWSER_TEST_F(LoginUITest, InterruptedAutoStartEnrollment) { |
192 OobeScreenWaiter(OobeDisplay::SCREEN_OOBE_NETWORK).Wait(); | 74 OobeScreenWaiter(OobeDisplay::SCREEN_OOBE_NETWORK).Wait(); |
193 } | 75 } |
194 | 76 |
195 } // namespace chromeos | 77 } // namespace chromeos |
OLD | NEW |