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

Side by Side Diff: chrome/browser/ui/startup/startup_browser_creator_win_unittest.cc

Issue 1598553003: Implement the Windows desktop search redirection feature. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix build errors due to prefs being moved in components Created 4 years, 10 months 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 StartupBrowserCreatorWinTest : public testing::Test {
23 public:
24 StartupBrowserCreatorWinTest() {}
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(StartupBrowserCreatorWinTest);
41 };
42
43 TEST_F(StartupBrowserCreatorWinTest,
44 GetURLsFromCommandLineWithDesktopSearchURL) {
45 const char kDesktopSearchURL[] =
46 "https://www.bing.com/search?q=keyword&form=WNSGPH";
47
48 TestingProfile profile;
49 TemplateURLServiceFactoryTestUtil template_url_service_factory_test_util(
50 &profile);
51
52 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
53 command_line.AppendArg(kDesktopSearchURL);
54
55 // Expected vectors of URLs.
56 const std::vector<GURL> desktop_search_url_vector({GURL(kDesktopSearchURL)});
57 const std::vector<GURL> default_search_url_vector(
58 {GetDefaultSearchURLForSearchTerms(
59 TemplateURLServiceFactory::GetForProfile(&profile), L"keyword")});
60
61 // Preference unset, feature enabled.
62 SetWindowsDesktopSearchFeatureEnabled(true);
63 EXPECT_EQ(desktop_search_url_vector,
64 StartupBrowserCreator::GetURLsFromCommandLine(
65 command_line, base::FilePath(), &profile));
66
67 // Preference set to disabled, feature enabled.
68 profile.GetPrefs()->SetBoolean(prefs::kWindowsDesktopSearchRedirectionPref,
69 false);
70 SetWindowsDesktopSearchFeatureEnabled(true);
71 EXPECT_EQ(desktop_search_url_vector,
72 StartupBrowserCreator::GetURLsFromCommandLine(
73 command_line, base::FilePath(), &profile));
74
75 // Preference set to enabled, feature enabled.
76 profile.GetPrefs()->SetBoolean(prefs::kWindowsDesktopSearchRedirectionPref,
77 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(prefs::kWindowsDesktopSearchRedirectionPref,
85 true);
86 SetWindowsDesktopSearchFeatureEnabled(false);
87 EXPECT_EQ(desktop_search_url_vector,
88 StartupBrowserCreator::GetURLsFromCommandLine(
89 command_line, base::FilePath(), &profile));
90 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/startup/startup_browser_creator_impl.cc ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698