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" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
13 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" | 13 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" |
14 #include "components/browsing_data/core/counters/autofill_counter.h" | 14 #include "components/browsing_data/core/counters/autofill_counter.h" |
| 15 #include "components/browsing_data/core/counters/passwords_counter.h" |
15 #include "components/browsing_data/core/pref_names.h" | 16 #include "components/browsing_data/core/pref_names.h" |
16 #include "components/prefs/pref_service.h" | 17 #include "components/prefs/pref_service.h" |
17 #include "components/sync_preferences/testing_pref_service_syncable.h" | 18 #include "components/sync_preferences/testing_pref_service_syncable.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 class FakeWebDataService : public autofill::AutofillWebDataService { | 23 class FakeWebDataService : public autofill::AutofillWebDataService { |
23 public: | 24 public: |
24 FakeWebDataService() | 25 FakeWebDataService() |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 base::StringPrintf("Test params: %d credit card(s), " | 82 base::StringPrintf("Test params: %d credit card(s), " |
82 "%d address(es), %d suggestion(s).", | 83 "%d address(es), %d suggestion(s).", |
83 test_case.num_credit_cards, test_case.num_addresses, | 84 test_case.num_credit_cards, test_case.num_addresses, |
84 test_case.num_suggestions)); | 85 test_case.num_suggestions)); |
85 | 86 |
86 base::string16 output = browsing_data::GetCounterTextFromResult(&result); | 87 base::string16 output = browsing_data::GetCounterTextFromResult(&result); |
87 EXPECT_EQ(output, base::ASCIIToUTF16(test_case.expected_output)); | 88 EXPECT_EQ(output, base::ASCIIToUTF16(test_case.expected_output)); |
88 } | 89 } |
89 } | 90 } |
90 | 91 |
| 92 // Tests the output of the Passwords counter. |
| 93 TEST_F(BrowsingDataUtilsTest, PasswordsCounterResult) { |
| 94 browsing_data::PasswordsCounter counter( |
| 95 scoped_refptr<password_manager::PasswordStore>(nullptr), nullptr); |
| 96 |
| 97 const struct TestCase { |
| 98 int num_passwords; |
| 99 int is_synced; |
| 100 std::string expected_output; |
| 101 } kTestCases[] = { |
| 102 {0, false, "none"}, {0, true, "none"}, |
| 103 {1, false, "1 password"}, {1, true, "1 password (synced)"}, |
| 104 {5, false, "5 passwords"}, {5, true, "5 passwords (synced)"}, |
| 105 }; |
| 106 |
| 107 for (const TestCase& test_case : kTestCases) { |
| 108 browsing_data::PasswordsCounter::PasswordResult result( |
| 109 &counter, test_case.num_passwords, test_case.is_synced); |
| 110 SCOPED_TRACE(base::StringPrintf("Test params: %d password(s), %d is_synced", |
| 111 test_case.num_passwords, |
| 112 test_case.is_synced)); |
| 113 base::string16 output = browsing_data::GetCounterTextFromResult(&result); |
| 114 EXPECT_EQ(output, base::ASCIIToUTF16(test_case.expected_output)); |
| 115 } |
| 116 } |
| 117 |
91 TEST_F(BrowsingDataUtilsTest, MigratePreferencesToBasic) { | 118 TEST_F(BrowsingDataUtilsTest, MigratePreferencesToBasic) { |
92 using namespace browsing_data::prefs; | 119 using namespace browsing_data::prefs; |
93 | 120 |
94 prefs()->SetBoolean(kDeleteBrowsingHistory, true); | 121 prefs()->SetBoolean(kDeleteBrowsingHistory, true); |
95 prefs()->SetBoolean(kDeleteCookies, false); | 122 prefs()->SetBoolean(kDeleteCookies, false); |
96 prefs()->SetBoolean(kDeleteCache, false); | 123 prefs()->SetBoolean(kDeleteCache, false); |
97 prefs()->SetInteger(kDeleteTimePeriod, 42); | 124 prefs()->SetInteger(kDeleteTimePeriod, 42); |
98 | 125 |
99 // History, cookies and cache should be migrated to their basic counterpart. | 126 // History, cookies and cache should be migrated to their basic counterpart. |
100 browsing_data::MigratePreferencesToBasic(prefs()); | 127 browsing_data::MigratePreferencesToBasic(prefs()); |
101 EXPECT_TRUE(prefs()->GetBoolean(kDeleteBrowsingHistoryBasic)); | 128 EXPECT_TRUE(prefs()->GetBoolean(kDeleteBrowsingHistoryBasic)); |
102 EXPECT_FALSE(prefs()->GetBoolean(kDeleteCookiesBasic)); | 129 EXPECT_FALSE(prefs()->GetBoolean(kDeleteCookiesBasic)); |
103 EXPECT_FALSE(prefs()->GetBoolean(kDeleteCacheBasic)); | 130 EXPECT_FALSE(prefs()->GetBoolean(kDeleteCacheBasic)); |
104 EXPECT_EQ(42, prefs()->GetInteger(kDeleteTimePeriodBasic)); | 131 EXPECT_EQ(42, prefs()->GetInteger(kDeleteTimePeriodBasic)); |
105 | 132 |
106 prefs()->SetBoolean(kDeleteBrowsingHistory, true); | 133 prefs()->SetBoolean(kDeleteBrowsingHistory, true); |
107 prefs()->SetBoolean(kDeleteCookies, true); | 134 prefs()->SetBoolean(kDeleteCookies, true); |
108 prefs()->SetBoolean(kDeleteCache, true); | 135 prefs()->SetBoolean(kDeleteCache, true); |
109 prefs()->SetInteger(kDeleteTimePeriod, 100); | 136 prefs()->SetInteger(kDeleteTimePeriod, 100); |
110 | 137 |
111 // After the first migration all settings should stay the same if the | 138 // After the first migration all settings should stay the same if the |
112 // migration is executed again. | 139 // migration is executed again. |
113 browsing_data::MigratePreferencesToBasic(prefs()); | 140 browsing_data::MigratePreferencesToBasic(prefs()); |
114 EXPECT_TRUE(prefs()->GetBoolean(kDeleteBrowsingHistoryBasic)); | 141 EXPECT_TRUE(prefs()->GetBoolean(kDeleteBrowsingHistoryBasic)); |
115 EXPECT_FALSE(prefs()->GetBoolean(kDeleteCookiesBasic)); | 142 EXPECT_FALSE(prefs()->GetBoolean(kDeleteCookiesBasic)); |
116 EXPECT_FALSE(prefs()->GetBoolean(kDeleteCacheBasic)); | 143 EXPECT_FALSE(prefs()->GetBoolean(kDeleteCacheBasic)); |
117 EXPECT_EQ(42, prefs()->GetInteger(kDeleteTimePeriodBasic)); | 144 EXPECT_EQ(42, prefs()->GetInteger(kDeleteTimePeriodBasic)); |
118 } | 145 } |
OLD | NEW |