blob: 632572b22bebe4d5d698cede49e6504c28b4361f [file] [log] [blame]
[email protected]3ecb2b582014-05-23 00:25:391// 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
[email protected]8d41e5a2014-05-28 03:18:495#include "components/gcm_driver/fake_gcm_app_handler.h"
[email protected]3ecb2b582014-05-23 00:25:396
7#include "base/run_loop.h"
8
9namespace gcm {
10
11FakeGCMAppHandler::FakeGCMAppHandler() : received_event_(NO_EVENT) {
12}
13
14FakeGCMAppHandler::~FakeGCMAppHandler() {
15}
16
17void FakeGCMAppHandler::WaitForNotification() {
18 run_loop_.reset(new base::RunLoop);
19 run_loop_->Run();
20 run_loop_.reset();
21}
22
23void FakeGCMAppHandler::ShutdownHandler() {
24}
25
26void FakeGCMAppHandler::OnMessage(const std::string& app_id,
27 const GCMClient::IncomingMessage& message) {
28 ClearResults();
29 received_event_ = MESSAGE_EVENT;
30 app_id_ = app_id;
31 message_ = message;
32 if (run_loop_)
33 run_loop_->Quit();
34}
35
36void FakeGCMAppHandler::OnMessagesDeleted(const std::string& app_id) {
37 ClearResults();
38 received_event_ = MESSAGES_DELETED_EVENT;
39 app_id_ = app_id;
40 if (run_loop_)
41 run_loop_->Quit();
42}
43
44void FakeGCMAppHandler::OnSendError(
45 const std::string& app_id,
46 const GCMClient::SendErrorDetails& send_error_details) {
47 ClearResults();
48 received_event_ = SEND_ERROR_EVENT;
49 app_id_ = app_id;
50 send_error_details_ = send_error_details;
51 if (run_loop_)
52 run_loop_->Quit();
53}
54
55void FakeGCMAppHandler::ClearResults() {
56 received_event_ = NO_EVENT;
57 app_id_.clear();
58 message_ = GCMClient::IncomingMessage();
59 send_error_details_ = GCMClient::SendErrorDetails();
60}
61
62} // namespace gcm