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

Unified Diff: chrome/browser/chromeos/login/screenshot_test.cc

Issue 441263002: Generalizing architecture for screenshot testing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: commented line removed Created 6 years, 4 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
Index: chrome/browser/chromeos/login/screenshot_test.cc
diff --git a/chrome/browser/chromeos/login/screenshot_test.cc b/chrome/browser/chromeos/login/screenshot_test.cc
new file mode 100644
index 0000000000000000000000000000000000000000..cfc2e6cf41e6d2829570ea793db7cdfc880c3a32
--- /dev/null
+++ b/chrome/browser/chromeos/login/screenshot_test.cc
@@ -0,0 +1,92 @@
+// 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_test.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 {
+
+ScreenshotTest::ScreenshotTest() : LoginManagerTest(false) {
+ waiter_loop_is_on_ = false;
+}
dzhioev (left Google) 2014/08/07 11:23:55 Add a new line.
+ScreenshotTest::~ScreenshotTest() {
+}
+
+void ScreenshotTest::SetUpOnMainThread() {
+ enable_test_screenshots_ = screenshot_tester.TryInitialize();
+ if (enable_test_screenshots_) {
+ InitializeAnimationHandler();
+ }
+ LoginManagerTest::SetUpOnMainThread();
+}
+
+void ScreenshotTest::SetUpCommandLine(base::CommandLine* command_line) {
+ LoginManagerTest::SetUpCommandLine(command_line);
+ if (enable_test_screenshots_) {
+ command_line->AppendSwitch(switches::kEnablePixelOutputInTests);
+ command_line->AppendSwitch(switches::kUIEnableImplSidePainting);
+ }
+}
+
+void ScreenshotTest::Observe(int type,
dzhioev (left Google) 2014/08/07 11:23:55 Why do we need this method?
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+}
+
+void ScreenshotTest::WaitUntilAnimationLoads() {
+ if (!IsAnimationLoaded()) {
+ base::RunLoop animation_waiter;
+ PrepareForAnimationWaiting(animation_waiter.QuitClosure());
+ animation_waiter.Run();
+ }
+ SynchronizeAnimationLoadWithCompositor();
+}
+
+void ScreenshotTest::InitializeAnimationHandler() {
+}
+
+void ScreenshotTest::RunScreenshotTesting(const std::string& test_name) {
+ if (enable_test_screenshots_) {
+ WaitUntilAnimationLoads();
+ screenshot_tester.Run(test_name);
+ }
+}
+
+bool ScreenshotTest::IsAnimationLoaded() {
+ return true;
+}
+
+void ScreenshotTest::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 ScreenshotTest::SynchronizeAnimationLoadWithCompositor() {
+ base::RunLoop waiter;
+ animation_waiter_quitter_ = waiter.QuitClosure();
+ timer_.Start(FROM_HERE,
+ base::TimeDelta::FromSeconds(5),
+ this,
+ &ScreenshotTest::HandleAnimationLoad);
+ waiter.Run();
+}
+
+void ScreenshotTest::HandleAnimationLoad() {
+ timer_.Stop();
+ content::BrowserThread::PostTask(
+ content::BrowserThread::UI, FROM_HERE, animation_waiter_quitter_);
+}
+
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698