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

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: Finishing after shutdown is still OK. 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 completion_inhibitor.Reset();
1482 1483
1483 // Verify that the deletion has not yet been completed and the observer has 1484 // Verify that the deletion has not yet been completed and the observer has
1484 // not been called. 1485 // not been called.
1485 EXPECT_TRUE(remover->is_removing()); 1486 EXPECT_TRUE(remover->is_removing());
1486 EXPECT_FALSE(completion_observer.called()); 1487 EXPECT_FALSE(completion_observer.called());
1487 1488
1488 // Destroying the profile should trigger the notification. 1489 // Destroying the profile should trigger the notification.
1489 DestroyBrowserContext(); 1490 DestroyBrowserContext();
1490 1491
1491 EXPECT_TRUE(completion_observer.called()); 1492 EXPECT_TRUE(completion_observer.called());
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1583 BrowsingDataRemoverFactory::GetForBrowserContext(GetBrowserContext())); 1584 BrowsingDataRemoverFactory::GetForBrowserContext(GetBrowserContext()));
1584 EXPECT_FALSE(remover->is_removing()); 1585 EXPECT_FALSE(remover->is_removing());
1585 1586
1586 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder_1( 1587 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder_1(
1587 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST)); 1588 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST));
1588 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder_2( 1589 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder_2(
1589 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::BLACKLIST)); 1590 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::BLACKLIST));
1590 filter_builder_2->AddRegisterableDomain("example.com"); 1591 filter_builder_2->AddRegisterableDomain("example.com");
1591 1592
1592 MultipleTasksObserver observer(remover); 1593 MultipleTasksObserver observer(remover);
1593 BrowsingDataRemoverCompletionInhibitor completion_inhibitor; 1594 BrowsingDataRemoverCompletionInhibitor completion_inhibitor(remover);
1594 1595
1595 // Test several tasks with various configuration of masks, filters, and target 1596 // Test several tasks with various configuration of masks, filters, and target
1596 // observers. 1597 // observers.
1597 std::list<BrowsingDataRemoverImpl::RemovalTask> tasks; 1598 std::list<BrowsingDataRemoverImpl::RemovalTask> tasks;
1598 tasks.emplace_back( 1599 tasks.emplace_back(
1599 base::Time(), base::Time::Max(), BrowsingDataRemover::DATA_TYPE_DOWNLOADS, 1600 base::Time(), base::Time::Max(), BrowsingDataRemover::DATA_TYPE_DOWNLOADS,
1600 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, 1601 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB,
1601 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::BLACKLIST), 1602 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::BLACKLIST),
1602 observer.target_a()); 1603 observer.target_a());
1603 tasks.emplace_back( 1604 tasks.emplace_back(
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1706 1707
1707 EXPECT_TRUE(remover->is_removing()); 1708 EXPECT_TRUE(remover->is_removing());
1708 1709
1709 // Add one more deletion and wait for it. 1710 // Add one more deletion and wait for it.
1710 BlockUntilBrowsingDataRemoved( 1711 BlockUntilBrowsingDataRemoved(
1711 base::Time(), base::Time::Max(), BrowsingDataRemover::DATA_TYPE_COOKIES, 1712 base::Time(), base::Time::Max(), BrowsingDataRemover::DATA_TYPE_COOKIES,
1712 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB); 1713 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB);
1713 1714
1714 EXPECT_FALSE(remover->is_removing()); 1715 EXPECT_FALSE(remover->is_removing());
1715 } 1716 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698