Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/netwerk/test/TestCommon.h
Line
Count
Source (jump to first uncovered line)
1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
 * License, v. 2.0. If a copy of the MPL was not distributed with this
3
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5
#ifndef TestCommon_h__
6
#define TestCommon_h__
7
8
#include <stdlib.h>
9
#include "nsThreadUtils.h"
10
#include "mozilla/Attributes.h"
11
12
//-----------------------------------------------------------------------------
13
14
class WaitForCondition final : public nsIRunnable
15
{
16
public:
17
  NS_DECL_THREADSAFE_ISUPPORTS
18
19
  void Wait(int pending)
20
0
  {
21
0
    MOZ_ASSERT(NS_IsMainThread());
22
0
    MOZ_ASSERT(mPending == 0);
23
0
24
0
    mPending = pending;
25
0
    mozilla::SpinEventLoopUntil([&]() { return !mPending; });
26
0
    NS_ProcessPendingEvents(nullptr);
27
0
  }
28
29
0
  void Notify() {
30
0
    NS_DispatchToMainThread(this);
31
0
  }
32
33
private:
34
0
  virtual ~WaitForCondition() { }
35
36
0
  NS_IMETHOD Run() override {
37
0
    MOZ_ASSERT(NS_IsMainThread());
38
0
    MOZ_ASSERT(mPending);
39
0
40
0
    --mPending;
41
0
    return NS_OK;
42
0
  }
43
44
  uint32_t mPending = 0;
45
};
46
NS_IMPL_ISUPPORTS(WaitForCondition, nsIRunnable)
47
48
#endif