Commit 5d489a14 authored by Dan Beam's avatar Dan Beam Committed by Commit Bot

Local NTP: allow stopping autocomplete for inactive tabs

It's possible that a user backgrounding a tab results in a focusout,
which can call stopAutocomplete().

I'm not aware of any reason why we should disallow stopping autocomplete
for inactive tabs, so remove this restriction from the policy.

Bug: 1020025
Change-Id: I937a67f1f45549629baa7fa0fd7e6901d2d37f33
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1907563
Auto-Submit: Dan Beam <dbeam@chromium.org>
Reviewed-by: default avatarMoe Ahmadi <mahmadi@chromium.org>
Commit-Queue: Dan Beam <dbeam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#714074}
parent 7743092f
...@@ -454,7 +454,7 @@ void SearchIPCRouter::QueryAutocomplete( ...@@ -454,7 +454,7 @@ void SearchIPCRouter::QueryAutocomplete(
} }
void SearchIPCRouter::StopAutocomplete(bool clear_result) { void SearchIPCRouter::StopAutocomplete(bool clear_result) {
if (!policy_->ShouldProcessStopAutocomplete(is_active_tab_)) { if (!policy_->ShouldProcessStopAutocomplete()) {
return; return;
} }
......
...@@ -207,7 +207,7 @@ class SearchIPCRouter : public content::WebContentsObserver, ...@@ -207,7 +207,7 @@ class SearchIPCRouter : public content::WebContentsObserver,
virtual bool ShouldProcessOptOutOfSearchSuggestions() = 0; virtual bool ShouldProcessOptOutOfSearchSuggestions() = 0;
virtual bool ShouldProcessThemeChangeMessages() = 0; virtual bool ShouldProcessThemeChangeMessages() = 0;
virtual bool ShouldProcessQueryAutocomplete(bool is_active_tab) = 0; virtual bool ShouldProcessQueryAutocomplete(bool is_active_tab) = 0;
virtual bool ShouldProcessStopAutocomplete(bool is_active_tab) = 0; virtual bool ShouldProcessStopAutocomplete() = 0;
virtual bool ShouldProcessBlocklistPromo() = 0; virtual bool ShouldProcessBlocklistPromo() = 0;
virtual bool ShouldProcessDeleteAutocompleteMatch() = 0; virtual bool ShouldProcessDeleteAutocompleteMatch() = 0;
}; };
......
...@@ -137,9 +137,8 @@ bool SearchIPCRouterPolicyImpl::ShouldProcessQueryAutocomplete( ...@@ -137,9 +137,8 @@ bool SearchIPCRouterPolicyImpl::ShouldProcessQueryAutocomplete(
return is_active_tab && !is_incognito_ && search::IsInstantNTP(web_contents_); return is_active_tab && !is_incognito_ && search::IsInstantNTP(web_contents_);
} }
bool SearchIPCRouterPolicyImpl::ShouldProcessStopAutocomplete( bool SearchIPCRouterPolicyImpl::ShouldProcessStopAutocomplete() {
bool is_active_tab) { return !is_incognito_ && search::IsInstantNTP(web_contents_);
return is_active_tab && !is_incognito_ && search::IsInstantNTP(web_contents_);
} }
bool SearchIPCRouterPolicyImpl::ShouldProcessBlocklistPromo() { bool SearchIPCRouterPolicyImpl::ShouldProcessBlocklistPromo() {
......
...@@ -55,7 +55,7 @@ class SearchIPCRouterPolicyImpl : public SearchIPCRouter::Policy { ...@@ -55,7 +55,7 @@ class SearchIPCRouterPolicyImpl : public SearchIPCRouter::Policy {
bool ShouldProcessOptOutOfSearchSuggestions() override; bool ShouldProcessOptOutOfSearchSuggestions() override;
bool ShouldProcessThemeChangeMessages() override; bool ShouldProcessThemeChangeMessages() override;
bool ShouldProcessQueryAutocomplete(bool is_active_tab) override; bool ShouldProcessQueryAutocomplete(bool is_active_tab) override;
bool ShouldProcessStopAutocomplete(bool is_active_tab) override; bool ShouldProcessStopAutocomplete() override;
bool ShouldProcessBlocklistPromo() override; bool ShouldProcessBlocklistPromo() override;
bool ShouldProcessDeleteAutocompleteMatch() override; bool ShouldProcessDeleteAutocompleteMatch() override;
......
...@@ -112,7 +112,7 @@ class MockSearchIPCRouterDelegate : public SearchIPCRouter::Delegate { ...@@ -112,7 +112,7 @@ class MockSearchIPCRouterDelegate : public SearchIPCRouter::Delegate {
QueryAutocomplete, QueryAutocomplete,
void(const base::string16& input, void(const base::string16& input,
chrome::mojom::EmbeddedSearch::QueryAutocompleteCallback callback)); chrome::mojom::EmbeddedSearch::QueryAutocompleteCallback callback));
MOCK_METHOD1(StopAutocomplete, void(bool clear_result)); MOCK_METHOD1(StopAutocomplete, void(bool));
MOCK_METHOD1(BlocklistPromo, void(const std::string& promo_id)); MOCK_METHOD1(BlocklistPromo, void(const std::string& promo_id));
}; };
...@@ -149,7 +149,7 @@ class MockSearchIPCRouterPolicy : public SearchIPCRouter::Policy { ...@@ -149,7 +149,7 @@ class MockSearchIPCRouterPolicy : public SearchIPCRouter::Policy {
MOCK_METHOD0(ShouldSendLocalBackgroundSelected, bool()); MOCK_METHOD0(ShouldSendLocalBackgroundSelected, bool());
MOCK_METHOD0(ShouldProcessThemeChangeMessages, bool()); MOCK_METHOD0(ShouldProcessThemeChangeMessages, bool());
MOCK_METHOD1(ShouldProcessQueryAutocomplete, bool(bool)); MOCK_METHOD1(ShouldProcessQueryAutocomplete, bool(bool));
MOCK_METHOD1(ShouldProcessStopAutocomplete, bool(bool)); MOCK_METHOD0(ShouldProcessStopAutocomplete, bool());
MOCK_METHOD0(ShouldProcessBlocklistPromo, bool()); MOCK_METHOD0(ShouldProcessBlocklistPromo, bool());
MOCK_METHOD0(ShouldProcessDeleteAutocompleteMatch, bool()); MOCK_METHOD0(ShouldProcessDeleteAutocompleteMatch, bool());
}; };
...@@ -1119,3 +1119,15 @@ TEST_F(SearchIPCRouterTest, IgnoreDeleteAutocompleteMatch) { ...@@ -1119,3 +1119,15 @@ TEST_F(SearchIPCRouterTest, IgnoreDeleteAutocompleteMatch) {
callback; callback;
GetSearchIPCRouter().DeleteAutocompleteMatch(0u, callback.Get()); GetSearchIPCRouter().DeleteAutocompleteMatch(0u, callback.Get());
} }
TEST_F(SearchIPCRouterTest, IgnoreStopAutoComplete) {
NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
SetupMockDelegateAndPolicy();
MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
EXPECT_CALL(*mock_delegate(), StopAutocomplete(_)).Times(0);
EXPECT_CALL(*policy, ShouldProcessStopAutocomplete())
.Times(1)
.WillOnce(Return(false));
GetSearchIPCRouter().StopAutocomplete(false);
}
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