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

Side by Side Diff: chrome/browser/chromeos/policy/remote_commands/device_command_screenshot_job_unittest.cc

Issue 1557693002: Convert Pass()→std::move() in //chrome/browser/chromeos/policy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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 "chrome/browser/chromeos/policy/remote_commands/device_command_screensh ot_job.h"
6
5 #include <map> 7 #include <map>
8 #include <utility>
6 #include <vector> 9 #include <vector>
7 10
8 #include "ash/test/ash_test_base.h" 11 #include "ash/test/ash_test_base.h"
9 #include "base/json/json_writer.h" 12 #include "base/json/json_writer.h"
10 #include "base/macros.h" 13 #include "base/macros.h"
11 #include "base/run_loop.h" 14 #include "base/run_loop.h"
12 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
13 #include "base/test/test_mock_time_task_runner.h" 16 #include "base/test/test_mock_time_task_runner.h"
14 #include "base/thread_task_runner_handle.h" 17 #include "base/thread_task_runner_handle.h"
15 #include "base/threading/sequenced_worker_pool.h" 18 #include "base/threading/sequenced_worker_pool.h"
16 #include "base/time/time.h" 19 #include "base/time/time.h"
17 #include "base/values.h" 20 #include "base/values.h"
18 #include "chrome/browser/chromeos/policy/remote_commands/device_command_screensh ot_job.h"
19 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
20 #include "content/public/test/test_browser_thread_bundle.h" 22 #include "content/public/test/test_browser_thread_bundle.h"
21 #include "policy/proto/device_management_backend.pb.h" 23 #include "policy/proto/device_management_backend.pb.h"
22 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
23 #include "third_party/skia/include/core/SkBitmap.h" 25 #include "third_party/skia/include/core/SkBitmap.h"
24 #include "ui/gfx/codec/png_codec.h" 26 #include "ui/gfx/codec/png_codec.h"
25 27
26 namespace policy { 28 namespace policy {
27 29
28 namespace em = enterprise_management; 30 namespace em = enterprise_management;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 UploadJob::Delegate* delegate_; 82 UploadJob::Delegate* delegate_;
81 scoped_ptr<UploadJob::ErrorCode> error_code_; 83 scoped_ptr<UploadJob::ErrorCode> error_code_;
82 bool add_datasegment_succeeds_; 84 bool add_datasegment_succeeds_;
83 }; 85 };
84 86
85 MockUploadJob::MockUploadJob(const GURL& upload_url, 87 MockUploadJob::MockUploadJob(const GURL& upload_url,
86 UploadJob::Delegate* delegate, 88 UploadJob::Delegate* delegate,
87 scoped_ptr<UploadJob::ErrorCode> error_code) 89 scoped_ptr<UploadJob::ErrorCode> error_code)
88 : upload_url_(upload_url), 90 : upload_url_(upload_url),
89 delegate_(delegate), 91 delegate_(delegate),
90 error_code_(error_code.Pass()) { 92 error_code_(std::move(error_code)) {}
91 }
92 93
93 MockUploadJob::~MockUploadJob() { 94 MockUploadJob::~MockUploadJob() {
94 } 95 }
95 96
96 void MockUploadJob::AddDataSegment( 97 void MockUploadJob::AddDataSegment(
97 const std::string& name, 98 const std::string& name,
98 const std::string& filename, 99 const std::string& filename,
99 const std::map<std::string, std::string>& header_entries, 100 const std::map<std::string, std::string>& header_entries,
100 scoped_ptr<std::string> data) { 101 scoped_ptr<std::string> data) {
101 } 102 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 UploadJob::Delegate*) override; 152 UploadJob::Delegate*) override;
152 153
153 private: 154 private:
154 scoped_ptr<UploadJob::ErrorCode> upload_job_error_code_; 155 scoped_ptr<UploadJob::ErrorCode> upload_job_error_code_;
155 bool screenshot_allowed_; 156 bool screenshot_allowed_;
156 }; 157 };
157 158
158 MockScreenshotDelegate::MockScreenshotDelegate( 159 MockScreenshotDelegate::MockScreenshotDelegate(
159 scoped_ptr<UploadJob::ErrorCode> upload_job_error_code, 160 scoped_ptr<UploadJob::ErrorCode> upload_job_error_code,
160 bool screenshot_allowed) 161 bool screenshot_allowed)
161 : upload_job_error_code_(upload_job_error_code.Pass()), 162 : upload_job_error_code_(std::move(upload_job_error_code)),
162 screenshot_allowed_(screenshot_allowed) { 163 screenshot_allowed_(screenshot_allowed) {}
163 }
164 164
165 MockScreenshotDelegate::~MockScreenshotDelegate() { 165 MockScreenshotDelegate::~MockScreenshotDelegate() {
166 } 166 }
167 167
168 bool MockScreenshotDelegate::IsScreenshotAllowed() { 168 bool MockScreenshotDelegate::IsScreenshotAllowed() {
169 return screenshot_allowed_; 169 return screenshot_allowed_;
170 } 170 }
171 171
172 void MockScreenshotDelegate::TakeSnapshot( 172 void MockScreenshotDelegate::TakeSnapshot(
173 gfx::NativeWindow window, 173 gfx::NativeWindow window,
174 const gfx::Rect& source_rect, 174 const gfx::Rect& source_rect,
175 const ui::GrabWindowSnapshotAsyncPNGCallback& callback) { 175 const ui::GrabWindowSnapshotAsyncPNGCallback& callback) {
176 const int width = source_rect.width(); 176 const int width = source_rect.width();
177 const int height = source_rect.height(); 177 const int height = source_rect.height();
178 scoped_refptr<base::RefCountedBytes> test_png = 178 scoped_refptr<base::RefCountedBytes> test_png =
179 GenerateTestPNG(width, height); 179 GenerateTestPNG(width, height);
180 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 180 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
181 base::Bind(callback, test_png)); 181 base::Bind(callback, test_png));
182 } 182 }
183 183
184 scoped_ptr<UploadJob> MockScreenshotDelegate::CreateUploadJob( 184 scoped_ptr<UploadJob> MockScreenshotDelegate::CreateUploadJob(
185 const GURL& upload_url, 185 const GURL& upload_url,
186 UploadJob::Delegate* delegate) { 186 UploadJob::Delegate* delegate) {
187 return make_scoped_ptr( 187 return make_scoped_ptr(new MockUploadJob(upload_url, delegate,
188 new MockUploadJob(upload_url, delegate, upload_job_error_code_.Pass())); 188 std::move(upload_job_error_code_)));
189 } 189 }
190 190
191 } // namespace 191 } // namespace
192 192
193 class DeviceCommandScreenshotTest : public ash::test::AshTestBase { 193 class DeviceCommandScreenshotTest : public ash::test::AshTestBase {
194 public: 194 public:
195 void VerifyResults(RemoteCommandJob* job, 195 void VerifyResults(RemoteCommandJob* job,
196 RemoteCommandJob::Status expected_status, 196 RemoteCommandJob::Status expected_status,
197 std::string expected_payload); 197 std::string expected_payload);
198 198
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 CreatePayloadFromResultCode( 292 CreatePayloadFromResultCode(
293 DeviceCommandScreenshotJob::FAILURE_USER_INPUT))); 293 DeviceCommandScreenshotJob::FAILURE_USER_INPUT)));
294 EXPECT_TRUE(success); 294 EXPECT_TRUE(success);
295 run_loop_.Run(); 295 run_loop_.Run();
296 } 296 }
297 297
298 TEST_F(DeviceCommandScreenshotTest, Failure) { 298 TEST_F(DeviceCommandScreenshotTest, Failure) {
299 using ErrorCode = UploadJob::ErrorCode; 299 using ErrorCode = UploadJob::ErrorCode;
300 scoped_ptr<ErrorCode> error_code( 300 scoped_ptr<ErrorCode> error_code(
301 new ErrorCode(UploadJob::AUTHENTICATION_ERROR)); 301 new ErrorCode(UploadJob::AUTHENTICATION_ERROR));
302 scoped_ptr<RemoteCommandJob> job(new DeviceCommandScreenshotJob( 302 scoped_ptr<RemoteCommandJob> job(
303 make_scoped_ptr(new MockScreenshotDelegate(error_code.Pass(), true)))); 303 new DeviceCommandScreenshotJob(make_scoped_ptr(
304 new MockScreenshotDelegate(std::move(error_code), true))));
304 InitializeScreenshotJob(job.get(), kUniqueID, test_start_time_, 305 InitializeScreenshotJob(job.get(), kUniqueID, test_start_time_,
305 kMockUploadUrl); 306 kMockUploadUrl);
306 bool success = job->Run( 307 bool success = job->Run(
307 base::TimeTicks::Now(), 308 base::TimeTicks::Now(),
308 base::Bind(&DeviceCommandScreenshotTest::VerifyResults, 309 base::Bind(&DeviceCommandScreenshotTest::VerifyResults,
309 base::Unretained(this), base::Unretained(job.get()), 310 base::Unretained(this), base::Unretained(job.get()),
310 RemoteCommandJob::FAILED, 311 RemoteCommandJob::FAILED,
311 CreatePayloadFromResultCode( 312 CreatePayloadFromResultCode(
312 DeviceCommandScreenshotJob::FAILURE_AUTHENTICATION))); 313 DeviceCommandScreenshotJob::FAILURE_AUTHENTICATION)));
313 EXPECT_TRUE(success); 314 EXPECT_TRUE(success);
314 run_loop_.Run(); 315 run_loop_.Run();
315 } 316 }
316 317
317 } // namespace policy 318 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698