Chromium Code Reviews| 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/watching_file_reader.h" | 5 #include "net/dns/watching_file_reader.h" |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/synchronization/lock.h" | 8 #include "base/synchronization/lock.h" |
| 9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 BreakNow("OnWatch"); | 98 BreakNow("OnWatch"); |
| 99 return !fail_on_watch_; | 99 return !fail_on_watch_; |
| 100 } | 100 } |
| 101 | 101 |
| 102 void OnWork() { | 102 void OnWork() { |
| 103 EXPECT_TRUE(message_loop_ == MessageLoop::current()); | 103 EXPECT_TRUE(message_loop_ == MessageLoop::current()); |
| 104 BreakNow("OnWork"); | 104 BreakNow("OnWork"); |
| 105 } | 105 } |
| 106 | 106 |
| 107 protected: | 107 protected: |
| 108 friend class BreakTask; | 108 void BreakCallback(std::string breakpoint) { |
| 109 class BreakTask : public Task { | 109 breakpoint_ = breakpoint; |
| 110 public: | 110 MessageLoop::current()->QuitNow(); |
| 111 BreakTask(WatchingFileReaderTest* test, std::string breakpoint) | 111 } |
| 112 : test_(test), breakpoint_(breakpoint) {} | |
| 113 virtual ~BreakTask() {} | |
| 114 virtual void Run() OVERRIDE { | |
| 115 test_->breakpoint_ = breakpoint_; | |
| 116 MessageLoop::current()->QuitNow(); | |
| 117 } | |
| 118 private: | |
| 119 WatchingFileReaderTest* test_; | |
| 120 std::string breakpoint_; | |
| 121 }; | |
| 122 | 112 |
| 123 void BreakNow(std::string b) { | 113 void BreakNow(std::string b) { |
| 124 message_loop_->PostTask(FROM_HERE, new BreakTask(this, b)); | 114 message_loop_->PostTask(FROM_HERE, |
| 115 new base::Bind(&WatchingFileReaderTest::BreakCallback, this, b)); | |
|
mmenke
2011/11/30 02:29:05
I'm no expert on the new callback system, but it d
groby-ooo-7-16
2011/11/30 03:03:42
You are absolutely correct, thank you for catching
| |
| 125 } | 116 } |
| 126 | 117 |
| 127 void RunUntilBreak(std::string b) { | 118 void RunUntilBreak(std::string b) { |
| 128 message_loop_->Run(); | 119 message_loop_->Run(); |
| 129 ASSERT_EQ(breakpoint_, b); | 120 ASSERT_EQ(breakpoint_, b); |
| 130 } | 121 } |
| 131 | 122 |
| 132 WatchingFileReaderTest() | 123 WatchingFileReaderTest() |
| 133 : watcher_shim_(NULL), | 124 : watcher_shim_(NULL), |
| 134 fail_on_watch_(false), | 125 fail_on_watch_(false), |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 watcher_shim_->PathChanged(); | 157 watcher_shim_->PathChanged(); |
| 167 RunUntilBreak("OnWork"); | 158 RunUntilBreak("OnWork"); |
| 168 | 159 |
| 169 message_loop_->AssertIdle(); | 160 message_loop_->AssertIdle(); |
| 170 } | 161 } |
| 171 | 162 |
| 172 } // namespace | 163 } // namespace |
| 173 | 164 |
| 174 } // namespace net | 165 } // namespace net |
| 175 | 166 |
| OLD | NEW |