Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: chrome/browser/chromeos/login/login_ui_browsertest.cc

Issue 441263002: Generalizing architecture for screenshot testing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rewritten using BrowserTestBase::Admixture Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_comparing_admixture.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 }
dzhioev (left Google) 2014/08/25 17:01:19 Either add new line here or remove empty line abov
Lisa Ignatyeva 2014/08/25 17:57:54 Done.
29 30
30 // A class that provides a way to wait until all the animation 31 // Abstract class ScreenshotComparingTest is overriden to
31 // has loaded and is properly shown on the screen. 32 // handle properly all the animation specific for LoginUITest.
32 class AnimationDelayHandler : public content::NotificationObserver { 33 class ScreenshotComparingAdmixtureForLoginUIVisible
34 : public ScreenshotComparingAdmixture {
33 public: 35 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, 36 virtual void Observe(int type,
42 const content::NotificationSource& source, 37 const content::NotificationSource& source,
43 const content::NotificationDetails& details) OVERRIDE; 38 const content::NotificationDetails& details) OVERRIDE;
44 39
45 // This method checks if animation is loaded, and, if not, 40 protected:
46 // waits until it is loaded and properly shown on the screen. 41 virtual void InitializeAnimationHandler() OVERRIDE;
47 void WaitUntilAnimationLoads(); 42 virtual bool IsAnimationLoaded() OVERRIDE;
48 43
49 private: 44 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_; 45 bool login_or_lock_webui_visible_;
70 base::Closure animation_waiter_quitter_;
71 content::NotificationRegistrar registrar_;
72 }; 46 };
73 47
74 } // anonymous namespace 48 void ScreenshotComparingAdmixtureForLoginUIVisible::Observe(
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, 49 int type,
93 const content::NotificationSource& source, 50 const content::NotificationSource& source,
94 const content::NotificationDetails& details) { 51 const content::NotificationDetails& details) {
95 if (chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE == type) { 52 if (chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE == type) {
96 login_or_lock_webui_visible_ = true; 53 login_or_lock_webui_visible_ = true;
97 registrar_.Remove(this, 54 registrar_.Remove(this,
98 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, 55 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
99 content::NotificationService::AllSources()); 56 content::NotificationService::AllSources());
100 } 57 }
101 if (waiter_loop_is_on_ && IsAnimationLoaded()) { 58 if (waiter_loop_is_on_ && IsAnimationLoaded()) {
102 content::BrowserThread::PostTask( 59 content::BrowserThread::PostTask(
103 content::BrowserThread::UI, FROM_HERE, animation_waiter_quitter_); 60 content::BrowserThread::UI, FROM_HERE, animation_waiter_quitter_);
104 } 61 }
105 } 62 }
106 63
107 void AnimationDelayHandler::InitializeForWaiting(const base::Closure& quitter) { 64 void
108 waiter_loop_is_on_ = true; 65 ScreenshotComparingAdmixtureForLoginUIVisible::InitializeAnimationHandler() {
109 animation_waiter_quitter_ = quitter; 66 waiter_loop_is_on_ = false;
67 registrar_.Add(this,
68 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
69 content::NotificationService::AllSources());
110 } 70 }
111 71
112 void AnimationDelayHandler::HandleAnimationLoad() { 72 bool ScreenshotComparingAdmixtureForLoginUIVisible::IsAnimationLoaded() {
113 timer_.Stop(); 73 return login_or_lock_webui_visible_;
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 } 74 }
141 75
142 class LoginUITest : public chromeos::LoginManagerTest { 76 class LoginUITest : public chromeos::LoginManagerTest {
143 public: 77 public:
144 bool enable_test_screenshots_; 78 bool enable_test_screenshots_;
145 LoginUITest() : LoginManagerTest(false) {} 79 LoginUITest() : LoginManagerTest(false) {
146 virtual ~LoginUITest() {} 80 screenshot_comparing = new ScreenshotComparingAdmixtureForLoginUIVisible;
147 virtual void SetUpOnMainThread() OVERRIDE { 81 AddAdmixture(screenshot_comparing);
148 enable_test_screenshots_ = screenshot_tester.TryInitialize();
149 if (enable_test_screenshots_) {
150 animation_delay_handler.Initialize();
151 }
152 LoginManagerTest::SetUpOnMainThread();
153 } 82 }
154 83
84 virtual ~LoginUITest() {}
85
155 protected: 86 protected:
156 AnimationDelayHandler animation_delay_handler; 87 ScreenshotComparingAdmixtureForLoginUIVisible* screenshot_comparing;
dzhioev (left Google) 2014/08/25 17:01:19 screenshot_comparing_;
Lisa Ignatyeva 2014/08/25 17:57:54 Done.
157 ScreenshotTester screenshot_tester;
158 }; 88 };
159 89
160 IN_PROC_BROWSER_TEST_F(LoginUITest, PRE_LoginUIVisible) { 90 IN_PROC_BROWSER_TEST_F(LoginUITest, PRE_LoginUIVisible) {
161 RegisterUser(kTestUser1); 91 RegisterUser(kTestUser1);
162 RegisterUser(kTestUser2); 92 RegisterUser(kTestUser2);
163 StartupUtils::MarkOobeCompleted(); 93 StartupUtils::MarkOobeCompleted();
164 } 94 }
165 95
166 // Verifies basic login UI properties. 96 // Verifies basic login UI properties.
167 IN_PROC_BROWSER_TEST_F(LoginUITest, LoginUIVisible) { 97 IN_PROC_BROWSER_TEST_F(LoginUITest, LoginUIVisible) {
168 JSExpect("!!document.querySelector('#account-picker')"); 98 JSExpect("!!document.querySelector('#account-picker')");
169 JSExpect("!!document.querySelector('#pod-row')"); 99 JSExpect("!!document.querySelector('#pod-row')");
170 JSExpect( 100 JSExpect(
171 "document.querySelectorAll('.pod:not(#user-pod-template)').length == 2"); 101 "document.querySelectorAll('.pod:not(#user-pod-template)').length == 2");
172 102
173 JSExpect("document.querySelectorAll('.pod:not(#user-pod-template)')[0]" 103 JSExpect("document.querySelectorAll('.pod:not(#user-pod-template)')[0]"
174 ".user.emailAddress == '" + std::string(kTestUser1) + "'"); 104 ".user.emailAddress == '" + std::string(kTestUser1) + "'");
175 JSExpect("document.querySelectorAll('.pod:not(#user-pod-template)')[1]" 105 JSExpect("document.querySelectorAll('.pod:not(#user-pod-template)')[1]"
176 ".user.emailAddress == '" + std::string(kTestUser2) + "'"); 106 ".user.emailAddress == '" + std::string(kTestUser2) + "'");
177 if (enable_test_screenshots_) { 107 screenshot_comparing->RunScreenshotTesting("LoginUITest-LoginUIVisible");
178 animation_delay_handler.WaitUntilAnimationLoads();
179 screenshot_tester.Run("LoginUITest-LoginUIVisible");
180 }
181 } 108 }
182 109
183 IN_PROC_BROWSER_TEST_F(LoginUITest, PRE_InterruptedAutoStartEnrollment) { 110 IN_PROC_BROWSER_TEST_F(LoginUITest, PRE_InterruptedAutoStartEnrollment) {
184 StartupUtils::MarkOobeCompleted(); 111 StartupUtils::MarkOobeCompleted();
185 PrefService* prefs = g_browser_process->local_state(); 112 PrefService* prefs = g_browser_process->local_state();
186 prefs->SetBoolean(prefs::kDeviceEnrollmentAutoStart, true); 113 prefs->SetBoolean(prefs::kDeviceEnrollmentAutoStart, true);
187 } 114 }
188 115
189 // Tests that the default first screen is the network screen after OOBE 116 // Tests that the default first screen is the network screen after OOBE
190 // when auto enrollment is enabled and device is not yet enrolled. 117 // when auto enrollment is enabled and device is not yet enrolled.
191 IN_PROC_BROWSER_TEST_F(LoginUITest, InterruptedAutoStartEnrollment) { 118 IN_PROC_BROWSER_TEST_F(LoginUITest, InterruptedAutoStartEnrollment) {
192 OobeScreenWaiter(OobeDisplay::SCREEN_OOBE_NETWORK).Wait(); 119 OobeScreenWaiter(OobeDisplay::SCREEN_OOBE_NETWORK).Wait();
193 } 120 }
194 121
195 } // namespace chromeos 122 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698