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() = ...@@ -41,10 +41,6 @@ TestCompletionCallbackBaseInternal::~TestCompletionCallbackBaseInternal() =
} // namespace internal } // namespace internal
TestClosure::TestClosure()
: closure_(base::Bind(&TestClosure::DidSetResult, base::Unretained(this))) {
}
TestClosure::~TestClosure() = default; TestClosure::~TestClosure() = default;
TestCompletionCallback::~TestCompletionCallback() = default; TestCompletionCallback::~TestCompletionCallback() = default;
......
...@@ -103,14 +103,14 @@ class TestClosure : public internal::TestCompletionCallbackBaseInternal { ...@@ -103,14 +103,14 @@ class TestClosure : public internal::TestCompletionCallbackBaseInternal {
public: public:
using internal::TestCompletionCallbackBaseInternal::WaitForResult; using internal::TestCompletionCallbackBaseInternal::WaitForResult;
TestClosure(); TestClosure() {}
~TestClosure() override; ~TestClosure() override;
const base::Closure& closure() const { return closure_; } base::OnceClosure closure() {
return base::BindOnce(&TestClosure::DidSetResult, base::Unretained(this));
}
private: private:
const base::Closure closure_;
DISALLOW_COPY_AND_ASSIGN(TestClosure); DISALLOW_COPY_AND_ASSIGN(TestClosure);
}; };
......
...@@ -24,12 +24,12 @@ namespace { ...@@ -24,12 +24,12 @@ namespace {
const int kMagicResult = 8888; const int kMagicResult = 8888;
void CallClosureAfterCheckingResult(const base::Closure& closure, void CallClosureAfterCheckingResult(base::OnceClosure closure,
bool* did_check_result, bool* did_check_result,
int result) { int result) {
DCHECK_EQ(result, kMagicResult); DCHECK_EQ(result, kMagicResult);
*did_check_result = true; *did_check_result = true;
closure.Run(); std::move(closure).Run();
} }
// ExampleEmployer is a toy version of HostResolver // ExampleEmployer is a toy version of HostResolver
......
...@@ -441,7 +441,9 @@ template <size_t N> ...@@ -441,7 +441,9 @@ template <size_t N>
} }
// A GoogleMock action to run a Closure. // 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. // A FakeWebSocketStream whose ReadFrames() function returns data.
class ReadableFakeWebSocketStream : public FakeWebSocketStream { class ReadableFakeWebSocketStream : public FakeWebSocketStream {
...@@ -1692,7 +1694,7 @@ TEST_F(WebSocketChannelEventInterfaceTest, ...@@ -1692,7 +1694,7 @@ TEST_F(WebSocketChannelEventInterfaceTest,
EXPECT_CALL(checkpoint, Call(1)); EXPECT_CALL(checkpoint, Call(1));
EXPECT_CALL(*event_interface_, EXPECT_CALL(*event_interface_,
OnDropChannel(false, kWebSocketErrorAbnormalClosure, _)) OnDropChannel(false, kWebSocketErrorAbnormalClosure, _))
.WillOnce(InvokeClosure(completion.closure())); .WillOnce(InvokeClosure(&completion));
} }
CreateChannelAndConnectSuccessfully(); CreateChannelAndConnectSuccessfully();
// OneShotTimer is not very friendly to testing; there is no apparent way to // OneShotTimer is not very friendly to testing; there is no apparent way to
...@@ -1727,7 +1729,7 @@ TEST_F(WebSocketChannelEventInterfaceTest, ...@@ -1727,7 +1729,7 @@ TEST_F(WebSocketChannelEventInterfaceTest,
EXPECT_CALL(*event_interface_, OnClosingHandshake()); EXPECT_CALL(*event_interface_, OnClosingHandshake());
EXPECT_CALL(*event_interface_, EXPECT_CALL(*event_interface_,
OnDropChannel(false, kWebSocketErrorAbnormalClosure, _)) OnDropChannel(false, kWebSocketErrorAbnormalClosure, _))
.WillOnce(InvokeClosure(completion.closure())); .WillOnce(InvokeClosure(&completion));
} }
CreateChannelAndConnectSuccessfully(); CreateChannelAndConnectSuccessfully();
channel_->SetClosingHandshakeTimeoutForTesting( channel_->SetClosingHandshakeTimeoutForTesting(
...@@ -2718,8 +2720,7 @@ TEST_F(WebSocketChannelStreamTimeoutTest, ServerInitiatedCloseTimesOut) { ...@@ -2718,8 +2720,7 @@ TEST_F(WebSocketChannelStreamTimeoutTest, ServerInitiatedCloseTimesOut) {
EXPECT_CALL(*mock_stream_, WriteFramesInternal(EqualsFrames(expected), _)) EXPECT_CALL(*mock_stream_, WriteFramesInternal(EqualsFrames(expected), _))
.WillOnce(Return(OK)); .WillOnce(Return(OK));
EXPECT_CALL(checkpoint, Call(1)); EXPECT_CALL(checkpoint, Call(1));
EXPECT_CALL(*mock_stream_, Close()) EXPECT_CALL(*mock_stream_, Close()).WillOnce(InvokeClosure(&completion));
.WillOnce(InvokeClosure(completion.closure()));
} }
CreateChannelAndConnectSuccessfully(); CreateChannelAndConnectSuccessfully();
...@@ -2744,8 +2745,7 @@ TEST_F(WebSocketChannelStreamTimeoutTest, ClientInitiatedCloseTimesOut) { ...@@ -2744,8 +2745,7 @@ TEST_F(WebSocketChannelStreamTimeoutTest, ClientInitiatedCloseTimesOut) {
InSequence s; InSequence s;
EXPECT_CALL(*mock_stream_, WriteFramesInternal(EqualsFrames(expected), _)) EXPECT_CALL(*mock_stream_, WriteFramesInternal(EqualsFrames(expected), _))
.WillOnce(Return(OK)); .WillOnce(Return(OK));
EXPECT_CALL(*mock_stream_, Close()) EXPECT_CALL(*mock_stream_, Close()).WillOnce(InvokeClosure(&completion));
.WillOnce(InvokeClosure(completion.closure()));
} }
CreateChannelAndConnectSuccessfully(); CreateChannelAndConnectSuccessfully();
...@@ -2787,8 +2787,7 @@ TEST_F(WebSocketChannelStreamTimeoutTest, ConnectionCloseTimesOut) { ...@@ -2787,8 +2787,7 @@ TEST_F(WebSocketChannelStreamTimeoutTest, ConnectionCloseTimesOut) {
EXPECT_CALL(*mock_stream_, ReadFramesInternal(_, _)) EXPECT_CALL(*mock_stream_, ReadFramesInternal(_, _))
.WillOnce(Return(ERR_IO_PENDING)); .WillOnce(Return(ERR_IO_PENDING));
// The timeout happens and so WebSocketChannel closes the stream. // The timeout happens and so WebSocketChannel closes the stream.
EXPECT_CALL(*mock_stream_, Close()) EXPECT_CALL(*mock_stream_, Close()).WillOnce(InvokeClosure(&completion));
.WillOnce(InvokeClosure(completion.closure()));
} }
CreateChannelAndConnectSuccessfully(); 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