MockQC stops create its own RP and MockOcclusionTracker
[chromium-blink-merge.git] / ipc / ipc_test_sink.cc
blob9e9d1fd3c2445191f4eb6e3840e7adf93a1b8f96
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ipc/ipc_test_sink.h"
7 #include "ipc/ipc_listener.h"
8 #include "ipc/ipc_message.h"
10 namespace IPC {
12 TestSink::TestSink() {
15 TestSink::~TestSink() {
18 bool TestSink::Send(Message* message) {
19 OnMessageReceived(*message);
20 delete message;
21 return true;
24 bool TestSink::Connect() {
25 NOTIMPLEMENTED();
26 return false;
29 void TestSink::Close() {
30 NOTIMPLEMENTED();
33 base::ProcessId TestSink::GetPeerPID() const {
34 NOTIMPLEMENTED();
35 return base::ProcessId();
39 bool TestSink::OnMessageReceived(const Message& msg) {
40 ObserverListBase<Listener>::Iterator it(filter_list_);
41 Listener* observer;
42 while ((observer = it.GetNext()) != NULL) {
43 if (observer->OnMessageReceived(msg))
44 return true;
47 // No filter handled the message, so store it.
48 messages_.push_back(Message(msg));
49 return true;
52 void TestSink::ClearMessages() {
53 messages_.clear();
56 const Message* TestSink::GetMessageAt(size_t index) const {
57 if (index >= messages_.size())
58 return NULL;
59 return &messages_[index];
62 const Message* TestSink::GetFirstMessageMatching(uint32 id) const {
63 for (size_t i = 0; i < messages_.size(); i++) {
64 if (messages_[i].type() == id)
65 return &messages_[i];
67 return NULL;
70 const Message* TestSink::GetUniqueMessageMatching(uint32 id) const {
71 size_t found_index = 0;
72 size_t found_count = 0;
73 for (size_t i = 0; i < messages_.size(); i++) {
74 if (messages_[i].type() == id) {
75 found_count++;
76 found_index = i;
79 if (found_count != 1)
80 return NULL; // Didn't find a unique one.
81 return &messages_[found_index];
84 void TestSink::AddFilter(Listener* filter) {
85 filter_list_.AddObserver(filter);
88 void TestSink::RemoveFilter(Listener* filter) {
89 filter_list_.RemoveObserver(filter);
92 #if defined(OS_POSIX) && !defined(OS_NACL)
94 int TestSink::GetClientFileDescriptor() const {
95 NOTREACHED();
96 return -1;
99 int TestSink::TakeClientFileDescriptor() {
100 NOTREACHED();
101 return -1;
104 #endif // defined(OS_POSIX) && !defined(OS_NACL)
106 } // namespace IPC