summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
Diffstat (limited to 'webkit')
-rw-r--r--webkit/support/test_webkit_platform_support.cc3
-rw-r--r--webkit/support/test_webmessageportchannel.cc91
-rw-r--r--webkit/support/test_webmessageportchannel.h47
-rw-r--r--webkit/support/webkit_support.gypi2
4 files changed, 142 insertions, 1 deletions
diff --git a/webkit/support/test_webkit_platform_support.cc b/webkit/support/test_webkit_platform_support.cc
index 0c09d15..8db2e94 100644
--- a/webkit/support/test_webkit_platform_support.cc
+++ b/webkit/support/test_webkit_platform_support.cc
@@ -43,6 +43,7 @@
#include "webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h"
#include "webkit/gpu/webgraphicscontext3d_in_process_impl.h"
#include "webkit/support/simple_database_system.h"
+#include "webkit/support/test_webmessageportchannel.h"
#include "webkit/support/webkit_support.h"
#include "webkit/support/weburl_loader_mock_factory.h"
#include "webkit/support/web_audio_device_mock.h"
@@ -224,7 +225,7 @@ bool TestWebKitPlatformSupport::isLinkVisited(unsigned long long linkHash) {
WebKit::WebMessagePortChannel*
TestWebKitPlatformSupport::createMessagePortChannel() {
- return NULL;
+ return new TestWebMessagePortChannel();
}
void TestWebKitPlatformSupport::prefetchHostName(const WebKit::WebString&) {
diff --git a/webkit/support/test_webmessageportchannel.cc b/webkit/support/test_webmessageportchannel.cc
new file mode 100644
index 0000000..c6b0c1a
--- /dev/null
+++ b/webkit/support/test_webmessageportchannel.cc
@@ -0,0 +1,91 @@
+// Copyright (c) 2011 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 "webkit/support/test_webmessageportchannel.h"
+
+#include "base/memory/scoped_ptr.h"
+#include "base/message_loop.h"
+#include "base/task.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebMessagePortChannelClient.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
+
+using WebKit::WebMessagePortChannel;
+using WebKit::WebMessagePortChannelArray;
+using WebKit::WebMessagePortChannelClient;
+using WebKit::WebString;
+
+class TestWebMessagePortChannel::Message {
+ public:
+ Message(WebString data, WebMessagePortChannelArray* ports)
+ : data_(data),
+ ports_(ports) {
+ }
+ ~Message() {
+ if (ports_ == NULL)
+ return;
+ for (size_t i = 0; i < ports_->size(); ++i)
+ (*ports_)[i]->destroy();
+ }
+ WebString data() const { return data_; }
+ WebMessagePortChannelArray* ports() { return ports_.get(); }
+
+ private:
+ WebString data_;
+ scoped_ptr<WebMessagePortChannelArray> ports_;
+ DISALLOW_COPY_AND_ASSIGN(Message);
+};
+
+TestWebMessagePortChannel::TestWebMessagePortChannel()
+ : client_(NULL) {
+ AddRef();
+}
+
+TestWebMessagePortChannel::~TestWebMessagePortChannel() {
+}
+
+void TestWebMessagePortChannel::setClient(WebMessagePortChannelClient* client) {
+ client_ = client;
+}
+
+void TestWebMessagePortChannel::destroy() {
+ while (!message_queue_.empty()) {
+ delete message_queue_.front();
+ message_queue_.pop();
+ }
+ Release();
+}
+
+void TestWebMessagePortChannel::entangle(WebMessagePortChannel* remote) {
+ remote_ = static_cast<TestWebMessagePortChannel*>(remote);
+}
+
+void TestWebMessagePortChannel::postMessage(const WebString& data,
+ WebMessagePortChannelArray* ports) {
+ if (remote_ == NULL)
+ return;
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ NewRunnableMethod(remote_.get(),
+ &TestWebMessagePortChannel::queueMessage,
+ new Message(data, ports)));
+}
+
+bool TestWebMessagePortChannel::tryGetMessage(WebString* data,
+ WebMessagePortChannelArray& ports) {
+ if (message_queue_.empty())
+ return false;
+ scoped_ptr<Message> message(message_queue_.front());
+ message_queue_.pop();
+ *data = message->data();
+ if (WebMessagePortChannelArray* message_ports = message->ports())
+ ports.swap(*message_ports);
+ return true;
+}
+
+void TestWebMessagePortChannel::queueMessage(Message* message) {
+ bool was_empty = message_queue_.empty();
+ message_queue_.push(message);
+ if (client_ && was_empty)
+ client_->messageAvailable();
+}
diff --git a/webkit/support/test_webmessageportchannel.h b/webkit/support/test_webmessageportchannel.h
new file mode 100644
index 0000000..101a6e4
--- /dev/null
+++ b/webkit/support/test_webmessageportchannel.h
@@ -0,0 +1,47 @@
+// Copyright (c) 2011 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 WEBKIT_SUPPORT_TEST_WEBMESSAGEPORTCHANNEL_H_
+#define WEBKIT_SUPPORT_TEST_WEBMESSAGEPORTCHANNEL_H_
+
+#include <queue>
+
+#include "base/compiler_specific.h"
+#include "base/memory/ref_counted.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebMessagePortChannel.h"
+
+namespace WebKit {
+class WebString;
+}
+
+class TestWebMessagePortChannel
+ : public WebKit::WebMessagePortChannel,
+ public base::RefCounted<TestWebMessagePortChannel> {
+ public:
+ TestWebMessagePortChannel();
+ virtual ~TestWebMessagePortChannel();
+
+ // WebMessagePortChannel implementation.
+ virtual void setClient(WebKit::WebMessagePortChannelClient*) OVERRIDE;
+ virtual void destroy() OVERRIDE;
+ // WebKit versions of WebCore::MessagePortChannel.
+ virtual void entangle(WebKit::WebMessagePortChannel*) OVERRIDE;
+ // Callee receives ownership of the passed vector.
+ virtual void postMessage(const WebKit::WebString&,
+ WebKit::WebMessagePortChannelArray*) OVERRIDE;
+ virtual bool tryGetMessage(WebKit::WebString*,
+ WebKit::WebMessagePortChannelArray&) OVERRIDE;
+
+ private:
+ class Message;
+ void queueMessage(Message*);
+
+ WebKit::WebMessagePortChannelClient* client_;
+ scoped_refptr<TestWebMessagePortChannel> remote_;
+ std::queue<Message*> message_queue_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestWebMessagePortChannel);
+};
+
+#endif
diff --git a/webkit/support/webkit_support.gypi b/webkit/support/webkit_support.gypi
index f807145..33bc013 100644
--- a/webkit/support/webkit_support.gypi
+++ b/webkit/support/webkit_support.gypi
@@ -43,6 +43,8 @@
'platform_support_win.cc',
'test_webkit_platform_support.cc',
'test_webkit_platform_support.h',
+ 'test_webmessageportchannel.cc',
+ 'test_webmessageportchannel.h',
'test_webplugin_page_delegate.cc',
'test_webplugin_page_delegate.h',
'webkit_support.cc',