summaryrefslogtreecommitdiffstats
path: root/webkit/support/test_webmessageportchannel.h
blob: bc2da1d9f9b981515b82dc0797562b0624b5adcf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (c) 2012 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/public/platform/WebMessagePortChannel.h"

namespace WebKit {
class WebString;
}

class TestWebMessagePortChannel
    : public WebKit::WebMessagePortChannel,
      public base::RefCounted<TestWebMessagePortChannel> {
 public:
  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;

 protected:
  virtual ~TestWebMessagePortChannel();

 private:
  friend class base::RefCounted<TestWebMessagePortChannel>;

  class Message;

  void queueMessage(Message*);

  WebKit::WebMessagePortChannelClient* client_;
  scoped_refptr<TestWebMessagePortChannel> remote_;
  std::queue<Message*> message_queue_;

  DISALLOW_COPY_AND_ASSIGN(TestWebMessagePortChannel);
};

#endif