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

Side by Side Diff: components/data_reduction_proxy/content/browser/content_lofi_ui_service_unittest.cc

Issue 1873263002: Convert //components/data_reduction_proxy from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address feedback Created 4 years, 8 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/data_reduction_proxy/content/browser/content_lofi_ui_servic e.h" 5 #include "components/data_reduction_proxy/content/browser/content_lofi_ui_servic e.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory>
10
9 #include "base/bind.h" 11 #include "base/bind.h"
10 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
11 #include "base/macros.h" 13 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
14 #include "base/run_loop.h" 15 #include "base/run_loop.h"
15 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
16 #include "content/public/browser/render_frame_host.h" 17 #include "content/public/browser/render_frame_host.h"
17 #include "content/public/browser/render_process_host.h" 18 #include "content/public/browser/render_process_host.h"
18 #include "content/public/browser/resource_request_info.h" 19 #include "content/public/browser/resource_request_info.h"
19 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
20 #include "content/public/test/test_renderer_host.h" 21 #include "content/public/test/test_renderer_host.h"
21 #include "net/socket/socket_test_util.h" 22 #include "net/socket/socket_test_util.h"
22 #include "net/url_request/url_request.h" 23 #include "net/url_request/url_request.h"
(...skipping 19 matching lines...) Expand all
42 net::TestDelegate delegate; 43 net::TestDelegate delegate;
43 context.set_client_socket_factory(&mock_socket_factory); 44 context.set_client_socket_factory(&mock_socket_factory);
44 context.Init(); 45 context.Init();
45 46
46 content_lofi_ui_service_.reset(new ContentLoFiUIService( 47 content_lofi_ui_service_.reset(new ContentLoFiUIService(
47 content::BrowserThread::GetMessageLoopProxyForThread( 48 content::BrowserThread::GetMessageLoopProxyForThread(
48 content::BrowserThread::UI), 49 content::BrowserThread::UI),
49 base::Bind(&ContentLoFiUIServiceTest::OnLoFiResponseReceivedCallback, 50 base::Bind(&ContentLoFiUIServiceTest::OnLoFiResponseReceivedCallback,
50 base::Unretained(this)))); 51 base::Unretained(this))));
51 52
52 scoped_ptr<net::URLRequest> request = CreateRequest(context, &delegate); 53 std::unique_ptr<net::URLRequest> request =
54 CreateRequest(context, &delegate);
53 55
54 content_lofi_ui_service_->OnLoFiReponseReceived(*request, is_preview); 56 content_lofi_ui_service_->OnLoFiReponseReceived(*request, is_preview);
55 57
56 content::BrowserThread::PostTask( 58 content::BrowserThread::PostTask(
57 content::BrowserThread::UI, FROM_HERE, 59 content::BrowserThread::UI, FROM_HERE,
58 base::Bind(&base::RunLoop::Quit, base::Unretained(ui_run_loop))); 60 base::Bind(&base::RunLoop::Quit, base::Unretained(ui_run_loop)));
59 } 61 }
60 62
61 scoped_ptr<net::URLRequest> CreateRequest( 63 std::unique_ptr<net::URLRequest> CreateRequest(
62 const net::TestURLRequestContext& context, 64 const net::TestURLRequestContext& context,
63 net::TestDelegate* delegate) { 65 net::TestDelegate* delegate) {
64 EXPECT_TRUE( 66 EXPECT_TRUE(
65 content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 67 content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
66 68
67 scoped_ptr<net::URLRequest> request = context.CreateRequest( 69 std::unique_ptr<net::URLRequest> request = context.CreateRequest(
68 GURL("http://www.google.com/"), net::IDLE, delegate); 70 GURL("http://www.google.com/"), net::IDLE, delegate);
69 71
70 content::ResourceRequestInfo::AllocateForTesting( 72 content::ResourceRequestInfo::AllocateForTesting(
71 request.get(), content::RESOURCE_TYPE_SUB_FRAME, NULL, 73 request.get(), content::RESOURCE_TYPE_SUB_FRAME, NULL,
72 web_contents()->GetMainFrame()->GetProcess()->GetID(), -1, 74 web_contents()->GetMainFrame()->GetProcess()->GetID(), -1,
73 web_contents()->GetMainFrame()->GetRoutingID(), 75 web_contents()->GetMainFrame()->GetRoutingID(),
74 false, // is_main_frame 76 false, // is_main_frame
75 false, // parent_is_main_frame 77 false, // parent_is_main_frame
76 false, // allow_download 78 false, // allow_download
77 false, // is_async 79 false, // is_async
(...skipping 11 matching lines...) Expand all
89 } 91 }
90 92
91 void VerifyOnLoFiResponseReceivedCallback(bool is_preview) { 93 void VerifyOnLoFiResponseReceivedCallback(bool is_preview) {
92 EXPECT_TRUE( 94 EXPECT_TRUE(
93 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 95 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
94 EXPECT_TRUE(callback_called_); 96 EXPECT_TRUE(callback_called_);
95 EXPECT_EQ(is_preview, is_preview_); 97 EXPECT_EQ(is_preview, is_preview_);
96 } 98 }
97 99
98 private: 100 private:
99 scoped_ptr<ContentLoFiUIService> content_lofi_ui_service_; 101 std::unique_ptr<ContentLoFiUIService> content_lofi_ui_service_;
100 bool callback_called_; 102 bool callback_called_;
101 bool is_preview_; 103 bool is_preview_;
102 }; 104 };
103 105
104 TEST_F(ContentLoFiUIServiceTest, OnLoFiResponseReceived) { 106 TEST_F(ContentLoFiUIServiceTest, OnLoFiResponseReceived) {
105 base::RunLoop ui_run_loop; 107 base::RunLoop ui_run_loop;
106 content::BrowserThread::PostTask( 108 content::BrowserThread::PostTask(
107 content::BrowserThread::IO, FROM_HERE, 109 content::BrowserThread::IO, FROM_HERE,
108 base::Bind(&ContentLoFiUIServiceTest::RunTestOnIOThread, 110 base::Bind(&ContentLoFiUIServiceTest::RunTestOnIOThread,
109 base::Unretained(this), &ui_run_loop, false)); 111 base::Unretained(this), &ui_run_loop, false));
110 ui_run_loop.Run(); 112 ui_run_loop.Run();
111 base::MessageLoop::current()->RunUntilIdle(); 113 base::MessageLoop::current()->RunUntilIdle();
112 VerifyOnLoFiResponseReceivedCallback(false); 114 VerifyOnLoFiResponseReceivedCallback(false);
113 } 115 }
114 116
115 TEST_F(ContentLoFiUIServiceTest, OnLoFiPreviewResponseReceived) { 117 TEST_F(ContentLoFiUIServiceTest, OnLoFiPreviewResponseReceived) {
116 base::RunLoop ui_run_loop; 118 base::RunLoop ui_run_loop;
117 content::BrowserThread::PostTask( 119 content::BrowserThread::PostTask(
118 content::BrowserThread::IO, FROM_HERE, 120 content::BrowserThread::IO, FROM_HERE,
119 base::Bind(&ContentLoFiUIServiceTest::RunTestOnIOThread, 121 base::Bind(&ContentLoFiUIServiceTest::RunTestOnIOThread,
120 base::Unretained(this), &ui_run_loop, true)); 122 base::Unretained(this), &ui_run_loop, true));
121 ui_run_loop.Run(); 123 ui_run_loop.Run();
122 base::MessageLoop::current()->RunUntilIdle(); 124 base::MessageLoop::current()->RunUntilIdle();
123 VerifyOnLoFiResponseReceivedCallback(true); 125 VerifyOnLoFiResponseReceivedCallback(true);
124 } 126 }
125 127
126 } // namespace data_reduction_proxy 128 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698