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

Unified Diff: components/password_manager/core/browser/affiliated_match_helper_unittest.cc

Issue 2657013002: Introduce ThreadTaskRunnerHandle::OverrideForTesting and TestMockTimeTaskRunner::ScopedContext. (Closed)
Patch Set: fix RecentTabHelperTest crash? Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: components/password_manager/core/browser/affiliated_match_helper_unittest.cc
diff --git a/components/password_manager/core/browser/affiliated_match_helper_unittest.cc b/components/password_manager/core/browser/affiliated_match_helper_unittest.cc
index acca937aeed7e45b9f30a8dc0b1f5bf49314b599..80e169e3ceadd21f70047a237a01b0d1c1cabc86 100644
--- a/components/password_manager/core/browser/affiliated_match_helper_unittest.cc
+++ b/components/password_manager/core/browser/affiliated_match_helper_unittest.cc
@@ -15,7 +15,7 @@
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
-#include "base/test/test_simple_task_runner.h"
+#include "base/test/scoped_mock_time_message_loop_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "components/password_manager/core/browser/affiliation_service.h"
#include "components/password_manager/core/browser/affiliation_utils.h"
@@ -166,37 +166,40 @@ PasswordStore::FormDigest GetTestObservedWebForm(const char* signon_realm,
class AffiliatedMatchHelperTest : public testing::Test {
public:
AffiliatedMatchHelperTest()
- : waiting_task_runner_(new base::TestSimpleTaskRunner),
- expecting_result_callback_(false),
- mock_affiliation_service_(nullptr) {}
+ : expecting_result_callback_(false), mock_affiliation_service_(nullptr) {}
~AffiliatedMatchHelperTest() override {}
protected:
void RunDeferredInitialization() {
- base::TimeDelta expected_init_delay = base::TimeDelta::FromSeconds(
- AffiliatedMatchHelper::kInitializationDelayOnStartupInSeconds);
- ASSERT_TRUE(waiting_task_runner()->HasPendingTask());
- ASSERT_EQ(expected_init_delay,
- waiting_task_runner()->NextPendingTaskDelay());
- waiting_task_runner()->RunUntilIdle();
- base::RunLoop().RunUntilIdle();
+ mock_time_task_runner_->RunUntilIdle();
+ ASSERT_EQ(AffiliatedMatchHelper::kInitializationDelayOnStartup,
+ mock_time_task_runner_->NextPendingTaskDelay());
+ mock_time_task_runner_->FastForwardBy(
+ AffiliatedMatchHelper::kInitializationDelayOnStartup);
+ }
+
+ void RunUntilIdle() {
+ // TODO(gab): Add support for base::RunLoop().RunUntilIdle() in scope of
+ // ScopedMockTimeMessageLoopTaskRunner and use it instead of this helper
+ // method.
+ mock_time_task_runner_->RunUntilIdle();
}
void AddLogin(const autofill::PasswordForm& form) {
password_store_->AddLogin(form);
- base::RunLoop().RunUntilIdle();
+ RunUntilIdle();
}
void UpdateLoginWithPrimaryKey(
const autofill::PasswordForm& new_form,
const autofill::PasswordForm& old_primary_key) {
password_store_->UpdateLoginWithPrimaryKey(new_form, old_primary_key);
- base::RunLoop().RunUntilIdle();
+ RunUntilIdle();
}
void RemoveLogin(const autofill::PasswordForm& form) {
password_store_->RemoveLogin(form);
- base::RunLoop().RunUntilIdle();
+ RunUntilIdle();
}
void AddAndroidAndNonAndroidTestLogins() {
@@ -256,7 +259,7 @@ class AffiliatedMatchHelperTest : public testing::Test {
observed_form,
base::Bind(&AffiliatedMatchHelperTest::OnAffiliatedRealmsCallback,
base::Unretained(this)));
- base::RunLoop().RunUntilIdle();
+ RunUntilIdle();
EXPECT_FALSE(expecting_result_callback_);
return last_result_realms_;
}
@@ -268,7 +271,7 @@ class AffiliatedMatchHelperTest : public testing::Test {
android_form,
base::Bind(&AffiliatedMatchHelperTest::OnAffiliatedRealmsCallback,
base::Unretained(this)));
- base::RunLoop().RunUntilIdle();
+ RunUntilIdle();
EXPECT_FALSE(expecting_result_callback_);
return last_result_realms_;
}
@@ -281,17 +284,13 @@ class AffiliatedMatchHelperTest : public testing::Test {
std::move(forms),
base::Bind(&AffiliatedMatchHelperTest::OnFormsCallback,
base::Unretained(this)));
- base::RunLoop().RunUntilIdle();
+ RunUntilIdle();
EXPECT_FALSE(expecting_result_callback_);
return std::move(last_result_forms_);
}
void DestroyMatchHelper() { match_helper_.reset(); }
- base::TestSimpleTaskRunner* waiting_task_runner() {
- return waiting_task_runner_.get();
- }
-
TestPasswordStore* password_store() { return password_store_.get(); }
MockAffiliationService* mock_affiliation_service() {
@@ -325,7 +324,6 @@ class AffiliatedMatchHelperTest : public testing::Test {
match_helper_.reset(
new AffiliatedMatchHelper(password_store_.get(), std::move(service)));
- match_helper_->SetTaskRunnerUsedForWaitingForTesting(waiting_task_runner_);
}
void TearDown() override {
@@ -334,8 +332,9 @@ class AffiliatedMatchHelperTest : public testing::Test {
password_store_ = nullptr;
}
- scoped_refptr<base::TestSimpleTaskRunner> waiting_task_runner_;
base::MessageLoop message_loop_;
+ base::ScopedMockTimeMessageLoopTaskRunner mock_time_task_runner_;
+
std::vector<std::string> last_result_realms_;
std::vector<std::unique_ptr<autofill::PasswordForm>> last_result_forms_;
bool expecting_result_callback_;
@@ -504,7 +503,7 @@ TEST_F(AffiliatedMatchHelperTest,
AddAndroidAndNonAndroidTestLogins();
match_helper()->Initialize();
- base::RunLoop().RunUntilIdle();
+ RunUntilIdle();
ExpectPrefetchForAndroidTestLogins();
ASSERT_NO_FATAL_FAILURE(RunDeferredInitialization());
@@ -516,7 +515,7 @@ TEST_F(AffiliatedMatchHelperTest,
TEST_F(AffiliatedMatchHelperTest,
PrefetchAffiliationsForAndroidCredentialsAddedInInitializationDelay) {
match_helper()->Initialize();
- base::RunLoop().RunUntilIdle();
+ RunUntilIdle();
AddAndroidAndNonAndroidTestLogins();
@@ -594,7 +593,7 @@ TEST_F(AffiliatedMatchHelperTest,
AddLogin(android_form2);
match_helper()->Initialize();
- base::RunLoop().RunUntilIdle();
+ RunUntilIdle();
// Store one credential between initialization and deferred initialization.
autofill::PasswordForm android_form3(android_form);
@@ -623,7 +622,7 @@ TEST_F(AffiliatedMatchHelperTest,
TEST_F(AffiliatedMatchHelperTest, DestroyBeforeDeferredInitialization) {
match_helper()->Initialize();
- base::RunLoop().RunUntilIdle();
+ RunUntilIdle();
DestroyMatchHelper();
ASSERT_NO_FATAL_FAILURE(RunDeferredInitialization());
}

Powered by Google App Engine
This is Rietveld 408576698