OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/startup/default_browser_infobar_delegate.h" | 5 #include "chrome/browser/ui/startup/default_browser_infobar_delegate.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/feature_list.h" | |
11 #include "base/macros.h" | 10 #include "base/macros.h" |
12 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
13 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "base/test/scoped_feature_list.h" |
14 #include "chrome/browser/infobars/infobar_service.h" | 14 #include "chrome/browser/infobars/infobar_service.h" |
15 #include "chrome/test/base/testing_profile.h" | 15 #include "chrome/test/base/testing_profile.h" |
16 #include "components/infobars/core/infobar.h" | 16 #include "components/infobars/core/infobar.h" |
17 #include "content/public/test/test_browser_thread_bundle.h" | 17 #include "content/public/test/test_browser_thread_bundle.h" |
18 #include "content/public/test/test_web_contents_factory.h" | 18 #include "content/public/test/test_web_contents_factory.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
20 | 20 |
21 namespace chrome { | 21 namespace chrome { |
22 | 22 |
23 // An implementation of DefaultBrowserWorker that will simply invoke the | 23 // An implementation of DefaultBrowserWorker that will simply invoke the |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 public: | 63 public: |
64 DefaultBrowserInfoBarDelegateTest() | 64 DefaultBrowserInfoBarDelegateTest() |
65 : profile_(new TestingProfile()), | 65 : profile_(new TestingProfile()), |
66 web_contents_(factory_.CreateWebContents(profile_.get())) { | 66 web_contents_(factory_.CreateWebContents(profile_.get())) { |
67 InfoBarService::CreateForWebContents(web_contents_); | 67 InfoBarService::CreateForWebContents(web_contents_); |
68 infobar_service_ = InfoBarService::FromWebContents(web_contents_); | 68 infobar_service_ = InfoBarService::FromWebContents(web_contents_); |
69 } | 69 } |
70 | 70 |
71 protected: | 71 protected: |
72 void EnableStickyDefaultBrowserPrompt() { | 72 void EnableStickyDefaultBrowserPrompt() { |
73 base::FeatureList::ClearInstanceForTesting(); | 73 scoped_feature_list_.InitAndEnableFeature(kStickyDefaultBrowserPrompt); |
74 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | |
75 feature_list->InitializeFromCommandLine(kStickyDefaultBrowserPrompt.name, | |
76 std::string()); | |
77 base::FeatureList::SetInstance(std::move(feature_list)); | |
78 } | 74 } |
79 | 75 |
80 void AddDefaultBrowserInfoBar() { | 76 void AddDefaultBrowserInfoBar() { |
81 infobar_service_->AddInfoBar(infobar_service_->CreateConfirmInfoBar( | 77 infobar_service_->AddInfoBar(infobar_service_->CreateConfirmInfoBar( |
82 base::MakeUnique<FakeDefaultBrowserInfoBarDelegate>())); | 78 base::MakeUnique<FakeDefaultBrowserInfoBarDelegate>())); |
83 } | 79 } |
84 | 80 |
85 InfoBarService* infobar_service() { return infobar_service_; } | 81 InfoBarService* infobar_service() { return infobar_service_; } |
86 | 82 |
87 private: | 83 private: |
88 // The DefaultBrowserWorker requires a FILE thread. Also provides a | 84 // The DefaultBrowserWorker requires a FILE thread. Also provides a |
89 // SingleThreadTaskRunner for the test profile and the default browser prompt. | 85 // SingleThreadTaskRunner for the test profile and the default browser prompt. |
90 content::TestBrowserThreadBundle thread_bundle; | 86 content::TestBrowserThreadBundle thread_bundle; |
91 | 87 |
92 // Required to get an InfoBarService. | 88 // Required to get an InfoBarService. |
93 std::unique_ptr<TestingProfile> profile_; | 89 std::unique_ptr<TestingProfile> profile_; |
94 content::TestWebContentsFactory factory_; | 90 content::TestWebContentsFactory factory_; |
95 content::WebContents* web_contents_; | 91 content::WebContents* web_contents_; |
96 | 92 |
97 // Manages the default browser prompt. | 93 // Manages the default browser prompt. |
98 InfoBarService* infobar_service_; | 94 InfoBarService* infobar_service_; |
99 | 95 |
| 96 base::test::ScopedFeatureList scoped_feature_list_; |
| 97 |
100 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserInfoBarDelegateTest); | 98 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserInfoBarDelegateTest); |
101 }; | 99 }; |
102 | 100 |
103 TEST_F(DefaultBrowserInfoBarDelegateTest, DefaultBehavior) { | 101 TEST_F(DefaultBrowserInfoBarDelegateTest, DefaultBehavior) { |
104 AddDefaultBrowserInfoBar(); | 102 AddDefaultBrowserInfoBar(); |
105 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 103 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
106 | 104 |
107 infobars::InfoBar* default_browser_infobar = infobar_service()->infobar_at(0); | 105 infobars::InfoBar* default_browser_infobar = infobar_service()->infobar_at(0); |
108 ConfirmInfoBarDelegate* default_browser_infobar_delegate = | 106 ConfirmInfoBarDelegate* default_browser_infobar_delegate = |
109 default_browser_infobar->delegate()->AsConfirmInfoBarDelegate(); | 107 default_browser_infobar->delegate()->AsConfirmInfoBarDelegate(); |
(...skipping 29 matching lines...) Expand all Loading... |
139 EXPECT_EQ(1U, infobar_service()->infobar_count()); | 137 EXPECT_EQ(1U, infobar_service()->infobar_count()); |
140 | 138 |
141 // Spin the message loop to allow the FakeDefaultBrowserWorker to complete, | 139 // Spin the message loop to allow the FakeDefaultBrowserWorker to complete, |
142 // which should destroy the infobar. | 140 // which should destroy the infobar. |
143 base::RunLoop().RunUntilIdle(); | 141 base::RunLoop().RunUntilIdle(); |
144 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 142 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
145 } | 143 } |
146 #endif // defined(OS_WIN) | 144 #endif // defined(OS_WIN) |
147 | 145 |
148 } // namespace chrome | 146 } // namespace chrome |
OLD | NEW |