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

Side by Side Diff: components/browsing_data/core/browsing_data_utils_unittest.cc

Issue 2228913003: Move part of browsing data counter text util method to components (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 4 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
OLDNEW
(Empty)
1 // Copyright 2016 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 #include "components/browsing_data/core/browsing_data_utils.h"
6
7 #include <string>
8
9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/stringprintf.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "base/threading/thread_task_runner_handle.h"
13 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
14 #include "components/browsing_data/core/counters/autofill_counter.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 namespace {
18
19 class FakeWebDataService : public autofill::AutofillWebDataService {
20 public:
21 FakeWebDataService()
22 : AutofillWebDataService(base::ThreadTaskRunnerHandle::Get(),
23 base::ThreadTaskRunnerHandle::Get()) {}
24
25 protected:
26 ~FakeWebDataService() override {}
27 };
28
29 } // namespace
30
31 class BrowsingDataUtilsTest : public testing::Test {
32 public:
33 BrowsingDataUtilsTest() {}
34 ~BrowsingDataUtilsTest() override {}
35
36 private:
37 base::MessageLoop loop_;
38 };
39
40 // Tests the complex output of the Autofill counter.
41 TEST_F(BrowsingDataUtilsTest, AutofillCounterResult) {
42 browsing_data::AutofillCounter counter(
43 scoped_refptr<FakeWebDataService>(new FakeWebDataService()));
44
45 // Test all configurations of zero and nonzero partial results for datatypes.
46 // Test singular and plural for each datatype.
47 const struct TestCase {
48 int num_credit_cards;
49 int num_addresses;
50 int num_suggestions;
51 std::string expected_output;
52 } kTestCases[] = {
53 {0, 0, 0, "none"},
54 {1, 0, 0, "1 credit card"},
55 {0, 5, 0, "5 addresses"},
56 {0, 0, 1, "1 suggestion"},
57 {0, 0, 2, "2 suggestions"},
58 {4, 7, 0, "4 credit cards, 7 addresses"},
59 {3, 0, 9, "3 credit cards, 9 other suggestions"},
60 {0, 1, 1, "1 address, 1 other suggestion"},
61 {9, 6, 3, "9 credit cards, 6 addresses, 3 others"},
62 {4, 2, 1, "4 credit cards, 2 addresses, 1 other"},
63 };
64
65 for (const TestCase& test_case : kTestCases) {
66 browsing_data::AutofillCounter::AutofillResult result(
67 &counter, test_case.num_suggestions, test_case.num_credit_cards,
68 test_case.num_addresses);
69
70 SCOPED_TRACE(
71 base::StringPrintf("Test params: %d credit card(s), "
72 "%d address(es), %d suggestion(s).",
73 test_case.num_credit_cards, test_case.num_addresses,
74 test_case.num_suggestions));
75
76 base::string16 output = browsing_data::GetCounterTextFromResult(&result);
77 EXPECT_EQ(output, base::ASCIIToUTF16(test_case.expected_output));
78 }
79 }
OLDNEW
« no previous file with comments | « components/browsing_data/core/browsing_data_utils.cc ('k') | components/browsing_data_strings.grdp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698