• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_MOCK_OWNER_KEY_UTILS_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_MOCK_OWNER_KEY_UTILS_H_
7 #pragma once
8 
9 #include <vector>
10 
11 #include "base/basictypes.h"
12 #include "base/file_path.h"
13 #include "crypto/rsa_private_key.h"
14 #include "chrome/browser/chromeos/cros/login_library.h"
15 #include "chrome/browser/chromeos/login/owner_key_utils.h"
16 #include "content/browser/browser_thread.h"
17 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19 
20 namespace chromeos {
21 
22 class MockKeyUtils : public OwnerKeyUtils {
23  public:
MockKeyUtils()24   MockKeyUtils() {}
25   MOCK_METHOD2(ImportPublicKey, bool(const FilePath& key_file,
26                                      std::vector<uint8>* output));
27   MOCK_METHOD3(Verify, bool(const std::string& data,
28                             const std::vector<uint8> signature,
29                             const std::vector<uint8> public_key));
30   MOCK_METHOD3(Sign, bool(const std::string& data,
31                           std::vector<uint8>* OUT_signature,
32                           crypto::RSAPrivateKey* key));
33   MOCK_METHOD1(FindPrivateKey,
34                crypto::RSAPrivateKey*(const std::vector<uint8>& key));
35   MOCK_METHOD0(GetOwnerKeyFilePath, FilePath());
36   MOCK_METHOD2(ExportPublicKeyToFile, bool(crypto::RSAPrivateKey* pair,
37                                            const FilePath& key_file));
38  protected:
~MockKeyUtils()39   virtual ~MockKeyUtils() {}
40 
41  private:
42   DISALLOW_COPY_AND_ASSIGN(MockKeyUtils);
43 };
44 
45 class MockInjector : public OwnerKeyUtils::Factory {
46  public:
47   // Takes ownership of |mock|.
MockInjector(MockKeyUtils * mock)48   explicit MockInjector(MockKeyUtils* mock) : transient_(mock) {
49   }
50 
~MockInjector()51   virtual ~MockInjector() {}
52 
53   // If this is called, its caller takes ownership of |transient_|.
54   // If it's never called, |transient_| remains our problem.
CreateOwnerKeyUtils()55   OwnerKeyUtils* CreateOwnerKeyUtils() {
56     return transient_.get();
57   }
58 
59  private:
60   scoped_refptr<MockKeyUtils> transient_;
61   DISALLOW_COPY_AND_ASSIGN(MockInjector);
62 };
63 
64 }  // namespace chromeos
65 
66 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_MOCK_OWNER_KEY_UTILS_H_
67