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

Unified Diff: chrome/browser/ui/startup/startup_browser_creator_win_unittest.cc

Issue 1477783004: Add a preference to control Windows desktop search redirection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix compile error. Created 5 years 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
« no previous file with comments | « chrome/browser/ui/startup/startup_browser_creator.cc ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/startup/startup_browser_creator_win_unittest.cc
diff --git a/chrome/browser/ui/startup/startup_browser_creator_win_unittest.cc b/chrome/browser/ui/startup/startup_browser_creator_win_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2dcf6564ce7b441a8468a84346d4669bc4da40cc
--- /dev/null
+++ b/chrome/browser/ui/startup/startup_browser_creator_win_unittest.cc
@@ -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));
+}
« no previous file with comments | « chrome/browser/ui/startup/startup_browser_creator.cc ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698