fake_gcm_app_handler.cc revision 5f1c94371a64b3196d4be9466099bb892df9b88e
1// Copyright 2014 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 "components/gcm_driver/fake_gcm_app_handler.h"
6
7#include "base/run_loop.h"
8
9namespace gcm {
10
11FakeGCMAppHandler::FakeGCMAppHandler()
12    : received_event_(NO_EVENT), connected_(false) {
13}
14
15FakeGCMAppHandler::~FakeGCMAppHandler() {
16}
17
18void FakeGCMAppHandler::WaitForNotification() {
19  run_loop_.reset(new base::RunLoop);
20  run_loop_->Run();
21  run_loop_.reset();
22}
23
24void FakeGCMAppHandler::ShutdownHandler() {
25}
26
27void FakeGCMAppHandler::OnMessage(const std::string& app_id,
28                                  const GCMClient::IncomingMessage& message) {
29  ClearResults();
30  received_event_ = MESSAGE_EVENT;
31  app_id_ = app_id;
32  message_ = message;
33  if (run_loop_)
34    run_loop_->Quit();
35}
36
37void FakeGCMAppHandler::OnMessagesDeleted(const std::string& app_id) {
38  ClearResults();
39  received_event_ = MESSAGES_DELETED_EVENT;
40  app_id_ = app_id;
41  if (run_loop_)
42    run_loop_->Quit();
43}
44
45void FakeGCMAppHandler::OnSendError(
46    const std::string& app_id,
47    const GCMClient::SendErrorDetails& send_error_details) {
48  ClearResults();
49  received_event_ = SEND_ERROR_EVENT;
50  app_id_ = app_id;
51  send_error_details_ = send_error_details;
52  if (run_loop_)
53    run_loop_->Quit();
54}
55
56void FakeGCMAppHandler::OnSendAcknowledged(
57    const std::string& app_id,
58    const std::string& message_id) {
59  ClearResults();
60  app_id_ = app_id;
61  acked_message_id_ = message_id;
62  if (run_loop_)
63    run_loop_->Quit();
64}
65
66void FakeGCMAppHandler::ClearResults() {
67  received_event_ = NO_EVENT;
68  app_id_.clear();
69  acked_message_id_.clear();
70  message_ = GCMClient::IncomingMessage();
71  send_error_details_ = GCMClient::SendErrorDetails();
72}
73
74void FakeGCMAppHandler::OnConnected(const net::IPEndPoint& ip_endpoint) {
75  connected_ = true;
76}
77
78void FakeGCMAppHandler::OnDisconnected() {
79  connected_ = false;
80}
81
82}  // namespace gcm
83