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

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

Issue 405093003: Taking screenshots while running a test (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added namespace chromeos & removed golden_screenshot_path_ field from ScreenshotTester Created 6 years, 5 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/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_, login_or_lock_webui_visible_;
69 base::Closure animation_waiter_quitter_;
70 content::NotificationRegistrar registrar_;
71 };
72
19 } // anonymous namespace 73 } // anonymous namespace
20 74
75 AnimationDelayHandler::AnimationDelayHandler()
76 : waiter_loop_is_on_(false), login_or_lock_webui_visible_(false) {
77 }
78
79 void AnimationDelayHandler::Initialize() {
80 waiter_loop_is_on_ = false;
81 registrar_.Add(this,
82 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
83 content::NotificationService::AllSources());
84 }
85
86 bool AnimationDelayHandler::IsAnimationLoaded() {
87 return login_or_lock_webui_visible_;
88 }
89
90 void AnimationDelayHandler::Observe(
91 int type,
92 const content::NotificationSource& source,
93 const content::NotificationDetails& details) {
94 if (chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE == type) {
95 login_or_lock_webui_visible_ = true;
96 registrar_.Remove(this,
97 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
98 content::NotificationService::AllSources());
99 }
100 if (waiter_loop_is_on_ && IsAnimationLoaded()) {
101 content::BrowserThread::PostTask(
102 content::BrowserThread::UI, FROM_HERE, animation_waiter_quitter_);
103 }
104 }
105
106 void AnimationDelayHandler::InitializeForWaiting(const base::Closure& quitter) {
107 waiter_loop_is_on_ = true;
108 animation_waiter_quitter_ = quitter;
109 }
110
111 void AnimationDelayHandler::HandleAnimationLoad() {
112 timer_.Stop();
113 content::BrowserThread::PostTask(
114 content::BrowserThread::UI, FROM_HERE, animation_waiter_quitter_);
115 }
116
117 // Current implementation is a mockup.
118 // It simply waits for 5 seconds, assuming that this time is enough for
119 // animation to load completely.
120 // TODO(elizavetai): Replace this temporary hack with getting a
121 // valid notification from compositor.
122 void AnimationDelayHandler::SynchronizeAnimationLoadWithCompositor() {
123 base::RunLoop waiter;
124 animation_waiter_quitter_ = waiter.QuitClosure();
125 timer_.Start(FROM_HERE,
126 base::TimeDelta::FromSeconds(5),
127 this,
128 &AnimationDelayHandler::HandleAnimationLoad);
129 waiter.Run();
130 }
131
132 void AnimationDelayHandler::WaitUntilAnimationLoads() {
133 if (!IsAnimationLoaded()) {
134 base::RunLoop animation_waiter;
135 InitializeForWaiting(animation_waiter.QuitClosure());
136 animation_waiter.Run();
137 }
138 SynchronizeAnimationLoadWithCompositor();
139 }
140
21 class LoginUITest : public chromeos::LoginManagerTest { 141 class LoginUITest : public chromeos::LoginManagerTest {
22 public: 142 public:
143 bool enable_test_screenshots_;
23 LoginUITest() : LoginManagerTest(false) {} 144 LoginUITest() : LoginManagerTest(false) {}
24 virtual ~LoginUITest() {} 145 virtual ~LoginUITest() {}
146 virtual void SetUpOnMainThread() OVERRIDE {
147 enable_test_screenshots_ = screenshot_tester.TryInitialize();
148 if (enable_test_screenshots_) {
ygorshenin1 2014/07/21 16:38:43 nit: you could get rid of curly braces in both bra
Lisa Ignatyeva 2014/07/21 16:52:39 I'd prefer keeping them both. As I understand, it'
149 animation_delay_handler.Initialize();
150 } else {
151 LOG(WARNING) << "Screenshots will not be taken";
152 }
153 LoginManagerTest::SetUpOnMainThread();
154 }
155
156 protected:
157 AnimationDelayHandler animation_delay_handler;
158 ScreenshotTester screenshot_tester;
25 }; 159 };
26 160
27 IN_PROC_BROWSER_TEST_F(LoginUITest, PRE_LoginUIVisible) { 161 IN_PROC_BROWSER_TEST_F(LoginUITest, PRE_LoginUIVisible) {
28 RegisterUser(kTestUser1); 162 RegisterUser(kTestUser1);
29 RegisterUser(kTestUser2); 163 RegisterUser(kTestUser2);
30 StartupUtils::MarkOobeCompleted(); 164 StartupUtils::MarkOobeCompleted();
31 } 165 }
32 166
33 // Verifies basic login UI properties. 167 // Verifies basic login UI properties.
34 IN_PROC_BROWSER_TEST_F(LoginUITest, LoginUIVisible) { 168 IN_PROC_BROWSER_TEST_F(LoginUITest, LoginUIVisible) {
35 JSExpect("!!document.querySelector('#account-picker')"); 169 JSExpect("!!document.querySelector('#account-picker')");
36 JSExpect("!!document.querySelector('#pod-row')"); 170 JSExpect("!!document.querySelector('#pod-row')");
37 JSExpect( 171 JSExpect(
38 "document.querySelectorAll('.pod:not(#user-pod-template)').length == 2"); 172 "document.querySelectorAll('.pod:not(#user-pod-template)').length == 2");
39 173
40 JSExpect("document.querySelectorAll('.pod:not(#user-pod-template)')[0]" 174 JSExpect("document.querySelectorAll('.pod:not(#user-pod-template)')[0]"
41 ".user.emailAddress == '" + std::string(kTestUser1) + "'"); 175 ".user.emailAddress == '" + std::string(kTestUser1) + "'");
42 JSExpect("document.querySelectorAll('.pod:not(#user-pod-template)')[1]" 176 JSExpect("document.querySelectorAll('.pod:not(#user-pod-template)')[1]"
43 ".user.emailAddress == '" + std::string(kTestUser2) + "'"); 177 ".user.emailAddress == '" + std::string(kTestUser2) + "'");
178 if (enable_test_screenshots_) {
179 animation_delay_handler.WaitUntilAnimationLoads();
180 screenshot_tester.Run("LoginUITest-LoginUIVisible");
181 }
44 } 182 }
45 183
46 IN_PROC_BROWSER_TEST_F(LoginUITest, PRE_InterruptedAutoStartEnrollment) { 184 IN_PROC_BROWSER_TEST_F(LoginUITest, PRE_InterruptedAutoStartEnrollment) {
47 StartupUtils::MarkOobeCompleted(); 185 StartupUtils::MarkOobeCompleted();
48
49 PrefService* prefs = g_browser_process->local_state(); 186 PrefService* prefs = g_browser_process->local_state();
50 prefs->SetBoolean(prefs::kDeviceEnrollmentAutoStart, true); 187 prefs->SetBoolean(prefs::kDeviceEnrollmentAutoStart, true);
51 } 188 }
52 189
53 // Tests that the default first screen is the network screen after OOBE 190 // Tests that the default first screen is the network screen after OOBE
54 // when auto enrollment is enabled and device is not yet enrolled. 191 // when auto enrollment is enabled and device is not yet enrolled.
55 IN_PROC_BROWSER_TEST_F(LoginUITest, InterruptedAutoStartEnrollment) { 192 IN_PROC_BROWSER_TEST_F(LoginUITest, InterruptedAutoStartEnrollment) {
56 OobeScreenWaiter(OobeDisplay::SCREEN_OOBE_NETWORK).Wait(); 193 OobeScreenWaiter(OobeDisplay::SCREEN_OOBE_NETWORK).Wait();
57 } 194 }
58 195
59 } // namespace chromeos 196 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/login/screenshot_tester.h » ('j') | chrome/browser/chromeos/login/screenshot_tester.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698