| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/memory/ref_counted.h" | 5 #include "base/memory/ref_counted.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "chrome/browser/predictors/resource_prefetcher.h" | 8 #include "chrome/browser/predictors/resource_prefetcher.h" |
| 9 #include "chrome/browser/predictors/resource_prefetcher_manager.h" | 9 #include "chrome/browser/predictors/resource_prefetcher_manager.h" |
| 10 #include "chrome/test/base/testing_profile.h" | 10 #include "chrome/test/base/testing_profile.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 class TestResourcePrefetcher : public ResourcePrefetcher { | 26 class TestResourcePrefetcher : public ResourcePrefetcher { |
| 27 public: | 27 public: |
| 28 TestResourcePrefetcher(ResourcePrefetcher::Delegate* delegate, | 28 TestResourcePrefetcher(ResourcePrefetcher::Delegate* delegate, |
| 29 const ResourcePrefetchPredictorConfig& config, | 29 const ResourcePrefetchPredictorConfig& config, |
| 30 const NavigationID& navigation_id, | 30 const NavigationID& navigation_id, |
| 31 PrefetchKeyType key_type, | 31 PrefetchKeyType key_type, |
| 32 scoped_ptr<RequestVector> requests) | 32 scoped_ptr<RequestVector> requests) |
| 33 : ResourcePrefetcher(delegate, config, navigation_id, | 33 : ResourcePrefetcher(delegate, config, navigation_id, |
| 34 key_type, requests.Pass()) { } | 34 key_type, requests.Pass()) { } |
| 35 | 35 |
| 36 virtual ~TestResourcePrefetcher() { } | 36 ~TestResourcePrefetcher() override {} |
| 37 | 37 |
| 38 MOCK_METHOD1(StartURLRequest, void(net::URLRequest* request)); | 38 MOCK_METHOD1(StartURLRequest, void(net::URLRequest* request)); |
| 39 | 39 |
| 40 void ReadFullResponse(net::URLRequest* request) override { | 40 void ReadFullResponse(net::URLRequest* request) override { |
| 41 EXPECT_TRUE(request->load_flags() & net::LOAD_PREFETCH); | 41 EXPECT_TRUE(request->load_flags() & net::LOAD_PREFETCH); |
| 42 FinishRequest(request, Request::PREFETCH_STATUS_FROM_CACHE); | 42 FinishRequest(request, Request::PREFETCH_STATUS_FROM_CACHE); |
| 43 } | 43 } |
| 44 | 44 |
| 45 private: | 45 private: |
| 46 DISALLOW_COPY_AND_ASSIGN(TestResourcePrefetcher); | 46 DISALLOW_COPY_AND_ASSIGN(TestResourcePrefetcher); |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 | 49 |
| 50 // Delegate for ResourcePrefetcher. | 50 // Delegate for ResourcePrefetcher. |
| 51 class TestResourcePrefetcherDelegate : public ResourcePrefetcher::Delegate { | 51 class TestResourcePrefetcherDelegate : public ResourcePrefetcher::Delegate { |
| 52 public: | 52 public: |
| 53 explicit TestResourcePrefetcherDelegate(base::MessageLoop* loop) | 53 explicit TestResourcePrefetcherDelegate(base::MessageLoop* loop) |
| 54 : request_context_getter_(new net::TestURLRequestContextGetter( | 54 : request_context_getter_(new net::TestURLRequestContextGetter( |
| 55 loop->message_loop_proxy())) { } | 55 loop->message_loop_proxy())) { } |
| 56 ~TestResourcePrefetcherDelegate() { } | 56 ~TestResourcePrefetcherDelegate() { } |
| 57 | 57 |
| 58 virtual net::URLRequestContext* GetURLRequestContext() override { | 58 net::URLRequestContext* GetURLRequestContext() override { |
| 59 return request_context_getter_->GetURLRequestContext(); | 59 return request_context_getter_->GetURLRequestContext(); |
| 60 } | 60 } |
| 61 | 61 |
| 62 MOCK_METHOD2(ResourcePrefetcherFinished, | 62 MOCK_METHOD2(ResourcePrefetcherFinished, |
| 63 void(ResourcePrefetcher* prefetcher, | 63 void(ResourcePrefetcher* prefetcher, |
| 64 ResourcePrefetcher::RequestVector* requests)); | 64 ResourcePrefetcher::RequestVector* requests)); |
| 65 | 65 |
| 66 private: | 66 private: |
| 67 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_; | 67 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_; |
| 68 | 68 |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 // We need to delete requests_ptr here, though it looks to be managed by the | 352 // We need to delete requests_ptr here, though it looks to be managed by the |
| 353 // scoped_ptr requests. The scoped_ptr requests releases itself and the raw | 353 // scoped_ptr requests. The scoped_ptr requests releases itself and the raw |
| 354 // pointer requests_ptr is passed to ResourcePrefetcherFinished(). In the | 354 // pointer requests_ptr is passed to ResourcePrefetcherFinished(). In the |
| 355 // test, ResourcePrefetcherFinished() is a mock function and does not handle | 355 // test, ResourcePrefetcherFinished() is a mock function and does not handle |
| 356 // the raw pointer properly. In the real code, requests_ptr will eventually be | 356 // the raw pointer properly. In the real code, requests_ptr will eventually be |
| 357 // passed to and managed by ResourcePrefetchPredictor::Result::Result. | 357 // passed to and managed by ResourcePrefetchPredictor::Result::Result. |
| 358 delete requests_ptr; | 358 delete requests_ptr; |
| 359 } | 359 } |
| 360 | 360 |
| 361 } // namespace predictors | 361 } // namespace predictors |
| OLD | NEW |