Home | History | Annotate | Download | only in test
      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 UI_COMPOSITOR_TEST_DRAW_WAITER_H_
      6 #define UI_COMPOSITOR_TEST_DRAW_WAITER_H_
      7 
      8 #include "base/run_loop.h"
      9 #include "ui/compositor/compositor_observer.h"
     10 
     11 class Compositor;
     12 
     13 namespace ui {
     14 
     15 // This is only to be used for test. It allows execution of other tasks on
     16 // the current message loop before the current task finishs (there is a
     17 // potential for re-entrancy).
     18 class DrawWaiterForTest : public CompositorObserver {
     19  public:
     20   // Waits for a draw to be issued by the compositor. If the test times out
     21   // here, there may be a logic error in the compositor code causing it
     22   // not to draw.
     23   static void Wait(Compositor* compositor);
     24 
     25   // Waits for a commit instead of a draw.
     26   static void WaitForCommit(Compositor* compositor);
     27 
     28  private:
     29   DrawWaiterForTest();
     30   virtual ~DrawWaiterForTest();
     31 
     32   void WaitImpl(Compositor* compositor);
     33 
     34   // CompositorObserver implementation.
     35   virtual void OnCompositingDidCommit(Compositor* compositor) OVERRIDE;
     36   virtual void OnCompositingStarted(Compositor* compositor,
     37                                     base::TimeTicks start_time) OVERRIDE;
     38   virtual void OnCompositingEnded(Compositor* compositor) OVERRIDE;
     39   virtual void OnCompositingAborted(Compositor* compositor) OVERRIDE;
     40   virtual void OnCompositingLockStateChanged(Compositor* compositor) OVERRIDE;
     41 
     42   scoped_ptr<base::RunLoop> wait_run_loop_;
     43 
     44   bool wait_for_commit_;
     45 
     46   DISALLOW_COPY_AND_ASSIGN(DrawWaiterForTest);
     47 };
     48 
     49 }  // namespace ui
     50 
     51 #endif  // UI_COMPOSITOR_TEST_DRAW_WAITER_H_
     52