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

Unified Diff: components/autofill/core/browser/suggestion_test_helpers.h

Issue 772253003: Create an autofill Suggestion class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge Created 6 years 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 side-by-side diff with in-line comments
Download patch
Index: components/autofill/core/browser/suggestion_test_helpers.h
diff --git a/components/autofill/core/browser/suggestion_test_helpers.h b/components/autofill/core/browser/suggestion_test_helpers.h
new file mode 100644
index 0000000000000000000000000000000000000000..76500e93eb1e872f23663dfb5ad5f3ddefe6cd11
--- /dev/null
+++ b/components/autofill/core/browser/suggestion_test_helpers.h
@@ -0,0 +1,76 @@
+// Copyright 2014 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.
+
+#ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_SUGGESTION_TEST_HELPERS_H_
+#define COMPONENTS_AUTOFILL_CORE_BROWSER_SUGGESTION_TEST_HELPERS_H_
+
+#include "components/autofill/core/browser/suggestion.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace autofill {
+
+// Gmock matcher that allows checking a member of the Suggestion class in a
+// vector. This wraps a GMock container matcher, converts the suggestion
+// members to a vector, and then runs the container matcher against the result
+// to test an argument. See SuggestionVectorIdsAre() below.
+template<typename EltType>
+class SuggestionVectorMembersAreMatcher
+ : public testing::MatcherInterface<const std::vector<Suggestion>&> {
+ public:
+ typedef std::vector<EltType> Container;
+ typedef testing::Matcher<Container> ContainerMatcher;
+
+ SuggestionVectorMembersAreMatcher(
+ const ContainerMatcher& seq_matcher,
+ EltType Suggestion::*elt)
+ : container_matcher_(seq_matcher),
+ element_(elt) {
+ }
+
+ virtual bool MatchAndExplain(const std::vector<Suggestion>& suggestions,
+ testing::MatchResultListener* listener) const {
+ Container container;
+ for (const auto& suggestion : suggestions)
+ container.push_back(suggestion.*element_);
+ return container_matcher_.MatchAndExplain(container, listener);
+ }
+
+ virtual void DescribeTo(::std::ostream* os) const {
+ container_matcher_.DescribeTo(os);
+ }
+
+ virtual void DescribeNegationTo(::std::ostream* os) const {
+ container_matcher_.DescribeNegationTo(os);
+ }
+
+ private:
+ ContainerMatcher container_matcher_;
+ EltType Suggestion::*element_;
+};
+
+// Use this matcher to compare a sequence vector's IDs to a list. In an
+// EXPECT_CALL statement, use the following for an vector<Suggestion> argument
+// to compare the IDs against a constant list:
+// SuggestionVectorIdsAre(testing::ElementsAre(1, 2, 3, 4))
+template<class EltsAreMatcher>
+inline testing::Matcher<const std::vector<Suggestion>&>
+SuggestionVectorIdsAre(const EltsAreMatcher& elts_are_matcher) {
+ return testing::MakeMatcher(
+ new SuggestionVectorMembersAreMatcher<int>(
+ elts_are_matcher, &Suggestion::frontend_id));
+}
+
+// Like SuggestionVectorIdsAre but tests the values instead of ID.
+template<class EltsAreMatcher>
+inline testing::Matcher<const std::vector<Suggestion>&>
+SuggestionVectorValuesAre(const EltsAreMatcher& elts_are_matcher) {
+ return testing::MakeMatcher(
+ new SuggestionVectorMembersAreMatcher<base::string16>(
+ elts_are_matcher, &Suggestion::value));
+}
+
+} // namespace autofill
+
+#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_SUGGESTION_TEST_HELPERS_H_
« no previous file with comments | « components/autofill/core/browser/suggestion.cc ('k') | components/autofill/core/browser/test_autofill_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698