| 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/pref_names.h" |
| 16 #include "components/prefs/pref_service.h" |
| 17 #include "components/sync_preferences/testing_pref_service_syncable.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 19 |
| 17 namespace { | 20 namespace { |
| 18 | 21 |
| 19 class FakeWebDataService : public autofill::AutofillWebDataService { | 22 class FakeWebDataService : public autofill::AutofillWebDataService { |
| 20 public: | 23 public: |
| 21 FakeWebDataService() | 24 FakeWebDataService() |
| 22 : AutofillWebDataService(base::ThreadTaskRunnerHandle::Get(), | 25 : AutofillWebDataService(base::ThreadTaskRunnerHandle::Get(), |
| 23 base::ThreadTaskRunnerHandle::Get()) {} | 26 base::ThreadTaskRunnerHandle::Get()) {} |
| 24 | 27 |
| 25 protected: | 28 protected: |
| 26 ~FakeWebDataService() override {} | 29 ~FakeWebDataService() override {} |
| 27 }; | 30 }; |
| 28 | 31 |
| 29 } // namespace | 32 } // namespace |
| 30 | 33 |
| 31 class BrowsingDataUtilsTest : public testing::Test { | 34 class BrowsingDataUtilsTest : public testing::Test { |
| 32 public: | 35 public: |
| 33 BrowsingDataUtilsTest() {} | 36 BrowsingDataUtilsTest() {} |
| 34 ~BrowsingDataUtilsTest() override {} | 37 ~BrowsingDataUtilsTest() override {} |
| 35 | 38 |
| 39 void SetUp() override { |
| 40 browsing_data::prefs::RegisterBrowserUserPrefs(prefs_.registry()); |
| 41 } |
| 42 |
| 43 PrefService* prefs() { return &prefs_; } |
| 44 |
| 36 private: | 45 private: |
| 37 base::MessageLoop loop_; | 46 base::MessageLoop loop_; |
| 47 sync_preferences::TestingPrefServiceSyncable prefs_; |
| 38 }; | 48 }; |
| 39 | 49 |
| 40 // Tests the complex output of the Autofill counter. | 50 // Tests the complex output of the Autofill counter. |
| 41 TEST_F(BrowsingDataUtilsTest, AutofillCounterResult) { | 51 TEST_F(BrowsingDataUtilsTest, AutofillCounterResult) { |
| 42 browsing_data::AutofillCounter counter( | 52 browsing_data::AutofillCounter counter( |
| 43 scoped_refptr<FakeWebDataService>(new FakeWebDataService())); | 53 scoped_refptr<FakeWebDataService>(new FakeWebDataService())); |
| 44 | 54 |
| 45 // Test all configurations of zero and nonzero partial results for datatypes. | 55 // Test all configurations of zero and nonzero partial results for datatypes. |
| 46 // Test singular and plural for each datatype. | 56 // Test singular and plural for each datatype. |
| 47 const struct TestCase { | 57 const struct TestCase { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 70 SCOPED_TRACE( | 80 SCOPED_TRACE( |
| 71 base::StringPrintf("Test params: %d credit card(s), " | 81 base::StringPrintf("Test params: %d credit card(s), " |
| 72 "%d address(es), %d suggestion(s).", | 82 "%d address(es), %d suggestion(s).", |
| 73 test_case.num_credit_cards, test_case.num_addresses, | 83 test_case.num_credit_cards, test_case.num_addresses, |
| 74 test_case.num_suggestions)); | 84 test_case.num_suggestions)); |
| 75 | 85 |
| 76 base::string16 output = browsing_data::GetCounterTextFromResult(&result); | 86 base::string16 output = browsing_data::GetCounterTextFromResult(&result); |
| 77 EXPECT_EQ(output, base::ASCIIToUTF16(test_case.expected_output)); | 87 EXPECT_EQ(output, base::ASCIIToUTF16(test_case.expected_output)); |
| 78 } | 88 } |
| 79 } | 89 } |
| 90 |
| 91 TEST_F(BrowsingDataUtilsTest, MigratePreferencesToBasic) { |
| 92 using namespace browsing_data::prefs; |
| 93 |
| 94 prefs()->SetBoolean(kDeleteBrowsingHistory, true); |
| 95 prefs()->SetBoolean(kDeleteCookies, false); |
| 96 prefs()->SetBoolean(kDeleteCache, false); |
| 97 prefs()->SetInteger(kDeleteTimePeriod, 42); |
| 98 |
| 99 // History, cookies and cache should be migrated to their basic counterpart. |
| 100 browsing_data::MigratePreferencesToBasic(prefs()); |
| 101 EXPECT_TRUE(prefs()->GetBoolean(kDeleteBrowsingHistoryBasic)); |
| 102 EXPECT_FALSE(prefs()->GetBoolean(kDeleteCookiesBasic)); |
| 103 EXPECT_FALSE(prefs()->GetBoolean(kDeleteCacheBasic)); |
| 104 EXPECT_EQ(42, prefs()->GetInteger(kDeleteTimePeriodBasic)); |
| 105 |
| 106 prefs()->SetBoolean(kDeleteBrowsingHistory, true); |
| 107 prefs()->SetBoolean(kDeleteCookies, true); |
| 108 prefs()->SetBoolean(kDeleteCache, true); |
| 109 prefs()->SetInteger(kDeleteTimePeriod, 100); |
| 110 |
| 111 // After the first migration all settings should stay the same if the |
| 112 // migration is executed again. |
| 113 browsing_data::MigratePreferencesToBasic(prefs()); |
| 114 EXPECT_TRUE(prefs()->GetBoolean(kDeleteBrowsingHistoryBasic)); |
| 115 EXPECT_FALSE(prefs()->GetBoolean(kDeleteCookiesBasic)); |
| 116 EXPECT_FALSE(prefs()->GetBoolean(kDeleteCacheBasic)); |
| 117 EXPECT_EQ(42, prefs()->GetInteger(kDeleteTimePeriodBasic)); |
| 118 } |
| OLD | NEW |