summaryrefslogtreecommitdiffstats
path: root/chrome/browser/password_manager
diff options
context:
space:
mode:
authoralbertb@chromium.org <albertb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-14 20:04:01 +0000
committeralbertb@chromium.org <albertb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-14 20:04:01 +0000
commit18b147138e014805955bfcb5dc93e2191d6e2447 (patch)
treed9ce47b6dc2569738022cb083f49838b52cb8fc7 /chrome/browser/password_manager
parent50e3e21c297fcc1945ece4ed163053d7128a141d (diff)
downloadchromium_src-18b147138e014805955bfcb5dc93e2191d6e2447.zip
chromium_src-18b147138e014805955bfcb5dc93e2191d6e2447.tar.gz
chromium_src-18b147138e014805955bfcb5dc93e2191d6e2447.tar.bz2
Integration tests for password sync.
BUG=none TEST=self Review URL: http://codereview.chromium.org/3701007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62632 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/password_manager')
-rw-r--r--chrome/browser/password_manager/password_form_data.cc74
-rw-r--r--chrome/browser/password_manager/password_form_data.h57
-rw-r--r--chrome/browser/password_manager/password_store.h1
3 files changed, 85 insertions, 47 deletions
diff --git a/chrome/browser/password_manager/password_form_data.cc b/chrome/browser/password_manager/password_form_data.cc
index ef9391d..b428d9a 100644
--- a/chrome/browser/password_manager/password_form_data.cc
+++ b/chrome/browser/password_manager/password_form_data.cc
@@ -36,3 +36,77 @@ PasswordForm* CreatePasswordFormFromData(
}
return form;
}
+
+bool operator==(const PasswordForm& lhs, const PasswordForm& rhs) {
+ return (lhs.scheme == rhs.scheme &&
+ lhs.signon_realm == rhs.signon_realm &&
+ lhs.origin == rhs.origin &&
+ lhs.action == rhs.action &&
+ lhs.submit_element == rhs.submit_element &&
+ lhs.username_element == rhs.username_element &&
+ lhs.password_element == rhs.password_element &&
+ lhs.username_value == rhs.username_value &&
+ lhs.password_value == rhs.password_value &&
+ lhs.blacklisted_by_user == rhs.blacklisted_by_user &&
+ lhs.preferred == rhs.preferred &&
+ lhs.ssl_valid == rhs.ssl_valid &&
+ lhs.date_created == rhs.date_created);
+}
+
+std::ostream& operator<<(std::ostream& os, const PasswordForm& form) {
+ return os << "scheme: " << form.scheme << std::endl
+ << "signon_realm: " << form.signon_realm << std::endl
+ << "origin: " << form.origin << std::endl
+ << "action: " << form.action << std::endl
+ << "submit_element: " << form.submit_element << std::endl
+ << "username_elem: " << form.username_element << std::endl
+ << "password_elem: " << form.password_element << std::endl
+ << "username_value: " << form.username_value << std::endl
+ << "password_value: " << form.password_value << std::endl
+ << "blacklisted: " << form.blacklisted_by_user << std::endl
+ << "preferred: " << form.preferred << std::endl
+ << "ssl_valid: " << form.ssl_valid << std::endl
+ << "date_created: " << form.date_created.ToDoubleT();
+}
+
+typedef std::set<const webkit_glue::PasswordForm*> SetOfForms;
+
+bool ContainsSamePasswordFormsPtr(
+ const std::vector<PasswordForm*>& first,
+ const std::vector<PasswordForm*>& second) {
+ if (first.size() != second.size())
+ return false;
+ SetOfForms expectations(first.begin(), first.end());
+ for (unsigned int i = 0; i < second.size(); ++i) {
+ const PasswordForm* actual = second[i];
+ bool found_match = false;
+ for (SetOfForms::iterator it = expectations.begin();
+ it != expectations.end(); ++it) {
+ const PasswordForm* expected = *it;
+ if (*expected == *actual) {
+ found_match = true;
+ expectations.erase(it);
+ break;
+ }
+ }
+ if (!found_match) {
+ LOG(ERROR) << "No match for:" << std::endl << *actual;
+ return false;
+ }
+ }
+ return true;
+}
+
+bool ContainsSamePasswordForms(
+ std::vector<webkit_glue::PasswordForm>& first,
+ std::vector<webkit_glue::PasswordForm>& second) {
+ std::vector<PasswordForm*> first_ptr;
+ for (unsigned int i = 0; i < first.size(); ++i) {
+ first_ptr.push_back(&first[i]);
+ }
+ std::vector<PasswordForm*> second_ptr;
+ for (unsigned int i = 0; i < second.size(); ++i) {
+ second_ptr.push_back(&second[i]);
+ }
+ return ContainsSamePasswordFormsPtr(first_ptr, second_ptr);
+}
diff --git a/chrome/browser/password_manager/password_form_data.h b/chrome/browser/password_manager/password_form_data.h
index 838c3ce..8b3d248 100644
--- a/chrome/browser/password_manager/password_form_data.h
+++ b/chrome/browser/password_manager/password_form_data.h
@@ -31,57 +31,20 @@ struct PasswordFormData {
webkit_glue::PasswordForm* CreatePasswordFormFromData(
const PasswordFormData& form_data);
-typedef std::set<webkit_glue::PasswordForm*> SetOfForms;
+// Checks whether two vectors of PasswordForms contain equivalent elements,
+// regardless of order.
+bool ContainsSamePasswordFormsPtr(
+ const std::vector<webkit_glue::PasswordForm*>& first,
+ const std::vector<webkit_glue::PasswordForm*>& second);
+
+bool ContainsSamePasswordForms(
+ std::vector<webkit_glue::PasswordForm>& first,
+ std::vector<webkit_glue::PasswordForm>& second);
// This gmock matcher is used to check that the |arg| contains exactly the same
// PasswordForms as |forms|, regardless of order.
MATCHER_P(ContainsAllPasswordForms, forms, "") {
- if (forms.size() != arg.size())
- return false;
- SetOfForms expectations(forms.begin(), forms.end());
- for (unsigned int i = 0; i < arg.size(); ++i) {
- webkit_glue::PasswordForm* actual = arg[i];
- bool found_match = false;
- for (SetOfForms::iterator it = expectations.begin();
- it != expectations.end(); ++it) {
- webkit_glue::PasswordForm* expected = *it;
- if (expected->scheme == actual->scheme &&
- expected->signon_realm == actual->signon_realm &&
- expected->origin == actual->origin &&
- expected->action == actual->action &&
- expected->submit_element == actual->submit_element &&
- expected->username_element == actual->username_element &&
- expected->password_element == actual->password_element &&
- expected->username_value == actual->username_value &&
- expected->password_value == actual->password_value &&
- expected->blacklisted_by_user == actual->blacklisted_by_user &&
- expected->preferred == actual->preferred &&
- expected->ssl_valid == actual->ssl_valid &&
- expected->date_created == actual->date_created) {
- found_match = true;
- expectations.erase(it);
- break;
- }
- }
- if (!found_match) {
- LOG(ERROR) << "No match for:" << std::endl
- << "scheme: " << actual->scheme << std::endl
- << "signon_realm: " << actual->signon_realm << std::endl
- << "origin: " << actual->origin << std::endl
- << "action: " << actual->action << std::endl
- << "submit_element: " << actual->submit_element << std::endl
- << "username_elem: " << actual->username_element << std::endl
- << "password_elem: " << actual->password_element << std::endl
- << "username_value: " << actual->username_value << std::endl
- << "password_value: " << actual->password_value << std::endl
- << "blacklisted: " << actual->blacklisted_by_user << std::endl
- << "preferred: " << actual->preferred << std::endl
- << "ssl_valid: " << actual->ssl_valid << std::endl
- << "date_created: " << actual->date_created.ToDoubleT();
- return false;
- }
- }
- return true;
+ return ContainsSamePasswordFormsPtr(forms, arg);
}
#endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_FORM_DATA_H_
diff --git a/chrome/browser/password_manager/password_store.h b/chrome/browser/password_manager/password_store.h
index 6b6efa8..6b538d9 100644
--- a/chrome/browser/password_manager/password_store.h
+++ b/chrome/browser/password_manager/password_store.h
@@ -83,6 +83,7 @@ class PasswordStore : public base::RefCountedThreadSafe<PasswordStore> {
friend class browser_sync::PasswordDataTypeController;
friend class browser_sync::PasswordModelAssociator;
friend class browser_sync::PasswordModelWorker;
+ friend class LivePasswordsSyncTest;
virtual ~PasswordStore() {}