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