Home | History | Annotate | Download | only in login
      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 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SCREENSHOT_TESTING_MIXIN_H_
      6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SCREENSHOT_TESTING_MIXIN_H_
      7 
      8 #include <string>
      9 
     10 #include "base/command_line.h"
     11 #include "base/timer/timer.h"
     12 #include "chrome/browser/chromeos/login/mixin_based_browser_test.h"
     13 #include "chrome/browser/chromeos/login/screenshot_tester.h"
     14 #include "content/public/test/browser_test_base.h"
     15 
     16 namespace chromeos {
     17 
     18 // Base mixin class for tests which support testing with screenshots.
     19 // Sets up everything required for taking screenshots.
     20 // Provides functionality to deal with animation load: screenshots
     21 // should be taken only when all the animation is loaded.
     22 class ScreenshotTestingMixin : public MixinBasedBrowserTest::Mixin {
     23  public:
     24   ScreenshotTestingMixin();
     25   virtual ~ScreenshotTestingMixin();
     26 
     27   // Override from BrowsertestBase::Mixin.
     28   virtual void SetUpInProcessBrowserTestFixture() OVERRIDE;
     29 
     30   // Override from BrowsertestBase::Mixin.
     31   virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE;
     32 
     33   // Runs screenshot testing if it is turned on by command line switches.
     34   void RunScreenshotTesting(const std::string& test_name);
     35 
     36  private:
     37   // It turns out that it takes some more time for the animation
     38   // to finish loading even after all the notifications have been sent.
     39   // That happens due to some properties of compositor.
     40   // This method should be used after getting all the necessary notifications
     41   // to wait for the actual load of animation.
     42   void SynchronizeAnimationLoadWithCompositor();
     43 
     44   // This method exists only because of the current implementation of
     45   // SynchronizeAnimationLoadWithCompositor.
     46   void HandleAnimationLoad();
     47 
     48   // Required for current implementation of
     49   // SynchronizeAnimationLoadWithCompositor()
     50   base::OneShotTimer<ScreenshotTestingMixin> timer_;
     51   base::Closure animation_waiter_quitter_;
     52 
     53   // Is true if testing with screenshots is turned on with all proper switches.
     54   bool enable_test_screenshots_;
     55 
     56   // |screenshot_tester_ | does everything connected with taking, loading and
     57   // comparing screenshots
     58   ScreenshotTester screenshot_tester_;
     59 };
     60 
     61 }  // namespace chromeos
     62 
     63 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_SCREENSHOT_TESTING_MIXIN_H_
     64