cc: Skip commit state timer on sync compositor
[chromium-blink-merge.git] / crypto / mock_apple_keychain.cc
blob1ddfc8679461c6fddf320642405dc31f98643c0b
1 // Copyright (c) 2012 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.
5 #include "base/logging.h"
6 #include "base/time/time.h"
7 #include "crypto/mock_apple_keychain.h"
9 namespace crypto {
11 OSStatus MockAppleKeychain::FindGenericPassword(
12 CFTypeRef keychainOrArray,
13 UInt32 serviceNameLength,
14 const char* serviceName,
15 UInt32 accountNameLength,
16 const char* accountName,
17 UInt32* passwordLength,
18 void** passwordData,
19 SecKeychainItemRef* itemRef) const {
20 // When simulating |noErr|, return canned |passwordData| and
21 // |passwordLength|. Otherwise, just return given code.
22 if (find_generic_result_ == noErr) {
23 static const char kPassword[] = "my_password";
24 DCHECK(passwordData);
25 // The function to free this data is mocked so the cast is fine.
26 *passwordData = const_cast<char*>(kPassword);
27 DCHECK(passwordLength);
28 *passwordLength = arraysize(kPassword);
29 password_data_count_++;
32 return find_generic_result_;
35 OSStatus MockAppleKeychain::ItemFreeContent(SecKeychainAttributeList* attrList,
36 void* data) const {
37 // No-op.
38 password_data_count_--;
39 return noErr;
42 OSStatus MockAppleKeychain::AddGenericPassword(
43 SecKeychainRef keychain,
44 UInt32 serviceNameLength,
45 const char* serviceName,
46 UInt32 accountNameLength,
47 const char* accountName,
48 UInt32 passwordLength,
49 const void* passwordData,
50 SecKeychainItemRef* itemRef) const {
51 called_add_generic_ = true;
53 DCHECK_GT(passwordLength, 0U);
54 DCHECK(passwordData);
55 add_generic_password_ =
56 std::string(const_cast<char*>(static_cast<const char*>(passwordData)),
57 passwordLength);
58 return noErr;
61 } // namespace crypto