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

Unified 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: removed debug output Created 6 years, 3 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_testing_mixin.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 12c91c489507bb121867a5f862d1821fabe654d3..73620226391895b1de560e63edcf7bdc221b3ed1 100644
--- a/chrome/browser/chromeos/login/login_ui_browsertest.cc
+++ b/chrome/browser/chromeos/login/login_ui_browsertest.cc
@@ -8,7 +8,7 @@
#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/screenshot_testing_mixin.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"
@@ -27,134 +27,19 @@ 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();
- }
- LoginManagerTest::SetUpOnMainThread();
+ LoginUITest() : LoginManagerTest(false) {
+ screenshot_testing_ = new ScreenshotTestingMixin;
+ AddMixin(screenshot_testing_);
}
+ virtual ~LoginUITest() {}
protected:
- AnimationDelayHandler animation_delay_handler;
- ScreenshotTester screenshot_tester;
+ ScreenshotTestingMixin* screenshot_testing_;
};
IN_PROC_BROWSER_TEST_F(LoginUITest, PRE_LoginUIVisible) {
@@ -174,10 +59,7 @@ 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");
- }
+ screenshot_testing_->RunScreenshotTesting("LoginUITest-LoginUIVisible");
}
IN_PROC_BROWSER_TEST_F(LoginUITest, PRE_InterruptedAutoStartEnrollment) {
« no previous file with comments | « no previous file | chrome/browser/chromeos/login/screenshot_testing_mixin.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698