Commit 6111392d authored by Mark Pearson's avatar Mark Pearson Committed by Commit Bot

Refactor SearchProviderTest.SendsWarmUpRequestOnFocus to Deflake It

and re-enable it

Call the scoped feature list earlier in test setup instead of in
the middle of a test.  Calling scoped feature list in the middle of
a test will clobber existing features, which could result in problems
as behavior changes mid-run.

(I am not ready to review this feature flag yet.  This feature has
caused problems in the past, so I'd like to keep the flag around for
longer.  It has little overhead in the code.)

Bug: 891959
Change-Id: I2cee38ff6ff2cc7de16ba1d260f831cee5a68349
Reviewed-on: https://chromium-review.googlesource.com/c/1263562Reviewed-by: default avatarJustin Donnelly <jdonnelly@chromium.org>
Commit-Queue: Mark Pearson <mpearson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#597222}
parent 0a81d0fe
...@@ -3615,37 +3615,47 @@ TEST_F(SearchProviderTest, DoesNotProvideOnFocus) { ...@@ -3615,37 +3615,47 @@ TEST_F(SearchProviderTest, DoesNotProvideOnFocus) {
EXPECT_TRUE(provider_->matches().empty()); EXPECT_TRUE(provider_->matches().empty());
} }
#if defined(THREAD_SANITIZER) // SearchProviderWarmUpTest --------------------------------------------------
// SearchProviderTest.SendsWarmUpRequestOnFocus is flaky on Linux TSan Tests //
// crbug.com/891959. // Like SearchProviderTest. The only addition is that it's a
#define MAYBE_SendsWarmUpRequestOnFocus DISABLED_SendsWarmUpRequestOnFocus // TestWithParam<bool>, where the boolean parameter represents whether the
#else // omnibox::kSearchProviderWarmUpOnFocus feature flag should be enabled.
#define MAYBE_SendsWarmUpRequestOnFocus SendsWarmUpRequestOnFocus class SearchProviderWarmUpTest : public SearchProviderTest,
#endif // defined(THREAD_SANITIZER) public testing::WithParamInterface<bool> {
TEST_F(SearchProviderTest, MAYBE_SendsWarmUpRequestOnFocus) { public:
SearchProviderWarmUpTest() {}
void SetUp() override;
protected:
base::test::ScopedFeatureList feature_list_;
DISALLOW_COPY_AND_ASSIGN(SearchProviderWarmUpTest);
};
void SearchProviderWarmUpTest::SetUp() {
if (GetParam())
feature_list_.InitAndEnableFeature(omnibox::kSearchProviderWarmUpOnFocus);
else
feature_list_.InitAndDisableFeature(omnibox::kSearchProviderWarmUpOnFocus);
SearchProviderTest::SetUp();
}
TEST_P(SearchProviderWarmUpTest, SendsWarmUpRequestOnFocus) {
AutocompleteInput input(base::ASCIIToUTF16("f"), AutocompleteInput input(base::ASCIIToUTF16("f"),
metrics::OmniboxEventProto::OTHER, metrics::OmniboxEventProto::OTHER,
ChromeAutocompleteSchemeClassifier(&profile_)); ChromeAutocompleteSchemeClassifier(&profile_));
input.set_prefer_keyword(true); input.set_prefer_keyword(true);
input.set_from_omnibox_focus(true); input.set_from_omnibox_focus(true);
{ if (!GetParam()) { // The warm-up feature ought to be disabled.
// First, verify that without the warm-up feature enabled, the provider // The provider immediately terminates with no matches.
// immediately terminates with no matches.
base::test::ScopedFeatureList feature_list;
feature_list.InitAndDisableFeature(omnibox::kSearchProviderWarmUpOnFocus);
provider_->Start(input, false); provider_->Start(input, false);
// RunUntilIdle so that SearchProvider has a chance to create the // RunUntilIdle so that SearchProvider has a chance to create the
// URLFetchers (if it wants to, which it shouldn't in this case). // URLFetchers (if it wants to, which it shouldn't in this case).
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_TRUE(provider_->done()); EXPECT_TRUE(provider_->done());
EXPECT_TRUE(provider_->matches().empty()); EXPECT_TRUE(provider_->matches().empty());
} } else { // The warm-up feature ought to be enabled.
{
// Then, check the behavior with the warm-up feature enabled.
base::test::ScopedFeatureList feature_list;
feature_list.InitAndEnableFeature(omnibox::kSearchProviderWarmUpOnFocus);
provider_->Start(input, false); provider_->Start(input, false);
// RunUntilIdle so that SearchProvider create the URLFetcher. // RunUntilIdle so that SearchProvider create the URLFetcher.
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -3663,3 +3673,7 @@ TEST_F(SearchProviderTest, MAYBE_SendsWarmUpRequestOnFocus) { ...@@ -3663,3 +3673,7 @@ TEST_F(SearchProviderTest, MAYBE_SendsWarmUpRequestOnFocus) {
EXPECT_TRUE(provider_->matches().empty()); EXPECT_TRUE(provider_->matches().empty());
} }
} }
INSTANTIATE_TEST_CASE_P(SearchProviderTest,
SearchProviderWarmUpTest,
testing::Values(false, true));
...@@ -95,13 +95,13 @@ class SearchProvider : public BaseSearchProvider, ...@@ -95,13 +95,13 @@ class SearchProvider : public BaseSearchProvider,
FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, AnswersCache); FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, AnswersCache);
FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, RemoveExtraAnswers); FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, RemoveExtraAnswers);
FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, DoesNotProvideOnFocus); FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, DoesNotProvideOnFocus);
FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, SendsWarmUpRequestOnFocus);
FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, DoTrimHttpScheme); FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, DoTrimHttpScheme);
FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, FRIEND_TEST_ALL_PREFIXES(SearchProviderTest,
DontTrimHttpSchemeIfInputHasScheme); DontTrimHttpSchemeIfInputHasScheme);
FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, FRIEND_TEST_ALL_PREFIXES(SearchProviderTest,
DontTrimHttpsSchemeIfInputHasScheme); DontTrimHttpsSchemeIfInputHasScheme);
FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, DoTrimHttpsScheme); FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, DoTrimHttpsScheme);
FRIEND_TEST_ALL_PREFIXES(SearchProviderWarmUpTest, SendsWarmUpRequestOnFocus);
FRIEND_TEST_ALL_PREFIXES(InstantExtendedPrefetchTest, ClearPrefetchedResults); FRIEND_TEST_ALL_PREFIXES(InstantExtendedPrefetchTest, ClearPrefetchedResults);
FRIEND_TEST_ALL_PREFIXES(InstantExtendedPrefetchTest, SetPrefetchQuery); FRIEND_TEST_ALL_PREFIXES(InstantExtendedPrefetchTest, SetPrefetchQuery);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment