summaryrefslogtreecommitdiffstats
path: root/chromeos/attestation/mock_attestation_flow.h
blob: bda8a721389e428640db6d86e5d7580aec9808cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright (c) 2012 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.

#ifndef CHROMEOS_ATTESTATION_MOCK_ATTESTATION_FLOW_H_
#define CHROMEOS_ATTESTATION_MOCK_ATTESTATION_FLOW_H_

#include "chromeos/attestation/attestation_flow.h"

#include "base/basictypes.h"
#include "base/callback.h"
#include "testing/gmock/include/gmock/gmock.h"

namespace chromeos {
namespace attestation {

// A fake server proxy which just appends "_response" to every request.
class FakeServerProxy : public ServerProxy {
 public:
  FakeServerProxy();
  virtual ~FakeServerProxy();

  void set_result(bool result) {
    result_ = result;
  }

  virtual void SendEnrollRequest(const std::string& request,
                                 const DataCallback& callback) OVERRIDE;

  virtual void SendCertificateRequest(const std::string& request,
                                      const DataCallback& callback) OVERRIDE;

 private:
  bool result_;

  DISALLOW_COPY_AND_ASSIGN(FakeServerProxy);
};

class MockServerProxy : public ServerProxy {
 public:
  MockServerProxy();
  virtual ~MockServerProxy();

  void DeferToFake(bool result);
  MOCK_METHOD2(SendEnrollRequest,
               void(const std::string&, const DataCallback&));
  MOCK_METHOD2(SendCertificateRequest,
               void(const std::string&, const DataCallback&));

 private:
  FakeServerProxy fake_;
};

// This class can be used to mock AttestationFlow callbacks.
class MockObserver {
 public:
  MockObserver();
  virtual ~MockObserver();

  MOCK_METHOD2(MockCertificateCallback, void(bool, const std::string&));
};

class MockAttestationFlow : public AttestationFlow {
 public:
  MockAttestationFlow();
  virtual ~MockAttestationFlow();

  MOCK_METHOD3(GetCertificate, void(AttestationCertificateProfile,
                                    bool,
                                    const CertificateCallback&));
};

}  // namespace attestation
}  // namespace chromeos

#endif  // CHROMEOS_ATTESTATION_MOCK_ATTESTATION_FLOW_H_