| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/message_loop.h" | 6 #include "base/message_loop.h" |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.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 28 matching lines...) Expand all Loading... |
| 39 | 39 |
| 40 private: | 40 private: |
| 41 DISALLOW_COPY_AND_ASSIGN(TestResourcePrefetcher); | 41 DISALLOW_COPY_AND_ASSIGN(TestResourcePrefetcher); |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 | 44 |
| 45 // Delegate for ResourcePrefetcher. | 45 // Delegate for ResourcePrefetcher. |
| 46 class TestResourcePrefetcherDelegate : public ResourcePrefetcher::Delegate { | 46 class TestResourcePrefetcherDelegate : public ResourcePrefetcher::Delegate { |
| 47 public: | 47 public: |
| 48 explicit TestResourcePrefetcherDelegate(MessageLoop* loop) | 48 explicit TestResourcePrefetcherDelegate(MessageLoop* loop) |
| 49 : request_context_getter_(new net::TestURLRequestContextGetter( | 49 : request_context_getter_(new TestURLRequestContextGetter( |
| 50 loop->message_loop_proxy())) { } | 50 loop->message_loop_proxy())) { } |
| 51 ~TestResourcePrefetcherDelegate() { } | 51 ~TestResourcePrefetcherDelegate() { } |
| 52 | 52 |
| 53 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE { | 53 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE { |
| 54 return request_context_getter_->GetURLRequestContext(); | 54 return request_context_getter_->GetURLRequestContext(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 MOCK_METHOD2(ResourcePrefetcherFinished, | 57 MOCK_METHOD2(ResourcePrefetcherFinished, |
| 58 void(ResourcePrefetcher* prefetcher, | 58 void(ResourcePrefetcher* prefetcher, |
| 59 ResourcePrefetcher::RequestVector* requests)); | 59 ResourcePrefetcher::RequestVector* requests)); |
| 60 | 60 |
| 61 private: | 61 private: |
| 62 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_; | 62 scoped_refptr<TestURLRequestContextGetter> request_context_getter_; |
| 63 | 63 |
| 64 DISALLOW_COPY_AND_ASSIGN(TestResourcePrefetcherDelegate); | 64 DISALLOW_COPY_AND_ASSIGN(TestResourcePrefetcherDelegate); |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 | 67 |
| 68 // The following unittest tests most of the ResourcePrefetcher except for: | 68 // The following unittest tests most of the ResourcePrefetcher except for: |
| 69 // 1. Call to ReadFullResponse. There does not seem to be a good way to test the | 69 // 1. Call to ReadFullResponse. There does not seem to be a good way to test the |
| 70 // function in a unittest, and probably requires a browser_test. | 70 // function in a unittest, and probably requires a browser_test. |
| 71 // 2. Setting of the Prefetch status for cache vs non cache. | 71 // 2. Setting of the Prefetch status for cache vs non cache. |
| 72 class ResourcePrefetcherTest : public testing::Test { | 72 class ResourcePrefetcherTest : public testing::Test { |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 ResourcePrefetcherFinished(Eq(prefetcher_.get()), | 332 ResourcePrefetcherFinished(Eq(prefetcher_.get()), |
| 333 Eq(requests_ptr))); | 333 Eq(requests_ptr))); |
| 334 | 334 |
| 335 OnResponse("http://m.google.com/resource1.jpg"); | 335 OnResponse("http://m.google.com/resource1.jpg"); |
| 336 CheckPrefetcherState(0, 1, 0); | 336 CheckPrefetcherState(0, 1, 0); |
| 337 | 337 |
| 338 delete requests_ptr; | 338 delete requests_ptr; |
| 339 } | 339 } |
| 340 | 340 |
| 341 } // namespace predictors | 341 } // namespace predictors |
| OLD | NEW |