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

Side by Side Diff: chrome/browser/browsing_data/browsing_data_counter_utils_unittest.cc

Issue 2080283002: Implement GetCounterTextFromResult() for the hosted apps counter. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed cast type. Created 4 years, 6 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
« no previous file with comments | « chrome/browser/browsing_data/browsing_data_counter_utils.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/browsing_data/browsing_data_counter_utils.h" 5 #include "chrome/browser/browsing_data/browsing_data_counter_utils.h"
6 6
7 #include <string>
8 #include <vector>
9
7 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
8 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/browsing_data/autofill_counter.h" 12 #include "chrome/browser/browsing_data/autofill_counter.h"
10 #include "chrome/test/base/testing_browser_process.h" 13 #include "chrome/test/base/testing_browser_process.h"
11 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
12 15
16 #if defined(ENABLE_EXTENSIONS)
17 #include "base/strings/string_split.h"
18 #include "chrome/browser/browsing_data/hosted_apps_counter.h"
19 #endif
20
13 // Tests the complex output of the Autofill counter. 21 // Tests the complex output of the Autofill counter.
14 TEST(BrowsingDataCounterUtilsTest, AutofillCounterResult) { 22 TEST(BrowsingDataCounterUtilsTest, AutofillCounterResult) {
15 AutofillCounter counter; 23 AutofillCounter counter;
16 24
17 // This test assumes that the strings are served exactly as defined, 25 // This test assumes that the strings are served exactly as defined,
18 // i.e. that the locale is set to the default "en". 26 // i.e. that the locale is set to the default "en".
19 ASSERT_EQ("en", TestingBrowserProcess::GetGlobal()->GetApplicationLocale()); 27 ASSERT_EQ("en", TestingBrowserProcess::GetGlobal()->GetApplicationLocale());
20 28
21 // Test all configurations of zero and nonzero partial results for datatypes. 29 // Test all configurations of zero and nonzero partial results for datatypes.
22 // Test singular and plural for each datatype. 30 // Test singular and plural for each datatype.
23 struct TestCase { 31 const struct TestCase {
24 int num_credit_cards; 32 int num_credit_cards;
25 int num_addresses; 33 int num_addresses;
26 int num_suggestions; 34 int num_suggestions;
27 std::string expected_output; 35 std::string expected_output;
28 } test_cases[] = { 36 } kTestCases[] = {
29 {0, 0, 0, "none"}, 37 {0, 0, 0, "none"},
30 {1, 0, 0, "1 credit card"}, 38 {1, 0, 0, "1 credit card"},
31 {0, 5, 0, "5 addresses"}, 39 {0, 5, 0, "5 addresses"},
32 {0, 0, 1, "1 suggestion"}, 40 {0, 0, 1, "1 suggestion"},
33 {0, 0, 2, "2 suggestions"}, 41 {0, 0, 2, "2 suggestions"},
34 {4, 7, 0, "4 credit cards, 7 addresses"}, 42 {4, 7, 0, "4 credit cards, 7 addresses"},
35 {3, 0, 9, "3 credit cards, 9 other suggestions"}, 43 {3, 0, 9, "3 credit cards, 9 other suggestions"},
36 {0, 1, 1, "1 address, 1 other suggestion"}, 44 {0, 1, 1, "1 address, 1 other suggestion"},
37 {9, 6, 3, "9 credit cards, 6 addresses, 3 others"}, 45 {9, 6, 3, "9 credit cards, 6 addresses, 3 others"},
38 {4, 2, 1, "4 credit cards, 2 addresses, 1 other"}, 46 {4, 2, 1, "4 credit cards, 2 addresses, 1 other"},
39 }; 47 };
40 48
41 for (const TestCase& test_case : test_cases) { 49 for (const TestCase& test_case : kTestCases) {
42 AutofillCounter::AutofillResult result( 50 AutofillCounter::AutofillResult result(
43 &counter, 51 &counter,
44 test_case.num_suggestions, 52 test_case.num_suggestions,
45 test_case.num_credit_cards, 53 test_case.num_credit_cards,
46 test_case.num_addresses); 54 test_case.num_addresses);
47 55
48 SCOPED_TRACE(base::StringPrintf( 56 SCOPED_TRACE(base::StringPrintf(
49 "Test params: %d credit card(s), " 57 "Test params: %d credit card(s), "
50 "%d address(es), %d suggestion(s).", 58 "%d address(es), %d suggestion(s).",
51 test_case.num_credit_cards, 59 test_case.num_credit_cards,
52 test_case.num_addresses, 60 test_case.num_addresses,
53 test_case.num_suggestions 61 test_case.num_suggestions
54 )); 62 ));
55 63
56 base::string16 output = GetCounterTextFromResult(&result); 64 base::string16 output = GetCounterTextFromResult(&result);
57 EXPECT_EQ(output, base::ASCIIToUTF16(test_case.expected_output)); 65 EXPECT_EQ(output, base::ASCIIToUTF16(test_case.expected_output));
58 } 66 }
59 } 67 }
68
69 #if defined(ENABLE_EXTENSIONS)
70 // Tests the complex output of the hosted apps counter.
71 TEST(BrowsingDataCounterUtilsTest, HostedAppsCounterResult) {
72 HostedAppsCounter counter;
73
74 // This test assumes that the strings are served exactly as defined,
75 // i.e. that the locale is set to the default "en".
76 ASSERT_EQ("en", TestingBrowserProcess::GetGlobal()->GetApplicationLocale());
77
78 // Test the output for various numbers of hosted apps.
79 const struct TestCase {
80 std::string apps_list;
81 std::string expected_output;
82 } kTestCases[] = {
83 { "", "none" },
84 { "App1", "1 app (App1)" },
85 { "App1, App2", "2 apps (App1, App2)" },
86 { "App1, App2, App3", "3 apps (App1, App2, and 1 more)" },
87 { "App1, App2, App3, App4", "4 apps (App1, App2, and 2 more)" },
88 { "App1, App2, App3, App4, App5", "5 apps (App1, App2, and 3 more)" },
89 };
90
91 for (const TestCase& test_case : kTestCases) {
92 // Split the list of installed apps by commas.
93 std::vector<std::string> apps = base::SplitString(
94 test_case.apps_list, ",",
95 base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
96
97 // The first two apps in the list are used as examples.
98 std::vector<std::string> examples;
99 examples.assign(
100 apps.begin(), apps.begin() + (apps.size() > 2 ? 2 : apps.size()));
101
102 HostedAppsCounter::HostedAppsResult result(
103 &counter,
104 apps.size(),
105 examples);
106
107 base::string16 output = GetCounterTextFromResult(&result);
108 EXPECT_EQ(output, base::ASCIIToUTF16(test_case.expected_output));
109 }
110 }
111 #endif
OLDNEW
« no previous file with comments | « chrome/browser/browsing_data/browsing_data_counter_utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698