/src/mozilla-central/xpcom/tests/gtest/TestStateWatching.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | |
7 | | #include "gtest/gtest.h" |
8 | | #include "mozilla/SharedThreadPool.h" |
9 | | #include "mozilla/StateWatching.h" |
10 | | #include "mozilla/TaskQueue.h" |
11 | | #include "mozilla/Unused.h" |
12 | | #include "nsISupportsImpl.h" |
13 | | #include "VideoUtils.h" |
14 | | |
15 | | namespace TestStateWatching { |
16 | | |
17 | | using namespace mozilla; |
18 | | |
19 | | struct Foo { |
20 | | NS_INLINE_DECL_THREADSAFE_REFCOUNTING(Foo) |
21 | 0 | void Notify() { mNotified = true; } |
22 | | bool mNotified = false; |
23 | | private: |
24 | 0 | ~Foo() {} |
25 | | }; |
26 | | |
27 | | TEST(WatchManager, Shutdown) |
28 | 0 | { |
29 | 0 | RefPtr<TaskQueue> queue = new TaskQueue( |
30 | 0 | GetMediaThreadPool(MediaThreadType::PLAYBACK)); |
31 | 0 |
|
32 | 0 | RefPtr<Foo> p = new Foo; |
33 | 0 | WatchManager<Foo> manager(p, queue); |
34 | 0 | Watchable<bool> notifier(false, "notifier"); |
35 | 0 |
|
36 | 0 | Unused << queue->Dispatch(NS_NewRunnableFunction( |
37 | 0 | "TestStateWatching::WatchManager_Shutdown_Test::TestBody", [&]() { |
38 | 0 | manager.Watch(notifier, &Foo::Notify); |
39 | 0 | notifier = true; // Trigger the call to Foo::Notify(). |
40 | 0 | manager.Shutdown(); // Shutdown() should cancel the call. |
41 | 0 | })); |
42 | 0 |
|
43 | 0 | queue->BeginShutdown(); |
44 | 0 | queue->AwaitShutdownAndIdle(); |
45 | 0 | EXPECT_FALSE(p->mNotified); |
46 | 0 | } |
47 | | |
48 | | } // namespace TestStateWatching |