1 /*
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  */
16 
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"
23 #include "uploader/proto/chrome_user_metrics_extension.pb.h"
24 #include "uploader/sender.h"
25 
26 class SenderMock : public Sender {
27  public:
28   SenderMock();
29 
30   bool Send(const std::string& content, const std::string& hash) override;
31   void Reset();
32 
is_good_proto()33   bool is_good_proto() { return is_good_proto_; }
send_call_count()34   int send_call_count() { return send_call_count_; }
last_message()35   const std::string last_message() { return last_message_; }
last_message_proto()36   metrics::ChromeUserMetricsExtension last_message_proto() {
37     return last_message_proto_;
38   }
set_should_succeed(bool succeed)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_
61