1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef __GMPTestMonitor_h__
7 #define __GMPTestMonitor_h__
8 
9 #include "nsThreadUtils.h"
10 #include "mozilla/SchedulerGroup.h"
11 #include "mozilla/SpinEventLoopUntil.h"
12 
13 class GMPTestMonitor {
14  public:
GMPTestMonitor()15   GMPTestMonitor() : mFinished(false) {}
16 
AwaitFinished()17   void AwaitFinished() {
18     MOZ_ASSERT(NS_IsMainThread());
19     mozilla::SpinEventLoopUntil("GMPTestMonitor::AwaitFinished"_ns,
20                                 [&]() { return mFinished; });
21     mFinished = false;
22   }
23 
24  private:
MarkFinished()25   void MarkFinished() {
26     MOZ_ASSERT(NS_IsMainThread());
27     mFinished = true;
28   }
29 
30  public:
SetFinished()31   void SetFinished() {
32     mozilla::SchedulerGroup::Dispatch(mozilla::TaskCategory::Other,
33                                       mozilla::NewNonOwningRunnableMethod(
34                                           "GMPTestMonitor::MarkFinished", this,
35                                           &GMPTestMonitor::MarkFinished));
36   }
37 
38  private:
39   bool mFinished;
40 };
41 
42 #endif  // __GMPTestMonitor_h__
43