blob: e79233f29c00033a916126c21f71b61fd64cb6fc [file] [log] [blame]
Bertrand SIMONNET52e5b992015-08-10 15:18:00 -07001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Bertrand SIMONNET46b49da2014-06-25 14:38:07 -070016
17#ifndef METRICS_UPLOADER_MOCK_SENDER_MOCK_H_
18#define METRICS_UPLOADER_MOCK_SENDER_MOCK_H_
19
20#include <string>
21
22#include "base/compiler_specific.h"
Bertrand SIMONNET4b915ae2015-07-28 15:38:14 -070023#include "uploader/proto/chrome_user_metrics_extension.pb.h"
Bertrand SIMONNET46b49da2014-06-25 14:38:07 -070024#include "uploader/sender.h"
25
26class SenderMock : public Sender {
27 public:
28 SenderMock();
29
Alex Vakulenkoe8a8e302014-08-14 12:56:21 -070030 bool Send(const std::string& content, const std::string& hash) override;
Bertrand SIMONNET46b49da2014-06-25 14:38:07 -070031 void Reset();
32
33 bool is_good_proto() { return is_good_proto_; }
34 int send_call_count() { return send_call_count_; }
35 const std::string last_message() { return last_message_; }
36 metrics::ChromeUserMetricsExtension last_message_proto() {
37 return last_message_proto_;
38 }
39 void set_should_succeed(bool succeed) { should_succeed_ = succeed; }
40
41 private:
42 // Is set to true if the proto was parsed successfully.
43 bool is_good_proto_;
44
45 // If set to true, the Send method will return true to simulate a successful
46 // send.
47 bool should_succeed_;
48
49 // Count of how many times Send was called since the last reset.
50 int send_call_count_;
51
52 // Last message received by Send.
53 std::string last_message_;
54
55 // If is_good_proto is true, last_message_proto is the deserialized
56 // representation of last_message.
57 metrics::ChromeUserMetricsExtension last_message_proto_;
58};
59
60#endif // METRICS_UPLOADER_MOCK_SENDER_MOCK_H_