Commit e9d0473a authored by elizavetai's avatar elizavetai Committed by Commit bot

Moving parts connected to screenshot testing from login_ui_browsertest.cc to...

Moving parts connected to screenshot testing from login_ui_browsertest.cc to separate files. Uses BrowserTestBase::Admixture added in https://codereview.chromium.org/468493003/.

BUG=395653

Review URL: https://codereview.chromium.org/441263002

Cr-Commit-Position: refs/heads/master@{#295964}
parent c6037c66
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/login/login_manager_test.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/startup_utils.h"
#include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h" #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h"
#include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
...@@ -27,134 +27,19 @@ namespace { ...@@ -27,134 +27,19 @@ namespace {
const char kTestUser1[] = "test-user1@gmail.com"; const char kTestUser1[] = "test-user1@gmail.com";
const char kTestUser2[] = "test-user2@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 { class LoginUITest : public chromeos::LoginManagerTest {
public: public:
bool enable_test_screenshots_; bool enable_test_screenshots_;
LoginUITest() : LoginManagerTest(false) {} LoginUITest() : LoginManagerTest(false) {
virtual ~LoginUITest() {} screenshot_testing_ = new ScreenshotTestingMixin;
virtual void SetUpOnMainThread() OVERRIDE { AddMixin(screenshot_testing_);
enable_test_screenshots_ = screenshot_tester.TryInitialize();
if (enable_test_screenshots_) {
animation_delay_handler.Initialize();
}
LoginManagerTest::SetUpOnMainThread();
} }
virtual ~LoginUITest() {}
protected: protected:
AnimationDelayHandler animation_delay_handler; ScreenshotTestingMixin* screenshot_testing_;
ScreenshotTester screenshot_tester;
}; };
IN_PROC_BROWSER_TEST_F(LoginUITest, PRE_LoginUIVisible) { IN_PROC_BROWSER_TEST_F(LoginUITest, PRE_LoginUIVisible) {
...@@ -174,10 +59,7 @@ IN_PROC_BROWSER_TEST_F(LoginUITest, LoginUIVisible) { ...@@ -174,10 +59,7 @@ IN_PROC_BROWSER_TEST_F(LoginUITest, LoginUIVisible) {
".user.emailAddress == '" + std::string(kTestUser1) + "'"); ".user.emailAddress == '" + std::string(kTestUser1) + "'");
JSExpect("document.querySelectorAll('.pod:not(#user-pod-template)')[1]" JSExpect("document.querySelectorAll('.pod:not(#user-pod-template)')[1]"
".user.emailAddress == '" + std::string(kTestUser2) + "'"); ".user.emailAddress == '" + std::string(kTestUser2) + "'");
if (enable_test_screenshots_) { screenshot_testing_->RunScreenshotTesting("LoginUITest-LoginUIVisible");
animation_delay_handler.WaitUntilAnimationLoads();
screenshot_tester.Run("LoginUITest-LoginUIVisible");
}
} }
IN_PROC_BROWSER_TEST_F(LoginUITest, PRE_InterruptedAutoStartEnrollment) { IN_PROC_BROWSER_TEST_F(LoginUITest, PRE_InterruptedAutoStartEnrollment) {
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/login/screenshot_testing_mixin.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
#include "ui/compositor/compositor_switches.h"
namespace chromeos {
ScreenshotTestingMixin::ScreenshotTestingMixin() {
}
ScreenshotTestingMixin::~ScreenshotTestingMixin() {
}
void ScreenshotTestingMixin::SetUpInProcessBrowserTestFixture() {
enable_test_screenshots_ = screenshot_tester_.TryInitialize();
}
void ScreenshotTestingMixin::SetUpCommandLine(base::CommandLine* command_line) {
if (enable_test_screenshots_) {
command_line->AppendSwitch(switches::kEnablePixelOutputInTests);
command_line->AppendSwitch(switches::kUIEnableImplSidePainting);
}
}
void ScreenshotTestingMixin::RunScreenshotTesting(
const std::string& test_name) {
if (enable_test_screenshots_) {
SynchronizeAnimationLoadWithCompositor();
screenshot_tester_.Run(test_name);
}
}
// 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 ScreenshotTestingMixin::SynchronizeAnimationLoadWithCompositor() {
base::RunLoop waiter;
animation_waiter_quitter_ = waiter.QuitClosure();
timer_.Start(FROM_HERE,
base::TimeDelta::FromSeconds(5),
this,
&ScreenshotTestingMixin::HandleAnimationLoad);
waiter.Run();
}
void ScreenshotTestingMixin::HandleAnimationLoad() {
timer_.Stop();
content::BrowserThread::PostTask(
content::BrowserThread::UI, FROM_HERE, animation_waiter_quitter_);
}
} // namespace chromeos
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SCREENSHOT_TESTING_MIXIN_H_
#define CHROME_BROWSER_CHROMEOS_LOGIN_SCREENSHOT_TESTING_MIXIN_H_
#include <string>
#include "base/command_line.h"
#include "base/timer/timer.h"
#include "chrome/browser/chromeos/login/mixin_based_browser_test.h"
#include "chrome/browser/chromeos/login/screenshot_tester.h"
#include "content/public/test/browser_test_base.h"
namespace chromeos {
// Base mixin class for tests which support testing with screenshots.
// Sets up everything required for taking screenshots.
// Provides functionality to deal with animation load: screenshots
// should be taken only when all the animation is loaded.
class ScreenshotTestingMixin : public MixinBasedBrowserTest::Mixin {
public:
ScreenshotTestingMixin();
virtual ~ScreenshotTestingMixin();
// Override from BrowsertestBase::Mixin.
virtual void SetUpInProcessBrowserTestFixture() OVERRIDE;
// Override from BrowsertestBase::Mixin.
virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE;
// Runs screenshot testing if it is turned on by command line switches.
void RunScreenshotTesting(const std::string& test_name);
private:
// 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();
// Required for current implementation of
// SynchronizeAnimationLoadWithCompositor()
base::OneShotTimer<ScreenshotTestingMixin> timer_;
base::Closure animation_waiter_quitter_;
// Is true if testing with screenshots is turned on with all proper switches.
bool enable_test_screenshots_;
// |screenshot_tester_ | does everything connected with taking, loading and
// comparing screenshots
ScreenshotTester screenshot_tester_;
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_LOGIN_SCREENSHOT_TESTING_MIXIN_H_
...@@ -309,6 +309,8 @@ ...@@ -309,6 +309,8 @@
'browser/chromeos/login/screenshot_tester.cc', 'browser/chromeos/login/screenshot_tester.cc',
'browser/chromeos/login/mixin_based_browser_test.h', 'browser/chromeos/login/mixin_based_browser_test.h',
'browser/chromeos/login/mixin_based_browser_test.cc', 'browser/chromeos/login/mixin_based_browser_test.cc',
'browser/chromeos/login/screenshot_testing_mixin.h',
'browser/chromeos/login/screenshot_testing_mixin.cc',
'browser/chromeos/login/users/wallpaper/wallpaper_manager_browsertest.cc', 'browser/chromeos/login/users/wallpaper/wallpaper_manager_browsertest.cc',
'browser/chromeos/login/users/wallpaper/wallpaper_manager_test_utils.cc', 'browser/chromeos/login/users/wallpaper/wallpaper_manager_test_utils.cc',
'browser/chromeos/login/users/wallpaper/wallpaper_manager_test_utils.h', 'browser/chromeos/login/users/wallpaper/wallpaper_manager_test_utils.h',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment