Index: components/password_manager/core/browser/password_manager_test_utils.cc |
diff --git a/components/password_manager/core/browser/password_manager_test_utils.cc b/components/password_manager/core/browser/password_manager_test_utils.cc |
index 42634fd59519312b5f04907727f5424697919327..38db125a960b8e81c2bb24865482b7177cf01f12 100644 |
--- a/components/password_manager/core/browser/password_manager_test_utils.cc |
+++ b/components/password_manager/core/browser/password_manager_test_utils.cc |
@@ -4,6 +4,7 @@ |
#include "components/password_manager/core/browser/password_manager_test_utils.h" |
+#include <ostream> |
#include <set> |
#include "base/strings/string_util.h" |
@@ -55,36 +56,47 @@ scoped_ptr<PasswordForm> CreatePasswordFormFromDataForTesting( |
typedef std::set<const autofill::PasswordForm*> SetOfForms; |
vabr (Chromium)
2015/03/19 13:28:12
Part of the problem I mentioned in the header-file
engedy
2015/03/20 13:17:15
I have changed this to multiset, and clarified the
|
-bool ContainsSamePasswordFormsPtr(const std::vector<PasswordForm*>& first, |
- const std::vector<PasswordForm*>& second) { |
- if (first.size() != second.size()) |
- return false; |
- |
+bool ContainsEqualPasswordFormsUnordered( |
+ const std::vector<autofill::PasswordForm*>& expectations, |
+ const std::vector<autofill::PasswordForm*>& actual_values, |
+ std::ostream* mismatch_output) { |
// TODO(cramya): As per b/7079906, the STLport of Android causes a crash |
// if we use expectations(first.begin(), first.end()) to copy a vector |
// into a set rather than std::copy that is used below. |
// Need to revert this once STLport is fixed. |
- SetOfForms expectations; |
- std::copy(first.begin(), first.end(), |
- std::inserter(expectations, expectations.begin())); |
- for (unsigned int i = 0; i < second.size(); ++i) { |
- const PasswordForm* actual = second[i]; |
+ SetOfForms remaining_expectations; |
+ std::copy( |
+ expectations.begin(), expectations.end(), |
+ std::inserter(remaining_expectations, remaining_expectations.begin())); |
+ bool had_mismatched_actual_form = false; |
+ for (const autofill::PasswordForm* actual : actual_values) { |
bool found_match = false; |
- for (SetOfForms::iterator it = expectations.begin(); |
- it != expectations.end(); ++it) { |
- const PasswordForm* expected = *it; |
- if (*expected == *actual) { |
+ for (SetOfForms::iterator it_expectation = remaining_expectations.begin(); |
+ it_expectation != remaining_expectations.end(); ++it_expectation) { |
+ if (**it_expectation == *actual) { |
found_match = true; |
- expectations.erase(it); |
+ remaining_expectations.erase(it_expectation); |
break; |
} |
} |
- if (!found_match) { |
- LOG(ERROR) << "No match for:" << std::endl << *actual; |
- return false; |
+ if (!found_match && mismatch_output) { |
+ *mismatch_output << std::endl |
+ << "Unmatched actual form:" << std::endl |
+ << *actual; |
} |
+ had_mismatched_actual_form |= !found_match; |
} |
- return true; |
+ |
+ if (mismatch_output) { |
+ for (const autofill::PasswordForm* remaining_expectation : |
+ remaining_expectations) { |
+ *mismatch_output << std::endl |
+ << "Unmatched expected form:" << std::endl |
+ << *remaining_expectation; |
+ } |
+ } |
+ |
+ return !had_mismatched_actual_form && remaining_expectations.empty(); |
} |
} // namespace password_manager |