Commit 9b78d2aa authored by Steve Kobes's avatar Steve Kobes Committed by Commit Bot

Use OnceClosure in net::TestClosure.

Bug: 1007815
Change-Id: I62c3b0bd99b685e7cea30244d88c8196d3646854
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2284141
Auto-Submit: Steve Kobes <skobes@chromium.org>
Reviewed-by: default avatarEric Roman <eroman@chromium.org>
Commit-Queue: Eric Roman <eroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#785867}
parent 22bf2425
......@@ -41,10 +41,6 @@ TestCompletionCallbackBaseInternal::~TestCompletionCallbackBaseInternal() =
} // namespace internal
TestClosure::TestClosure()
: closure_(base::Bind(&TestClosure::DidSetResult, base::Unretained(this))) {
}
TestClosure::~TestClosure() = default;
TestCompletionCallback::~TestCompletionCallback() = default;
......
......@@ -103,14 +103,14 @@ class TestClosure : public internal::TestCompletionCallbackBaseInternal {
public:
using internal::TestCompletionCallbackBaseInternal::WaitForResult;
TestClosure();
TestClosure() {}
~TestClosure() override;
const base::Closure& closure() const { return closure_; }
base::OnceClosure closure() {
return base::BindOnce(&TestClosure::DidSetResult, base::Unretained(this));
}
private:
const base::Closure closure_;
DISALLOW_COPY_AND_ASSIGN(TestClosure);
};
......
......@@ -24,12 +24,12 @@ namespace {
const int kMagicResult = 8888;
void CallClosureAfterCheckingResult(const base::Closure& closure,
void CallClosureAfterCheckingResult(base::OnceClosure closure,
bool* did_check_result,
int result) {
DCHECK_EQ(result, kMagicResult);
*did_check_result = true;
closure.Run();
std::move(closure).Run();
}
// ExampleEmployer is a toy version of HostResolver
......
......@@ -441,7 +441,9 @@ template <size_t N>
}
// A GoogleMock action to run a Closure.
ACTION_P(InvokeClosure, closure) { closure.Run(); }
ACTION_P(InvokeClosure, test_closure) {
test_closure->closure().Run();
}
// A FakeWebSocketStream whose ReadFrames() function returns data.
class ReadableFakeWebSocketStream : public FakeWebSocketStream {
......@@ -1692,7 +1694,7 @@ TEST_F(WebSocketChannelEventInterfaceTest,
EXPECT_CALL(checkpoint, Call(1));
EXPECT_CALL(*event_interface_,
OnDropChannel(false, kWebSocketErrorAbnormalClosure, _))
.WillOnce(InvokeClosure(completion.closure()));
.WillOnce(InvokeClosure(&completion));
}
CreateChannelAndConnectSuccessfully();
// OneShotTimer is not very friendly to testing; there is no apparent way to
......@@ -1727,7 +1729,7 @@ TEST_F(WebSocketChannelEventInterfaceTest,
EXPECT_CALL(*event_interface_, OnClosingHandshake());
EXPECT_CALL(*event_interface_,
OnDropChannel(false, kWebSocketErrorAbnormalClosure, _))
.WillOnce(InvokeClosure(completion.closure()));
.WillOnce(InvokeClosure(&completion));
}
CreateChannelAndConnectSuccessfully();
channel_->SetClosingHandshakeTimeoutForTesting(
......@@ -2718,8 +2720,7 @@ TEST_F(WebSocketChannelStreamTimeoutTest, ServerInitiatedCloseTimesOut) {
EXPECT_CALL(*mock_stream_, WriteFramesInternal(EqualsFrames(expected), _))
.WillOnce(Return(OK));
EXPECT_CALL(checkpoint, Call(1));
EXPECT_CALL(*mock_stream_, Close())
.WillOnce(InvokeClosure(completion.closure()));
EXPECT_CALL(*mock_stream_, Close()).WillOnce(InvokeClosure(&completion));
}
CreateChannelAndConnectSuccessfully();
......@@ -2744,8 +2745,7 @@ TEST_F(WebSocketChannelStreamTimeoutTest, ClientInitiatedCloseTimesOut) {
InSequence s;
EXPECT_CALL(*mock_stream_, WriteFramesInternal(EqualsFrames(expected), _))
.WillOnce(Return(OK));
EXPECT_CALL(*mock_stream_, Close())
.WillOnce(InvokeClosure(completion.closure()));
EXPECT_CALL(*mock_stream_, Close()).WillOnce(InvokeClosure(&completion));
}
CreateChannelAndConnectSuccessfully();
......@@ -2787,8 +2787,7 @@ TEST_F(WebSocketChannelStreamTimeoutTest, ConnectionCloseTimesOut) {
EXPECT_CALL(*mock_stream_, ReadFramesInternal(_, _))
.WillOnce(Return(ERR_IO_PENDING));
// The timeout happens and so WebSocketChannel closes the stream.
EXPECT_CALL(*mock_stream_, Close())
.WillOnce(InvokeClosure(completion.closure()));
EXPECT_CALL(*mock_stream_, Close()).WillOnce(InvokeClosure(&completion));
}
CreateChannelAndConnectSuccessfully();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment