| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <launch.h> | 5 #include <launch.h> |
| 6 | 6 |
| 7 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
| 8 #include "base/mac/launchd.h" | 8 #include "base/mac/launchd.h" |
| 9 #include "base/mac/scoped_nsobject.h" | 9 #include "base/mac/scoped_nsobject.h" |
| 10 #include "base/test/test_timeouts.h" |
| 11 #include "base/time/time.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "third_party/google_toolbox_for_mac/src/Foundation/GTMServiceManagement
.h" | 13 #include "third_party/google_toolbox_for_mac/src/Foundation/GTMServiceManagement
.h" |
| 12 | 14 |
| 13 namespace { | 15 namespace { |
| 14 | 16 |
| 15 // Returns the parameters needed to launch a really simple script from launchd. | 17 // Returns the parameters needed to launch a really simple script from launchd. |
| 16 NSDictionary* TestJobDictionary(NSString* label_ns) { | 18 NSDictionary* TestJobDictionary(NSString* label_ns) { |
| 17 NSString* shell_script_ns = @"sleep 10; echo TestGTMSMJobSubmitRemove"; | 19 NSString* shell_script_ns = @"sleep 10; echo TestGTMSMJobSubmitRemove"; |
| 18 base::scoped_nsobject<NSMutableArray> job_arguments( | 20 base::scoped_nsobject<NSMutableArray> job_arguments( |
| 19 [[NSMutableArray alloc] init]); | 21 [[NSMutableArray alloc] init]); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 NSDictionary* job_dictionary_ns = TestJobDictionary(label_ns); | 53 NSDictionary* job_dictionary_ns = TestJobDictionary(label_ns); |
| 52 CFDictionaryRef job_dictionary_cf = base::mac::NSToCFCast(job_dictionary_ns); | 54 CFDictionaryRef job_dictionary_cf = base::mac::NSToCFCast(job_dictionary_ns); |
| 53 ASSERT_TRUE(GTMSMJobSubmit(job_dictionary_cf, &error)); | 55 ASSERT_TRUE(GTMSMJobSubmit(job_dictionary_cf, &error)); |
| 54 | 56 |
| 55 // The new job should be running. | 57 // The new job should be running. |
| 56 pid = base::mac::PIDForJob(label); | 58 pid = base::mac::PIDForJob(label); |
| 57 EXPECT_GT(pid, 0); | 59 EXPECT_GT(pid, 0); |
| 58 | 60 |
| 59 // Remove the job. | 61 // Remove the job. |
| 60 ASSERT_TRUE(GTMSMJobRemove(label_cf, &error)); | 62 ASSERT_TRUE(GTMSMJobRemove(label_cf, &error)); |
| 61 pid = base::mac::PIDForJob(label); | 63 |
| 64 // Wait for the job to be killed. |
| 65 base::TimeDelta timeout_in_ms = TestTimeouts::action_timeout(); |
| 66 base::Time start_time = base::Time::Now(); |
| 67 while (1) { |
| 68 pid = base::mac::PIDForJob(label); |
| 69 if (pid < 0) |
| 70 break; |
| 71 |
| 72 base::Time current_time = base::Time::Now(); |
| 73 if (current_time - start_time > timeout_in_ms) |
| 74 break; |
| 75 } |
| 76 |
| 62 EXPECT_LT(pid, 0); | 77 EXPECT_LT(pid, 0); |
| 63 | 78 |
| 64 // Attempting to remove the job again should fail. | 79 // Attempting to remove the job again should fail. |
| 65 EXPECT_FALSE(GTMSMJobRemove(label_cf, &error)); | 80 EXPECT_FALSE(GTMSMJobRemove(label_cf, &error)); |
| 66 } | 81 } |
| OLD | NEW |