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

Unified 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: last DCHECK replaced with DCHECK_CURRENTLY_ON 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/chromeos/login/screenshot_tester.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/login/login_ui_browsertest.cc
diff --git a/chrome/browser/chromeos/login/login_ui_browsertest.cc b/chrome/browser/chromeos/login/login_ui_browsertest.cc
index 4f545ed00681ad34b67e7ec3bb894d7bf469e614..29bf936ed14a4c7ae22a5748470f2863c139b327 100644
--- a/chrome/browser/chromeos/login/login_ui_browsertest.cc
+++ b/chrome/browser/chromeos/login/login_ui_browsertest.cc
@@ -2,12 +2,23 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/command_line.h"
#include "base/prefs/pref_service.h"
+#include "base/timer/timer.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/login/login_manager_test.h"
+#include "chrome/browser/chromeos/login/screenshot_tester.h"
#include "chrome/browser/chromeos/login/startup_utils.h"
#include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h"
+#include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
#include "chrome/common/pref_names.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/notification_observer.h"
+#include "content/public/browser/notification_registrar.h"
+#include "content/public/browser/notification_service.h"
+#include "content/public/browser/notification_types.h"
+#include "ui/compositor/compositor_switches.h"
namespace chromeos {
@@ -16,12 +27,136 @@ namespace {
const char kTestUser1[] = "test-user1@gmail.com";
const char kTestUser2[] = "test-user2@gmail.com";
+// A class that provides a way to wait until all the animation
+// has loaded and is properly shown on the screen.
+class AnimationDelayHandler : public content::NotificationObserver {
+ public:
+ AnimationDelayHandler();
+
+ // Should be run as early as possible on order not to miss notifications.
+ // It seems though that it can't be moved to constructor(?).
+ void Initialize();
+
+ // Override from content::NotificationObserver.
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) OVERRIDE;
+
+ // This method checks if animation is loaded, and, if not,
+ // waits until it is loaded and properly shown on the screen.
+ void WaitUntilAnimationLoads();
+
+ private:
+ void InitializeForWaiting(const base::Closure& quitter);
+
+ // It turns out that it takes some more time for the animation
+ // to finish loading even after all the notifications have been sent.
+ // That happens due to some properties of compositor.
+ // This method should be used after getting all the necessary notifications
+ // to wait for the actual load of animation.
+ void SynchronizeAnimationLoadWithCompositor();
+
+ // This method exists only because of the current implementation of
+ // SynchronizeAnimationLoadWithCompositor.
+ void HandleAnimationLoad();
+
+ // Returns true if, according to the notificatons received, animation has
+ // finished loading by now.
+ bool IsAnimationLoaded();
+
+ base::OneShotTimer<AnimationDelayHandler> timer_;
+ bool waiter_loop_is_on_;
+ bool login_or_lock_webui_visible_;
+ base::Closure animation_waiter_quitter_;
+ content::NotificationRegistrar registrar_;
+};
+
} // anonymous namespace
+AnimationDelayHandler::AnimationDelayHandler()
+ : waiter_loop_is_on_(false), login_or_lock_webui_visible_(false) {
+}
+
+void AnimationDelayHandler::Initialize() {
+ waiter_loop_is_on_ = false;
+ registrar_.Add(this,
+ chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
+ content::NotificationService::AllSources());
+}
+
+bool AnimationDelayHandler::IsAnimationLoaded() {
+ return login_or_lock_webui_visible_;
+}
+
+void AnimationDelayHandler::Observe(
+ int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ if (chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE == type) {
+ login_or_lock_webui_visible_ = true;
+ registrar_.Remove(this,
+ chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
+ content::NotificationService::AllSources());
+ }
+ if (waiter_loop_is_on_ && IsAnimationLoaded()) {
+ content::BrowserThread::PostTask(
+ content::BrowserThread::UI, FROM_HERE, animation_waiter_quitter_);
+ }
+}
+
+void AnimationDelayHandler::InitializeForWaiting(const base::Closure& quitter) {
+ waiter_loop_is_on_ = true;
+ animation_waiter_quitter_ = quitter;
+}
+
+void AnimationDelayHandler::HandleAnimationLoad() {
+ timer_.Stop();
+ content::BrowserThread::PostTask(
+ content::BrowserThread::UI, FROM_HERE, animation_waiter_quitter_);
+}
+
+// Current implementation is a mockup.
+// It simply waits for 5 seconds, assuming that this time is enough for
+// animation to load completely.
+// TODO(elizavetai): Replace this temporary hack with getting a
+// valid notification from compositor.
+void AnimationDelayHandler::SynchronizeAnimationLoadWithCompositor() {
+ base::RunLoop waiter;
+ animation_waiter_quitter_ = waiter.QuitClosure();
+ timer_.Start(FROM_HERE,
+ base::TimeDelta::FromSeconds(5),
+ this,
+ &AnimationDelayHandler::HandleAnimationLoad);
+ waiter.Run();
+}
+
+void AnimationDelayHandler::WaitUntilAnimationLoads() {
+ if (!IsAnimationLoaded()) {
+ base::RunLoop animation_waiter;
+ InitializeForWaiting(animation_waiter.QuitClosure());
+ animation_waiter.Run();
+ }
+ SynchronizeAnimationLoadWithCompositor();
+}
+
class LoginUITest : public chromeos::LoginManagerTest {
public:
+ bool enable_test_screenshots_;
LoginUITest() : LoginManagerTest(false) {}
virtual ~LoginUITest() {}
+ virtual void SetUpOnMainThread() OVERRIDE {
+ enable_test_screenshots_ = screenshot_tester.TryInitialize();
+ if (enable_test_screenshots_) {
+ animation_delay_handler.Initialize();
+ } else {
+ LOG(WARNING) << "Screenshots will not be taken";
+ }
+ LoginManagerTest::SetUpOnMainThread();
+ }
+
+ protected:
+ AnimationDelayHandler animation_delay_handler;
+ ScreenshotTester screenshot_tester;
};
IN_PROC_BROWSER_TEST_F(LoginUITest, PRE_LoginUIVisible) {
@@ -41,11 +176,14 @@ IN_PROC_BROWSER_TEST_F(LoginUITest, LoginUIVisible) {
".user.emailAddress == '" + std::string(kTestUser1) + "'");
JSExpect("document.querySelectorAll('.pod:not(#user-pod-template)')[1]"
".user.emailAddress == '" + std::string(kTestUser2) + "'");
+ if (enable_test_screenshots_) {
+ animation_delay_handler.WaitUntilAnimationLoads();
+ screenshot_tester.Run("LoginUITest-LoginUIVisible");
+ }
}
IN_PROC_BROWSER_TEST_F(LoginUITest, PRE_InterruptedAutoStartEnrollment) {
StartupUtils::MarkOobeCompleted();
-
PrefService* prefs = g_browser_process->local_state();
prefs->SetBoolean(prefs::kDeviceEnrollmentAutoStart, true);
}
« no previous file with comments | « no previous file | chrome/browser/chromeos/login/screenshot_tester.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698