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

Side by Side 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: add about_flags.cc entry 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/startup/startup_browser_creator.h"
6
7 #include <vector>
8
9 #include "base/command_line.h"
10 #include "base/feature_list.h"
11 #include "base/macros.h"
12 #include "base/prefs/pref_service.h"
13 #include "chrome/browser/search_engines/template_url_service_factory.h"
14 #include "chrome/browser/search_engines/template_url_service_factory_test_util.h "
15 #include "chrome/test/base/testing_profile.h"
16 #include "components/search_engines/desktop_search_win.h"
17 #include "components/search_engines/util.h"
18 #include "content/public/test/test_browser_thread_bundle.h"
19 #include "testing/gtest/include/gtest/gtest.h"
20 #include "url/gurl.h"
21
22 class StartupBrowserCreatorWinUnitTest : public testing::Test {
Peter Kasting 2015/12/03 05:41:39 Nit: I would probably remove "Unit" from this name
fdoray 2015/12/03 17:16:17 Done.
23 public:
24 StartupBrowserCreatorWinUnitTest() {}
25
26 protected:
27 void SetWindowsDesktopSearchFeatureEnabled(bool enabled) {
28 base::FeatureList::ClearInstanceForTesting();
29 scoped_ptr<base::FeatureList> feature_list(new base::FeatureList);
30 if (enabled) {
31 feature_list->InitializeFromCommandLine(
32 kWindowsDesktopSearchRedirectionFeature.name, std::string());
33 }
34 base::FeatureList::SetInstance(std::move(feature_list));
35 }
36
37 private:
38 content::TestBrowserThreadBundle thread_bundle_;
39
40 DISALLOW_COPY_AND_ASSIGN(StartupBrowserCreatorWinUnitTest);
41 };
42
43 TEST_F(StartupBrowserCreatorWinUnitTest,
44 GetURLsFromCommandLineWithDesktopSearchURL) {
45 const char kWindowsDesktopSearchRedirectionPref[] =
46 "windows_desktop_search_redirection";
47 const char kDesktopSearchURL[] =
48 "https://www.bing.com/search?q=keyword&form=WNSGPH";
49
50 TestingProfile profile;
51 TemplateURLServiceFactoryTestUtil template_url_service_factory_test_util(
52 &profile);
53
54 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
55 command_line.AppendArg(kDesktopSearchURL);
56
57 // Expected vectors of URLs.
58 const std::vector<GURL> desktop_search_url_vector({GURL(kDesktopSearchURL)});
59 const std::vector<GURL> default_search_url_vector(
60 {GetDefaultSearchURLForSearchTerms(
61 TemplateURLServiceFactory::GetForProfile(&profile), L"keyword")});
62
63 // Preference unset, feature enabled.
64 SetWindowsDesktopSearchFeatureEnabled(true);
65 EXPECT_EQ(desktop_search_url_vector,
66 StartupBrowserCreator::GetURLsFromCommandLine(
67 command_line, base::FilePath(), &profile));
68
69 // Preference set to disabled, feature enabled.
70 profile.GetPrefs()->SetBoolean(kWindowsDesktopSearchRedirectionPref, false);
71 SetWindowsDesktopSearchFeatureEnabled(true);
72 EXPECT_EQ(desktop_search_url_vector,
73 StartupBrowserCreator::GetURLsFromCommandLine(
74 command_line, base::FilePath(), &profile));
75
76 // Preference set to enabled, feature enabled.
77 profile.GetPrefs()->SetBoolean(kWindowsDesktopSearchRedirectionPref, true);
78 SetWindowsDesktopSearchFeatureEnabled(true);
79 EXPECT_EQ(default_search_url_vector,
80 StartupBrowserCreator::GetURLsFromCommandLine(
81 command_line, base::FilePath(), &profile));
82
83 // Preference set to enabled, feature disabled.
84 profile.GetPrefs()->SetBoolean(kWindowsDesktopSearchRedirectionPref, true);
85 SetWindowsDesktopSearchFeatureEnabled(false);
86 EXPECT_EQ(desktop_search_url_vector,
87 StartupBrowserCreator::GetURLsFromCommandLine(
88 command_line, base::FilePath(), &profile));
89 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698