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

Side by Side Diff: chrome/browser/prerender/prerender_interceptor_unittest.cc

Issue 5693001: Fix memory leak in PrerenderInterceptorTest... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years 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
« no previous file with comments | « no previous file | tools/heapcheck/suppressions.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/browser/prerender/prerender_interceptor.h" 5 #include "chrome/browser/prerender/prerender_interceptor.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
11 #include "base/message_loop_proxy.h" 11 #include "base/message_loop_proxy.h"
12 #include "base/scoped_ptr.h" 12 #include "base/scoped_ptr.h"
13 #include "chrome/browser/browser_thread.h" 13 #include "chrome/browser/browser_thread.h"
14 #include "googleurl/src/gurl.h" 14 #include "googleurl/src/gurl.h"
15 #include "net/base/load_flags.h" 15 #include "net/base/load_flags.h"
16 #include "net/test/test_server.h" 16 #include "net/test/test_server.h"
17 #include "net/url_request/url_request_unittest.h" 17 #include "net/url_request/url_request_unittest.h"
18 18
19 class PrerenderInterceptorTest : public testing::Test { 19 class PrerenderInterceptorTest : public testing::Test {
20 public: 20 protected:
21 PrerenderInterceptorTest(); 21 PrerenderInterceptorTest();
22 22
23 void MakeTestUrl(const std::string& base); 23 void MakeTestUrl(const std::string& base);
24 virtual void SetUp(); 24 virtual void SetUp();
25 25
26 net::TestServer test_server_; 26 net::TestServer test_server_;
27 GURL gurl_; 27 GURL gurl_;
28 GURL last_intercepted_gurl_; 28 GURL last_intercepted_gurl_;
29 scoped_ptr<net::URLRequest> req_; 29 scoped_ptr<net::URLRequest> req_;
30
30 private: 31 private:
31 void SetLastInterceptedGurl(const GURL& url); 32 void SetLastInterceptedGurl(const GURL& url);
32 33
33 PrerenderInterceptor prerender_interceptor_; 34 PrerenderInterceptor prerender_interceptor_;
34 MessageLoopForIO io_loop_; 35 MessageLoopForIO io_loop_;
35 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; 36 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_;
36 BrowserThread ui_thread_; 37 BrowserThread ui_thread_;
38 TestDelegate delegate_for_req_;
37 }; 39 };
38 40
39 PrerenderInterceptorTest::PrerenderInterceptorTest() 41 PrerenderInterceptorTest::PrerenderInterceptorTest()
40 : test_server_(net::TestServer::TYPE_HTTP, 42 : test_server_(net::TestServer::TYPE_HTTP,
41 FilePath(FILE_PATH_LITERAL("chrome/test/data"))), 43 FilePath(FILE_PATH_LITERAL("chrome/test/data"))),
42 last_intercepted_gurl_("http://not.initialized/"), 44 last_intercepted_gurl_("http://not.initialized/"),
43 ALLOW_THIS_IN_INITIALIZER_LIST( 45 ALLOW_THIS_IN_INITIALIZER_LIST(
44 prerender_interceptor_( 46 prerender_interceptor_(
45 NewCallback(this, 47 NewCallback(this,
46 &PrerenderInterceptorTest::SetLastInterceptedGurl))), 48 &PrerenderInterceptorTest::SetLastInterceptedGurl))),
47 ui_thread_(BrowserThread::UI, &io_loop_) { 49 ui_thread_(BrowserThread::UI, &io_loop_) {
48 } 50 }
49 51
50 void PrerenderInterceptorTest::SetUp() { 52 void PrerenderInterceptorTest::SetUp() {
51 testing::Test::SetUp(); 53 testing::Test::SetUp();
52 last_intercepted_gurl_ = GURL("http://nothing.intercepted/"); 54 last_intercepted_gurl_ = GURL("http://nothing.intercepted/");
53 55
54 io_message_loop_proxy_ = base::MessageLoopProxy::CreateForCurrentThread(); 56 io_message_loop_proxy_ = base::MessageLoopProxy::CreateForCurrentThread();
55 ASSERT_TRUE(test_server_.Start()); 57 ASSERT_TRUE(test_server_.Start());
56 } 58 }
57 59
58 void PrerenderInterceptorTest::MakeTestUrl(const std::string& base) { 60 void PrerenderInterceptorTest::MakeTestUrl(const std::string& base) {
59 gurl_ = test_server_.GetURL(base); 61 gurl_ = test_server_.GetURL(base);
60 req_.reset(new TestURLRequest(gurl_, new TestDelegate())); 62 req_.reset(new TestURLRequest(gurl_, &delegate_for_req_));
61 } 63 }
62 64
63 void PrerenderInterceptorTest::SetLastInterceptedGurl(const GURL& url) { 65 void PrerenderInterceptorTest::SetLastInterceptedGurl(const GURL& url) {
64 last_intercepted_gurl_ = url; 66 last_intercepted_gurl_ = url;
65 } 67 }
66 68
67 // Temporarily disabling PrerenderInterceptorTest's due to a leak. 69 namespace {
68 // I have a fix, but will land in the morning. 70
69 // http://crbug.com/65993 71 TEST_F(PrerenderInterceptorTest, Interception) {
70 TEST_F(PrerenderInterceptorTest, DISABLED_Interception) {
71 MakeTestUrl("files/prerender/doc1.html"); 72 MakeTestUrl("files/prerender/doc1.html");
72 req_->set_load_flags(req_->load_flags() | net::LOAD_PREFETCH); 73 req_->set_load_flags(req_->load_flags() | net::LOAD_PREFETCH);
73 req_->Start(); 74 req_->Start();
74 75
75 MessageLoop::current()->Run(); 76 MessageLoop::current()->Run();
76 EXPECT_EQ(URLRequestStatus::SUCCESS, req_->status().status()); 77 EXPECT_EQ(URLRequestStatus::SUCCESS, req_->status().status());
77 EXPECT_EQ(gurl_, last_intercepted_gurl_); 78 EXPECT_EQ(gurl_, last_intercepted_gurl_);
78 } 79 }
79 80
80 TEST_F(PrerenderInterceptorTest, DISABLED_NotAPrefetch) { 81 TEST_F(PrerenderInterceptorTest, NotAPrefetch) {
81 MakeTestUrl("files/prerender/doc2.html"); 82 MakeTestUrl("files/prerender/doc2.html");
82 req_->set_load_flags(req_->load_flags() & ~net::LOAD_PREFETCH); 83 req_->set_load_flags(req_->load_flags() & ~net::LOAD_PREFETCH);
83 req_->Start(); 84 req_->Start();
84 85
85 MessageLoop::current()->Run(); 86 MessageLoop::current()->Run();
86 EXPECT_EQ(URLRequestStatus::SUCCESS, req_->status().status()); 87 EXPECT_EQ(URLRequestStatus::SUCCESS, req_->status().status());
87 EXPECT_NE(gurl_, last_intercepted_gurl_); 88 EXPECT_NE(gurl_, last_intercepted_gurl_);
88 } 89 }
89 90
90 TEST_F(PrerenderInterceptorTest, DISABLED_WrongMimeType) { 91 TEST_F(PrerenderInterceptorTest, WrongMimeType) {
91 MakeTestUrl("files/prerender/image.jpeg"); 92 MakeTestUrl("files/prerender/image.jpeg");
92 req_->set_load_flags(req_->load_flags() | net::LOAD_PREFETCH); 93 req_->set_load_flags(req_->load_flags() | net::LOAD_PREFETCH);
93 req_->Start(); 94 req_->Start();
94 95
95 MessageLoop::current()->Run(); 96 MessageLoop::current()->Run();
96 EXPECT_EQ(URLRequestStatus::SUCCESS, req_->status().status()); 97 EXPECT_EQ(URLRequestStatus::SUCCESS, req_->status().status());
97 EXPECT_NE(gurl_, last_intercepted_gurl_); 98 EXPECT_NE(gurl_, last_intercepted_gurl_);
98 } 99 }
99 100
101 } // namespace
OLDNEW
« no previous file with comments | « no previous file | tools/heapcheck/suppressions.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698