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

Unified Diff: mojo/edk/system/channel_unittest.cc

Issue 852113002: Remove RawChannel::Init() and Channel::Init() failure cases. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 11 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 | « mojo/edk/system/channel.cc ('k') | mojo/edk/system/message_pipe_test_utils.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/edk/system/channel_unittest.cc
diff --git a/mojo/edk/system/channel_unittest.cc b/mojo/edk/system/channel_unittest.cc
index 741c99ff2541caec09a214627d89fe8553de9406..e82b32191770589281dff3a3ef39baaa59fa88e0 100644
--- a/mojo/edk/system/channel_unittest.cc
+++ b/mojo/edk/system/channel_unittest.cc
@@ -22,17 +22,9 @@ namespace mojo {
namespace system {
namespace {
-enum Tristate { TRISTATE_UNKNOWN = -1, TRISTATE_FALSE = 0, TRISTATE_TRUE = 1 };
-
-Tristate BoolToTristate(bool b) {
- return b ? TRISTATE_TRUE : TRISTATE_FALSE;
-}
-
class ChannelTest : public testing::Test {
public:
- ChannelTest()
- : io_thread_(base::TestIOThread::kAutoStart),
- init_result_(TRISTATE_UNKNOWN) {}
+ ChannelTest() : io_thread_(base::TestIOThread::kAutoStart) {}
~ChannelTest() override {}
void SetUp() override {
@@ -51,9 +43,7 @@ class ChannelTest : public testing::Test {
CHECK(raw_channel_);
CHECK(channel_);
- CHECK_EQ(init_result_, TRISTATE_UNKNOWN);
-
- init_result_ = BoolToTristate(channel_->Init(raw_channel_.Pass()));
+ channel_->Init(raw_channel_.Pass());
}
void ShutdownChannelOnIOThread() {
@@ -68,7 +58,6 @@ class ChannelTest : public testing::Test {
scoped_ptr<RawChannel>* mutable_raw_channel() { return &raw_channel_; }
Channel* channel() { return channel_.get(); }
scoped_refptr<Channel>* mutable_channel() { return &channel_; }
- Tristate init_result() const { return init_result_; }
private:
void SetUpOnIOThread() {
@@ -85,8 +74,6 @@ class ChannelTest : public testing::Test {
embedder::ScopedPlatformHandle other_platform_handle_;
scoped_refptr<Channel> channel_;
- Tristate init_result_;
-
DISALLOW_COPY_AND_ASSIGN(ChannelTest);
};
@@ -101,7 +88,6 @@ TEST_F(ChannelTest, InitShutdown) {
io_thread()->PostTaskAndWait(
FROM_HERE,
base::Bind(&ChannelTest::InitChannelOnIOThread, base::Unretained(this)));
- EXPECT_EQ(TRISTATE_TRUE, init_result());
io_thread()->PostTaskAndWait(
FROM_HERE, base::Bind(&ChannelTest::ShutdownChannelOnIOThread,
@@ -112,74 +98,6 @@ TEST_F(ChannelTest, InitShutdown) {
*mutable_channel() = nullptr;
}
-// ChannelTest.InitFails -------------------------------------------------------
-
-class MockRawChannelOnInitFails : public RawChannel {
- public:
- MockRawChannelOnInitFails() : on_init_called_(false) {}
- ~MockRawChannelOnInitFails() override {}
-
- // |RawChannel| public methods:
- size_t GetSerializedPlatformHandleSize() const override { return 0; }
-
- private:
- // |RawChannel| protected methods:
- IOResult Read(size_t*) override {
- CHECK(false);
- return IO_FAILED_UNKNOWN;
- }
- IOResult ScheduleRead() override {
- CHECK(false);
- return IO_FAILED_UNKNOWN;
- }
- embedder::ScopedPlatformHandleVectorPtr GetReadPlatformHandles(
- size_t,
- const void*) override {
- CHECK(false);
- return embedder::ScopedPlatformHandleVectorPtr();
- }
- IOResult WriteNoLock(size_t*, size_t*) override {
- CHECK(false);
- return IO_FAILED_UNKNOWN;
- }
- IOResult ScheduleWriteNoLock() override {
- CHECK(false);
- return IO_FAILED_UNKNOWN;
- }
- bool OnInit() override {
- EXPECT_FALSE(on_init_called_);
- on_init_called_ = true;
- return false;
- }
- void OnShutdownNoLock(scoped_ptr<ReadBuffer>,
- scoped_ptr<WriteBuffer>) override {
- CHECK(false);
- }
-
- bool on_init_called_;
-
- DISALLOW_COPY_AND_ASSIGN(MockRawChannelOnInitFails);
-};
-
-TEST_F(ChannelTest, InitFails) {
- io_thread()->PostTaskAndWait(FROM_HERE,
- base::Bind(&ChannelTest::CreateChannelOnIOThread,
- base::Unretained(this)));
- ASSERT_TRUE(channel());
-
- ASSERT_TRUE(raw_channel());
- mutable_raw_channel()->reset(new MockRawChannelOnInitFails());
-
- io_thread()->PostTaskAndWait(
- FROM_HERE,
- base::Bind(&ChannelTest::InitChannelOnIOThread, base::Unretained(this)));
- EXPECT_EQ(TRISTATE_FALSE, init_result());
-
- // Should destroy |Channel| with no |Shutdown()| (on not-the-I/O-thread).
- EXPECT_TRUE(channel()->HasOneRef());
- *mutable_channel() = nullptr;
-}
-
// ChannelTest.CloseBeforeAttachAndRun -----------------------------------------
TEST_F(ChannelTest, CloseBeforeRun) {
@@ -191,7 +109,6 @@ TEST_F(ChannelTest, CloseBeforeRun) {
io_thread()->PostTaskAndWait(
FROM_HERE,
base::Bind(&ChannelTest::InitChannelOnIOThread, base::Unretained(this)));
- EXPECT_EQ(TRISTATE_TRUE, init_result());
scoped_refptr<ChannelEndpoint> channel_endpoint;
scoped_refptr<MessagePipe> mp(
@@ -219,7 +136,6 @@ TEST_F(ChannelTest, ShutdownAfterAttach) {
io_thread()->PostTaskAndWait(
FROM_HERE,
base::Bind(&ChannelTest::InitChannelOnIOThread, base::Unretained(this)));
- EXPECT_EQ(TRISTATE_TRUE, init_result());
scoped_refptr<ChannelEndpoint> channel_endpoint;
scoped_refptr<MessagePipe> mp(
@@ -262,7 +178,6 @@ TEST_F(ChannelTest, WaitAfterAttachRunAndShutdown) {
io_thread()->PostTaskAndWait(
FROM_HERE,
base::Bind(&ChannelTest::InitChannelOnIOThread, base::Unretained(this)));
- EXPECT_EQ(TRISTATE_TRUE, init_result());
scoped_refptr<ChannelEndpoint> channel_endpoint;
scoped_refptr<MessagePipe> mp(
« no previous file with comments | « mojo/edk/system/channel.cc ('k') | mojo/edk/system/message_pipe_test_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698