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/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
11 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
12 #include "chrome/browser/browsing_data/autofill_counter.h" | 13 #include "chrome/browser/browsing_data/autofill_counter.h" |
13 #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" |
14 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
15 | 17 |
16 #if defined(ENABLE_EXTENSIONS) | 18 #if defined(ENABLE_EXTENSIONS) |
17 #include "base/strings/string_split.h" | 19 #include "base/strings/string_split.h" |
18 #include "chrome/browser/browsing_data/hosted_apps_counter.h" | 20 #include "chrome/browser/browsing_data/hosted_apps_counter.h" |
19 #endif | 21 #endif |
20 | 22 |
| 23 class BrowsingDataCounterUtilsTest : public testing::Test { |
| 24 public: |
| 25 BrowsingDataCounterUtilsTest() : profile_(new TestingProfile()) {} |
| 26 |
| 27 ~BrowsingDataCounterUtilsTest() override {} |
| 28 |
| 29 void TearDown() override { |
| 30 profile_.reset(); |
| 31 } |
| 32 |
| 33 TestingProfile* GetProfile() { return profile_.get(); } |
| 34 |
| 35 private: |
| 36 base::MessageLoop loop_; |
| 37 std::unique_ptr<TestingProfile> profile_; |
| 38 }; |
| 39 |
21 // Tests the complex output of the Autofill counter. | 40 // Tests the complex output of the Autofill counter. |
22 TEST(BrowsingDataCounterUtilsTest, AutofillCounterResult) { | 41 TEST_F(BrowsingDataCounterUtilsTest, AutofillCounterResult) { |
23 AutofillCounter counter; | 42 AutofillCounter counter(GetProfile()); |
24 | 43 |
25 // This test assumes that the strings are served exactly as defined, | 44 // This test assumes that the strings are served exactly as defined, |
26 // i.e. that the locale is set to the default "en". | 45 // i.e. that the locale is set to the default "en". |
27 ASSERT_EQ("en", TestingBrowserProcess::GetGlobal()->GetApplicationLocale()); | 46 ASSERT_EQ("en", TestingBrowserProcess::GetGlobal()->GetApplicationLocale()); |
28 | 47 |
29 // Test all configurations of zero and nonzero partial results for datatypes. | 48 // Test all configurations of zero and nonzero partial results for datatypes. |
30 // Test singular and plural for each datatype. | 49 // Test singular and plural for each datatype. |
31 const struct TestCase { | 50 const struct TestCase { |
32 int num_credit_cards; | 51 int num_credit_cards; |
33 int num_addresses; | 52 int num_addresses; |
(...skipping 27 matching lines...) Expand all Loading... |
61 test_case.num_suggestions | 80 test_case.num_suggestions |
62 )); | 81 )); |
63 | 82 |
64 base::string16 output = GetCounterTextFromResult(&result); | 83 base::string16 output = GetCounterTextFromResult(&result); |
65 EXPECT_EQ(output, base::ASCIIToUTF16(test_case.expected_output)); | 84 EXPECT_EQ(output, base::ASCIIToUTF16(test_case.expected_output)); |
66 } | 85 } |
67 } | 86 } |
68 | 87 |
69 #if defined(ENABLE_EXTENSIONS) | 88 #if defined(ENABLE_EXTENSIONS) |
70 // Tests the complex output of the hosted apps counter. | 89 // Tests the complex output of the hosted apps counter. |
71 TEST(BrowsingDataCounterUtilsTest, HostedAppsCounterResult) { | 90 TEST_F(BrowsingDataCounterUtilsTest, HostedAppsCounterResult) { |
72 HostedAppsCounter counter; | 91 HostedAppsCounter counter(GetProfile()); |
73 | 92 |
74 // This test assumes that the strings are served exactly as defined, | 93 // This test assumes that the strings are served exactly as defined, |
75 // i.e. that the locale is set to the default "en". | 94 // i.e. that the locale is set to the default "en". |
76 ASSERT_EQ("en", TestingBrowserProcess::GetGlobal()->GetApplicationLocale()); | 95 ASSERT_EQ("en", TestingBrowserProcess::GetGlobal()->GetApplicationLocale()); |
77 | 96 |
78 // Test the output for various numbers of hosted apps. | 97 // Test the output for various numbers of hosted apps. |
79 const struct TestCase { | 98 const struct TestCase { |
80 std::string apps_list; | 99 std::string apps_list; |
81 std::string expected_output; | 100 std::string expected_output; |
82 } kTestCases[] = { | 101 } kTestCases[] = { |
(...skipping 19 matching lines...) Expand all Loading... |
102 HostedAppsCounter::HostedAppsResult result( | 121 HostedAppsCounter::HostedAppsResult result( |
103 &counter, | 122 &counter, |
104 apps.size(), | 123 apps.size(), |
105 examples); | 124 examples); |
106 | 125 |
107 base::string16 output = GetCounterTextFromResult(&result); | 126 base::string16 output = GetCounterTextFromResult(&result); |
108 EXPECT_EQ(output, base::ASCIIToUTF16(test_case.expected_output)); | 127 EXPECT_EQ(output, base::ASCIIToUTF16(test_case.expected_output)); |
109 } | 128 } |
110 } | 129 } |
111 #endif | 130 #endif |
OLD | NEW |