OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/dns/serial_worker.h" | 5 #include "net/dns/serial_worker.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/synchronization/lock.h" | 9 #include "base/synchronization/lock.h" |
10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 namespace net { | 13 namespace net { |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 class SerialWorkerTest : public testing::Test { | 17 class SerialWorkerTest : public testing::Test { |
18 public: | 18 public: |
19 // The class under test | 19 // The class under test |
20 class TestSerialWorker : public SerialWorker { | 20 class TestSerialWorker : public SerialWorker { |
21 public: | 21 public: |
22 explicit TestSerialWorker(SerialWorkerTest* t) | 22 explicit TestSerialWorker(SerialWorkerTest* t) |
23 : test_(t) {} | 23 : test_(t) {} |
24 virtual void DoWork() OVERRIDE { | 24 virtual void DoWork() override { |
25 ASSERT_TRUE(test_); | 25 ASSERT_TRUE(test_); |
26 test_->OnWork(); | 26 test_->OnWork(); |
27 } | 27 } |
28 virtual void OnWorkFinished() OVERRIDE { | 28 virtual void OnWorkFinished() override { |
29 ASSERT_TRUE(test_); | 29 ASSERT_TRUE(test_); |
30 test_->OnWorkFinished(); | 30 test_->OnWorkFinished(); |
31 } | 31 } |
32 private: | 32 private: |
33 virtual ~TestSerialWorker() {} | 33 virtual ~TestSerialWorker() {} |
34 SerialWorkerTest* test_; | 34 SerialWorkerTest* test_; |
35 }; | 35 }; |
36 | 36 |
37 // Mocks | 37 // Mocks |
38 | 38 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 | 89 |
90 // Lets OnWork run and waits for it to complete. Can only return if OnWork is | 90 // Lets OnWork run and waits for it to complete. Can only return if OnWork is |
91 // executed on a concurrent thread. | 91 // executed on a concurrent thread. |
92 void WaitForWork() { | 92 void WaitForWork() { |
93 RunUntilBreak("OnWork"); | 93 RunUntilBreak("OnWork"); |
94 work_allowed_.Signal(); | 94 work_allowed_.Signal(); |
95 work_called_.Wait(); | 95 work_called_.Wait(); |
96 } | 96 } |
97 | 97 |
98 // test::Test methods | 98 // test::Test methods |
99 virtual void SetUp() OVERRIDE { | 99 virtual void SetUp() override { |
100 message_loop_ = base::MessageLoop::current(); | 100 message_loop_ = base::MessageLoop::current(); |
101 worker_ = new TestSerialWorker(this); | 101 worker_ = new TestSerialWorker(this); |
102 } | 102 } |
103 | 103 |
104 virtual void TearDown() OVERRIDE { | 104 virtual void TearDown() override { |
105 // Cancel the worker to catch if it makes a late DoWork call. | 105 // Cancel the worker to catch if it makes a late DoWork call. |
106 worker_->Cancel(); | 106 worker_->Cancel(); |
107 // Check if OnWork is stalled. | 107 // Check if OnWork is stalled. |
108 EXPECT_FALSE(work_running_) << "OnWork should be done by TearDown"; | 108 EXPECT_FALSE(work_running_) << "OnWork should be done by TearDown"; |
109 // Release it for cleanliness. | 109 // Release it for cleanliness. |
110 if (work_running_) { | 110 if (work_running_) { |
111 WaitForWork(); | 111 WaitForWork(); |
112 } | 112 } |
113 } | 113 } |
114 | 114 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 RunUntilBreak("OnWorkFinished"); | 154 RunUntilBreak("OnWorkFinished"); |
155 | 155 |
156 // No more tasks should remain. | 156 // No more tasks should remain. |
157 EXPECT_TRUE(message_loop_->IsIdleForTesting()); | 157 EXPECT_TRUE(message_loop_->IsIdleForTesting()); |
158 } | 158 } |
159 | 159 |
160 } // namespace | 160 } // namespace |
161 | 161 |
162 } // namespace net | 162 } // namespace net |
163 | 163 |
OLD | NEW |