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