Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(475)

Side by Side Diff: chrome/browser/browsing_data/autofill_counter_browsertest.cc

Issue 2671743002: Separate state of basic and advanced tab in CBD dialog (Closed)
Patch Set: rebase and fix compilation Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "components/browsing_data/core/counters/autofill_counter.h" 5 #include "components/browsing_data/core/counters/autofill_counter.h"
6 6
7 #include "base/guid.h" 7 #include "base/guid.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 18 matching lines...) Expand all
29 class AutofillCounterTest : public InProcessBrowserTest { 29 class AutofillCounterTest : public InProcessBrowserTest {
30 public: 30 public:
31 AutofillCounterTest() {} 31 AutofillCounterTest() {}
32 ~AutofillCounterTest() override {} 32 ~AutofillCounterTest() override {}
33 33
34 void SetUpOnMainThread() override { 34 void SetUpOnMainThread() override {
35 web_data_service_ = WebDataServiceFactory::GetAutofillWebDataForProfile( 35 web_data_service_ = WebDataServiceFactory::GetAutofillWebDataForProfile(
36 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS); 36 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS);
37 37
38 SetAutofillDeletionPref(true); 38 SetAutofillDeletionPref(true);
39 SetDeletionPeriodPref(browsing_data::ALL_TIME); 39 SetDeletionPeriodPref(browsing_data::TimePeriod::ALL_TIME);
40 } 40 }
41 41
42 // Autocomplete suggestions -------------------------------------------------- 42 // Autocomplete suggestions --------------------------------------------------
43 43
44 void AddAutocompleteSuggestion(const std::string& name, 44 void AddAutocompleteSuggestion(const std::string& name,
45 const std::string& value) { 45 const std::string& value) {
46 autofill::FormFieldData field; 46 autofill::FormFieldData field;
47 field.name = base::ASCIIToUTF16(name); 47 field.name = base::ASCIIToUTF16(name);
48 field.value = base::ASCIIToUTF16(value); 48 field.value = base::ASCIIToUTF16(value);
49 49
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 browsing_data::BrowsingDataCounter::ResultInt num_credit_cards_; 198 browsing_data::BrowsingDataCounter::ResultInt num_credit_cards_;
199 browsing_data::BrowsingDataCounter::ResultInt num_addresses_; 199 browsing_data::BrowsingDataCounter::ResultInt num_addresses_;
200 200
201 DISALLOW_COPY_AND_ASSIGN(AutofillCounterTest); 201 DISALLOW_COPY_AND_ASSIGN(AutofillCounterTest);
202 }; 202 };
203 203
204 // Tests that we count the correct number of autocomplete suggestions. 204 // Tests that we count the correct number of autocomplete suggestions.
205 IN_PROC_BROWSER_TEST_F(AutofillCounterTest, AutocompleteSuggestions) { 205 IN_PROC_BROWSER_TEST_F(AutofillCounterTest, AutocompleteSuggestions) {
206 Profile* profile = browser()->profile(); 206 Profile* profile = browser()->profile();
207 browsing_data::AutofillCounter counter(GetWebDataService()); 207 browsing_data::AutofillCounter counter(GetWebDataService());
208 counter.Init(profile->GetPrefs(), base::Bind(&AutofillCounterTest::Callback, 208 counter.Init(
209 base::Unretained(this))); 209 profile->GetPrefs(), browsing_data::ClearBrowsingDataTab::ADVANCED,
210 base::Bind(&AutofillCounterTest::Callback, base::Unretained(this)));
210 counter.Restart(); 211 counter.Restart();
211 WaitForCounting(); 212 WaitForCounting();
212 EXPECT_EQ(0, GetNumSuggestions()); 213 EXPECT_EQ(0, GetNumSuggestions());
213 214
214 AddAutocompleteSuggestion("email", "example@example.com"); 215 AddAutocompleteSuggestion("email", "example@example.com");
215 counter.Restart(); 216 counter.Restart();
216 WaitForCounting(); 217 WaitForCounting();
217 EXPECT_EQ(1, GetNumSuggestions()); 218 EXPECT_EQ(1, GetNumSuggestions());
218 219
219 AddAutocompleteSuggestion("tel", "+123456789"); 220 AddAutocompleteSuggestion("tel", "+123456789");
(...skipping 14 matching lines...) Expand all
234 ClearAutocompleteSuggestions(); 235 ClearAutocompleteSuggestions();
235 counter.Restart(); 236 counter.Restart();
236 WaitForCounting(); 237 WaitForCounting();
237 EXPECT_EQ(0, GetNumSuggestions()); 238 EXPECT_EQ(0, GetNumSuggestions());
238 } 239 }
239 240
240 // Tests that we count the correct number of credit cards. 241 // Tests that we count the correct number of credit cards.
241 IN_PROC_BROWSER_TEST_F(AutofillCounterTest, CreditCards) { 242 IN_PROC_BROWSER_TEST_F(AutofillCounterTest, CreditCards) {
242 Profile* profile = browser()->profile(); 243 Profile* profile = browser()->profile();
243 browsing_data::AutofillCounter counter(GetWebDataService()); 244 browsing_data::AutofillCounter counter(GetWebDataService());
244 counter.Init(profile->GetPrefs(), base::Bind(&AutofillCounterTest::Callback, 245 counter.Init(
245 base::Unretained(this))); 246 profile->GetPrefs(), browsing_data::ClearBrowsingDataTab::ADVANCED,
247 base::Bind(&AutofillCounterTest::Callback, base::Unretained(this)));
246 counter.Restart(); 248 counter.Restart();
247 WaitForCounting(); 249 WaitForCounting();
248 EXPECT_EQ(0, GetNumCreditCards()); 250 EXPECT_EQ(0, GetNumCreditCards());
249 251
250 AddCreditCard("0000-0000-0000-0000", "1", "2015"); 252 AddCreditCard("0000-0000-0000-0000", "1", "2015");
251 counter.Restart(); 253 counter.Restart();
252 WaitForCounting(); 254 WaitForCounting();
253 EXPECT_EQ(1, GetNumCreditCards()); 255 EXPECT_EQ(1, GetNumCreditCards());
254 256
255 AddCreditCard("0123-4567-8910-1112", "10", "2015"); 257 AddCreditCard("0123-4567-8910-1112", "10", "2015");
(...skipping 14 matching lines...) Expand all
270 ClearCreditCardsAndAddresses(); 272 ClearCreditCardsAndAddresses();
271 counter.Restart(); 273 counter.Restart();
272 WaitForCounting(); 274 WaitForCounting();
273 EXPECT_EQ(0, GetNumCreditCards()); 275 EXPECT_EQ(0, GetNumCreditCards());
274 } 276 }
275 277
276 // Tests that we count the correct number of addresses. 278 // Tests that we count the correct number of addresses.
277 IN_PROC_BROWSER_TEST_F(AutofillCounterTest, Addresses) { 279 IN_PROC_BROWSER_TEST_F(AutofillCounterTest, Addresses) {
278 Profile* profile = browser()->profile(); 280 Profile* profile = browser()->profile();
279 browsing_data::AutofillCounter counter(GetWebDataService()); 281 browsing_data::AutofillCounter counter(GetWebDataService());
280 counter.Init(profile->GetPrefs(), base::Bind(&AutofillCounterTest::Callback, 282 counter.Init(
281 base::Unretained(this))); 283 profile->GetPrefs(), browsing_data::ClearBrowsingDataTab::ADVANCED,
284 base::Bind(&AutofillCounterTest::Callback, base::Unretained(this)));
282 counter.Restart(); 285 counter.Restart();
283 WaitForCounting(); 286 WaitForCounting();
284 EXPECT_EQ(0, GetNumAddresses()); 287 EXPECT_EQ(0, GetNumAddresses());
285 288
286 AddAddress("John", "Doe", "Main Street 12345"); 289 AddAddress("John", "Doe", "Main Street 12345");
287 counter.Restart(); 290 counter.Restart();
288 WaitForCounting(); 291 WaitForCounting();
289 EXPECT_EQ(1, GetNumAddresses()); 292 EXPECT_EQ(1, GetNumAddresses());
290 293
291 AddAddress("Jane", "Smith", "Main Street 12346"); 294 AddAddress("Jane", "Smith", "Main Street 12346");
(...skipping 28 matching lines...) Expand all
320 323
321 AddCreditCard("0000-0000-0000-0000", "1", "2015"); 324 AddCreditCard("0000-0000-0000-0000", "1", "2015");
322 AddCreditCard("1211-1098-7654-3210", "10", "2030"); 325 AddCreditCard("1211-1098-7654-3210", "10", "2030");
323 326
324 AddAddress("John", "Doe", "Main Street 12345"); 327 AddAddress("John", "Doe", "Main Street 12345");
325 AddAddress("Jane", "Smith", "Main Street 12346"); 328 AddAddress("Jane", "Smith", "Main Street 12346");
326 AddAddress("John", "Smith", "Side Street 47"); 329 AddAddress("John", "Smith", "Side Street 47");
327 330
328 Profile* profile = browser()->profile(); 331 Profile* profile = browser()->profile();
329 browsing_data::AutofillCounter counter(GetWebDataService()); 332 browsing_data::AutofillCounter counter(GetWebDataService());
330 counter.Init(profile->GetPrefs(), base::Bind(&AutofillCounterTest::Callback, 333 counter.Init(
331 base::Unretained(this))); 334 profile->GetPrefs(), browsing_data::ClearBrowsingDataTab::ADVANCED,
335 base::Bind(&AutofillCounterTest::Callback, base::Unretained(this)));
332 counter.Restart(); 336 counter.Restart();
333 WaitForCounting(); 337 WaitForCounting();
334 EXPECT_EQ(5, GetNumSuggestions()); 338 EXPECT_EQ(5, GetNumSuggestions());
335 EXPECT_EQ(2, GetNumCreditCards()); 339 EXPECT_EQ(2, GetNumCreditCards());
336 EXPECT_EQ(3, GetNumAddresses()); 340 EXPECT_EQ(3, GetNumAddresses());
337 } 341 }
338 342
339 // Tests that the counting respects time ranges. 343 // Tests that the counting respects time ranges.
340 IN_PROC_BROWSER_TEST_F(AutofillCounterTest, TimeRanges) { 344 IN_PROC_BROWSER_TEST_F(AutofillCounterTest, TimeRanges) {
341 // This test makes time comparisons that are precise to a microsecond, but the 345 // This test makes time comparisons that are precise to a microsecond, but the
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 const browsing_data::BrowsingDataCounter::ResultInt expected_num_addresses; 379 const browsing_data::BrowsingDataCounter::ResultInt expected_num_addresses;
376 } test_cases[] = { 380 } test_cases[] = {
377 { base::Time(), 2, 3, 3}, 381 { base::Time(), 2, 3, 3},
378 { time1, 2, 3, 3}, 382 { time1, 2, 3, 3},
379 { time2, 1, 2, 2}, 383 { time2, 1, 2, 2},
380 { time3, 1, 1, 0} 384 { time3, 1, 1, 0}
381 }; 385 };
382 386
383 Profile* profile = browser()->profile(); 387 Profile* profile = browser()->profile();
384 browsing_data::AutofillCounter counter(GetWebDataService()); 388 browsing_data::AutofillCounter counter(GetWebDataService());
385 counter.Init(profile->GetPrefs(), base::Bind(&AutofillCounterTest::Callback, 389 counter.Init(
386 base::Unretained(this))); 390 profile->GetPrefs(), browsing_data::ClearBrowsingDataTab::ADVANCED,
391 base::Bind(&AutofillCounterTest::Callback, base::Unretained(this)));
387 392
388 for (const TestCase& test_case : test_cases) { 393 for (const TestCase& test_case : test_cases) {
389 counter.SetPeriodStartForTesting(test_case.period_start); 394 counter.SetPeriodStartForTesting(test_case.period_start);
390 counter.Restart(); 395 counter.Restart();
391 WaitForCounting(); 396 WaitForCounting();
392 EXPECT_EQ(test_case.expected_num_suggestions, GetNumSuggestions()); 397 EXPECT_EQ(test_case.expected_num_suggestions, GetNumSuggestions());
393 EXPECT_EQ(test_case.expected_num_credit_cards, GetNumCreditCards()); 398 EXPECT_EQ(test_case.expected_num_credit_cards, GetNumCreditCards());
394 EXPECT_EQ(test_case.expected_num_addresses, GetNumAddresses()); 399 EXPECT_EQ(test_case.expected_num_addresses, GetNumAddresses());
395 } 400 }
396 } 401 }
397 402
398 } // namespace 403 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698