Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/login/screenshot_comparing_admixture.h" | |
| 6 | |
| 7 #include "chrome/browser/browser_process.h" | |
| 8 #include "chrome/browser/chrome_notification_types.h" | |
| 9 #include "content/public/browser/browser_thread.h" | |
| 10 #include "content/public/browser/notification_service.h" | |
| 11 #include "content/public/browser/notification_types.h" | |
| 12 #include "ui/compositor/compositor_switches.h" | |
| 13 | |
| 14 namespace chromeos { | |
| 15 | |
| 16 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.
| |
| 17 } | |
| 18 | |
| 19 ScreenshotComparingAdmixture::~ScreenshotComparingAdmixture() { | |
| 20 } | |
| 21 | |
| 22 void ScreenshotComparingAdmixture::SetUpInProcessBrowserTestFixture() { | |
| 23 enable_test_screenshots_ = screenshot_tester_.TryInitialize(); | |
| 24 } | |
| 25 | |
| 26 void ScreenshotComparingAdmixture::SetUpCommandLine( | |
| 27 base::CommandLine* command_line) { | |
| 28 if (enable_test_screenshots_) { | |
| 29 command_line->AppendSwitch(switches::kEnablePixelOutputInTests); | |
| 30 command_line->AppendSwitch(switches::kUIEnableImplSidePainting); | |
| 31 } | |
| 32 } | |
| 33 | |
| 34 void ScreenshotComparingAdmixture::SetUpOnMainThread() { | |
| 35 if (enable_test_screenshots_) { | |
| 36 InitializeAnimationHandler(); | |
| 37 } | |
| 38 } | |
| 39 | |
| 40 void ScreenshotComparingAdmixture::WaitUntilAnimationLoads() { | |
| 41 if (!IsAnimationLoaded()) { | |
| 42 base::RunLoop animation_waiter; | |
| 43 PrepareForAnimationWaiting(animation_waiter.QuitClosure()); | |
| 44 animation_waiter.Run(); | |
| 45 } | |
| 46 SynchronizeAnimationLoadWithCompositor(); | |
| 47 } | |
| 48 | |
| 49 void ScreenshotComparingAdmixture::RunScreenshotTesting( | |
| 50 const std::string& test_name) { | |
| 51 if (enable_test_screenshots_) { | |
| 52 WaitUntilAnimationLoads(); | |
| 53 screenshot_tester_.Run(test_name); | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 void ScreenshotComparingAdmixture::PrepareForAnimationWaiting( | |
| 58 const base::Closure& quitter) { | |
| 59 waiter_loop_is_on_ = true; | |
| 60 animation_waiter_quitter_ = quitter; | |
| 61 } | |
| 62 | |
| 63 // Current implementation is a mockup. | |
| 64 // It simply waits for 5 seconds, assuming that this time is enough for | |
| 65 // animation to load completely. | |
| 66 // TODO(elizavetai): Replace this temporary hack with getting a | |
| 67 // valid notification from compositor. | |
| 68 void ScreenshotComparingAdmixture::SynchronizeAnimationLoadWithCompositor() { | |
| 69 base::RunLoop waiter; | |
| 70 animation_waiter_quitter_ = waiter.QuitClosure(); | |
| 71 timer_.Start(FROM_HERE, | |
| 72 base::TimeDelta::FromSeconds(5), | |
| 73 this, | |
| 74 &ScreenshotComparingAdmixture::HandleAnimationLoad); | |
| 75 waiter.Run(); | |
| 76 } | |
| 77 | |
| 78 void ScreenshotComparingAdmixture::HandleAnimationLoad() { | |
| 79 timer_.Stop(); | |
| 80 content::BrowserThread::PostTask( | |
| 81 content::BrowserThread::UI, FROM_HERE, animation_waiter_quitter_); | |
| 82 } | |
| 83 | |
| 84 } // namespace chromeos | |
| OLD | NEW |