Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(215)

Side by Side Diff: chrome/browser/predictors/resource_prefetcher_unittest.cc

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 29 matching lines...) Expand all
40 } 40 }
41 41
42 private: 42 private:
43 DISALLOW_COPY_AND_ASSIGN(TestResourcePrefetcher); 43 DISALLOW_COPY_AND_ASSIGN(TestResourcePrefetcher);
44 }; 44 };
45 45
46 46
47 // Delegate for ResourcePrefetcher. 47 // Delegate for ResourcePrefetcher.
48 class TestResourcePrefetcherDelegate : public ResourcePrefetcher::Delegate { 48 class TestResourcePrefetcherDelegate : public ResourcePrefetcher::Delegate {
49 public: 49 public:
50 explicit TestResourcePrefetcherDelegate(MessageLoop* loop) 50 explicit TestResourcePrefetcherDelegate(base::MessageLoop* loop)
51 : request_context_getter_(new net::TestURLRequestContextGetter( 51 : request_context_getter_(new net::TestURLRequestContextGetter(
52 loop->message_loop_proxy())) { } 52 loop->message_loop_proxy())) { }
53 ~TestResourcePrefetcherDelegate() { } 53 ~TestResourcePrefetcherDelegate() { }
54 54
55 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE { 55 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE {
56 return request_context_getter_->GetURLRequestContext(); 56 return request_context_getter_->GetURLRequestContext();
57 } 57 }
58 58
59 MOCK_METHOD2(ResourcePrefetcherFinished, 59 MOCK_METHOD2(ResourcePrefetcherFinished,
60 void(ResourcePrefetcher* prefetcher, 60 void(ResourcePrefetcher* prefetcher,
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 prefetcher_->OnCertificateRequested(GetInFlightRequest(url), NULL); 121 prefetcher_->OnCertificateRequested(GetInFlightRequest(url), NULL);
122 } 122 }
123 void OnSSLCertificateError(const std::string& url) { 123 void OnSSLCertificateError(const std::string& url) {
124 prefetcher_->OnSSLCertificateError(GetInFlightRequest(url), 124 prefetcher_->OnSSLCertificateError(GetInFlightRequest(url),
125 net::SSLInfo(), false); 125 net::SSLInfo(), false);
126 } 126 }
127 void OnResponse(const std::string& url) { 127 void OnResponse(const std::string& url) {
128 prefetcher_->OnResponseStarted(GetInFlightRequest(url)); 128 prefetcher_->OnResponseStarted(GetInFlightRequest(url));
129 } 129 }
130 130
131 MessageLoop loop_; 131 base::MessageLoop loop_;
132 content::TestBrowserThread io_thread_; 132 content::TestBrowserThread io_thread_;
133 ResourcePrefetchPredictorConfig config_; 133 ResourcePrefetchPredictorConfig config_;
134 TestResourcePrefetcherDelegate prefetcher_delegate_; 134 TestResourcePrefetcherDelegate prefetcher_delegate_;
135 scoped_ptr<TestResourcePrefetcher> prefetcher_; 135 scoped_ptr<TestResourcePrefetcher> prefetcher_;
136 136
137 private: 137 private:
138 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetcherTest); 138 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetcherTest);
139 }; 139 };
140 140
141 ResourcePrefetcherTest::ResourcePrefetcherTest() 141 ResourcePrefetcherTest::ResourcePrefetcherTest()
142 : loop_(MessageLoop::TYPE_IO), 142 : loop_(base::MessageLoop::TYPE_IO),
143 io_thread_(content::BrowserThread::IO, &loop_), 143 io_thread_(content::BrowserThread::IO, &loop_),
144 prefetcher_delegate_(&loop_) { 144 prefetcher_delegate_(&loop_) {
145 config_.max_prefetches_inflight_per_navigation = 5; 145 config_.max_prefetches_inflight_per_navigation = 5;
146 config_.max_prefetches_inflight_per_host_per_navigation = 2; 146 config_.max_prefetches_inflight_per_host_per_navigation = 2;
147 } 147 }
148 148
149 ResourcePrefetcherTest::~ResourcePrefetcherTest() { 149 ResourcePrefetcherTest::~ResourcePrefetcherTest() {
150 } 150 }
151 151
152 TEST_F(ResourcePrefetcherTest, TestPrefetcherFinishes) { 152 TEST_F(ResourcePrefetcherTest, TestPrefetcherFinishes) {
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 ResourcePrefetcherFinished(Eq(prefetcher_.get()), 337 ResourcePrefetcherFinished(Eq(prefetcher_.get()),
338 Eq(requests_ptr))); 338 Eq(requests_ptr)));
339 339
340 OnResponse("http://m.google.com/resource1.jpg"); 340 OnResponse("http://m.google.com/resource1.jpg");
341 CheckPrefetcherState(0, 1, 0); 341 CheckPrefetcherState(0, 1, 0);
342 342
343 delete requests_ptr; 343 delete requests_ptr;
344 } 344 }
345 345
346 } // namespace predictors 346 } // namespace predictors
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698