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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 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.
4
5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_SUGGESTION_TEST_HELPERS_H_
6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_SUGGESTION_TEST_HELPERS_H_
7
8 #include "components/autofill/core/browser/suggestion.h"
9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace autofill {
13
14 // Gmock matcher that allows checking a member of the Suggestion class in a
15 // vector. This wraps a GMock container matcher, converts the suggestion
16 // members to a vector, and then runs the container matcher against the result
17 // to test an argument. See SuggestionVectorIdsAre() below.
18 template<typename EltType>
19 class SuggestionVectorMembersAreMatcher
20 : public testing::MatcherInterface<const std::vector<Suggestion>&> {
21 public:
22 typedef std::vector<EltType> Container;
23 typedef testing::Matcher<Container> ContainerMatcher;
24
25 SuggestionVectorMembersAreMatcher(
26 const ContainerMatcher& seq_matcher,
27 EltType Suggestion::*elt)
28 : container_matcher_(seq_matcher),
29 element_(elt) {
30 }
31
32 virtual bool MatchAndExplain(const std::vector<Suggestion>& suggestions,
33 testing::MatchResultListener* listener) const {
34 Container container;
35 for (const auto& suggestion : suggestions)
36 container.push_back(suggestion.*element_);
37 return container_matcher_.MatchAndExplain(container, listener);
38 }
39
40 virtual void DescribeTo(::std::ostream* os) const {
41 container_matcher_.DescribeTo(os);
42 }
43
44 virtual void DescribeNegationTo(::std::ostream* os) const {
45 container_matcher_.DescribeNegationTo(os);
46 }
47
48 private:
49 ContainerMatcher container_matcher_;
50 EltType Suggestion::*element_;
51 };
52
53 // Use this matcher to compare a sequence vector's IDs to a list. In an
54 // EXPECT_CALL statement, use the following for an vector<Suggestion> argument
55 // to compare the IDs against a constant list:
56 // SuggestionVectorIdsAre(testing::ElementsAre(1, 2, 3, 4))
57 template<class EltsAreMatcher>
58 inline testing::Matcher<const std::vector<Suggestion>&>
59 SuggestionVectorIdsAre(const EltsAreMatcher& elts_are_matcher) {
60 return testing::MakeMatcher(
61 new SuggestionVectorMembersAreMatcher<int>(
62 elts_are_matcher, &Suggestion::frontend_id));
63 }
64
65 // Like SuggestionVectorIdsAre but tests the values instead of ID.
66 template<class EltsAreMatcher>
67 inline testing::Matcher<const std::vector<Suggestion>&>
68 SuggestionVectorValuesAre(const EltsAreMatcher& elts_are_matcher) {
69 return testing::MakeMatcher(
70 new SuggestionVectorMembersAreMatcher<base::string16>(
71 elts_are_matcher, &Suggestion::value));
72 }
73
74 } // namespace autofill
75
76 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_SUGGESTION_TEST_HELPERS_H_
OLDNEW
« 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