OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/views/passwords/manage_passwords_bubble_view.h" | 5 #include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/feature_list.h" | 10 #include "base/feature_list.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 using testing::Field; | 31 using testing::Field; |
32 using testing::_; | 32 using testing::_; |
33 | 33 |
34 namespace { | 34 namespace { |
35 | 35 |
36 const char kDisplayDispositionMetric[] = "PasswordBubble.DisplayDisposition"; | 36 const char kDisplayDispositionMetric[] = "PasswordBubble.DisplayDisposition"; |
37 | 37 |
38 // A helper class that will create FakeURLFetcher and record the requested URLs. | 38 // A helper class that will create FakeURLFetcher and record the requested URLs. |
39 class TestURLFetcherCallback { | 39 class TestURLFetcherCallback { |
40 public: | 40 public: |
41 scoped_ptr<net::FakeURLFetcher> CreateURLFetcher( | 41 std::unique_ptr<net::FakeURLFetcher> CreateURLFetcher( |
42 const GURL& url, | 42 const GURL& url, |
43 net::URLFetcherDelegate* d, | 43 net::URLFetcherDelegate* d, |
44 const std::string& response_data, | 44 const std::string& response_data, |
45 net::HttpStatusCode response_code, | 45 net::HttpStatusCode response_code, |
46 net::URLRequestStatus::Status status) { | 46 net::URLRequestStatus::Status status) { |
47 OnRequestDone(url); | 47 OnRequestDone(url); |
48 return scoped_ptr<net::FakeURLFetcher>(new net::FakeURLFetcher( | 48 return std::unique_ptr<net::FakeURLFetcher>( |
49 url, d, response_data, response_code, status)); | 49 new net::FakeURLFetcher(url, d, response_data, response_code, status)); |
50 } | 50 } |
51 | 51 |
52 MOCK_METHOD1(OnRequestDone, void(const GURL&)); | 52 MOCK_METHOD1(OnRequestDone, void(const GURL&)); |
53 }; | 53 }; |
54 | 54 |
55 bool IsBubbleShowing() { | 55 bool IsBubbleShowing() { |
56 return ManagePasswordsBubbleView::manage_password_bubble() && | 56 return ManagePasswordsBubbleView::manage_password_bubble() && |
57 ManagePasswordsBubbleView::manage_password_bubble()-> | 57 ManagePasswordsBubbleView::manage_password_bubble()-> |
58 GetWidget()->IsVisible(); | 58 GetWidget()->IsVisible(); |
59 } | 59 } |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 EXPECT_FALSE(IsBubbleShowing()); | 125 EXPECT_FALSE(IsBubbleShowing()); |
126 } | 126 } |
127 | 127 |
128 IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, | 128 IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, |
129 CommandExecutionInManagingState) { | 129 CommandExecutionInManagingState) { |
130 SetupManagingPasswords(); | 130 SetupManagingPasswords(); |
131 EXPECT_FALSE(IsBubbleShowing()); | 131 EXPECT_FALSE(IsBubbleShowing()); |
132 ExecuteManagePasswordsCommand(); | 132 ExecuteManagePasswordsCommand(); |
133 EXPECT_TRUE(IsBubbleShowing()); | 133 EXPECT_TRUE(IsBubbleShowing()); |
134 | 134 |
135 scoped_ptr<base::HistogramSamples> samples( | 135 std::unique_ptr<base::HistogramSamples> samples( |
136 GetSamples(kDisplayDispositionMetric)); | 136 GetSamples(kDisplayDispositionMetric)); |
137 EXPECT_EQ( | 137 EXPECT_EQ( |
138 0, | 138 0, |
139 samples->GetCount( | 139 samples->GetCount( |
140 metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING)); | 140 metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING)); |
141 EXPECT_EQ(0, | 141 EXPECT_EQ(0, |
142 samples->GetCount( | 142 samples->GetCount( |
143 metrics_util::MANUAL_WITH_PASSWORD_PENDING)); | 143 metrics_util::MANUAL_WITH_PASSWORD_PENDING)); |
144 EXPECT_EQ(1, | 144 EXPECT_EQ(1, |
145 samples->GetCount( | 145 samples->GetCount( |
146 metrics_util::MANUAL_MANAGE_PASSWORDS)); | 146 metrics_util::MANUAL_MANAGE_PASSWORDS)); |
147 } | 147 } |
148 | 148 |
149 IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, | 149 IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, |
150 CommandExecutionInAutomaticState) { | 150 CommandExecutionInAutomaticState) { |
151 // Open with pending password: automagical! | 151 // Open with pending password: automagical! |
152 SetupPendingPassword(); | 152 SetupPendingPassword(); |
153 EXPECT_TRUE(IsBubbleShowing()); | 153 EXPECT_TRUE(IsBubbleShowing()); |
154 | 154 |
155 // Bubble should not be focused by default. | 155 // Bubble should not be focused by default. |
156 EXPECT_FALSE(ManagePasswordsBubbleView::manage_password_bubble()-> | 156 EXPECT_FALSE(ManagePasswordsBubbleView::manage_password_bubble()-> |
157 GetFocusManager()->GetFocusedView()); | 157 GetFocusManager()->GetFocusedView()); |
158 // Bubble can be active if user clicks it. | 158 // Bubble can be active if user clicks it. |
159 EXPECT_TRUE(ManagePasswordsBubbleView::manage_password_bubble()-> | 159 EXPECT_TRUE(ManagePasswordsBubbleView::manage_password_bubble()-> |
160 CanActivate()); | 160 CanActivate()); |
161 | 161 |
162 scoped_ptr<base::HistogramSamples> samples( | 162 std::unique_ptr<base::HistogramSamples> samples( |
163 GetSamples(kDisplayDispositionMetric)); | 163 GetSamples(kDisplayDispositionMetric)); |
164 EXPECT_EQ( | 164 EXPECT_EQ( |
165 1, | 165 1, |
166 samples->GetCount( | 166 samples->GetCount( |
167 metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING)); | 167 metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING)); |
168 EXPECT_EQ(0, | 168 EXPECT_EQ(0, |
169 samples->GetCount( | 169 samples->GetCount( |
170 metrics_util::MANUAL_WITH_PASSWORD_PENDING)); | 170 metrics_util::MANUAL_WITH_PASSWORD_PENDING)); |
171 EXPECT_EQ(0, | 171 EXPECT_EQ(0, |
172 samples->GetCount( | 172 samples->GetCount( |
173 metrics_util::MANUAL_MANAGE_PASSWORDS)); | 173 metrics_util::MANUAL_MANAGE_PASSWORDS)); |
174 } | 174 } |
175 | 175 |
176 IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, | 176 IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, |
177 CommandExecutionInPendingState) { | 177 CommandExecutionInPendingState) { |
178 // Open once with pending password: automagical! | 178 // Open once with pending password: automagical! |
179 SetupPendingPassword(); | 179 SetupPendingPassword(); |
180 EXPECT_TRUE(IsBubbleShowing()); | 180 EXPECT_TRUE(IsBubbleShowing()); |
181 ManagePasswordsBubbleView::CloseCurrentBubble(); | 181 ManagePasswordsBubbleView::CloseCurrentBubble(); |
182 // This opening should be measured as manual. | 182 // This opening should be measured as manual. |
183 ExecuteManagePasswordsCommand(); | 183 ExecuteManagePasswordsCommand(); |
184 EXPECT_TRUE(IsBubbleShowing()); | 184 EXPECT_TRUE(IsBubbleShowing()); |
185 | 185 |
186 scoped_ptr<base::HistogramSamples> samples( | 186 std::unique_ptr<base::HistogramSamples> samples( |
187 GetSamples(kDisplayDispositionMetric)); | 187 GetSamples(kDisplayDispositionMetric)); |
188 EXPECT_EQ( | 188 EXPECT_EQ( |
189 1, | 189 1, |
190 samples->GetCount( | 190 samples->GetCount( |
191 metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING)); | 191 metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING)); |
192 EXPECT_EQ(1, | 192 EXPECT_EQ(1, |
193 samples->GetCount( | 193 samples->GetCount( |
194 metrics_util::MANUAL_WITH_PASSWORD_PENDING)); | 194 metrics_util::MANUAL_WITH_PASSWORD_PENDING)); |
195 EXPECT_EQ(0, | 195 EXPECT_EQ(0, |
196 samples->GetCount( | 196 samples->GetCount( |
197 metrics_util::MANUAL_MANAGE_PASSWORDS)); | 197 metrics_util::MANUAL_MANAGE_PASSWORDS)); |
198 } | 198 } |
199 | 199 |
200 IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, | 200 IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, |
201 CommandExecutionInAutomaticSaveState) { | 201 CommandExecutionInAutomaticSaveState) { |
202 SetupAutomaticPassword(); | 202 SetupAutomaticPassword(); |
203 EXPECT_TRUE(IsBubbleShowing()); | 203 EXPECT_TRUE(IsBubbleShowing()); |
204 ManagePasswordsBubbleView::CloseCurrentBubble(); | 204 ManagePasswordsBubbleView::CloseCurrentBubble(); |
205 content::RunAllPendingInMessageLoop(); | 205 content::RunAllPendingInMessageLoop(); |
206 // Re-opening should count as manual. | 206 // Re-opening should count as manual. |
207 ExecuteManagePasswordsCommand(); | 207 ExecuteManagePasswordsCommand(); |
208 EXPECT_TRUE(IsBubbleShowing()); | 208 EXPECT_TRUE(IsBubbleShowing()); |
209 | 209 |
210 scoped_ptr<base::HistogramSamples> samples( | 210 std::unique_ptr<base::HistogramSamples> samples( |
211 GetSamples(kDisplayDispositionMetric)); | 211 GetSamples(kDisplayDispositionMetric)); |
212 EXPECT_EQ( | 212 EXPECT_EQ( |
213 1, | 213 1, |
214 samples->GetCount( | 214 samples->GetCount( |
215 metrics_util::AUTOMATIC_GENERATED_PASSWORD_CONFIRMATION)); | 215 metrics_util::AUTOMATIC_GENERATED_PASSWORD_CONFIRMATION)); |
216 EXPECT_EQ(0, | 216 EXPECT_EQ(0, |
217 samples->GetCount( | 217 samples->GetCount( |
218 metrics_util::MANUAL_WITH_PASSWORD_PENDING)); | 218 metrics_util::MANUAL_WITH_PASSWORD_PENDING)); |
219 EXPECT_EQ(1, | 219 EXPECT_EQ(1, |
220 samples->GetCount( | 220 samples->GetCount( |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 EXPECT_EQ(1, tab_model->active_index()); | 277 EXPECT_EQ(1, tab_model->active_index()); |
278 SetupPendingPassword(); | 278 SetupPendingPassword(); |
279 EXPECT_TRUE(IsBubbleShowing()); | 279 EXPECT_TRUE(IsBubbleShowing()); |
280 // Back to the first tab. | 280 // Back to the first tab. |
281 tab_model->ActivateTabAt(0, true); | 281 tab_model->ActivateTabAt(0, true); |
282 EXPECT_FALSE(IsBubbleShowing()); | 282 EXPECT_FALSE(IsBubbleShowing()); |
283 } | 283 } |
284 | 284 |
285 IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, AutoSignin) { | 285 IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, AutoSignin) { |
286 base::FeatureList::ClearInstanceForTesting(); | 286 base::FeatureList::ClearInstanceForTesting(); |
287 scoped_ptr<base::FeatureList> feature_list(new base::FeatureList); | 287 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
288 feature_list->InitializeFromCommandLine( | 288 feature_list->InitializeFromCommandLine( |
289 features::kCredentialManagementAPI.name, std::string()); | 289 features::kCredentialManagementAPI.name, std::string()); |
290 base::FeatureList::SetInstance(std::move(feature_list)); | 290 base::FeatureList::SetInstance(std::move(feature_list)); |
291 ASSERT_TRUE(base::FeatureList::IsEnabled(features::kCredentialManagementAPI)); | 291 ASSERT_TRUE(base::FeatureList::IsEnabled(features::kCredentialManagementAPI)); |
292 | 292 |
293 ScopedVector<autofill::PasswordForm> local_credentials; | 293 ScopedVector<autofill::PasswordForm> local_credentials; |
294 test_form()->origin = GURL("https://example.com"); | 294 test_form()->origin = GURL("https://example.com"); |
295 test_form()->display_name = base::ASCIIToUTF16("Peter"); | 295 test_form()->display_name = base::ASCIIToUTF16("Peter"); |
296 test_form()->username_value = base::ASCIIToUTF16("pet12@gmail.com"); | 296 test_form()->username_value = base::ASCIIToUTF16("pet12@gmail.com"); |
297 GURL icon_url("https://google.com/icon.png"); | 297 GURL icon_url("https://google.com/icon.png"); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 content::RunAllPendingInMessageLoop(); | 338 content::RunAllPendingInMessageLoop(); |
339 EXPECT_TRUE(IsBubbleShowing()); | 339 EXPECT_TRUE(IsBubbleShowing()); |
340 | 340 |
341 // Bring the first window back. The toast closes by timeout. | 341 // Bring the first window back. The toast closes by timeout. |
342 focused_window->window()->Close(); | 342 focused_window->window()->Close(); |
343 browser()->window()->Activate(); | 343 browser()->window()->Activate(); |
344 content::RunAllPendingInMessageLoop(); | 344 content::RunAllPendingInMessageLoop(); |
345 EXPECT_TRUE(browser()->window()->IsActive()); | 345 EXPECT_TRUE(browser()->window()->IsActive()); |
346 EXPECT_FALSE(IsBubbleShowing()); | 346 EXPECT_FALSE(IsBubbleShowing()); |
347 } | 347 } |
OLD | NEW |