| 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 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 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 ~TestSerialWorker() override {} |
| 34 SerialWorkerTest* test_; | 34 SerialWorkerTest* test_; |
| 35 }; | 35 }; |
| 36 | 36 |
| 37 // Mocks | 37 // Mocks |
| 38 | 38 |
| 39 void OnWork() { | 39 void OnWork() { |
| 40 { // Check that OnWork is executed serially. | 40 { // Check that OnWork is executed serially. |
| 41 base::AutoLock lock(work_lock_); | 41 base::AutoLock lock(work_lock_); |
| 42 EXPECT_FALSE(work_running_) << "DoRead is not called serially!"; | 42 EXPECT_FALSE(work_running_) << "DoRead is not called serially!"; |
| 43 work_running_ = true; | 43 work_running_ = true; |
| (...skipping 110 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 |