Index: crypto/mock_apple_keychain.cc |
diff --git a/crypto/mock_apple_keychain.cc b/crypto/mock_apple_keychain.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9fb6ad6a9473b218bd2dc5f27cf96cdb8acdac80 |
--- /dev/null |
+++ b/crypto/mock_apple_keychain.cc |
@@ -0,0 +1,61 @@ |
+// 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. |
+ |
+#include "base/logging.h" |
+#include "base/time.h" |
+#include "crypto/mock_apple_keychain.h" |
+ |
+namespace crypto { |
+ |
+OSStatus MockAppleKeychain::FindGenericPassword( |
+ CFTypeRef keychainOrArray, |
+ UInt32 serviceNameLength, |
+ const char* serviceName, |
+ UInt32 accountNameLength, |
+ const char* accountName, |
+ UInt32* passwordLength, |
+ void** passwordData, |
+ SecKeychainItemRef* itemRef) const { |
+ // When simulating |noErr|, return canned |passwordData| and |
+ // |passwordLength|. Otherwise, just return given code. |
+ if (find_generic_result_ == noErr) { |
+ static char password[] = "my_password"; |
Ryan Sleevi
2012/08/23 22:22:58
nit: static const char kPassword[] = "my_password"
msarda
2012/08/27 14:24:07
Done.
|
+ |
+ DCHECK(passwordData); |
+ *passwordData = static_cast<void*>(password); |
+ DCHECK(passwordLength); |
+ *passwordLength = strlen(password); |
Ryan Sleevi
2012/08/23 22:22:58
arraysize
msarda
2012/08/27 14:24:07
Done.
|
+ password_data_count_++; |
+ } |
+ |
+ return find_generic_result_; |
+} |
+ |
+OSStatus MockAppleKeychain::ItemFreeContent(SecKeychainAttributeList* attrList, |
+ void* data) const { |
+ // No-op. |
+ password_data_count_--; |
+ return noErr; |
+} |
+ |
+OSStatus MockAppleKeychain::AddGenericPassword( |
+ SecKeychainRef keychain, |
+ UInt32 serviceNameLength, |
+ const char* serviceName, |
+ UInt32 accountNameLength, |
+ const char* accountName, |
+ UInt32 passwordLength, |
+ const void* passwordData, |
+ SecKeychainItemRef* itemRef) const { |
+ called_add_generic_ = true; |
+ |
+ DCHECK(passwordLength > 0); |
Ryan Sleevi
2012/08/23 22:22:58
DCHECK_GT
msarda
2012/08/27 14:24:07
Done.
|
+ DCHECK(passwordData); |
+ add_generic_password_ = |
+ std::string(const_cast<char*>(static_cast<const char*>(passwordData)), |
+ passwordLength); |
+ return noErr; |
+} |
+ |
+} // namespace crypto |