Chromium Code Reviews| 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()); |
| 20 | 25 |
| 21 // Test all configurations of zero and nonzero partial results for datatypes. | 26 // Test all configurations of zero and nonzero partial results for datatypes. |
| 22 // Test singular and plural for each datatype. | 27 // Test singular and plural for each datatype. |
| 23 struct TestCase { | 28 const struct TestCase { |
| 24 int num_credit_cards; | 29 int num_credit_cards; |
| 25 int num_addresses; | 30 int num_addresses; |
| 26 int num_suggestions; | 31 int num_suggestions; |
| 27 std::string expected_output; | 32 std::string expected_output; |
| 28 } test_cases[] = { | 33 } kTestCases = { |
|
vabr (Chromium)
2016/06/20 14:16:50
The Android compiler says: Do not forget the dropp
msramek
2016/06/20 14:41:02
Actually, all compilers that tried running unit te
| |
| 29 {0, 0, 0, "none"}, | 34 {0, 0, 0, "none"}, |
| 30 {1, 0, 0, "1 credit card"}, | 35 {1, 0, 0, "1 credit card"}, |
| 31 {0, 5, 0, "5 addresses"}, | 36 {0, 5, 0, "5 addresses"}, |
| 32 {0, 0, 1, "1 suggestion"}, | 37 {0, 0, 1, "1 suggestion"}, |
| 33 {0, 0, 2, "2 suggestions"}, | 38 {0, 0, 2, "2 suggestions"}, |
| 34 {4, 7, 0, "4 credit cards, 7 addresses"}, | 39 {4, 7, 0, "4 credit cards, 7 addresses"}, |
| 35 {3, 0, 9, "3 credit cards, 9 other suggestions"}, | 40 {3, 0, 9, "3 credit cards, 9 other suggestions"}, |
| 36 {0, 1, 1, "1 address, 1 other suggestion"}, | 41 {0, 1, 1, "1 address, 1 other suggestion"}, |
| 37 {9, 6, 3, "9 credit cards, 6 addresses, 3 others"}, | 42 {9, 6, 3, "9 credit cards, 6 addresses, 3 others"}, |
| 38 {4, 2, 1, "4 credit cards, 2 addresses, 1 other"}, | 43 {4, 2, 1, "4 credit cards, 2 addresses, 1 other"}, |
| (...skipping 11 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 const struct TestCase { | |
| 76 std::string apps_list; | |
| 77 std::string expected_output; | |
| 78 } kTestCases[] = { | |
| 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 : kTestCases) { | |
| 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 |