OLD | NEW |
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 Loading... |
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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 EXPECT_EQ(unique_id, job->unique_id()); | 239 EXPECT_EQ(unique_id, job->unique_id()); |
240 EXPECT_EQ(RemoteCommandJob::NOT_STARTED, job->status()); | 240 EXPECT_EQ(RemoteCommandJob::NOT_STARTED, job->status()); |
241 } | 241 } |
242 | 242 |
243 std::string DeviceCommandScreenshotTest::CreatePayloadFromResultCode( | 243 std::string DeviceCommandScreenshotTest::CreatePayloadFromResultCode( |
244 DeviceCommandScreenshotJob::ResultCode result_code) { | 244 DeviceCommandScreenshotJob::ResultCode result_code) { |
245 std::string payload; | 245 std::string payload; |
246 base::DictionaryValue root_dict; | 246 base::DictionaryValue root_dict; |
247 if (result_code != DeviceCommandScreenshotJob::SUCCESS) | 247 if (result_code != DeviceCommandScreenshotJob::SUCCESS) |
248 root_dict.Set(kResultFieldName, new base::FundamentalValue(result_code)); | 248 root_dict.Set(kResultFieldName, new base::FundamentalValue(result_code)); |
249 base::JSONWriter::Write(&root_dict, &payload); | 249 base::JSONWriter::Write(root_dict, &payload); |
250 return payload; | 250 return payload; |
251 } | 251 } |
252 | 252 |
253 void DeviceCommandScreenshotTest::VerifyResults( | 253 void DeviceCommandScreenshotTest::VerifyResults( |
254 RemoteCommandJob* job, | 254 RemoteCommandJob* job, |
255 RemoteCommandJob::Status expected_status, | 255 RemoteCommandJob::Status expected_status, |
256 std::string expected_payload) { | 256 std::string expected_payload) { |
257 EXPECT_EQ(expected_status, job->status()); | 257 EXPECT_EQ(expected_status, job->status()); |
258 if (job->status() == RemoteCommandJob::SUCCEEDED) { | 258 if (job->status() == RemoteCommandJob::SUCCEEDED) { |
259 scoped_ptr<std::string> payload = job->GetResultPayload(); | 259 scoped_ptr<std::string> payload = job->GetResultPayload(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 base::Bind(&DeviceCommandScreenshotTest::VerifyResults, | 307 base::Bind(&DeviceCommandScreenshotTest::VerifyResults, |
308 base::Unretained(this), base::Unretained(job.get()), | 308 base::Unretained(this), base::Unretained(job.get()), |
309 RemoteCommandJob::FAILED, | 309 RemoteCommandJob::FAILED, |
310 CreatePayloadFromResultCode( | 310 CreatePayloadFromResultCode( |
311 DeviceCommandScreenshotJob::FAILURE_AUTHENTICATION))); | 311 DeviceCommandScreenshotJob::FAILURE_AUTHENTICATION))); |
312 EXPECT_TRUE(success); | 312 EXPECT_TRUE(success); |
313 run_loop_.Run(); | 313 run_loop_.Run(); |
314 } | 314 } |
315 | 315 |
316 } // namespace policy | 316 } // namespace policy |
OLD | NEW |