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

Unified Diff: components/proximity_auth/fake_connection.cc

Issue 1351473003: Refactor fake Connection subclasses in proximity_auth/ tests to a single file. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@client_rename
Patch Set: rebase Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/proximity_auth/fake_connection.h ('k') | components/proximity_auth/messenger_impl_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/proximity_auth/fake_connection.cc
diff --git a/components/proximity_auth/fake_connection.cc b/components/proximity_auth/fake_connection.cc
new file mode 100644
index 0000000000000000000000000000000000000000..68ddae593257d94d9aae3d5376a3ac2e58160d1a
--- /dev/null
+++ b/components/proximity_auth/fake_connection.cc
@@ -0,0 +1,53 @@
+// Copyright 2015 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 "components/proximity_auth/fake_connection.h"
+
+#include "components/proximity_auth/wire_message.h"
+
+namespace proximity_auth {
+
+FakeConnection::FakeConnection(const RemoteDevice& remote_device)
+ : Connection(RemoteDevice()) {
+ Connect();
+}
+
+FakeConnection::~FakeConnection() {
+ Disconnect();
+}
+
+void FakeConnection::Connect() {
+ SetStatus(CONNECTED);
+}
+
+void FakeConnection::Disconnect() {
+ SetStatus(DISCONNECTED);
+}
+
+void FakeConnection::FinishSendingMessageWithSuccess(bool success) {
+ CHECK(current_message_);
+ // Capture a copy of the message, as OnDidSendMessage() might reentrantly
+ // call SendMessage().
+ scoped_ptr<WireMessage> sent_message = current_message_.Pass();
+ OnDidSendMessage(*sent_message, success);
+}
+
+void FakeConnection::ReceiveMessageWithPayload(const std::string& payload) {
+ pending_payload_ = payload;
+ OnBytesReceived(std::string());
+ pending_payload_.clear();
+}
+
+void FakeConnection::SendMessageImpl(scoped_ptr<WireMessage> message) {
+ CHECK(!current_message_);
+ current_message_ = message.Pass();
+}
+
+scoped_ptr<WireMessage> FakeConnection::DeserializeWireMessage(
+ bool* is_incomplete_message) {
+ *is_incomplete_message = false;
+ return make_scoped_ptr(new WireMessage(pending_payload_));
+}
+
+} // namespace proximity_auth
« no previous file with comments | « components/proximity_auth/fake_connection.h ('k') | components/proximity_auth/messenger_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698