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

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

Issue 10866013: Convert the browsing_data pyauto tests to chrome tests. Remove the ClearBrowsingData automation cod… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix flake in unittest harness Created 8 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/browsing_data/browsing_data_remover.h" 5 #include "chrome/browser/browsing_data/browsing_data_remover.h"
6 6
7 #include <set> 7 #include <set>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/file_path.h" 12 #include "base/file_path.h"
13 #include "base/file_util.h" 13 #include "base/file_util.h"
14 #include "base/message_loop.h" 14 #include "base/message_loop.h"
15 #include "base/platform_file.h" 15 #include "base/platform_file.h"
16 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
17 #include "chrome/browser/autofill/autofill_profile.h"
18 #include "chrome/browser/autofill/credit_card.h"
19 #include "chrome/browser/autofill/personal_data_manager.h"
20 #include "chrome/browser/autofill/personal_data_manager_factory.h"
21 #include "chrome/browser/autofill/personal_data_manager_observer.h"
17 #include "chrome/browser/browsing_data/browsing_data_helper.h" 22 #include "chrome/browser/browsing_data/browsing_data_helper.h"
18 #include "chrome/browser/extensions/mock_extension_special_storage_policy.h" 23 #include "chrome/browser/extensions/mock_extension_special_storage_policy.h"
19 #include "chrome/browser/history/history.h" 24 #include "chrome/browser/history/history.h"
20 #include "chrome/browser/history/history_service_factory.h" 25 #include "chrome/browser/history/history_service_factory.h"
21 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 26 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
22 #include "chrome/common/chrome_notification_types.h" 27 #include "chrome/common/chrome_notification_types.h"
23 #include "chrome/common/pref_names.h" 28 #include "chrome/common/pref_names.h"
24 #include "chrome/test/base/testing_browser_process.h" 29 #include "chrome/test/base/testing_browser_process.h"
25 #include "chrome/test/base/testing_pref_service.h" 30 #include "chrome/test/base/testing_pref_service.h"
26 #include "chrome/test/base/testing_profile.h" 31 #include "chrome/test/base/testing_profile.h"
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 // For History requests. 310 // For History requests.
306 CancelableRequestConsumer consumer_; 311 CancelableRequestConsumer consumer_;
307 bool query_url_success_; 312 bool query_url_success_;
308 313
309 // TestingProfile owns the history service; we shouldn't delete it. 314 // TestingProfile owns the history service; we shouldn't delete it.
310 HistoryService* history_service_; 315 HistoryService* history_service_;
311 316
312 DISALLOW_COPY_AND_ASSIGN(RemoveHistoryTester); 317 DISALLOW_COPY_AND_ASSIGN(RemoveHistoryTester);
313 }; 318 };
314 319
320 class RemoveAutofillTester : public BrowsingDataRemoverTester,
321 public PersonalDataManagerObserver {
322 public:
323 explicit RemoveAutofillTester(TestingProfile* profile)
324 : personal_data_manager_(
325 PersonalDataManagerFactory::GetForProfile(profile)) {
326 personal_data_manager_->SetObserver(this);
327 }
328
329 ~RemoveAutofillTester() {
Ben Goodger (Google) 2012/08/22 15:57:44 virtual dtor?
330 personal_data_manager_->RemoveObserver(this);
331 }
332
333 // Returns true if there are autofill profiles.
334 bool HasProfile() {
335 return !personal_data_manager_->profiles().empty() &&
336 !personal_data_manager_->credit_cards().empty();
337 }
338
339 void AddProfile() {
340 AutofillProfile profile;
341 profile.SetInfo(NAME_FIRST, ASCIIToUTF16("Bob"));
342 profile.SetInfo(NAME_LAST, ASCIIToUTF16("Smith"));
343 profile.SetInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("94043"));
344 profile.SetInfo(EMAIL_ADDRESS, ASCIIToUTF16("sue@example.com"));
345 profile.SetInfo(COMPANY_NAME, ASCIIToUTF16("Company X"));
346
347 std::vector<AutofillProfile> profiles;
348 profiles.push_back(profile);
349 personal_data_manager_->SetProfiles(&profiles);
350 MessageLoop::current()->Run();
351
352 CreditCard card;
353 card.SetInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("1234-5678-9012-3456"));
354
355 std::vector<CreditCard> cards;
356 cards.push_back(card);
357 personal_data_manager_->SetCreditCards(&cards);
358 MessageLoop::current()->Run();
359 }
360
361 private:
362 virtual void OnPersonalDataChanged() OVERRIDE {
363 MessageLoop::current()->Quit();
364 }
365
366 PersonalDataManager* personal_data_manager_;
367 DISALLOW_COPY_AND_ASSIGN(RemoveAutofillTester);
368 };
369
315 class RemoveLocalStorageTester : public BrowsingDataRemoverTester { 370 class RemoveLocalStorageTester : public BrowsingDataRemoverTester {
316 public: 371 public:
317 explicit RemoveLocalStorageTester(TestingProfile* profile) 372 explicit RemoveLocalStorageTester(TestingProfile* profile)
318 : profile_(profile), dom_storage_context_(NULL) { 373 : profile_(profile), dom_storage_context_(NULL) {
319 dom_storage_context_ = 374 dom_storage_context_ =
320 content::BrowserContext::GetDefaultStoragePartition(profile)-> 375 content::BrowserContext::GetDefaultStoragePartition(profile)->
321 GetDOMStorageContext(); 376 GetDOMStorageContext();
322 } 377 }
323 378
324 // Returns true, if the given origin URL exists. 379 // Returns true, if the given origin URL exists.
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 profile_.reset(); 507 profile_.reset();
453 message_loop_.RunAllPending(); 508 message_loop_.RunAllPending();
454 } 509 }
455 510
456 void BlockUntilBrowsingDataRemoved(BrowsingDataRemover::TimePeriod period, 511 void BlockUntilBrowsingDataRemoved(BrowsingDataRemover::TimePeriod period,
457 int remove_mask, 512 int remove_mask,
458 bool include_protected_origins, 513 bool include_protected_origins,
459 BrowsingDataRemoverTester* tester) { 514 BrowsingDataRemoverTester* tester) {
460 BrowsingDataRemover* remover = new BrowsingDataRemover( 515 BrowsingDataRemover* remover = new BrowsingDataRemover(
461 profile_.get(), period, 516 profile_.get(), period,
462 base::Time::Now() + base::TimeDelta::FromMilliseconds(10)); 517 // Pick a time that's a bit into the future, since there could be
518 // pending writes.
519 base::Time::Now() + base::TimeDelta::FromSeconds(10));
463 remover->OverrideQuotaManagerForTesting(GetMockManager()); 520 remover->OverrideQuotaManagerForTesting(GetMockManager());
464 remover->AddObserver(tester); 521 remover->AddObserver(tester);
465 522
466 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails()); 523 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails());
467 524
468 // BrowsingDataRemover deletes itself when it completes. 525 // BrowsingDataRemover deletes itself when it completes.
469 int origin_set_mask = BrowsingDataHelper::UNPROTECTED_WEB; 526 int origin_set_mask = BrowsingDataHelper::UNPROTECTED_WEB;
470 if (include_protected_origins) 527 if (include_protected_origins)
471 origin_set_mask |= BrowsingDataHelper::PROTECTED_WEB; 528 origin_set_mask |= BrowsingDataHelper::PROTECTED_WEB;
472 remover->Remove(remove_mask, origin_set_mask); 529 remover->Remove(remove_mask, origin_set_mask);
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 ASSERT_TRUE(tester->HistoryContainsURL(kOrigin2)); 1206 ASSERT_TRUE(tester->HistoryContainsURL(kOrigin2));
1150 1207
1151 BlockUntilOriginDataRemoved(BrowsingDataRemover::LAST_HOUR, 1208 BlockUntilOriginDataRemoved(BrowsingDataRemover::LAST_HOUR,
1152 BrowsingDataRemover::REMOVE_HISTORY, kOrigin2, tester.get()); 1209 BrowsingDataRemover::REMOVE_HISTORY, kOrigin2, tester.get());
1153 1210
1154 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); 1211 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1155 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); 1212 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1156 EXPECT_TRUE(tester->HistoryContainsURL(kOrigin1)); 1213 EXPECT_TRUE(tester->HistoryContainsURL(kOrigin1));
1157 EXPECT_TRUE(tester->HistoryContainsURL(kOrigin2)); 1214 EXPECT_TRUE(tester->HistoryContainsURL(kOrigin2));
1158 } 1215 }
1216
1217 // Verify that clearing autofill form data works.
1218 TEST_F(BrowsingDataRemoverTest, AutofillRemoval) {
1219 GetProfile()->CreateWebDataService();
1220 scoped_ptr<RemoveAutofillTester> tester(
1221 new RemoveAutofillTester(GetProfile()));
1222
1223 ASSERT_FALSE(tester->HasProfile());
1224 tester->AddProfile();
1225 ASSERT_TRUE(tester->HasProfile());
1226
1227 BlockUntilBrowsingDataRemoved(
1228 BrowsingDataRemover::LAST_HOUR,
1229 BrowsingDataRemover::REMOVE_FORM_DATA, false, tester.get());
1230
1231 EXPECT_EQ(BrowsingDataRemover::REMOVE_FORM_DATA, GetRemovalMask());
1232 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1233 ASSERT_FALSE(tester->HasProfile());
1234 }
OLDNEW
« no previous file with comments | « chrome/browser/browsing_data/browsing_data_remover_browsertest.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698