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

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

Issue 2802013002: Move BrowsingDataRemoverImpl:: CompletionInhibitor to the public interface (Closed)
Patch Set: Simplified ProfileManagerBrowsertest Created 3 years, 8 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <list> 8 #include <list>
9 #include <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
(...skipping 1420 matching lines...) Expand 10 before | Expand all | Expand 10 after
1431 void OnBrowsingDataRemoverDone() override { 1431 void OnBrowsingDataRemoverDone() override {
1432 BrowsingDataRemoverCompletionObserver::OnBrowsingDataRemoverDone(); 1432 BrowsingDataRemoverCompletionObserver::OnBrowsingDataRemoverDone();
1433 called_ = true; 1433 called_ = true;
1434 } 1434 }
1435 1435
1436 private: 1436 private:
1437 bool called_ = false; 1437 bool called_ = false;
1438 }; 1438 };
1439 1439
1440 TEST_F(BrowsingDataRemoverImplTest, CompletionInhibition) { 1440 TEST_F(BrowsingDataRemoverImplTest, CompletionInhibition) {
1441 BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>(
1442 BrowsingDataRemoverFactory::GetForBrowserContext(GetBrowserContext()));
1443
1441 // The |completion_inhibitor| on the stack should prevent removal sessions 1444 // The |completion_inhibitor| on the stack should prevent removal sessions
1442 // from completing until after ContinueToCompletion() is called. 1445 // from completing until after ContinueToCompletion() is called.
1443 BrowsingDataRemoverCompletionInhibitor completion_inhibitor; 1446 BrowsingDataRemoverCompletionInhibitor completion_inhibitor(remover);
1444
1445 BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>(
1446 BrowsingDataRemoverFactory::GetForBrowserContext(GetBrowserContext()));
1447 InspectableCompletionObserver completion_observer(remover); 1447 InspectableCompletionObserver completion_observer(remover);
1448 remover->RemoveAndReply( 1448 remover->RemoveAndReply(
1449 base::Time(), base::Time::Max(), BrowsingDataRemover::DATA_TYPE_COOKIES, 1449 base::Time(), base::Time::Max(), BrowsingDataRemover::DATA_TYPE_COOKIES,
1450 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, &completion_observer); 1450 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, &completion_observer);
1451 1451
1452 // Process messages until the inhibitor is notified, and then some, to make 1452 // Process messages until the inhibitor is notified, and then some, to make
1453 // sure we do not complete asynchronously before ContinueToCompletion() is 1453 // sure we do not complete asynchronously before ContinueToCompletion() is
1454 // called. 1454 // called.
1455 completion_inhibitor.BlockUntilNearCompletion(); 1455 completion_inhibitor.BlockUntilNearCompletion();
1456 base::RunLoop().RunUntilIdle(); 1456 base::RunLoop().RunUntilIdle();
1457 1457
1458 // Verify that the removal has not yet been completed and the observer has 1458 // Verify that the removal has not yet been completed and the observer has
1459 // not been called. 1459 // not been called.
1460 EXPECT_TRUE(remover->is_removing()); 1460 EXPECT_TRUE(remover->is_removing());
1461 EXPECT_FALSE(completion_observer.called()); 1461 EXPECT_FALSE(completion_observer.called());
1462 1462
1463 // Now run the removal process until completion, and verify that observers are 1463 // Now run the removal process until completion, and verify that observers are
1464 // now notified, and the notifications is sent out. 1464 // now notified, and the notifications is sent out.
1465 completion_inhibitor.ContinueToCompletion(); 1465 completion_inhibitor.ContinueToCompletion();
1466 completion_observer.BlockUntilCompletion(); 1466 completion_observer.BlockUntilCompletion();
1467 1467
1468 EXPECT_FALSE(remover->is_removing()); 1468 EXPECT_FALSE(remover->is_removing());
1469 EXPECT_TRUE(completion_observer.called()); 1469 EXPECT_TRUE(completion_observer.called());
1470 } 1470 }
1471 1471
1472 TEST_F(BrowsingDataRemoverImplTest, EarlyShutdown) { 1472 TEST_F(BrowsingDataRemoverImplTest, EarlyShutdown) {
1473 BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>( 1473 BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>(
1474 BrowsingDataRemoverFactory::GetForBrowserContext(GetBrowserContext())); 1474 BrowsingDataRemoverFactory::GetForBrowserContext(GetBrowserContext()));
1475 InspectableCompletionObserver completion_observer(remover); 1475 InspectableCompletionObserver completion_observer(remover);
1476 BrowsingDataRemoverCompletionInhibitor completion_inhibitor; 1476 BrowsingDataRemoverCompletionInhibitor completion_inhibitor(remover);
1477 remover->RemoveAndReply( 1477 remover->RemoveAndReply(
1478 base::Time(), base::Time::Max(), BrowsingDataRemover::DATA_TYPE_COOKIES, 1478 base::Time(), base::Time::Max(), BrowsingDataRemover::DATA_TYPE_COOKIES,
1479 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, &completion_observer); 1479 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, &completion_observer);
1480 1480
1481 completion_inhibitor.BlockUntilNearCompletion(); 1481 completion_inhibitor.BlockUntilNearCompletion();
1482 1482
1483 // Verify that the deletion has not yet been completed and the observer has 1483 // Verify that the deletion has not yet been completed and the observer has
1484 // not been called. 1484 // not been called.
1485 EXPECT_TRUE(remover->is_removing()); 1485 EXPECT_TRUE(remover->is_removing());
1486 EXPECT_FALSE(completion_observer.called()); 1486 EXPECT_FALSE(completion_observer.called());
1487 1487
1488 // Destroying the profile should trigger the notification. 1488 // Destroying the profile should trigger the notification.
1489 DestroyBrowserContext(); 1489 DestroyBrowserContext();
1490 1490
1491 EXPECT_TRUE(completion_observer.called()); 1491 EXPECT_TRUE(completion_observer.called());
1492 1492
1493 // Finishing after shutdown shouldn't break anything. 1493 // Finishing after shutdown shouldn't break anything.
1494 completion_inhibitor.ContinueToCompletion(); 1494 completion_inhibitor.ContinueToCompletion();
Bernhard Bauer 2017/04/12 16:35:34 You could still keep these if you remove the DCHEC
msramek 2017/04/12 19:16:55 Sigh... I forgot that |continue_to_completion_call
1495 completion_observer.BlockUntilCompletion(); 1495 completion_observer.BlockUntilCompletion();
1496 } 1496 }
1497 1497
1498 TEST_F(BrowsingDataRemoverImplTest, RemoveDownloadsByTimeOnly) { 1498 TEST_F(BrowsingDataRemoverImplTest, RemoveDownloadsByTimeOnly) {
1499 RemoveDownloadsTester tester(GetBrowserContext()); 1499 RemoveDownloadsTester tester(GetBrowserContext());
1500 base::Callback<bool(const GURL&)> filter = 1500 base::Callback<bool(const GURL&)> filter =
1501 BrowsingDataFilterBuilder::BuildNoopFilter(); 1501 BrowsingDataFilterBuilder::BuildNoopFilter();
1502 1502
1503 EXPECT_CALL( 1503 EXPECT_CALL(
1504 *tester.download_manager(), 1504 *tester.download_manager(),
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1583 BrowsingDataRemoverFactory::GetForBrowserContext(GetBrowserContext())); 1583 BrowsingDataRemoverFactory::GetForBrowserContext(GetBrowserContext()));
1584 EXPECT_FALSE(remover->is_removing()); 1584 EXPECT_FALSE(remover->is_removing());
1585 1585
1586 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder_1( 1586 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder_1(
1587 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST)); 1587 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST));
1588 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder_2( 1588 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder_2(
1589 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::BLACKLIST)); 1589 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::BLACKLIST));
1590 filter_builder_2->AddRegisterableDomain("example.com"); 1590 filter_builder_2->AddRegisterableDomain("example.com");
1591 1591
1592 MultipleTasksObserver observer(remover); 1592 MultipleTasksObserver observer(remover);
1593 BrowsingDataRemoverCompletionInhibitor completion_inhibitor; 1593 BrowsingDataRemoverCompletionInhibitor completion_inhibitor(remover);
1594 1594
1595 // Test several tasks with various configuration of masks, filters, and target 1595 // Test several tasks with various configuration of masks, filters, and target
1596 // observers. 1596 // observers.
1597 std::list<BrowsingDataRemoverImpl::RemovalTask> tasks; 1597 std::list<BrowsingDataRemoverImpl::RemovalTask> tasks;
1598 tasks.emplace_back( 1598 tasks.emplace_back(
1599 base::Time(), base::Time::Max(), BrowsingDataRemover::DATA_TYPE_DOWNLOADS, 1599 base::Time(), base::Time::Max(), BrowsingDataRemover::DATA_TYPE_DOWNLOADS,
1600 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, 1600 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB,
1601 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::BLACKLIST), 1601 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::BLACKLIST),
1602 observer.target_a()); 1602 observer.target_a());
1603 tasks.emplace_back( 1603 tasks.emplace_back(
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1706 1706
1707 EXPECT_TRUE(remover->is_removing()); 1707 EXPECT_TRUE(remover->is_removing());
1708 1708
1709 // Add one more deletion and wait for it. 1709 // Add one more deletion and wait for it.
1710 BlockUntilBrowsingDataRemoved( 1710 BlockUntilBrowsingDataRemoved(
1711 base::Time(), base::Time::Max(), BrowsingDataRemover::DATA_TYPE_COOKIES, 1711 base::Time(), base::Time::Max(), BrowsingDataRemover::DATA_TYPE_COOKIES,
1712 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB); 1712 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB);
1713 1713
1714 EXPECT_FALSE(remover->is_removing()); 1714 EXPECT_FALSE(remover->is_removing());
1715 } 1715 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698