forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a preference to control Windows desktop search redirection.
This CL adds a new preference called "windows_desktop_search_redirection", that controls whether Windows desktop searches should be redirected to the default search engine. The preference can be enabled, disabled or unset. Enabled and disabled mean that redirection of desktop searches has been explicitly enabled or disabled. Unset means no value has been explicitly set and that the browser should ask the user whether they want to use the feature (prompt + checkbox to edit the preference from chrome://settings will be implemented in an upcoming CL). BUG=539963 Review URL: https://codereview.chromium.org/1477783004 Cr-Commit-Position: refs/heads/master@{#363064}
- Loading branch information
Showing
16 changed files
with
250 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
chrome/browser/ui/startup/startup_browser_creator_win_unittest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Copyright 2015 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/ui/startup/startup_browser_creator.h" | ||
|
||
#include <vector> | ||
|
||
#include "base/command_line.h" | ||
#include "base/feature_list.h" | ||
#include "base/macros.h" | ||
#include "base/prefs/pref_service.h" | ||
#include "chrome/browser/search_engines/template_url_service_factory.h" | ||
#include "chrome/browser/search_engines/template_url_service_factory_test_util.h" | ||
#include "chrome/test/base/testing_profile.h" | ||
#include "components/search_engines/desktop_search_win.h" | ||
#include "components/search_engines/util.h" | ||
#include "content/public/test/test_browser_thread_bundle.h" | ||
#include "testing/gtest/include/gtest/gtest.h" | ||
#include "url/gurl.h" | ||
|
||
class StartupBrowserCreatorWinTest : public testing::Test { | ||
public: | ||
StartupBrowserCreatorWinTest() {} | ||
|
||
protected: | ||
void SetWindowsDesktopSearchFeatureEnabled(bool enabled) { | ||
base::FeatureList::ClearInstanceForTesting(); | ||
scoped_ptr<base::FeatureList> feature_list(new base::FeatureList); | ||
if (enabled) { | ||
feature_list->InitializeFromCommandLine( | ||
kWindowsDesktopSearchRedirectionFeature.name, std::string()); | ||
} | ||
base::FeatureList::SetInstance(std::move(feature_list)); | ||
} | ||
|
||
private: | ||
content::TestBrowserThreadBundle thread_bundle_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(StartupBrowserCreatorWinTest); | ||
}; | ||
|
||
TEST_F(StartupBrowserCreatorWinTest, | ||
GetURLsFromCommandLineWithDesktopSearchURL) { | ||
const char kDesktopSearchURL[] = | ||
"https://www.bing.com/search?q=keyword&form=WNSGPH"; | ||
|
||
TestingProfile profile; | ||
TemplateURLServiceFactoryTestUtil template_url_service_factory_test_util( | ||
&profile); | ||
|
||
base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | ||
command_line.AppendArg(kDesktopSearchURL); | ||
|
||
// Expected vectors of URLs. | ||
const std::vector<GURL> desktop_search_url_vector({GURL(kDesktopSearchURL)}); | ||
const std::vector<GURL> default_search_url_vector( | ||
{GetDefaultSearchURLForSearchTerms( | ||
TemplateURLServiceFactory::GetForProfile(&profile), L"keyword")}); | ||
|
||
// Preference unset, feature enabled. | ||
SetWindowsDesktopSearchFeatureEnabled(true); | ||
EXPECT_EQ(desktop_search_url_vector, | ||
StartupBrowserCreator::GetURLsFromCommandLine( | ||
command_line, base::FilePath(), &profile)); | ||
|
||
// Preference set to disabled, feature enabled. | ||
profile.GetPrefs()->SetBoolean(prefs::kWindowsDesktopSearchRedirectionPref, | ||
false); | ||
SetWindowsDesktopSearchFeatureEnabled(true); | ||
EXPECT_EQ(desktop_search_url_vector, | ||
StartupBrowserCreator::GetURLsFromCommandLine( | ||
command_line, base::FilePath(), &profile)); | ||
|
||
// Preference set to enabled, feature enabled. | ||
profile.GetPrefs()->SetBoolean(prefs::kWindowsDesktopSearchRedirectionPref, | ||
true); | ||
SetWindowsDesktopSearchFeatureEnabled(true); | ||
EXPECT_EQ(default_search_url_vector, | ||
StartupBrowserCreator::GetURLsFromCommandLine( | ||
command_line, base::FilePath(), &profile)); | ||
|
||
// Preference set to enabled, feature disabled. | ||
profile.GetPrefs()->SetBoolean(prefs::kWindowsDesktopSearchRedirectionPref, | ||
true); | ||
SetWindowsDesktopSearchFeatureEnabled(false); | ||
EXPECT_EQ(desktop_search_url_vector, | ||
StartupBrowserCreator::GetURLsFromCommandLine( | ||
command_line, base::FilePath(), &profile)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2015 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef COMPONENTS_SEARCH_ENGINES_DESKTOP_SEARCH_WIN_H_ | ||
#define COMPONENTS_SEARCH_ENGINES_DESKTOP_SEARCH_WIN_H_ | ||
|
||
#include "base/feature_list.h" | ||
#include "base/strings/string16.h" | ||
|
||
class GURL; | ||
class PrefService; | ||
class SearchTermsData; | ||
|
||
namespace user_prefs { | ||
class PrefRegistrySyncable; | ||
} | ||
|
||
namespace prefs { | ||
// Name of the Windows desktop search redirection preference. | ||
extern const char kWindowsDesktopSearchRedirectionPref[]; | ||
} | ||
|
||
// Windows desktop search redirection feature. This is exposed in the header | ||
// file so that it can be referenced from about_flags.cc. | ||
extern const base::Feature kWindowsDesktopSearchRedirectionFeature; | ||
|
||
// Registers the Windows desktop search redirection preference into |registry|. | ||
void RegisterWindowsDesktopSearchRedirectionPref( | ||
user_prefs::PrefRegistrySyncable* registry); | ||
|
||
// Indicates whether Windows desktop searches should be redirected to the | ||
// default search engine. This is only true when both the preference and the | ||
// feature are enabled. The preference value is read from |pref_service|. | ||
bool ShouldRedirectWindowsDesktopSearchToDefaultSearchEngine( | ||
PrefService* pref_service); | ||
|
||
// Detects whether a URL comes from a Windows Desktop search. If so, puts the | ||
// search terms in |search_terms| and returns true. | ||
bool DetectWindowsDesktopSearch(const GURL& url, | ||
const SearchTermsData& search_terms_data, | ||
base::string16* search_terms); | ||
|
||
#endif // COMPONENTS_SEARCH_ENGINES_DESKTOP_SEARCH_WIN_H_ |
Oops, something went wrong.