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/disk_cache/disk_cache_test_util.h" | 5 #include "net/disk_cache/disk_cache_test_util.h" |
6 | 6 |
7 #include "base/files/file.h" | 7 #include "base/files/file.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 base::MessageLoop::current()->Run(); | 98 base::MessageLoop::current()->Run(); |
99 return completed_; | 99 return completed_; |
100 } | 100 } |
101 | 101 |
102 // Quits the message loop when all callbacks are called or we've been waiting | 102 // Quits the message loop when all callbacks are called or we've been waiting |
103 // too long for them (2 secs without a callback). | 103 // too long for them (2 secs without a callback). |
104 void MessageLoopHelper::TimerExpired() { | 104 void MessageLoopHelper::TimerExpired() { |
105 CHECK_LE(callbacks_called_, num_callbacks_); | 105 CHECK_LE(callbacks_called_, num_callbacks_); |
106 if (callbacks_called_ == num_callbacks_) { | 106 if (callbacks_called_ == num_callbacks_) { |
107 completed_ = true; | 107 completed_ = true; |
108 base::MessageLoop::current()->Quit(); | 108 base::MessageLoop::current()->QuitWhenIdle(); |
109 } else { | 109 } else { |
110 // Not finished yet. See if we have to abort. | 110 // Not finished yet. See if we have to abort. |
111 if (last_ == callbacks_called_) | 111 if (last_ == callbacks_called_) |
112 num_iterations_++; | 112 num_iterations_++; |
113 else | 113 else |
114 last_ = callbacks_called_; | 114 last_ = callbacks_called_; |
115 if (40 == num_iterations_) | 115 if (40 == num_iterations_) |
116 base::MessageLoop::current()->Quit(); | 116 base::MessageLoop::current()->QuitWhenIdle(); |
117 } | 117 } |
118 } | 118 } |
119 | 119 |
120 // ----------------------------------------------------------------------- | 120 // ----------------------------------------------------------------------- |
121 | 121 |
122 CallbackTest::CallbackTest(MessageLoopHelper* helper, | 122 CallbackTest::CallbackTest(MessageLoopHelper* helper, |
123 bool reuse) | 123 bool reuse) |
124 : helper_(helper), | 124 : helper_(helper), |
125 reuse_(reuse ? 0 : 1) { | 125 reuse_(reuse ? 0 : 1) { |
126 } | 126 } |
127 | 127 |
128 CallbackTest::~CallbackTest() { | 128 CallbackTest::~CallbackTest() { |
129 } | 129 } |
130 | 130 |
131 // On the actual callback, increase the number of tests received and check for | 131 // On the actual callback, increase the number of tests received and check for |
132 // errors (an unexpected test received) | 132 // errors (an unexpected test received) |
133 void CallbackTest::Run(int result) { | 133 void CallbackTest::Run(int result) { |
134 last_result_ = result; | 134 last_result_ = result; |
135 | 135 |
136 if (reuse_) { | 136 if (reuse_) { |
137 DCHECK_EQ(1, reuse_); | 137 DCHECK_EQ(1, reuse_); |
138 if (2 == reuse_) | 138 if (2 == reuse_) |
139 helper_->set_callback_reused_error(true); | 139 helper_->set_callback_reused_error(true); |
140 reuse_++; | 140 reuse_++; |
141 } | 141 } |
142 | 142 |
143 helper_->CallbackWasCalled(); | 143 helper_->CallbackWasCalled(); |
144 } | 144 } |
OLD | NEW |