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

Unified Diff: mojo/common/test/multiprocess_test_base_unittest.cc

Issue 176063002: Reland: Add some handle read/write helpers to mojo/common/test/test_utils.h (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | mojo/common/test/test_utils.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/common/test/multiprocess_test_base_unittest.cc
diff --git a/mojo/common/test/multiprocess_test_base_unittest.cc b/mojo/common/test/multiprocess_test_base_unittest.cc
index 7b0a7ffb617e28e7269837045d418019b7107097..659b83dbb1629d9cda3b97987899ec3e9f363406 100644
--- a/mojo/common/test/multiprocess_test_base_unittest.cc
+++ b/mojo/common/test/multiprocess_test_base_unittest.cc
@@ -6,22 +6,19 @@
#include "base/logging.h"
#include "build/build_config.h"
+#include "mojo/common/test/test_utils.h"
#include "mojo/system/embedder/scoped_platform_handle.h"
#if defined(OS_POSIX)
#include <fcntl.h>
-#include <unistd.h>
-
-#include "base/posix/eintr_wrapper.h"
#endif
#if defined(OS_WIN)
-#include <windows.h>
-
#include "base/win/windows_version.h"
#endif
namespace mojo {
+namespace test {
namespace {
// Returns true and logs a warning on Windows prior to Vista.
@@ -46,57 +43,19 @@ bool IsNonBlocking(const embedder::PlatformHandle& handle) {
#endif
}
-// Note: On POSIX, this method sets the handle to block.
bool WriteByte(const embedder::PlatformHandle& handle, char c) {
-#if defined(OS_WIN)
- DWORD num_bytes_written = 0;
- OVERLAPPED overlapped = { 0 };
-
- if (!WriteFile(handle.handle, &c, 1, &num_bytes_written, &overlapped)) {
- if (GetLastError() != ERROR_IO_PENDING)
- return false;
-
- if (GetOverlappedResult(handle.handle, &overlapped, &num_bytes_written,
- TRUE)) {
- return num_bytes_written == 1;
- }
-
- return false;
- }
- return num_bytes_written == 1;
-#else
- // We're lazy. Set it to block.
- PCHECK(fcntl(handle.fd, F_SETFL, 0) == 0);
-
- return HANDLE_EINTR(write(handle.fd, &c, 1)) == 1;
-#endif
+ size_t bytes_written = 0;
+ BlockingWrite(handle, &c, 1, &bytes_written);
+ return bytes_written == 1;
}
-// Note: On POSIX, this method sets the handle to block.
bool ReadByte(const embedder::PlatformHandle& handle, char* c) {
-#if defined(OS_WIN)
- DWORD num_bytes_read = 0;
- OVERLAPPED overlapped = { 0 };
-
- if (!ReadFile(handle.handle, c, 1, &num_bytes_read, &overlapped)) {
- if (GetLastError() != ERROR_IO_PENDING)
- return false;
-
- if (GetOverlappedResult(handle.handle, &overlapped, &num_bytes_read, TRUE))
- return num_bytes_read == 1;
-
- return false;
- }
- return num_bytes_read == 1;
-#else
- // We're lazy. Set it to block.
- PCHECK(fcntl(handle.fd, F_SETFL, 0) == 0);
-
- return HANDLE_EINTR(read(handle.fd, c, 1)) == 1;
-#endif
+ size_t bytes_read = 0;
+ BlockingRead(handle, c, 1, &bytes_read);
+ return bytes_read == 1;
}
-typedef test::MultiprocessTestBase MultiprocessTestBaseTest;
+typedef MultiprocessTestBase MultiprocessTestBaseTest;
TEST_F(MultiprocessTestBaseTest, RunChild) {
if (SkipTest())
@@ -172,4 +131,5 @@ MOJO_MULTIPROCESS_TEST_CHILD_MAIN(PassedChannel) {
}
} // namespace
+} // namespace test
} // namespace mojo
« no previous file with comments | « no previous file | mojo/common/test/test_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698