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> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "chrome/browser/browsing_data/autofill_counter.h" | 13 #include "chrome/browser/web_data_service_factory.h" |
14 #include "chrome/test/base/testing_browser_process.h" | 14 #include "chrome/test/base/testing_browser_process.h" |
15 #include "chrome/test/base/testing_profile.h" | 15 #include "chrome/test/base/testing_profile.h" |
| 16 #include "components/browsing_data/core/counters/autofill_counter.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 | 18 |
18 #if defined(ENABLE_EXTENSIONS) | 19 #if defined(ENABLE_EXTENSIONS) |
19 #include "base/strings/string_split.h" | 20 #include "base/strings/string_split.h" |
20 #include "chrome/browser/browsing_data/hosted_apps_counter.h" | 21 #include "chrome/browser/browsing_data/hosted_apps_counter.h" |
21 #endif | 22 #endif |
22 | 23 |
23 class BrowsingDataCounterUtilsTest : public testing::Test { | 24 class BrowsingDataCounterUtilsTest : public testing::Test { |
24 public: | 25 public: |
25 BrowsingDataCounterUtilsTest() {} | 26 BrowsingDataCounterUtilsTest() {} |
26 ~BrowsingDataCounterUtilsTest() override {} | 27 ~BrowsingDataCounterUtilsTest() override {} |
27 | 28 |
28 TestingProfile* GetProfile() { return &profile_; } | 29 TestingProfile* GetProfile() { return &profile_; } |
29 | 30 |
30 private: | 31 private: |
31 base::MessageLoop loop_; | 32 base::MessageLoop loop_; |
32 TestingProfile profile_; | 33 TestingProfile profile_; |
33 }; | 34 }; |
34 | 35 |
35 // Tests the complex output of the Autofill counter. | 36 // Tests the complex output of the Autofill counter. |
36 TEST_F(BrowsingDataCounterUtilsTest, AutofillCounterResult) { | 37 TEST_F(BrowsingDataCounterUtilsTest, AutofillCounterResult) { |
37 AutofillCounter counter(GetProfile()); | 38 browsing_data::AutofillCounter counter( |
| 39 WebDataServiceFactory::GetAutofillWebDataForProfile( |
| 40 GetProfile(), ServiceAccessType::EXPLICIT_ACCESS) |
| 41 .get()); |
38 | 42 |
39 // This test assumes that the strings are served exactly as defined, | 43 // This test assumes that the strings are served exactly as defined, |
40 // i.e. that the locale is set to the default "en". | 44 // i.e. that the locale is set to the default "en". |
41 ASSERT_EQ("en", TestingBrowserProcess::GetGlobal()->GetApplicationLocale()); | 45 ASSERT_EQ("en", TestingBrowserProcess::GetGlobal()->GetApplicationLocale()); |
42 | 46 |
43 // Test all configurations of zero and nonzero partial results for datatypes. | 47 // Test all configurations of zero and nonzero partial results for datatypes. |
44 // Test singular and plural for each datatype. | 48 // Test singular and plural for each datatype. |
45 const struct TestCase { | 49 const struct TestCase { |
46 int num_credit_cards; | 50 int num_credit_cards; |
47 int num_addresses; | 51 int num_addresses; |
48 int num_suggestions; | 52 int num_suggestions; |
49 std::string expected_output; | 53 std::string expected_output; |
50 } kTestCases[] = { | 54 } kTestCases[] = { |
51 {0, 0, 0, "none"}, | 55 {0, 0, 0, "none"}, |
52 {1, 0, 0, "1 credit card"}, | 56 {1, 0, 0, "1 credit card"}, |
53 {0, 5, 0, "5 addresses"}, | 57 {0, 5, 0, "5 addresses"}, |
54 {0, 0, 1, "1 suggestion"}, | 58 {0, 0, 1, "1 suggestion"}, |
55 {0, 0, 2, "2 suggestions"}, | 59 {0, 0, 2, "2 suggestions"}, |
56 {4, 7, 0, "4 credit cards, 7 addresses"}, | 60 {4, 7, 0, "4 credit cards, 7 addresses"}, |
57 {3, 0, 9, "3 credit cards, 9 other suggestions"}, | 61 {3, 0, 9, "3 credit cards, 9 other suggestions"}, |
58 {0, 1, 1, "1 address, 1 other suggestion"}, | 62 {0, 1, 1, "1 address, 1 other suggestion"}, |
59 {9, 6, 3, "9 credit cards, 6 addresses, 3 others"}, | 63 {9, 6, 3, "9 credit cards, 6 addresses, 3 others"}, |
60 {4, 2, 1, "4 credit cards, 2 addresses, 1 other"}, | 64 {4, 2, 1, "4 credit cards, 2 addresses, 1 other"}, |
61 }; | 65 }; |
62 | 66 |
63 for (const TestCase& test_case : kTestCases) { | 67 for (const TestCase& test_case : kTestCases) { |
64 AutofillCounter::AutofillResult result( | 68 browsing_data::AutofillCounter::AutofillResult result( |
65 &counter, | 69 &counter, test_case.num_suggestions, test_case.num_credit_cards, |
66 test_case.num_suggestions, | |
67 test_case.num_credit_cards, | |
68 test_case.num_addresses); | 70 test_case.num_addresses); |
69 | 71 |
70 SCOPED_TRACE(base::StringPrintf( | 72 SCOPED_TRACE(base::StringPrintf( |
71 "Test params: %d credit card(s), " | 73 "Test params: %d credit card(s), " |
72 "%d address(es), %d suggestion(s).", | 74 "%d address(es), %d suggestion(s).", |
73 test_case.num_credit_cards, | 75 test_case.num_credit_cards, |
74 test_case.num_addresses, | 76 test_case.num_addresses, |
75 test_case.num_suggestions | 77 test_case.num_suggestions |
76 )); | 78 )); |
77 | 79 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 HostedAppsCounter::HostedAppsResult result( | 118 HostedAppsCounter::HostedAppsResult result( |
117 &counter, | 119 &counter, |
118 apps.size(), | 120 apps.size(), |
119 examples); | 121 examples); |
120 | 122 |
121 base::string16 output = GetCounterTextFromResult(&result); | 123 base::string16 output = GetCounterTextFromResult(&result); |
122 EXPECT_EQ(output, base::ASCIIToUTF16(test_case.expected_output)); | 124 EXPECT_EQ(output, base::ASCIIToUTF16(test_case.expected_output)); |
123 } | 125 } |
124 } | 126 } |
125 #endif | 127 #endif |
OLD | NEW |