| 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 "sandbox/linux/services/broker_process.h" | 5 #include "sandbox/linux/services/broker_process.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
| 10 #include <sys/types.h> | 10 #include <sys/types.h> |
| 11 #include <sys/wait.h> | 11 #include <sys/wait.h> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #if defined(OS_ANDROID) | 15 #if defined(OS_ANDROID) |
| 16 #include "base/android/path_utils.h" | 16 #include "base/android/path_utils.h" |
| 17 #endif | 17 #endif |
| 18 #include "base/file_path.h" | 18 #include "base/file_path.h" |
| 19 #include "base/logging.h" | 19 #include "base/logging.h" |
| 20 #include "sandbox/linux/tests/unit_tests.h" | 20 #include "sandbox/linux/tests/unit_tests.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 22 |
| 23 namespace sandbox { | 23 namespace sandbox { |
| 24 | 24 |
| 25 #if defined(OS_ANDROID) |
| 26 #define DISABLE_ON_ANDROID(function) DISABLED_##function |
| 27 #else |
| 28 #define DISABLE_ON_ANDROID(function) function |
| 29 #endif |
| 30 |
| 25 TEST(BrokerProcess, CreateAndDestroy) { | 31 TEST(BrokerProcess, CreateAndDestroy) { |
| 26 std::vector<std::string> read_whitelist; | 32 std::vector<std::string> read_whitelist; |
| 27 read_whitelist.push_back("/proc/cpuinfo"); | 33 read_whitelist.push_back("/proc/cpuinfo"); |
| 28 | 34 |
| 29 BrokerProcess* open_broker = new BrokerProcess(read_whitelist, | 35 BrokerProcess* open_broker = new BrokerProcess(read_whitelist, |
| 30 std::vector<std::string>()); | 36 std::vector<std::string>()); |
| 31 ASSERT_TRUE(open_broker->Init(NULL)); | 37 ASSERT_TRUE(open_broker->Init(NULL)); |
| 32 pid_t broker_pid = open_broker->broker_pid(); | 38 pid_t broker_pid = open_broker->broker_pid(); |
| 33 delete(open_broker); | 39 delete(open_broker); |
| 34 | 40 |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 // Don't do anything here, so that ASSERT works in the subfunction as | 187 // Don't do anything here, so that ASSERT works in the subfunction as |
| 182 // expected. | 188 // expected. |
| 183 } | 189 } |
| 184 | 190 |
| 185 TEST(BrokerProcess, OpenCpuinfoNoClientCheck) { | 191 TEST(BrokerProcess, OpenCpuinfoNoClientCheck) { |
| 186 TestOpenCpuinfo(false /* fast_check_in_client */); | 192 TestOpenCpuinfo(false /* fast_check_in_client */); |
| 187 // Don't do anything here, so that ASSERT works in the subfunction as | 193 // Don't do anything here, so that ASSERT works in the subfunction as |
| 188 // expected. | 194 // expected. |
| 189 } | 195 } |
| 190 | 196 |
| 191 TEST(BrokerProcess, OpenFileRW) { | 197 // Disabled until we implement a mkstemp that doesn't require JNI. |
| 198 TEST(BrokerProcess, DISABLE_ON_ANDROID(OpenFileRW)) { |
| 192 const char basename[] = "BrokerProcessXXXXXX"; | 199 const char basename[] = "BrokerProcessXXXXXX"; |
| 193 char template_name[2048]; | 200 char template_name[2048]; |
| 194 #if defined(OS_ANDROID) | 201 #if defined(OS_ANDROID) |
| 195 FilePath cache_directory; | 202 FilePath cache_directory; |
| 196 ASSERT_TRUE(base::android::GetCacheDirectory(&cache_directory)); | 203 ASSERT_TRUE(base::android::GetCacheDirectory(&cache_directory)); |
| 197 ssize_t length = snprintf(template_name, sizeof(template_name), | 204 ssize_t length = snprintf(template_name, sizeof(template_name), |
| 198 "%s%s", | 205 "%s%s", |
| 199 cache_directory.value().c_str(), basename); | 206 cache_directory.value().c_str(), basename); |
| 200 ASSERT_LT(length, static_cast<ssize_t>(sizeof(template_name))); | 207 ASSERT_LT(length, static_cast<ssize_t>(sizeof(template_name))); |
| 201 #else | 208 #else |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 // expected. | 302 // expected. |
| 296 } | 303 } |
| 297 | 304 |
| 298 TEST(BrokerProcess, ComplexFlagsNoClientCheck) { | 305 TEST(BrokerProcess, ComplexFlagsNoClientCheck) { |
| 299 TestComplexFlags(false /* fast_check_in_client */); | 306 TestComplexFlags(false /* fast_check_in_client */); |
| 300 // Don't do anything here, so that ASSERT works in the subfunction as | 307 // Don't do anything here, so that ASSERT works in the subfunction as |
| 301 // expected. | 308 // expected. |
| 302 } | 309 } |
| 303 | 310 |
| 304 } // namespace sandbox | 311 } // namespace sandbox |
| OLD | NEW |