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