Commit 8fd9a5d1 authored by Adam Rice's avatar Adam Rice Committed by Commit Bot

Move MockWebSocketChannel into its own file

Allow MockWebSocketChannel to be used from WebSocketStream tests in addition to
the existing DOMWebSocket tests by putting it in its own file.

BUG=983030

Change-Id: I96f5afc57d7b18b9baa4e9504ecba443e332ddea
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1736350Reviewed-by: default avatarYutaka Hirano <yhirano@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Adam Rice <ricea@chromium.org>
Cr-Commit-Position: refs/heads/master@{#684241}
parent d5ae1cb9
...@@ -417,6 +417,8 @@ jumbo_source_set("unit_tests") { ...@@ -417,6 +417,8 @@ jumbo_source_set("unit_tests") {
"webdatabase/quota_tracker_test.cc", "webdatabase/quota_tracker_test.cc",
"webshare/navigator_share_test.cc", "webshare/navigator_share_test.cc",
"websockets/dom_websocket_test.cc", "websockets/dom_websocket_test.cc",
"websockets/mock_websocket_channel.cc",
"websockets/mock_websocket_channel.h",
"websockets/websocket_channel_impl_test.cc", "websockets/websocket_channel_impl_test.cc",
"websockets/websocket_common_test.cc", "websockets/websocket_common_test.cc",
"worklet/animation_and_paint_worklet_thread_test.cc", "worklet/animation_and_paint_worklet_thread_test.cc",
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "third_party/blink/renderer/core/fileapi/blob.h" #include "third_party/blink/renderer/core/fileapi/blob.h"
#include "third_party/blink/renderer/core/testing/dummy_page_holder.h" #include "third_party/blink/renderer/core/testing/dummy_page_holder.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_typed_array.h" #include "third_party/blink/renderer/core/typed_arrays/dom_typed_array.h"
#include "third_party/blink/renderer/modules/websockets/mock_websocket_channel.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h" #include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/heap/handle.h" #include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/testing/unit_test_helpers.h" #include "third_party/blink/renderer/platform/testing/unit_test_helpers.h"
...@@ -41,45 +42,6 @@ namespace { ...@@ -41,45 +42,6 @@ namespace {
typedef testing::StrictMock<testing::MockFunction<void(int)>> typedef testing::StrictMock<testing::MockFunction<void(int)>>
Checkpoint; // NOLINT Checkpoint; // NOLINT
class MockWebSocketChannel : public WebSocketChannel {
public:
static MockWebSocketChannel* Create() {
return MakeGarbageCollected<testing::StrictMock<MockWebSocketChannel>>();
}
~MockWebSocketChannel() override = default;
MOCK_METHOD2(Connect, bool(const KURL&, const String&));
MOCK_METHOD2(Send,
WebSocketChannel::SendResult(const std::string&,
base::OnceClosure));
MOCK_METHOD4(Send,
WebSocketChannel::SendResult(const DOMArrayBuffer&,
unsigned,
unsigned,
base::OnceClosure));
MOCK_METHOD1(SendMock, void(BlobDataHandle*));
void Send(scoped_refptr<BlobDataHandle> handle) override {
SendMock(handle.get());
}
MOCK_CONST_METHOD0(BufferedAmount, unsigned());
MOCK_METHOD2(Close, void(int, const String&));
MOCK_METHOD3(FailMock,
void(const String&,
mojom::ConsoleMessageLevel,
SourceLocation*));
void Fail(const String& reason,
mojom::ConsoleMessageLevel level,
std::unique_ptr<SourceLocation> location) override {
FailMock(reason, level, location.get());
}
MOCK_METHOD0(Disconnect, void());
MOCK_METHOD0(ApplyBackpressure, void());
MOCK_METHOD0(RemoveBackpressure, void());
MockWebSocketChannel() = default;
};
class DOMWebSocketWithMockChannel final : public DOMWebSocket { class DOMWebSocketWithMockChannel final : public DOMWebSocket {
public: public:
static DOMWebSocketWithMockChannel* Create(ExecutionContext* context) { static DOMWebSocketWithMockChannel* Create(ExecutionContext* context) {
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/modules/websockets/mock_websocket_channel.h"
// Generated constructors and destructors for GMock objects are very large. By
// putting them in a separate file we can speed up compile times.
namespace blink {
MockWebSocketChannel* MockWebSocketChannel::Create() {
return MakeGarbageCollected<testing::StrictMock<MockWebSocketChannel>>();
}
MockWebSocketChannel::MockWebSocketChannel() = default;
MockWebSocketChannel::~MockWebSocketChannel() = default;
} // namespace blink
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_WEBSOCKETS_MOCK_WEBSOCKET_CHANNEL_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_WEBSOCKETS_MOCK_WEBSOCKET_CHANNEL_H_
#include <memory>
#include "base/memory/scoped_refptr.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "third_party/blink/public/mojom/devtools/console_message.mojom-blink.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer.h"
#include "third_party/blink/renderer/modules/websockets/websocket_channel.h"
#include "third_party/blink/renderer/platform/blob/blob_data.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
namespace blink {
class SourceLocation;
class MockWebSocketChannel : public WebSocketChannel {
public:
static MockWebSocketChannel* Create();
MockWebSocketChannel();
~MockWebSocketChannel() override;
MOCK_METHOD2(Connect, bool(const KURL&, const String&));
MOCK_METHOD2(Send,
WebSocketChannel::SendResult(const std::string&,
base::OnceClosure));
MOCK_METHOD4(Send,
WebSocketChannel::SendResult(const DOMArrayBuffer&,
unsigned,
unsigned,
base::OnceClosure));
MOCK_METHOD1(SendMock, void(BlobDataHandle*));
void Send(scoped_refptr<BlobDataHandle> handle) override {
SendMock(handle.get());
}
MOCK_CONST_METHOD0(BufferedAmount, unsigned());
MOCK_METHOD2(Close, void(int, const String&));
MOCK_METHOD3(FailMock,
void(const String&,
mojom::ConsoleMessageLevel,
SourceLocation*));
void Fail(const String& reason,
mojom::ConsoleMessageLevel level,
std::unique_ptr<SourceLocation> location) override {
FailMock(reason, level, location.get());
}
MOCK_METHOD0(Disconnect, void());
MOCK_METHOD0(ApplyBackpressure, void());
MOCK_METHOD0(RemoveBackpressure, void());
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_WEBSOCKETS_MOCK_WEBSOCKET_CHANNEL_H_
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