OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <algorithm> | 5 #include <algorithm> |
6 #include <map> | 6 #include <map> |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 | 194 |
195 class TestDistillerURLFetcher : public DistillerURLFetcher { | 195 class TestDistillerURLFetcher : public DistillerURLFetcher { |
196 public: | 196 public: |
197 explicit TestDistillerURLFetcher(bool delay_fetch) | 197 explicit TestDistillerURLFetcher(bool delay_fetch) |
198 : DistillerURLFetcher(NULL), delay_fetch_(delay_fetch) { | 198 : DistillerURLFetcher(NULL), delay_fetch_(delay_fetch) { |
199 responses_[kImageURLs[0]] = string(kImageData[0]); | 199 responses_[kImageURLs[0]] = string(kImageData[0]); |
200 responses_[kImageURLs[1]] = string(kImageData[1]); | 200 responses_[kImageURLs[1]] = string(kImageData[1]); |
201 } | 201 } |
202 | 202 |
203 virtual void FetchURL(const string& url, | 203 virtual void FetchURL(const string& url, |
204 const URLFetcherCallback& callback) OVERRIDE { | 204 const URLFetcherCallback& callback) override { |
205 ASSERT_FALSE(callback.is_null()); | 205 ASSERT_FALSE(callback.is_null()); |
206 url_ = url; | 206 url_ = url; |
207 callback_ = callback; | 207 callback_ = callback; |
208 if (!delay_fetch_) { | 208 if (!delay_fetch_) { |
209 PostCallbackTask(); | 209 PostCallbackTask(); |
210 } | 210 } |
211 } | 211 } |
212 | 212 |
213 void PostCallbackTask() { | 213 void PostCallbackTask() { |
214 ASSERT_TRUE(base::MessageLoop::current()); | 214 ASSERT_TRUE(base::MessageLoop::current()); |
215 ASSERT_FALSE(callback_.is_null()); | 215 ASSERT_FALSE(callback_.is_null()); |
216 base::MessageLoop::current()->PostTask( | 216 base::MessageLoop::current()->PostTask( |
217 FROM_HERE, base::Bind(callback_, responses_[url_])); | 217 FROM_HERE, base::Bind(callback_, responses_[url_])); |
218 } | 218 } |
219 | 219 |
220 private: | 220 private: |
221 std::map<string, string> responses_; | 221 std::map<string, string> responses_; |
222 string url_; | 222 string url_; |
223 URLFetcherCallback callback_; | 223 URLFetcherCallback callback_; |
224 bool delay_fetch_; | 224 bool delay_fetch_; |
225 }; | 225 }; |
226 | 226 |
227 class TestDistillerURLFetcherFactory : public DistillerURLFetcherFactory { | 227 class TestDistillerURLFetcherFactory : public DistillerURLFetcherFactory { |
228 public: | 228 public: |
229 TestDistillerURLFetcherFactory() : DistillerURLFetcherFactory(NULL) {} | 229 TestDistillerURLFetcherFactory() : DistillerURLFetcherFactory(NULL) {} |
230 | 230 |
231 virtual ~TestDistillerURLFetcherFactory() {} | 231 virtual ~TestDistillerURLFetcherFactory() {} |
232 virtual DistillerURLFetcher* CreateDistillerURLFetcher() const OVERRIDE { | 232 virtual DistillerURLFetcher* CreateDistillerURLFetcher() const override { |
233 return new TestDistillerURLFetcher(false); | 233 return new TestDistillerURLFetcher(false); |
234 } | 234 } |
235 }; | 235 }; |
236 | 236 |
237 class MockDistillerURLFetcherFactory : public DistillerURLFetcherFactory { | 237 class MockDistillerURLFetcherFactory : public DistillerURLFetcherFactory { |
238 public: | 238 public: |
239 MockDistillerURLFetcherFactory() : DistillerURLFetcherFactory(NULL) {} | 239 MockDistillerURLFetcherFactory() : DistillerURLFetcherFactory(NULL) {} |
240 virtual ~MockDistillerURLFetcherFactory() {} | 240 virtual ~MockDistillerURLFetcherFactory() {} |
241 | 241 |
242 MOCK_CONST_METHOD0(CreateDistillerURLFetcher, DistillerURLFetcher*()); | 242 MOCK_CONST_METHOD0(CreateDistillerURLFetcher, DistillerURLFetcher*()); |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
626 | 626 |
627 ASSERT_TRUE(distiller_page); | 627 ASSERT_TRUE(distiller_page); |
628 // Post the task to execute javascript and then delete the distiller. | 628 // Post the task to execute javascript and then delete the distiller. |
629 distiller_page->OnDistillationDone(GURL(kURL), distilled_value.get()); | 629 distiller_page->OnDistillationDone(GURL(kURL), distilled_value.get()); |
630 distiller_.reset(); | 630 distiller_.reset(); |
631 | 631 |
632 base::MessageLoop::current()->RunUntilIdle(); | 632 base::MessageLoop::current()->RunUntilIdle(); |
633 } | 633 } |
634 | 634 |
635 } // namespace dom_distiller | 635 } // namespace dom_distiller |
OLD | NEW |