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

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

Issue 1974153002: Add an experiment for the default browser infobar on Windows 10 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Specific include rule for unittests Created 4 years, 6 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 2016 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/default_browser_infobar_delegate.h"
6
7 #include <memory>
8 #include <string>
9
10 #include "base/feature_list.h"
11 #include "base/macros.h"
12 #include "base/memory/ptr_util.h"
13 #include "base/run_loop.h"
14 #include "chrome/browser/ui/views/infobars/confirm_infobar.h"
15 #include "components/infobars/core/confirm_infobar_delegate.h"
16 #include "components/infobars/core/infobar.h"
17 #include "components/infobars/core/infobar_manager.h"
18 #include "content/public/test/test_browser_thread_bundle.h"
19 #include "testing/gtest/include/gtest/gtest.h"
20
21 namespace chrome {
22
23 class FakeDefaultBrowserWorker
24 : public shell_integration::DefaultBrowserWorker {
25 public:
26 FakeDefaultBrowserWorker(
27 const shell_integration::DefaultWebClientWorkerCallback& callback)
28 : shell_integration::DefaultBrowserWorker(callback) {}
29
30 private:
31 ~FakeDefaultBrowserWorker() override = default;
Peter Kasting 2016/06/01 00:21:12 Nit: Is this declaration necessary, or the similar
Patrick Monette 2016/06/01 18:43:48 Removed.
32
33 // Check if Chrome is the default browser.
Peter Kasting 2016/06/01 00:21:12 Nit: These two comments are misleading because the
Patrick Monette 2016/06/01 18:43:48 Done.
Peter Kasting 2016/06/01 19:32:10 New comment added, but these comments not yet remo
Patrick Monette 2016/06/01 22:07:39 My bad.
34 shell_integration::DefaultWebClientState CheckIsDefaultImpl() override {
35 return shell_integration::NOT_DEFAULT;
36 }
37
38 // Set Chrome as the default browser.
39 void SetAsDefaultImpl(const base::Closure& on_finished_callback) override {
40 on_finished_callback.Run();
41 }
42
43 DISALLOW_COPY_AND_ASSIGN(FakeDefaultBrowserWorker);
44 };
45
46 class FakeDefaultBrowserInfoBarDelegate : public DefaultBrowserInfoBarDelegate {
47 public:
48 FakeDefaultBrowserInfoBarDelegate()
49 : DefaultBrowserInfoBarDelegate(nullptr) {}
50
51 ~FakeDefaultBrowserInfoBarDelegate() override = default;
52
53 private:
54 scoped_refptr<shell_integration::DefaultBrowserWorker>
55 CreateDefaultBrowserWorker(
56 const shell_integration::DefaultWebClientWorkerCallback& callback) {
Peter Kasting 2016/06/01 00:21:12 Nit: override
Patrick Monette 2016/06/01 18:43:48 Done.
57 return new FakeDefaultBrowserWorker(callback);
58 }
59
60 DISALLOW_COPY_AND_ASSIGN(FakeDefaultBrowserInfoBarDelegate);
61 };
62
63 class FakeInfoBarManager : public infobars::InfoBarManager {
64 public:
65 FakeInfoBarManager() = default;
66
67 std::unique_ptr<infobars::InfoBar> CreateConfirmInfoBar(
Peter Kasting 2016/06/01 00:21:12 Instead of re-implementing this here, which is wha
Patrick Monette 2016/06/01 18:43:48 Okay this works! I initially didn't want to do tha
68 std::unique_ptr<ConfirmInfoBarDelegate> delegate) override {
69 return base::WrapUnique(new ConfirmInfoBar(std::move(delegate)));
70 }
71
72 private:
73 // infobars::InfoBarManager:
74 int GetActiveEntryID() override { return 0; }
75 void OpenURL(const GURL& url, WindowOpenDisposition disposition) override {}
76
77 DISALLOW_COPY_AND_ASSIGN(FakeInfoBarManager);
78 };
79
80 class DefaultBrowserInfoBarDelegateTest : public ::testing::Test {
81 public:
82 DefaultBrowserInfoBarDelegateTest() = default;
83
84 protected:
85 void EnableStickDefaultBrowserPrompt() {
Peter Kasting 2016/06/01 00:21:12 Nit: Sticky
Patrick Monette 2016/06/01 18:43:48 Done.
86 base::FeatureList::ClearInstanceForTesting();
87 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList);
88 feature_list->InitializeFromCommandLine(kStickyDefaultBrowserPrompt.name,
89 std::string());
90 base::FeatureList::SetInstance(std::move(feature_list));
91 }
92
93 void AddDefaultBrowserInfoBar() {
94 infobar_manager_.AddInfoBar(infobar_manager_.CreateConfirmInfoBar(
95 base::WrapUnique(new FakeDefaultBrowserInfoBarDelegate())));
96 }
97
98 infobars::InfoBarManager& infobar_manager() { return infobar_manager_; }
Peter Kasting 2016/06/01 00:21:12 Nit: We normally avoid APIs that return non-const
Patrick Monette 2016/06/01 18:43:48 Done.
99
100 private:
101 FakeInfoBarManager infobar_manager_;
102
103 // For UI and File thread.
Peter Kasting 2016/06/01 00:21:12 Nit: If this test needs these, expand briefly on w
Patrick Monette 2016/06/01 18:43:48 Done.
104 content::TestBrowserThreadBundle thread_bundle;
105
106 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserInfoBarDelegateTest);
107 };
108
109 TEST_F(DefaultBrowserInfoBarDelegateTest, DefaultBehavior) {
110 AddDefaultBrowserInfoBar();
111 ASSERT_EQ(1U, infobar_manager().infobar_count());
112
113 infobars::InfoBar* default_browser_infobar = infobar_manager().infobar_at(0);
114 ConfirmInfoBarDelegate* default_browser_infobar_delegate =
115 default_browser_infobar->delegate()->AsConfirmInfoBarDelegate();
116
117 // Clicking the button should returns true, which means the infobar should
118 // immediatly be dismissed. Unfortunately, this does not simulate a real click
119 // on the button so the infobar still exist after calling Accept().
Peter Kasting 2016/06/01 00:21:12 This comment is a bit misleading. Accept() knows
Patrick Monette 2016/06/01 18:43:48 Done. I removed the tidbit about the experiment si
Peter Kasting 2016/06/01 19:32:10 The main reason I liked that was that, until I rea
Patrick Monette 2016/06/01 22:07:40 Alright I'll add it then.
120 EXPECT_TRUE(default_browser_infobar_delegate->Accept());
121 }
122
123 #if defined(OS_WIN)
124 TEST_F(DefaultBrowserInfoBarDelegateTest, StickyDefaultBrowserPrompt) {
125 EnableStickDefaultBrowserPrompt();
126
127 // For most Windows versions, this experiment is disabled.
128 if (!IsStickyDefaultBrowserPromptEnabled())
129 return;
130
131 AddDefaultBrowserInfoBar();
132 ASSERT_EQ(1U, infobar_manager().infobar_count());
133
134 infobars::InfoBar* default_browser_infobar = infobar_manager().infobar_at(0);
135 ConfirmInfoBarDelegate* default_browser_infobar_delegate =
136 default_browser_infobar->delegate()->AsConfirmInfoBarDelegate();
137
138 // Clicking the button should returns false, which means the infobar should
139 // not be dismissed immediatly. It will be dismissed after the
140 // DefaultBrowserWorker is done (i.e. after RunUntilIdle()).
Peter Kasting 2016/06/01 00:21:12 Nit: For parallel structure with my above suggesti
Patrick Monette 2016/06/01 18:43:48 Thanks for the suggestion!
141 EXPECT_FALSE(default_browser_infobar_delegate->Accept());
142 ASSERT_EQ(1U, infobar_manager().infobar_count());
Peter Kasting 2016/06/01 00:21:12 Nit: EXPECT
Patrick Monette 2016/06/01 18:43:49 Done.
143
144 base::RunLoop().RunUntilIdle();
145 ASSERT_EQ(0U, infobar_manager().infobar_count());
146 }
147 #endif // defined(OS_WIN)
148
149 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698