Chromium Code Reviews| 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/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/metrics/histogram_samples.h" | 12 #include "base/metrics/histogram_samples.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/test/scoped_feature_list.h" | 14 #include "base/test/scoped_feature_list.h" |
| 15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 16 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/browser/ui/passwords/manage_passwords_test.h" | 17 #include "chrome/browser/ui/passwords/manage_passwords_test.h" |
| 18 #include "chrome/browser/ui/passwords/passwords_model_delegate.h" | 18 #include "chrome/browser/ui/passwords/passwords_model_delegate.h" |
| 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 20 #include "chrome/browser/ui/views/frame/browser_view.h" | 20 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 21 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_views.h" | 21 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_views.h" |
| 22 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 22 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
| 23 #include "chrome/test/base/interactive_test_utils.h" | 23 #include "chrome/test/base/interactive_test_utils.h" |
| 24 #include "content/public/browser/notification_types.h" | 24 #include "content/public/browser/notification_types.h" |
| 25 #include "content/public/browser/render_view_host.h" | 25 #include "content/public/browser/render_view_host.h" |
| 26 #include "content/public/common/content_features.h" | 26 #include "content/public/common/content_features.h" |
| 27 #include "net/url_request/test_url_fetcher_factory.h" | 27 #include "net/url_request/test_url_fetcher_factory.h" |
| 28 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
| 29 #include "ui/base/ui_base_switches.h" | |
| 30 #include "ui/base/ui_features.h" | |
| 29 #include "ui/views/test/widget_test.h" | 31 #include "ui/views/test/widget_test.h" |
| 30 | 32 |
| 31 using testing::Eq; | 33 using testing::Eq; |
| 32 using testing::Field; | 34 using testing::Field; |
| 33 using testing::_; | 35 using testing::_; |
| 34 | 36 |
| 35 namespace { | 37 namespace { |
| 36 | 38 |
| 37 const char kDisplayDispositionMetric[] = "PasswordBubble.DisplayDisposition"; | 39 const char kDisplayDispositionMetric[] = "PasswordBubble.DisplayDisposition"; |
| 38 | 40 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 56 bool IsBubbleShowing() { | 58 bool IsBubbleShowing() { |
| 57 return ManagePasswordsBubbleView::manage_password_bubble() && | 59 return ManagePasswordsBubbleView::manage_password_bubble() && |
| 58 ManagePasswordsBubbleView::manage_password_bubble()-> | 60 ManagePasswordsBubbleView::manage_password_bubble()-> |
| 59 GetWidget()->IsVisible(); | 61 GetWidget()->IsVisible(); |
| 60 } | 62 } |
| 61 | 63 |
| 62 } // namespace | 64 } // namespace |
| 63 | 65 |
| 64 namespace metrics_util = password_manager::metrics_util; | 66 namespace metrics_util = password_manager::metrics_util; |
| 65 | 67 |
| 66 using ManagePasswordsBubbleViewTest = ManagePasswordsTest; | 68 class ManagePasswordsBubbleViewTest : public ManagePasswordsTest { |
| 69 public: | |
| 70 ManagePasswordsBubbleViewTest() {} | |
| 71 ~ManagePasswordsBubbleViewTest() override {} | |
| 72 | |
| 73 // content::BrowserTestBase: | |
| 74 void SetUpCommandLine(base::CommandLine* command_line) override { | |
| 75 #if defined(OS_MACOSX) | |
| 76 command_line->AppendSwitch(switches::kExtendMdToSecondaryUi); | |
| 77 #endif | |
| 78 } | |
| 79 | |
| 80 private: | |
| 81 DISALLOW_COPY_AND_ASSIGN(ManagePasswordsBubbleViewTest); | |
| 82 }; | |
| 67 | 83 |
| 68 IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, BasicOpenAndClose) { | 84 IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, BasicOpenAndClose) { |
| 85 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | |
|
tapted
2017/04/19 03:31:07
ah, I need to try again on that CL to do this by d
varkha
2017/04/19 08:34:17
Acknowledged.
| |
| 69 EXPECT_FALSE(IsBubbleShowing()); | 86 EXPECT_FALSE(IsBubbleShowing()); |
| 70 SetupPendingPassword(); | 87 SetupPendingPassword(); |
| 71 EXPECT_TRUE(IsBubbleShowing()); | 88 EXPECT_TRUE(IsBubbleShowing()); |
| 72 const ManagePasswordsBubbleView* bubble = | 89 const ManagePasswordsBubbleView* bubble = |
| 73 ManagePasswordsBubbleView::manage_password_bubble(); | 90 ManagePasswordsBubbleView::manage_password_bubble(); |
| 74 EXPECT_TRUE(bubble->initially_focused_view()); | 91 EXPECT_TRUE(bubble->initially_focused_view()); |
| 75 EXPECT_FALSE(bubble->GetFocusManager()->GetFocusedView()); | 92 EXPECT_FALSE(bubble->GetFocusManager()->GetFocusedView()); |
| 76 ManagePasswordsBubbleView::CloseCurrentBubble(); | 93 ManagePasswordsBubbleView::CloseCurrentBubble(); |
| 77 EXPECT_FALSE(IsBubbleShowing()); | 94 EXPECT_FALSE(IsBubbleShowing()); |
| 78 | 95 |
| 79 // And, just for grins, ensure that we can re-open the bubble. | 96 // And, just for grins, ensure that we can re-open the bubble. |
| 80 ManagePasswordsBubbleView::ShowBubble( | 97 ManagePasswordsBubbleView::ShowBubble( |
| 81 browser()->tab_strip_model()->GetActiveWebContents(), | 98 browser()->tab_strip_model()->GetActiveWebContents(), |
| 82 ManagePasswordsBubbleView::USER_GESTURE); | 99 ManagePasswordsBubbleView::USER_GESTURE); |
| 83 EXPECT_TRUE(IsBubbleShowing()); | 100 EXPECT_TRUE(IsBubbleShowing()); |
| 84 bubble = ManagePasswordsBubbleView::manage_password_bubble(); | 101 bubble = ManagePasswordsBubbleView::manage_password_bubble(); |
| 85 EXPECT_TRUE(bubble->initially_focused_view()); | 102 EXPECT_TRUE(bubble->initially_focused_view()); |
| 86 EXPECT_EQ(bubble->initially_focused_view(), | 103 EXPECT_EQ(bubble->initially_focused_view(), |
| 87 bubble->GetFocusManager()->GetFocusedView()); | 104 bubble->GetFocusManager()->GetFocusedView()); |
| 88 ManagePasswordsBubbleView::CloseCurrentBubble(); | 105 ManagePasswordsBubbleView::CloseCurrentBubble(); |
| 89 EXPECT_FALSE(IsBubbleShowing()); | 106 EXPECT_FALSE(IsBubbleShowing()); |
| 90 } | 107 } |
| 91 | 108 |
| 92 // Same as 'BasicOpenAndClose', but use the command rather than the static | 109 // Same as 'BasicOpenAndClose', but use the command rather than the static |
| 93 // method directly. | 110 // method directly. |
| 94 IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, CommandControlsBubble) { | 111 IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, CommandControlsBubble) { |
| 112 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | |
| 95 // The command only works if the icon is visible, so get into management mode. | 113 // The command only works if the icon is visible, so get into management mode. |
| 96 SetupManagingPasswords(); | 114 SetupManagingPasswords(); |
| 97 EXPECT_FALSE(IsBubbleShowing()); | 115 EXPECT_FALSE(IsBubbleShowing()); |
| 98 ExecuteManagePasswordsCommand(); | 116 ExecuteManagePasswordsCommand(); |
| 99 EXPECT_TRUE(IsBubbleShowing()); | 117 EXPECT_TRUE(IsBubbleShowing()); |
| 100 const ManagePasswordsBubbleView* bubble = | 118 const ManagePasswordsBubbleView* bubble = |
| 101 ManagePasswordsBubbleView::manage_password_bubble(); | 119 ManagePasswordsBubbleView::manage_password_bubble(); |
| 102 EXPECT_TRUE(bubble->initially_focused_view()); | 120 EXPECT_TRUE(bubble->initially_focused_view()); |
| 103 EXPECT_EQ(bubble->initially_focused_view(), | 121 EXPECT_EQ(bubble->initially_focused_view(), |
| 104 bubble->GetFocusManager()->GetFocusedView()); | 122 bubble->GetFocusManager()->GetFocusedView()); |
| 105 ManagePasswordsBubbleView::CloseCurrentBubble(); | 123 ManagePasswordsBubbleView::CloseCurrentBubble(); |
| 106 EXPECT_FALSE(IsBubbleShowing()); | 124 EXPECT_FALSE(IsBubbleShowing()); |
| 125 content::RunAllPendingInMessageLoop(); | |
|
tapted
2017/04/19 03:31:06
It's not obvious why adding this was necessary. co
varkha
2017/04/19 08:34:17
Done. Added a comment.
| |
| 107 | 126 |
| 108 // And, just for grins, ensure that we can re-open the bubble. | 127 // And, just for grins, ensure that we can re-open the bubble. |
| 109 ExecuteManagePasswordsCommand(); | 128 ExecuteManagePasswordsCommand(); |
| 110 EXPECT_TRUE(IsBubbleShowing()); | 129 EXPECT_TRUE(IsBubbleShowing()); |
| 111 ManagePasswordsBubbleView::CloseCurrentBubble(); | 130 ManagePasswordsBubbleView::CloseCurrentBubble(); |
| 112 EXPECT_FALSE(IsBubbleShowing()); | 131 EXPECT_FALSE(IsBubbleShowing()); |
| 113 } | 132 } |
| 114 | 133 |
| 115 IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, | 134 IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, |
| 116 CommandExecutionInManagingState) { | 135 CommandExecutionInManagingState) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 samples->GetCount( | 178 samples->GetCount( |
| 160 metrics_util::MANUAL_MANAGE_PASSWORDS)); | 179 metrics_util::MANUAL_MANAGE_PASSWORDS)); |
| 161 } | 180 } |
| 162 | 181 |
| 163 IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, | 182 IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, |
| 164 CommandExecutionInPendingState) { | 183 CommandExecutionInPendingState) { |
| 165 // Open once with pending password: automagical! | 184 // Open once with pending password: automagical! |
| 166 SetupPendingPassword(); | 185 SetupPendingPassword(); |
| 167 EXPECT_TRUE(IsBubbleShowing()); | 186 EXPECT_TRUE(IsBubbleShowing()); |
| 168 ManagePasswordsBubbleView::CloseCurrentBubble(); | 187 ManagePasswordsBubbleView::CloseCurrentBubble(); |
| 188 content::RunAllPendingInMessageLoop(); | |
|
tapted
2017/04/19 03:31:06
(same comment)
varkha
2017/04/19 08:34:17
Done. Added a comment.
| |
| 189 | |
| 169 // This opening should be measured as manual. | 190 // This opening should be measured as manual. |
| 170 ExecuteManagePasswordsCommand(); | 191 ExecuteManagePasswordsCommand(); |
| 171 EXPECT_TRUE(IsBubbleShowing()); | 192 EXPECT_TRUE(IsBubbleShowing()); |
| 172 | 193 |
| 173 std::unique_ptr<base::HistogramSamples> samples( | 194 std::unique_ptr<base::HistogramSamples> samples( |
| 174 GetSamples(kDisplayDispositionMetric)); | 195 GetSamples(kDisplayDispositionMetric)); |
| 175 EXPECT_EQ( | 196 EXPECT_EQ( |
| 176 1, | 197 1, |
| 177 samples->GetCount( | 198 samples->GetCount( |
| 178 metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING)); | 199 metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING)); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 307 } | 328 } |
| 308 | 329 |
| 309 IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, AutoSigninNoFocus) { | 330 IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, AutoSigninNoFocus) { |
| 310 test_form()->origin = GURL("https://example.com"); | 331 test_form()->origin = GURL("https://example.com"); |
| 311 test_form()->display_name = base::ASCIIToUTF16("Peter"); | 332 test_form()->display_name = base::ASCIIToUTF16("Peter"); |
| 312 test_form()->username_value = base::ASCIIToUTF16("pet12@gmail.com"); | 333 test_form()->username_value = base::ASCIIToUTF16("pet12@gmail.com"); |
| 313 std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials; | 334 std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials; |
| 314 local_credentials.push_back( | 335 local_credentials.push_back( |
| 315 base::MakeUnique<autofill::PasswordForm>(*test_form())); | 336 base::MakeUnique<autofill::PasswordForm>(*test_form())); |
| 316 | 337 |
| 317 // Open another window with focus. | 338 // Open another window with focus and wait for it to become active. |
| 318 Browser* focused_window = CreateBrowser(browser()->profile()); | 339 Browser* focused_window = CreateBrowser(browser()->profile()); |
| 319 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(focused_window)); | 340 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(focused_window)); |
| 320 content::RunAllPendingInMessageLoop(); | 341 content::RunAllPendingInMessageLoop(); |
| 321 | 342 |
| 322 gfx::NativeWindow window = browser()->window()->GetNativeWindow(); | 343 ui_test_utils::BrowserActivationWaiter focused_waiter(focused_window); |
| 323 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); | 344 focused_waiter.WaitForActivation(); |
|
tapted
2017/04/19 03:31:07
BringBrowserWindowToFront does exactly this. I don
varkha
2017/04/19 08:34:17
Done.
| |
| 324 ASSERT_NE(nullptr, widget); | |
| 325 | 345 |
| 326 views::test::WidgetActivationWaiter inactive_waiter(widget, false); | |
|
tapted
2017/04/19 03:31:06
Note I don't think this |inactive_waiter| was ever
varkha
2017/04/19 08:34:17
Acknowledged.
| |
| 327 inactive_waiter.Wait(); | |
| 328 ManagePasswordsBubbleView::set_auto_signin_toast_timeout(0); | 346 ManagePasswordsBubbleView::set_auto_signin_toast_timeout(0); |
| 329 SetupAutoSignin(std::move(local_credentials)); | 347 SetupAutoSignin(std::move(local_credentials)); |
| 330 content::RunAllPendingInMessageLoop(); | |
| 331 EXPECT_TRUE(IsBubbleShowing()); | 348 EXPECT_TRUE(IsBubbleShowing()); |
| 332 | 349 |
| 350 // Auto-close of the auto-sign-in dialog is not implemented for a Cocoa | |
| 351 // browser. | |
| 352 #if !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER) | |
| 333 // Bring the first window back. The toast closes by timeout. | 353 // Bring the first window back. The toast closes by timeout. |
| 334 focused_window->window()->Close(); | 354 focused_window->window()->Close(); |
| 335 browser()->window()->Activate(); | 355 browser()->window()->Activate(); |
| 336 content::RunAllPendingInMessageLoop(); | 356 content::RunAllPendingInMessageLoop(); |
| 337 views::test::WidgetActivationWaiter active_waiter(widget, true); | 357 ui_test_utils::BrowserActivationWaiter waiter(browser()); |
| 338 active_waiter.Wait(); | 358 waiter.WaitForActivation(); |
|
tapted
2017/04/19 03:31:06
I think the 5 lines above can just be replaced by
varkha
2017/04/19 08:34:17
Done.
| |
| 359 | |
| 339 EXPECT_FALSE(IsBubbleShowing()); | 360 EXPECT_FALSE(IsBubbleShowing()); |
|
tapted
2017/04/19 03:31:06
Then the comment above the #ifdef can move down he
varkha
2017/04/19 08:34:17
Done.
| |
| 361 #endif | |
| 340 } | 362 } |
| OLD | NEW |