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

Side by Side Diff: chrome/browser/service_process/service_process_control_mac_unittest.mm

Issue 588833002: mac: Fix launchd test on 10.10 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments from thestig. Created 6 years, 3 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
« no previous file with comments | « no previous file | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <launch.h>
6
7 #include "base/mac/launchd.h"
8 #include "base/mac/mac_util.h"
9 #include "base/mac/scoped_nsobject.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "third_party/google_toolbox_for_mac/src/Foundation/GTMServiceManagement .h"
12
13 namespace {
14
15 // Returns the parameters needed to launch a really simple script from launchd.
16 NSDictionary* TestJobDictionary(NSString* label_ns) {
17 NSString* shell_script_ns = @"sleep 10; echo TestGTMSMJobSubmitRemove";
18 base::scoped_nsobject<NSMutableArray> job_arguments(
19 [[NSMutableArray alloc] init]);
20 [job_arguments addObject:@"/bin/sh"];
21 [job_arguments addObject:@"-c"];
22 [job_arguments addObject:shell_script_ns];
23
24 NSMutableDictionary* job_dictionary_ns = [NSMutableDictionary dictionary];
25 [job_dictionary_ns setObject:label_ns forKey:@LAUNCH_JOBKEY_LABEL];
26 [job_dictionary_ns setObject:[NSNumber numberWithBool:YES]
27 forKey:@LAUNCH_JOBKEY_RUNATLOAD];
28 [job_dictionary_ns setObject:job_arguments
29 forKey:@LAUNCH_JOBKEY_PROGRAMARGUMENTS];
30 return job_dictionary_ns;
31 };
32
33 } // namespace
34
35 TEST(ServiceProcessControlMac, TestGTMSMJobSubmitRemove) {
36 NSString* label_ns = @"com.chromium.ServiceProcessStateFileManipulationTest";
37 std::string label(label_ns.UTF8String);
38 CFStringRef label_cf = base::mac::NSToCFCast(label_ns);
39
40 // If the job is loaded or running, remove it.
41 pid_t pid = base::mac::PIDForJob(label);
42 CFErrorRef error = NULL;
43 if (pid >= 0)
44 ASSERT_TRUE(GTMSMJobRemove(label_cf, &error));
45
46 // The job should not be loaded or running.
47 pid = base::mac::PIDForJob(label);
48 EXPECT_LT(pid, 0);
49
50 // Submit a new job.
51 NSDictionary* job_dictionary_ns = TestJobDictionary(label_ns);
52 CFDictionaryRef job_dictionary_cf = base::mac::NSToCFCast(job_dictionary_ns);
53 ASSERT_TRUE(GTMSMJobSubmit(job_dictionary_cf, &error));
54
55 // The new job should be running.
56 pid = base::mac::PIDForJob(label);
57 EXPECT_GT(pid, 0);
58
59 // Remove the job.
60 ASSERT_TRUE(GTMSMJobRemove(label_cf, &error));
61 pid = base::mac::PIDForJob(label);
62 EXPECT_LT(pid, 0);
63
64 // Attempting to remove the job again should fail.
65 EXPECT_FALSE(GTMSMJobRemove(label_cf, &error));
66 }
OLDNEW
« no previous file with comments | « no previous file | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698