| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/common/mac/mock_launchd.h" | 5 #include "chrome/common/mac/mock_launchd.h" |
| 6 | 6 |
| 7 #include <CoreFoundation/CoreFoundation.h> | 7 #include <CoreFoundation/CoreFoundation.h> |
| 8 #include <sys/socket.h> | 8 #include <sys/socket.h> |
| 9 #include <sys/un.h> | 9 #include <sys/un.h> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
| 14 #include "base/mac/foundation_util.h" | 14 #include "base/mac/foundation_util.h" |
| 15 #include "base/mac/scoped_cftyperef.h" | 15 #include "base/mac/scoped_cftyperef.h" |
| 16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
| 17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| 19 #include "base/strings/sys_string_conversions.h" | 19 #include "base/strings/sys_string_conversions.h" |
| 20 #include "chrome/common/chrome_version_info.h" | |
| 21 #include "chrome/common/mac/launchd.h" | 20 #include "chrome/common/mac/launchd.h" |
| 22 #include "chrome/common/service_process_util.h" | 21 #include "chrome/common/service_process_util.h" |
| 22 #include "components/version_info/version_info.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 24 |
| 25 static sockaddr_un* throwaway_sockaddr_un; | 25 static sockaddr_un* throwaway_sockaddr_un; |
| 26 static const size_t kMaxPipeNameLength = | 26 static const size_t kMaxPipeNameLength = |
| 27 sizeof(throwaway_sockaddr_un->sun_path); | 27 sizeof(throwaway_sockaddr_un->sun_path); |
| 28 | 28 |
| 29 // static | 29 // static |
| 30 bool MockLaunchd::MakeABundle(const base::FilePath& dst, | 30 bool MockLaunchd::MakeABundle(const base::FilePath& dst, |
| 31 const std::string& name, | 31 const std::string& name, |
| 32 base::FilePath* bundle_root, | 32 base::FilePath* bundle_root, |
| 33 base::FilePath* executable) { | 33 base::FilePath* executable) { |
| 34 *bundle_root = dst.Append(name + std::string(".app")); | 34 *bundle_root = dst.Append(name + std::string(".app")); |
| 35 base::FilePath contents = bundle_root->AppendASCII("Contents"); | 35 base::FilePath contents = bundle_root->AppendASCII("Contents"); |
| 36 base::FilePath mac_os = contents.AppendASCII("MacOS"); | 36 base::FilePath mac_os = contents.AppendASCII("MacOS"); |
| 37 *executable = mac_os.Append(name); | 37 *executable = mac_os.Append(name); |
| 38 base::FilePath info_plist = contents.Append("Info.plist"); | 38 base::FilePath info_plist = contents.Append("Info.plist"); |
| 39 | 39 |
| 40 if (!base::CreateDirectory(mac_os)) { | 40 if (!base::CreateDirectory(mac_os)) { |
| 41 return false; | 41 return false; |
| 42 } | 42 } |
| 43 const char *data = "#! testbundle\n"; | 43 const char *data = "#! testbundle\n"; |
| 44 int len = strlen(data); | 44 int len = strlen(data); |
| 45 if (base::WriteFile(*executable, data, len) != len) { | 45 if (base::WriteFile(*executable, data, len) != len) { |
| 46 return false; | 46 return false; |
| 47 } | 47 } |
| 48 if (chmod(executable->value().c_str(), 0555) != 0) { | 48 if (chmod(executable->value().c_str(), 0555) != 0) { |
| 49 return false; | 49 return false; |
| 50 } | 50 } |
| 51 | 51 |
| 52 chrome::VersionInfo version_info; | |
| 53 | |
| 54 const char info_plist_format[] = | 52 const char info_plist_format[] = |
| 55 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" | 53 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
| 56 "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" " | 54 "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" " |
| 57 "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n" | 55 "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n" |
| 58 "<plist version=\"1.0\">\n" | 56 "<plist version=\"1.0\">\n" |
| 59 "<dict>\n" | 57 "<dict>\n" |
| 60 " <key>CFBundleDevelopmentRegion</key>\n" | 58 " <key>CFBundleDevelopmentRegion</key>\n" |
| 61 " <string>English</string>\n" | 59 " <string>English</string>\n" |
| 62 " <key>CFBundleExecutable</key>\n" | 60 " <key>CFBundleExecutable</key>\n" |
| 63 " <string>%s</string>\n" | 61 " <string>%s</string>\n" |
| 64 " <key>CFBundleIdentifier</key>\n" | 62 " <key>CFBundleIdentifier</key>\n" |
| 65 " <string>com.test.%s</string>\n" | 63 " <string>com.test.%s</string>\n" |
| 66 " <key>CFBundleInfoDictionaryVersion</key>\n" | 64 " <key>CFBundleInfoDictionaryVersion</key>\n" |
| 67 " <string>6.0</string>\n" | 65 " <string>6.0</string>\n" |
| 68 " <key>CFBundleShortVersionString</key>\n" | 66 " <key>CFBundleShortVersionString</key>\n" |
| 69 " <string>%s</string>\n" | 67 " <string>%s</string>\n" |
| 70 " <key>CFBundleVersion</key>\n" | 68 " <key>CFBundleVersion</key>\n" |
| 71 " <string>1</string>\n" | 69 " <string>1</string>\n" |
| 72 "</dict>\n" | 70 "</dict>\n" |
| 73 "</plist>\n"; | 71 "</plist>\n"; |
| 74 std::string info_plist_data = | 72 std::string info_plist_data = |
| 75 base::StringPrintf(info_plist_format, | 73 base::StringPrintf(info_plist_format, |
| 76 name.c_str(), | 74 name.c_str(), |
| 77 name.c_str(), | 75 name.c_str(), |
| 78 version_info.Version().c_str()); | 76 version_info::GetVersionNumber().c_str()); |
| 79 len = info_plist_data.length(); | 77 len = info_plist_data.length(); |
| 80 if (base::WriteFile(info_plist, info_plist_data.c_str(), len) != len) { | 78 if (base::WriteFile(info_plist, info_plist_data.c_str(), len) != len) { |
| 81 return false; | 79 return false; |
| 82 } | 80 } |
| 83 const UInt8* bundle_root_path = | 81 const UInt8* bundle_root_path = |
| 84 reinterpret_cast<const UInt8*>(bundle_root->value().c_str()); | 82 reinterpret_cast<const UInt8*>(bundle_root->value().c_str()); |
| 85 base::ScopedCFTypeRef<CFURLRef> url( | 83 base::ScopedCFTypeRef<CFURLRef> url( |
| 86 CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, | 84 CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, |
| 87 bundle_root_path, | 85 bundle_root_path, |
| 88 bundle_root->value().length(), | 86 bundle_root->value().length(), |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 Type type, | 259 Type type, |
| 262 CFStringRef name) { | 260 CFStringRef name) { |
| 263 delete_called_ = true; | 261 delete_called_ = true; |
| 264 return true; | 262 return true; |
| 265 } | 263 } |
| 266 | 264 |
| 267 void MockLaunchd::SignalReady() { | 265 void MockLaunchd::SignalReady() { |
| 268 ASSERT_TRUE(as_service_); | 266 ASSERT_TRUE(as_service_); |
| 269 running_lock_.reset(TakeNamedLock(pipe_name_, true)); | 267 running_lock_.reset(TakeNamedLock(pipe_name_, true)); |
| 270 } | 268 } |
| OLD | NEW |