Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(730)

Side by Side Diff: chrome/common/ipc_test_sink.cc

Issue 6290008: Move the TestSink for doing IPC tests from chrome/common into IPC and create ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/common/ipc_test_sink.h ('k') | chrome/renderer/mock_render_thread.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010 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.
4
5 #include "chrome/common/ipc_test_sink.h"
6 #include "ipc/ipc_message.h"
7
8 namespace IPC {
9
10 TestSink::TestSink() {
11 }
12
13 TestSink::~TestSink() {
14 }
15
16 bool TestSink::Send(IPC::Message* message) {
17 OnMessageReceived(*message);
18 delete message;
19 return true;
20 }
21
22 bool TestSink::OnMessageReceived(const Message& msg) {
23 messages_.push_back(Message(msg));
24 return true;
25 }
26
27 void TestSink::ClearMessages() {
28 messages_.clear();
29 }
30
31 const Message* TestSink::GetMessageAt(size_t index) const {
32 if (index >= messages_.size())
33 return NULL;
34 return &messages_[index];
35 }
36
37 const Message* TestSink::GetFirstMessageMatching(uint32 id) const {
38 for (size_t i = 0; i < messages_.size(); i++) {
39 if (messages_[i].type() == id)
40 return &messages_[i];
41 }
42 return NULL;
43 }
44
45 const Message* TestSink::GetUniqueMessageMatching(uint32 id) const {
46 size_t found_index = 0;
47 size_t found_count = 0;
48 for (size_t i = 0; i < messages_.size(); i++) {
49 if (messages_[i].type() == id) {
50 found_count++;
51 found_index = i;
52 }
53 }
54 if (found_count != 1)
55 return NULL; // Didn't find a unique one.
56 return &messages_[found_index];
57 }
58
59 } // namespace IPC
OLDNEW
« no previous file with comments | « chrome/common/ipc_test_sink.h ('k') | chrome/renderer/mock_render_thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698