Chromium Code Reviews| Index: chrome/browser/chromeos/login/screenshot_comparing_admixture.cc |
| diff --git a/chrome/browser/chromeos/login/screenshot_comparing_admixture.cc b/chrome/browser/chromeos/login/screenshot_comparing_admixture.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ebf865a7ec82aa9380b9a85e91274f26deabcae2 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/login/screenshot_comparing_admixture.cc |
| @@ -0,0 +1,84 @@ |
| +// 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_comparing_admixture.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 { |
| + |
| +ScreenshotComparingAdmixture::ScreenshotComparingAdmixture() : registrar_() { |
|
dzhioev (left Google)
2014/08/25 17:01:19
No need for |registrar_| explicit initialization.
Lisa Ignatyeva
2014/08/25 17:57:54
Done.
|
| +} |
| + |
| +ScreenshotComparingAdmixture::~ScreenshotComparingAdmixture() { |
| +} |
| + |
| +void ScreenshotComparingAdmixture::SetUpInProcessBrowserTestFixture() { |
| + enable_test_screenshots_ = screenshot_tester_.TryInitialize(); |
| +} |
| + |
| +void ScreenshotComparingAdmixture::SetUpCommandLine( |
| + base::CommandLine* command_line) { |
| + if (enable_test_screenshots_) { |
| + command_line->AppendSwitch(switches::kEnablePixelOutputInTests); |
| + command_line->AppendSwitch(switches::kUIEnableImplSidePainting); |
| + } |
| +} |
| + |
| +void ScreenshotComparingAdmixture::SetUpOnMainThread() { |
| + if (enable_test_screenshots_) { |
| + InitializeAnimationHandler(); |
| + } |
| +} |
| + |
| +void ScreenshotComparingAdmixture::WaitUntilAnimationLoads() { |
| + if (!IsAnimationLoaded()) { |
| + base::RunLoop animation_waiter; |
| + PrepareForAnimationWaiting(animation_waiter.QuitClosure()); |
| + animation_waiter.Run(); |
| + } |
| + SynchronizeAnimationLoadWithCompositor(); |
| +} |
| + |
| +void ScreenshotComparingAdmixture::RunScreenshotTesting( |
| + const std::string& test_name) { |
| + if (enable_test_screenshots_) { |
| + WaitUntilAnimationLoads(); |
| + screenshot_tester_.Run(test_name); |
| + } |
| +} |
| + |
| +void ScreenshotComparingAdmixture::PrepareForAnimationWaiting( |
| + const base::Closure& quitter) { |
| + waiter_loop_is_on_ = true; |
| + animation_waiter_quitter_ = 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 ScreenshotComparingAdmixture::SynchronizeAnimationLoadWithCompositor() { |
| + base::RunLoop waiter; |
| + animation_waiter_quitter_ = waiter.QuitClosure(); |
| + timer_.Start(FROM_HERE, |
| + base::TimeDelta::FromSeconds(5), |
| + this, |
| + &ScreenshotComparingAdmixture::HandleAnimationLoad); |
| + waiter.Run(); |
| +} |
| + |
| +void ScreenshotComparingAdmixture::HandleAnimationLoad() { |
| + timer_.Stop(); |
| + content::BrowserThread::PostTask( |
| + content::BrowserThread::UI, FROM_HERE, animation_waiter_quitter_); |
| +} |
| + |
| +} // namespace chromeos |