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

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

Issue 1131113004: Convert JsonWriter::Write to taking a const ref for the in-param (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix platform specific stuff Created 5 years, 7 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 <map> 5 #include <map>
6 #include <vector> 6 #include <vector>
7 7
8 #include "ash/test/ash_test_base.h" 8 #include "ash/test/ash_test_base.h"
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 RemoteCommandJob::UniqueIDType unique_id, 42 RemoteCommandJob::UniqueIDType unique_id,
43 base::TimeDelta age_of_command, 43 base::TimeDelta age_of_command,
44 const std::string upload_url) { 44 const std::string upload_url) {
45 em::RemoteCommand command_proto; 45 em::RemoteCommand command_proto;
46 command_proto.set_type( 46 command_proto.set_type(
47 enterprise_management::RemoteCommand_Type_DEVICE_SCREENSHOT); 47 enterprise_management::RemoteCommand_Type_DEVICE_SCREENSHOT);
48 command_proto.set_unique_id(unique_id); 48 command_proto.set_unique_id(unique_id);
49 command_proto.set_age_of_command(age_of_command.InMilliseconds()); 49 command_proto.set_age_of_command(age_of_command.InMilliseconds());
50 std::string payload; 50 std::string payload;
51 base::DictionaryValue root_dict; 51 base::DictionaryValue root_dict;
52 root_dict.Set(kUploadUrlFieldName, new base::StringValue(upload_url)); 52 root_dict.SetString(kUploadUrlFieldName, upload_url);
53 base::JSONWriter::Write(&root_dict, &payload); 53 base::JSONWriter::Write(root_dict, &payload);
54 command_proto.set_payload(payload); 54 command_proto.set_payload(payload);
55 return command_proto; 55 return command_proto;
56 } 56 }
57 57
58 class MockUploadJob : public policy::UploadJob { 58 class MockUploadJob : public policy::UploadJob {
59 public: 59 public:
60 // If |error_code| is a null pointer OnSuccess() will be invoked when the 60 // If |error_code| is a null pointer OnSuccess() will be invoked when the
61 // Start() method is called, otherwise OnFailure() will be invoked with the 61 // Start() method is called, otherwise OnFailure() will be invoked with the
62 // respective |error_code|. 62 // respective |error_code|.
63 MockUploadJob(const GURL& upload_url, 63 MockUploadJob(const GURL& upload_url,
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 EXPECT_EQ(unique_id, job->unique_id()); 231 EXPECT_EQ(unique_id, job->unique_id());
232 EXPECT_EQ(RemoteCommandJob::NOT_STARTED, job->status()); 232 EXPECT_EQ(RemoteCommandJob::NOT_STARTED, job->status());
233 } 233 }
234 234
235 std::string DeviceCommandScreenshotTest::CreatePayloadFromResultCode( 235 std::string DeviceCommandScreenshotTest::CreatePayloadFromResultCode(
236 DeviceCommandScreenshotJob::ResultCode result_code) { 236 DeviceCommandScreenshotJob::ResultCode result_code) {
237 std::string payload; 237 std::string payload;
238 base::DictionaryValue root_dict; 238 base::DictionaryValue root_dict;
239 if (result_code != DeviceCommandScreenshotJob::SUCCESS) 239 if (result_code != DeviceCommandScreenshotJob::SUCCESS)
240 root_dict.Set(kResultFieldName, new base::FundamentalValue(result_code)); 240 root_dict.Set(kResultFieldName, new base::FundamentalValue(result_code));
241 base::JSONWriter::Write(&root_dict, &payload); 241 base::JSONWriter::Write(root_dict, &payload);
242 return payload; 242 return payload;
243 } 243 }
244 244
245 void DeviceCommandScreenshotTest::VerifyResults( 245 void DeviceCommandScreenshotTest::VerifyResults(
246 RemoteCommandJob* job, 246 RemoteCommandJob* job,
247 RemoteCommandJob::Status expected_status, 247 RemoteCommandJob::Status expected_status,
248 std::string expected_payload) { 248 std::string expected_payload) {
249 EXPECT_EQ(expected_status, job->status()); 249 EXPECT_EQ(expected_status, job->status());
250 if (job->status() == RemoteCommandJob::SUCCEEDED) { 250 if (job->status() == RemoteCommandJob::SUCCEEDED) {
251 scoped_ptr<std::string> payload = job->GetResultPayload(); 251 scoped_ptr<std::string> payload = job->GetResultPayload();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 base::Bind(&DeviceCommandScreenshotTest::VerifyResults, 283 base::Bind(&DeviceCommandScreenshotTest::VerifyResults,
284 base::Unretained(this), base::Unretained(job.get()), 284 base::Unretained(this), base::Unretained(job.get()),
285 RemoteCommandJob::FAILED, 285 RemoteCommandJob::FAILED,
286 CreatePayloadFromResultCode( 286 CreatePayloadFromResultCode(
287 DeviceCommandScreenshotJob::FAILURE_AUTHENTICATION))); 287 DeviceCommandScreenshotJob::FAILURE_AUTHENTICATION)));
288 EXPECT_TRUE(success); 288 EXPECT_TRUE(success);
289 run_loop_.Run(); 289 run_loop_.Run();
290 } 290 }
291 291
292 } // namespace policy 292 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698