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" |
11 #include "content/public/test/test_browser_thread.h" | 11 #include "content/public/test/test_browser_thread.h" |
| 12 #include "net/base/load_flags.h" |
12 #include "net/url_request/redirect_info.h" | 13 #include "net/url_request/redirect_info.h" |
13 #include "net/url_request/url_request.h" | 14 #include "net/url_request/url_request.h" |
14 #include "net/url_request/url_request_test_util.h" | 15 #include "net/url_request/url_request_test_util.h" |
15 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 | 18 |
18 using testing::Eq; | 19 using testing::Eq; |
19 using testing::Property; | 20 using testing::Property; |
20 | 21 |
21 namespace predictors { | 22 namespace predictors { |
22 | 23 |
23 // Wrapper over the ResourcePrefetcher that stubs out the StartURLRequest call | 24 // Wrapper over the ResourcePrefetcher that stubs out the StartURLRequest call |
24 // since we do not want to do network fetches in this unittest. | 25 // since we do not want to do network fetches in this unittest. |
25 class TestResourcePrefetcher : public ResourcePrefetcher { | 26 class TestResourcePrefetcher : public ResourcePrefetcher { |
26 public: | 27 public: |
27 TestResourcePrefetcher(ResourcePrefetcher::Delegate* delegate, | 28 TestResourcePrefetcher(ResourcePrefetcher::Delegate* delegate, |
28 const ResourcePrefetchPredictorConfig& config, | 29 const ResourcePrefetchPredictorConfig& config, |
29 const NavigationID& navigation_id, | 30 const NavigationID& navigation_id, |
30 PrefetchKeyType key_type, | 31 PrefetchKeyType key_type, |
31 scoped_ptr<RequestVector> requests) | 32 scoped_ptr<RequestVector> requests) |
32 : ResourcePrefetcher(delegate, config, navigation_id, | 33 : ResourcePrefetcher(delegate, config, navigation_id, |
33 key_type, requests.Pass()) { } | 34 key_type, requests.Pass()) { } |
34 | 35 |
35 virtual ~TestResourcePrefetcher() { } | 36 virtual ~TestResourcePrefetcher() { } |
36 | 37 |
37 MOCK_METHOD1(StartURLRequest, void(net::URLRequest* request)); | 38 MOCK_METHOD1(StartURLRequest, void(net::URLRequest* request)); |
38 | 39 |
39 void ReadFullResponse(net::URLRequest* request) override { | 40 void ReadFullResponse(net::URLRequest* request) override { |
| 41 EXPECT_TRUE(request->load_flags() & net::LOAD_PREFETCH); |
40 FinishRequest(request, Request::PREFETCH_STATUS_FROM_CACHE); | 42 FinishRequest(request, Request::PREFETCH_STATUS_FROM_CACHE); |
41 } | 43 } |
42 | 44 |
43 private: | 45 private: |
44 DISALLOW_COPY_AND_ASSIGN(TestResourcePrefetcher); | 46 DISALLOW_COPY_AND_ASSIGN(TestResourcePrefetcher); |
45 }; | 47 }; |
46 | 48 |
47 | 49 |
48 // Delegate for ResourcePrefetcher. | 50 // Delegate for ResourcePrefetcher. |
49 class TestResourcePrefetcherDelegate : public ResourcePrefetcher::Delegate { | 51 class TestResourcePrefetcherDelegate : public ResourcePrefetcher::Delegate { |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 // 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 |
351 // 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 |
352 // pointer requests_ptr is passed to ResourcePrefetcherFinished(). In the | 354 // pointer requests_ptr is passed to ResourcePrefetcherFinished(). In the |
353 // test, ResourcePrefetcherFinished() is a mock function and does not handle | 355 // test, ResourcePrefetcherFinished() is a mock function and does not handle |
354 // 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 |
355 // passed to and managed by ResourcePrefetchPredictor::Result::Result. | 357 // passed to and managed by ResourcePrefetchPredictor::Result::Result. |
356 delete requests_ptr; | 358 delete requests_ptr; |
357 } | 359 } |
358 | 360 |
359 } // namespace predictors | 361 } // namespace predictors |
OLD | NEW |