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

Side by Side Diff: util/mac/service_management_test.mm

Issue 1451793002: Add RandomString() and its test, and use it everywhere it makes sense (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Fix tpyo Created 5 years, 1 month 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 | « test/scoped_temp_dir_win.cc ('k') | util/mach/child_port_handshake.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Crashpad Authors. All rights reserved. 1 // Copyright 2014 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 #include "util/mac/service_management.h" 15 #include "util/mac/service_management.h"
16 16
17 #import <Foundation/Foundation.h> 17 #import <Foundation/Foundation.h>
18 #include <launch.h> 18 #include <launch.h>
19 19
20 #include <string> 20 #include <string>
21 #include <vector> 21 #include <vector>
22 22
23 #include "base/mac/foundation_util.h" 23 #include "base/mac/foundation_util.h"
24 #include "base/mac/scoped_cftyperef.h" 24 #include "base/mac/scoped_cftyperef.h"
25 #include "base/strings/stringprintf.h" 25 #include "base/strings/stringprintf.h"
26 #include "base/strings/sys_string_conversions.h" 26 #include "base/strings/sys_string_conversions.h"
27 #include "base/rand_util.h"
28 #include "gtest/gtest.h" 27 #include "gtest/gtest.h"
29 #include "util/misc/clock.h" 28 #include "util/misc/clock.h"
29 #include "util/misc/random_string.h"
30 #include "util/posix/process_info.h" 30 #include "util/posix/process_info.h"
31 #include "util/stdlib/objc.h" 31 #include "util/stdlib/objc.h"
32 32
33 namespace crashpad { 33 namespace crashpad {
34 namespace test { 34 namespace test {
35 namespace { 35 namespace {
36 36
37 // Ensures that the process with the specified PID is running, identifying it by 37 // Ensures that the process with the specified PID is running, identifying it by
38 // requiring that its argv[argc - 1] compare equal to last_arg. 38 // requiring that its argv[argc - 1] compare equal to last_arg.
39 void ExpectProcessIsRunning(pid_t pid, std::string& last_arg) { 39 void ExpectProcessIsRunning(pid_t pid, std::string& last_arg) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 SleepNanoseconds(1E6); // 1 millisecond 101 SleepNanoseconds(1E6); // 1 millisecond
102 } 102 }
103 } 103 }
104 104
105 ASSERT_FALSE(job_argv.empty()); 105 ASSERT_FALSE(job_argv.empty());
106 EXPECT_NE(last_arg, job_argv.back()); 106 EXPECT_NE(last_arg, job_argv.back());
107 } 107 }
108 108
109 TEST(ServiceManagement, SubmitRemoveJob) { 109 TEST(ServiceManagement, SubmitRemoveJob) {
110 @autoreleasepool { 110 @autoreleasepool {
111 std::string cookie; 111 const std::string cookie = RandomString();
112 for (int index = 0; index < 16; ++index) {
113 cookie.append(1, base::RandInt('A', 'Z'));
114 }
115 112
116 std::string shell_script = 113 std::string shell_script =
117 base::StringPrintf("sleep 10; echo %s", cookie.c_str()); 114 base::StringPrintf("sleep 10; echo %s", cookie.c_str());
118 NSString* shell_script_ns = base::SysUTF8ToNSString(shell_script); 115 NSString* shell_script_ns = base::SysUTF8ToNSString(shell_script);
119 116
120 const char kJobLabel[] = "org.chromium.crashpad.test.service_management"; 117 const char kJobLabel[] = "org.chromium.crashpad.test.service_management";
121 NSDictionary* job_dictionary_ns = @{ 118 NSDictionary* job_dictionary_ns = @{
122 @LAUNCH_JOBKEY_LABEL : @"org.chromium.crashpad.test.service_management", 119 @LAUNCH_JOBKEY_LABEL : @"org.chromium.crashpad.test.service_management",
123 @LAUNCH_JOBKEY_RUNATLOAD : @YES, 120 @LAUNCH_JOBKEY_RUNATLOAD : @YES,
124 @LAUNCH_JOBKEY_PROGRAMARGUMENTS : 121 @LAUNCH_JOBKEY_PROGRAMARGUMENTS :
(...skipping 29 matching lines...) Expand all
154 // an error. 151 // an error.
155 EXPECT_FALSE(ServiceManagementRemoveJob(kJobLabel, false)); 152 EXPECT_FALSE(ServiceManagementRemoveJob(kJobLabel, false));
156 153
157 ExpectProcessIsNotRunning(job_pid, shell_script); 154 ExpectProcessIsNotRunning(job_pid, shell_script);
158 } 155 }
159 } 156 }
160 157
161 } // namespace 158 } // namespace
162 } // namespace test 159 } // namespace test
163 } // namespace crashpad 160 } // namespace crashpad
OLDNEW
« no previous file with comments | « test/scoped_temp_dir_win.cc ('k') | util/mach/child_port_handshake.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698