OLD | NEW |
---|---|
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 | |
10 #include "base/strings/string_split.h" | |
7 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
8 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/browsing_data/autofill_counter.h" | 13 #include "chrome/browser/browsing_data/autofill_counter.h" |
14 #include "chrome/browser/browsing_data/hosted_apps_counter.h" | |
10 #include "chrome/test/base/testing_browser_process.h" | 15 #include "chrome/test/base/testing_browser_process.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
12 | 17 |
13 // Tests the complex output of the Autofill counter. | 18 // Tests the complex output of the Autofill counter. |
14 TEST(BrowsingDataCounterUtilsTest, AutofillCounterResult) { | 19 TEST(BrowsingDataCounterUtilsTest, AutofillCounterResult) { |
15 AutofillCounter counter; | 20 AutofillCounter counter; |
16 | 21 |
17 // This test assumes that the strings are served exactly as defined, | 22 // This test assumes that the strings are served exactly as defined, |
18 // i.e. that the locale is set to the default "en". | 23 // i.e. that the locale is set to the default "en". |
19 ASSERT_EQ("en", TestingBrowserProcess::GetGlobal()->GetApplicationLocale()); | 24 ASSERT_EQ("en", TestingBrowserProcess::GetGlobal()->GetApplicationLocale()); |
(...skipping 30 matching lines...) Expand all Loading... | |
50 "%d address(es), %d suggestion(s).", | 55 "%d address(es), %d suggestion(s).", |
51 test_case.num_credit_cards, | 56 test_case.num_credit_cards, |
52 test_case.num_addresses, | 57 test_case.num_addresses, |
53 test_case.num_suggestions | 58 test_case.num_suggestions |
54 )); | 59 )); |
55 | 60 |
56 base::string16 output = GetCounterTextFromResult(&result); | 61 base::string16 output = GetCounterTextFromResult(&result); |
57 EXPECT_EQ(output, base::ASCIIToUTF16(test_case.expected_output)); | 62 EXPECT_EQ(output, base::ASCIIToUTF16(test_case.expected_output)); |
58 } | 63 } |
59 } | 64 } |
65 | |
66 // Tests the complex output of the hosted apps counter. | |
67 TEST(BrowsingDataCounterUtilsTest, HostedAppsCounterResult) { | |
68 HostedAppsCounter counter; | |
69 | |
70 // This test assumes that the strings are served exactly as defined, | |
71 // i.e. that the locale is set to the default "en". | |
72 ASSERT_EQ("en", TestingBrowserProcess::GetGlobal()->GetApplicationLocale()); | |
73 | |
74 // Test the output for various numbers of hosted apps. | |
75 struct TestCase { | |
vabr (Chromium)
2016/06/20 13:51:43
nit: This could be const.
(If you make it const, c
msramek
2016/06/20 14:06:18
Done. Here and above.
| |
76 std::string apps_list; | |
77 std::string expected_output; | |
78 } test_cases[] = { | |
79 { "", "none" }, | |
80 { "App1", "1 app (App1)" }, | |
81 { "App1, App2", "2 apps (App1, App2)" }, | |
82 { "App1, App2, App3", "3 apps (App1, App2, and 1 more)" }, | |
83 { "App1, App2, App3, App4", "4 apps (App1, App2, and 2 more)" }, | |
84 { "App1, App2, App3, App4, App5", "5 apps (App1, App2, and 3 more)" }, | |
85 }; | |
86 | |
87 for (const TestCase& test_case : test_cases) { | |
88 // Split the list of installed apps by commas. | |
89 std::vector<std::string> apps = base::SplitString( | |
90 test_case.apps_list, ",", | |
91 base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); | |
92 | |
93 // The first two apps in the list are used as examples. | |
94 std::vector<std::string> examples; | |
95 examples.assign( | |
96 apps.begin(), apps.begin() + (apps.size() > 2 ? 2 : apps.size())); | |
97 | |
98 HostedAppsCounter::HostedAppsResult result( | |
99 &counter, | |
100 apps.size(), | |
101 examples); | |
102 | |
103 base::string16 output = GetCounterTextFromResult(&result); | |
104 EXPECT_EQ(output, base::ASCIIToUTF16(test_case.expected_output)); | |
105 } | |
106 } | |
OLD | NEW |