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) {
EXPECT_TRUE(provider_->matches().empty());
}
#if defined(THREAD_SANITIZER)
// SearchProviderTest.SendsWarmUpRequestOnFocus is flaky on Linux TSan Tests
// crbug.com/891959.
#define MAYBE_SendsWarmUpRequestOnFocus DISABLED_SendsWarmUpRequestOnFocus
#else
#define MAYBE_SendsWarmUpRequestOnFocus SendsWarmUpRequestOnFocus
#endif // defined(THREAD_SANITIZER)
TEST_F(SearchProviderTest, MAYBE_SendsWarmUpRequestOnFocus) {
// SearchProviderWarmUpTest --------------------------------------------------
//
// Like SearchProviderTest. The only addition is that it's a
// TestWithParam<bool>, where the boolean parameter represents whether the
// omnibox::kSearchProviderWarmUpOnFocus feature flag should be enabled.
class SearchProviderWarmUpTest : public SearchProviderTest,
public testing::WithParamInterface<bool> {
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"),
metrics::OmniboxEventProto::OTHER,
ChromeAutocompleteSchemeClassifier(&profile_));
input.set_prefer_keyword(true);
input.set_from_omnibox_focus(true);
{
// First, verify that without the warm-up feature enabled, the provider
// immediately terminates with no matches.
base::test::ScopedFeatureList feature_list;
feature_list.InitAndDisableFeature(omnibox::kSearchProviderWarmUpOnFocus);
if (!GetParam()) { // The warm-up feature ought to be disabled.
// The provider immediately terminates with no matches.
provider_->Start(input, false);
// RunUntilIdle so that SearchProvider has a chance to create the
// URLFetchers (if it wants to, which it shouldn't in this case).
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(provider_->done());
EXPECT_TRUE(provider_->matches().empty());
}
{
// Then, check the behavior with the warm-up feature enabled.
base::test::ScopedFeatureList feature_list;
feature_list.InitAndEnableFeature(omnibox::kSearchProviderWarmUpOnFocus);
} else { // The warm-up feature ought to be enabled.
provider_->Start(input, false);
// RunUntilIdle so that SearchProvider create the URLFetcher.
base::RunLoop().RunUntilIdle();
......@@ -3663,3 +3673,7 @@ TEST_F(SearchProviderTest, MAYBE_SendsWarmUpRequestOnFocus) {
EXPECT_TRUE(provider_->matches().empty());
}
}
INSTANTIATE_TEST_CASE_P(SearchProviderTest,
SearchProviderWarmUpTest,
testing::Values(false, true));
......@@ -95,13 +95,13 @@ class SearchProvider : public BaseSearchProvider,
FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, AnswersCache);
FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, RemoveExtraAnswers);
FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, DoesNotProvideOnFocus);
FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, SendsWarmUpRequestOnFocus);
FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, DoTrimHttpScheme);
FRIEND_TEST_ALL_PREFIXES(SearchProviderTest,
DontTrimHttpSchemeIfInputHasScheme);
FRIEND_TEST_ALL_PREFIXES(SearchProviderTest,
DontTrimHttpsSchemeIfInputHasScheme);
FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, DoTrimHttpsScheme);
FRIEND_TEST_ALL_PREFIXES(SearchProviderWarmUpTest, SendsWarmUpRequestOnFocus);
FRIEND_TEST_ALL_PREFIXES(InstantExtendedPrefetchTest, ClearPrefetchedResults);
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