| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/browsing_data/core/browsing_data_utils.h" | 5 #include "components/browsing_data/core/browsing_data_utils.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 PrefService* prefs() { return &prefs_; } | 45 PrefService* prefs() { return &prefs_; } |
| 46 | 46 |
| 47 private: | 47 private: |
| 48 base::MessageLoop loop_; | 48 base::MessageLoop loop_; |
| 49 sync_preferences::TestingPrefServiceSyncable prefs_; | 49 sync_preferences::TestingPrefServiceSyncable prefs_; |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 // Tests the complex output of the Autofill counter. | 52 // Tests the complex output of the Autofill counter. |
| 53 TEST_F(BrowsingDataUtilsTest, AutofillCounterResult) { | 53 TEST_F(BrowsingDataUtilsTest, AutofillCounterResult) { |
| 54 browsing_data::AutofillCounter counter( | 54 browsing_data::AutofillCounter counter( |
| 55 scoped_refptr<FakeWebDataService>(new FakeWebDataService())); | 55 scoped_refptr<FakeWebDataService>(new FakeWebDataService()), nullptr); |
| 56 | 56 |
| 57 // Test all configurations of zero and nonzero partial results for datatypes. | 57 // Test all configurations of zero and nonzero partial results for datatypes. |
| 58 // Test singular and plural for each datatype. | 58 // Test singular and plural for each datatype. |
| 59 const struct TestCase { | 59 const struct TestCase { |
| 60 int num_credit_cards; | 60 int num_credit_cards; |
| 61 int num_addresses; | 61 int num_addresses; |
| 62 int num_suggestions; | 62 int num_suggestions; |
| 63 bool sync_enabled; |
| 63 std::string expected_output; | 64 std::string expected_output; |
| 64 } kTestCases[] = { | 65 } kTestCases[] = { |
| 65 {0, 0, 0, "none"}, | 66 {0, 0, 0, false, "none"}, |
| 66 {1, 0, 0, "1 credit card"}, | 67 {0, 0, 0, true, "none"}, |
| 67 {0, 5, 0, "5 addresses"}, | 68 {1, 0, 0, false, "1 credit card"}, |
| 68 {0, 0, 1, "1 suggestion"}, | 69 {0, 5, 0, false, "5 addresses"}, |
| 69 {0, 0, 2, "2 suggestions"}, | 70 {0, 0, 1, false, "1 suggestion"}, |
| 70 {4, 7, 0, "4 credit cards, 7 addresses"}, | 71 {0, 0, 2, false, "2 suggestions"}, |
| 71 {3, 0, 9, "3 credit cards, 9 other suggestions"}, | 72 {0, 0, 2, true, "2 suggestions (synced)"}, |
| 72 {0, 1, 1, "1 address, 1 other suggestion"}, | 73 {4, 7, 0, false, "4 credit cards, 7 addresses"}, |
| 73 {9, 6, 3, "9 credit cards, 6 addresses, 3 others"}, | 74 {4, 7, 0, true, "4 credit cards, 7 addresses (synced)"}, |
| 74 {4, 2, 1, "4 credit cards, 2 addresses, 1 other"}, | 75 {3, 0, 9, false, "3 credit cards, 9 other suggestions"}, |
| 76 {0, 1, 1, false, "1 address, 1 other suggestion"}, |
| 77 {9, 6, 3, false, "9 credit cards, 6 addresses, 3 others"}, |
| 78 {4, 2, 1, false, "4 credit cards, 2 addresses, 1 other"}, |
| 79 {4, 2, 1, true, "4 credit cards, 2 addresses, 1 other (synced)"}, |
| 75 }; | 80 }; |
| 76 | 81 |
| 77 for (const TestCase& test_case : kTestCases) { | 82 for (const TestCase& test_case : kTestCases) { |
| 78 browsing_data::AutofillCounter::AutofillResult result( | 83 browsing_data::AutofillCounter::AutofillResult result( |
| 79 &counter, test_case.num_suggestions, test_case.num_credit_cards, | 84 &counter, test_case.num_suggestions, test_case.num_credit_cards, |
| 80 test_case.num_addresses); | 85 test_case.num_addresses, test_case.sync_enabled); |
| 81 | 86 |
| 82 SCOPED_TRACE( | 87 SCOPED_TRACE( |
| 83 base::StringPrintf("Test params: %d credit card(s), " | 88 base::StringPrintf("Test params: %d credit card(s), " |
| 84 "%d address(es), %d suggestion(s).", | 89 "%d address(es), %d suggestion(s).", |
| 85 test_case.num_credit_cards, test_case.num_addresses, | 90 test_case.num_credit_cards, test_case.num_addresses, |
| 86 test_case.num_suggestions)); | 91 test_case.num_suggestions)); |
| 87 | 92 |
| 88 base::string16 output = browsing_data::GetCounterTextFromResult(&result); | 93 base::string16 output = browsing_data::GetCounterTextFromResult(&result); |
| 89 EXPECT_EQ(output, base::ASCIIToUTF16(test_case.expected_output)); | 94 EXPECT_EQ(output, base::ASCIIToUTF16(test_case.expected_output)); |
| 90 } | 95 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 prefs()->SetInteger(kDeleteTimePeriod, 100); | 145 prefs()->SetInteger(kDeleteTimePeriod, 100); |
| 141 | 146 |
| 142 // After the first migration all settings should stay the same if the | 147 // After the first migration all settings should stay the same if the |
| 143 // migration is executed again. | 148 // migration is executed again. |
| 144 browsing_data::MigratePreferencesToBasic(prefs()); | 149 browsing_data::MigratePreferencesToBasic(prefs()); |
| 145 EXPECT_TRUE(prefs()->GetBoolean(kDeleteBrowsingHistoryBasic)); | 150 EXPECT_TRUE(prefs()->GetBoolean(kDeleteBrowsingHistoryBasic)); |
| 146 EXPECT_FALSE(prefs()->GetBoolean(kDeleteCookiesBasic)); | 151 EXPECT_FALSE(prefs()->GetBoolean(kDeleteCookiesBasic)); |
| 147 EXPECT_FALSE(prefs()->GetBoolean(kDeleteCacheBasic)); | 152 EXPECT_FALSE(prefs()->GetBoolean(kDeleteCacheBasic)); |
| 148 EXPECT_EQ(42, prefs()->GetInteger(kDeleteTimePeriodBasic)); | 153 EXPECT_EQ(42, prefs()->GetInteger(kDeleteTimePeriodBasic)); |
| 149 } | 154 } |
| OLD | NEW |