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

Side by Side Diff: chrome/browser/keychain_mock_mac.h

Issue 151176: Implement Add and Update for PasswordStoreMac.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/keychain_mock_mac.cc » ('j') | chrome/browser/keychain_mock_mac.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_KEYCHAIN_MOCK_MAC_H_ 5 #ifndef CHROME_BROWSER_KEYCHAIN_MOCK_MAC_H_
6 #define CHROME_BROWSER_KEYCHAIN_MOCK_MAC_H_ 6 #define CHROME_BROWSER_KEYCHAIN_MOCK_MAC_H_
7 7
8 #include <set>
8 #include <vector> 9 #include <vector>
9 10
10 #include "chrome/browser/keychain_mac.h" 11 #include "chrome/browser/keychain_mac.h"
11 12
12 // Mock Keychain wrapper for testing code that interacts with the OS Keychain. 13 // Mock Keychain wrapper for testing code that interacts with the OS Keychain.
13 // The basic idea of this mock is that it has a static array of data, and 14 // The basic idea of this mock is that it has a static array of data, and
14 // SecKeychainItemRef values are just indexes into that array (offset by 1 to 15 // SecKeychainItemRef values are just indexes into that array (offset by 1 to
15 // prevent problems with clients that null-check refs), cast to pointers. 16 // prevent problems with clients that null-check refs), cast to pointers.
16 // 17 //
17 // Note that "const" is pretty much meaningless for this class; the const-ness 18 // Note that "const" is pretty much meaningless for this class; the const-ness
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 const void *passwordData, 56 const void *passwordData,
56 SecKeychainItemRef *itemRef) const; 57 SecKeychainItemRef *itemRef) const;
57 virtual void Free(CFTypeRef ref) const; 58 virtual void Free(CFTypeRef ref) const;
58 59
59 // Return the counts of objects returned by Create/Copy functions but never 60 // Return the counts of objects returned by Create/Copy functions but never
60 // Free'd as they should have been. 61 // Free'd as they should have been.
61 int UnfreedSearchCount() const; 62 int UnfreedSearchCount() const;
62 int UnfreedKeychainItemCount() const; 63 int UnfreedKeychainItemCount() const;
63 int UnfreedAttributeDataCount() const; 64 int UnfreedAttributeDataCount() const;
64 65
66 // Returns true if all items added with AddInternetPassword have a creator
67 // code set.
68 bool CreatorCodesSetForAddedItems() const;
69
65 struct KeychainTestData { 70 struct KeychainTestData {
66 const SecAuthenticationType auth_type; 71 const SecAuthenticationType auth_type;
67 const char* server; 72 const char* server;
68 const SecProtocolType protocol; 73 const SecProtocolType protocol;
69 const char* path; 74 const char* path;
70 const UInt32 port; 75 const UInt32 port;
71 const char* security_domain; 76 const char* security_domain;
72 const char* creation_date; 77 const char* creation_date;
73 const char* username; 78 const char* username;
74 const char* password; 79 const char* password;
(...skipping 10 matching lines...) Expand all
85 // docs don't indicate whether it is or not, so clients should not assume 90 // docs don't indicate whether it is or not, so clients should not assume
86 // that it will be. 91 // that it will be.
87 void SetTestDataString(int item, UInt32 tag, const char* value); 92 void SetTestDataString(int item, UInt32 tag, const char* value);
88 // Sets the data of the corresponding attribute of the item-th test item to 93 // Sets the data of the corresponding attribute of the item-th test item to
89 // |value|. Assumes that the space has alread been allocated, and the length 94 // |value|. Assumes that the space has alread been allocated, and the length
90 // set. 95 // set.
91 void SetTestDataPort(int item, UInt32 value); 96 void SetTestDataPort(int item, UInt32 value);
92 void SetTestDataProtocol(int item, SecProtocolType value); 97 void SetTestDataProtocol(int item, SecProtocolType value);
93 void SetTestDataAuthType(int item, SecAuthenticationType value); 98 void SetTestDataAuthType(int item, SecAuthenticationType value);
94 void SetTestDataNegativeItem(int item, Boolean value); 99 void SetTestDataNegativeItem(int item, Boolean value);
100 void SetTestDataCreator(int item, OSType value);
95 // Sets the password data and length for the item-th test item. 101 // Sets the password data and length for the item-th test item.
96 void SetTestDataPasswordBytes(int item, const void* data, size_t length); 102 void SetTestDataPasswordBytes(int item, const void* data, size_t length);
97 // Sets the password for the item-th test item. As with SetTestDataString, 103 // Sets the password for the item-th test item. As with SetTestDataString,
98 // the data will not be null-terminated. 104 // the data will not be null-terminated.
99 void SetTestDataPasswordString(int item, const char* value); 105 void SetTestDataPasswordString(int item, const char* value);
100 106
101 // Returns the index of |tag| in |attribute_list|, or -1 if it's not found. 107 // Returns the address of the attribute in attribute_list with tag |tag|, or
102 static int IndexForTag(const SecKeychainAttributeList& attribute_list, 108 // NULL if the attribute is not found.
103 UInt32 tag); 109 static SecKeychainAttribute* AttributeWithTag(
110 const SecKeychainAttributeList& attribute_list, UInt32 tag);
104 111
105 static const int kDummySearchRef = 1000; 112 static const int kDummySearchRef = 1000;
106 113
107 typedef struct { 114 typedef struct {
108 void* data; 115 void* data;
109 UInt32 length; 116 UInt32 length;
110 } KeychainPasswordData; 117 } KeychainPasswordData;
111 118
112 SecKeychainAttributeList* keychain_attr_list_; 119 SecKeychainAttributeList* keychain_attr_list_;
113 KeychainPasswordData* keychain_data_; 120 KeychainPasswordData* keychain_data_;
114 unsigned int item_capacity_; 121 unsigned int item_capacity_;
115 mutable unsigned int item_count_; 122 mutable unsigned int item_count_;
116 123
117 // Tracks the items that should be returned in subsequent calls to 124 // Tracks the items that should be returned in subsequent calls to
118 // SearchCopyNext, based on the last call to SearchCreateFromAttributes. 125 // SearchCopyNext, based on the last call to SearchCreateFromAttributes.
119 // We can't handle multiple active searches, since we don't track the search 126 // We can't handle multiple active searches, since we don't track the search
120 // ref we return, but we don't need to for our mocking. 127 // ref we return, but we don't need to for our mocking.
121 mutable std::vector<unsigned int> remaining_search_results_; 128 mutable std::vector<unsigned int> remaining_search_results_;
122 129
123 // Track copies and releases to make sure they balance. Really these should 130 // Track copies and releases to make sure they balance. Really these should
124 // be maps to track per item, but this should be good enough to catch 131 // be maps to track per item, but this should be good enough to catch
125 // real mistakes. 132 // real mistakes.
126 mutable int search_copy_count_; 133 mutable int search_copy_count_;
127 mutable int keychain_item_copy_count_; 134 mutable int keychain_item_copy_count_;
128 mutable int attribute_data_copy_count_; 135 mutable int attribute_data_copy_count_;
136
137 // Tracks which items (by index) were added with AddInternetPassword.
138 mutable std::set<unsigned int> added_via_api_;
129 }; 139 };
130 140
131 #endif // CHROME_BROWSER_KEYCHAIN_MOCK_MAC_H_ 141 #endif // CHROME_BROWSER_KEYCHAIN_MOCK_MAC_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/keychain_mock_mac.cc » ('j') | chrome/browser/keychain_mock_mac.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698