Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(300)

Side by Side Diff: chrome/browser/chromeos/login/mock_owner_key_utils.h

Issue 3141031: [Chrome OS] Wire up ownership API from libcros (Closed)
Patch Set: address davemoore comments Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2010 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/crypto/rsa_private_key.h"
13 #include "base/file_path.h"
14 #include "chrome/browser/chrome_thread.h"
15 #include "chrome/browser/chromeos/cros/login_library.h"
16 #include "chrome/browser/chromeos/login/owner_key_utils.h"
17 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19
20 using ::base::RSAPrivateKey;
21
22 namespace chromeos {
23
24 class MockKeyUtils : public OwnerKeyUtils {
25 public:
26 MockKeyUtils() {}
27 MOCK_METHOD0(GenerateKeyPair, RSAPrivateKey*());
28 MOCK_METHOD2(ExportPublicKeyViaDbus, bool(RSAPrivateKey* pair,
29 LoginLibrary::Delegate<bool>*));
30 MOCK_METHOD2(ExportPublicKeyToFile, bool(RSAPrivateKey* pair,
31 const FilePath& key_file));
32 MOCK_METHOD2(ImportPublicKey, bool(const FilePath& key_file,
33 std::vector<uint8>* output));
34 MOCK_METHOD1(FindPrivateKey, RSAPrivateKey*(const std::vector<uint8>& key));
35 MOCK_METHOD0(GetOwnerKeyFilePath, FilePath());
36
37 // To simulate doing a LoginLibrary::SetOwnerKey call
38 static void SetOwnerKeyCallback(LoginLibrary::Delegate<bool>* callback,
39 bool value) {
40 callback->Run(value);
41 }
42
43 static bool ExportPublicKeyViaDbusWin(RSAPrivateKey* key,
44 LoginLibrary::Delegate<bool>* d) {
45 ChromeThread::PostTask(
46 ChromeThread::UI, FROM_HERE,
47 NewRunnableFunction(&SetOwnerKeyCallback, d, true));
48 return true;
49 }
50
51 static bool ExportPublicKeyViaDbusFail(RSAPrivateKey* key,
52 LoginLibrary::Delegate<bool>* d) {
53 ChromeThread::PostTask(
54 ChromeThread::UI, FROM_HERE,
55 NewRunnableFunction(&SetOwnerKeyCallback, d, false));
56 return false;
57 }
58
59 protected:
60 virtual ~MockKeyUtils() {}
61
62 private:
63 DISALLOW_COPY_AND_ASSIGN(MockKeyUtils);
64 };
65
66 class MockInjector : public OwnerKeyUtils::Factory {
67 public:
68 // Takes ownership of |mock|.
69 explicit MockInjector(MockKeyUtils* mock) : transient_(mock) {
70 }
71
72 virtual ~MockInjector() {}
73
74 // If this is called, its caller takes ownership of |transient_|.
75 // If it's never called, |transient_| remains our problem.
76 OwnerKeyUtils* CreateOwnerKeyUtils() {
77 return transient_.get();
78 }
79
80 private:
81 scoped_refptr<MockKeyUtils> transient_;
82 DISALLOW_COPY_AND_ASSIGN(MockInjector);
83 };
84
85 } // namespace chromeos
86
87 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_MOCK_OWNER_KEY_UTILS_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/cros/mock_login_library.h ('k') | chrome/browser/chromeos/login/owner_key_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698