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/tab_dialogs.h" | |
| 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 20 #include "chrome/browser/ui/views/frame/browser_view.h" | 21 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 21 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_views.h" | 22 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_views.h" |
| 22 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 23 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
| 23 #include "chrome/test/base/interactive_test_utils.h" | 24 #include "chrome/test/base/interactive_test_utils.h" |
| 24 #include "content/public/browser/notification_types.h" | 25 #include "content/public/browser/notification_types.h" |
| 25 #include "content/public/browser/render_view_host.h" | 26 #include "content/public/browser/render_view_host.h" |
| 26 #include "content/public/common/content_features.h" | 27 #include "content/public/common/content_features.h" |
| 27 #include "net/url_request/test_url_fetcher_factory.h" | 28 #include "net/url_request/test_url_fetcher_factory.h" |
| 28 #include "testing/gmock/include/gmock/gmock.h" | 29 #include "testing/gmock/include/gmock/gmock.h" |
| 30 #include "ui/base/ui_base_switches.h" | |
| 31 #include "ui/base/ui_features.h" | |
| 29 #include "ui/views/test/widget_test.h" | 32 #include "ui/views/test/widget_test.h" |
|
msw
2017/04/19 18:23:17
nit: remove if no longer needed
varkha
2017/04/20 04:14:20
Done.
| |
| 30 | 33 |
| 31 using testing::Eq; | 34 using testing::Eq; |
| 32 using testing::Field; | 35 using testing::Field; |
| 33 using testing::_; | 36 using testing::_; |
| 34 | 37 |
| 35 namespace { | 38 namespace { |
| 36 | 39 |
| 37 const char kDisplayDispositionMetric[] = "PasswordBubble.DisplayDisposition"; | 40 const char kDisplayDispositionMetric[] = "PasswordBubble.DisplayDisposition"; |
| 38 | 41 |
| 39 // A helper class that will create FakeURLFetcher and record the requested URLs. | 42 // A helper class that will create FakeURLFetcher and record the requested URLs. |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 56 bool IsBubbleShowing() { | 59 bool IsBubbleShowing() { |
| 57 return ManagePasswordsBubbleView::manage_password_bubble() && | 60 return ManagePasswordsBubbleView::manage_password_bubble() && |
| 58 ManagePasswordsBubbleView::manage_password_bubble()-> | 61 ManagePasswordsBubbleView::manage_password_bubble()-> |
| 59 GetWidget()->IsVisible(); | 62 GetWidget()->IsVisible(); |
| 60 } | 63 } |
| 61 | 64 |
| 62 } // namespace | 65 } // namespace |
| 63 | 66 |
| 64 namespace metrics_util = password_manager::metrics_util; | 67 namespace metrics_util = password_manager::metrics_util; |
| 65 | 68 |
| 66 using ManagePasswordsBubbleViewTest = ManagePasswordsTest; | 69 class ManagePasswordsBubbleViewTest : public ManagePasswordsTest { |
| 70 public: | |
| 71 ManagePasswordsBubbleViewTest() {} | |
| 72 ~ManagePasswordsBubbleViewTest() override {} | |
| 73 | |
| 74 // content::BrowserTestBase: | |
| 75 void SetUpCommandLine(base::CommandLine* command_line) override { | |
| 76 #if defined(OS_MACOSX) | |
| 77 command_line->AppendSwitch(switches::kExtendMdToSecondaryUi); | |
| 78 #endif | |
| 79 } | |
| 80 | |
| 81 private: | |
| 82 DISALLOW_COPY_AND_ASSIGN(ManagePasswordsBubbleViewTest); | |
| 83 }; | |
| 67 | 84 |
| 68 IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, BasicOpenAndClose) { | 85 IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, BasicOpenAndClose) { |
| 86 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | |
| 69 EXPECT_FALSE(IsBubbleShowing()); | 87 EXPECT_FALSE(IsBubbleShowing()); |
| 70 SetupPendingPassword(); | 88 SetupPendingPassword(); |
| 71 EXPECT_TRUE(IsBubbleShowing()); | 89 EXPECT_TRUE(IsBubbleShowing()); |
| 72 const ManagePasswordsBubbleView* bubble = | 90 const ManagePasswordsBubbleView* bubble = |
| 73 ManagePasswordsBubbleView::manage_password_bubble(); | 91 ManagePasswordsBubbleView::manage_password_bubble(); |
| 74 EXPECT_TRUE(bubble->initially_focused_view()); | 92 EXPECT_TRUE(bubble->initially_focused_view()); |
| 75 EXPECT_FALSE(bubble->GetFocusManager()->GetFocusedView()); | 93 EXPECT_FALSE(bubble->GetFocusManager()->GetFocusedView()); |
| 76 ManagePasswordsBubbleView::CloseCurrentBubble(); | 94 ManagePasswordsBubbleView::CloseCurrentBubble(); |
| 77 EXPECT_FALSE(IsBubbleShowing()); | 95 EXPECT_FALSE(IsBubbleShowing()); |
| 96 // Drain message pump to ensure the bubble view is cleared so that it can be | |
| 97 // created again (it is checked on Mac to prevent re-opening the bubble when | |
| 98 // clicking the location bar button repeatedly). | |
| 99 content::RunAllPendingInMessageLoop(); | |
| 78 | 100 |
| 79 // And, just for grins, ensure that we can re-open the bubble. | 101 // And, just for grins, ensure that we can re-open the bubble. |
| 80 ManagePasswordsBubbleView::ShowBubble( | 102 TabDialogs::FromWebContents( |
| 81 browser()->tab_strip_model()->GetActiveWebContents(), | 103 browser()->tab_strip_model()->GetActiveWebContents()) |
| 82 ManagePasswordsBubbleView::USER_GESTURE); | 104 ->ShowManagePasswordsBubble(true /* user_action */); |
| 83 EXPECT_TRUE(IsBubbleShowing()); | 105 EXPECT_TRUE(IsBubbleShowing()); |
| 84 bubble = ManagePasswordsBubbleView::manage_password_bubble(); | 106 bubble = ManagePasswordsBubbleView::manage_password_bubble(); |
| 85 EXPECT_TRUE(bubble->initially_focused_view()); | 107 EXPECT_TRUE(bubble->initially_focused_view()); |
| 86 EXPECT_EQ(bubble->initially_focused_view(), | 108 EXPECT_EQ(bubble->initially_focused_view(), |
| 87 bubble->GetFocusManager()->GetFocusedView()); | 109 bubble->GetFocusManager()->GetFocusedView()); |
| 88 ManagePasswordsBubbleView::CloseCurrentBubble(); | 110 ManagePasswordsBubbleView::CloseCurrentBubble(); |
| 89 EXPECT_FALSE(IsBubbleShowing()); | 111 EXPECT_FALSE(IsBubbleShowing()); |
| 90 } | 112 } |
| 91 | 113 |
| 92 // Same as 'BasicOpenAndClose', but use the command rather than the static | 114 // Same as 'BasicOpenAndClose', but use the command rather than the static |
| 93 // method directly. | 115 // method directly. |
| 94 IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, CommandControlsBubble) { | 116 IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, CommandControlsBubble) { |
| 117 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | |
| 95 // The command only works if the icon is visible, so get into management mode. | 118 // The command only works if the icon is visible, so get into management mode. |
| 96 SetupManagingPasswords(); | 119 SetupManagingPasswords(); |
| 97 EXPECT_FALSE(IsBubbleShowing()); | 120 EXPECT_FALSE(IsBubbleShowing()); |
| 98 ExecuteManagePasswordsCommand(); | 121 ExecuteManagePasswordsCommand(); |
| 99 EXPECT_TRUE(IsBubbleShowing()); | 122 EXPECT_TRUE(IsBubbleShowing()); |
| 100 const ManagePasswordsBubbleView* bubble = | 123 const ManagePasswordsBubbleView* bubble = |
| 101 ManagePasswordsBubbleView::manage_password_bubble(); | 124 ManagePasswordsBubbleView::manage_password_bubble(); |
| 102 EXPECT_TRUE(bubble->initially_focused_view()); | 125 EXPECT_TRUE(bubble->initially_focused_view()); |
| 103 EXPECT_EQ(bubble->initially_focused_view(), | 126 EXPECT_EQ(bubble->initially_focused_view(), |
| 104 bubble->GetFocusManager()->GetFocusedView()); | 127 bubble->GetFocusManager()->GetFocusedView()); |
| 105 ManagePasswordsBubbleView::CloseCurrentBubble(); | 128 ManagePasswordsBubbleView::CloseCurrentBubble(); |
| 106 EXPECT_FALSE(IsBubbleShowing()); | 129 EXPECT_FALSE(IsBubbleShowing()); |
| 130 // Drain message pump to ensure the bubble view is cleared so that it can be | |
| 131 // created again (it is checked on Mac to prevent re-opening the bubble when | |
| 132 // clicking the location bar button repeatedly). | |
| 133 content::RunAllPendingInMessageLoop(); | |
| 107 | 134 |
| 108 // And, just for grins, ensure that we can re-open the bubble. | 135 // And, just for grins, ensure that we can re-open the bubble. |
| 109 ExecuteManagePasswordsCommand(); | 136 ExecuteManagePasswordsCommand(); |
| 110 EXPECT_TRUE(IsBubbleShowing()); | 137 EXPECT_TRUE(IsBubbleShowing()); |
| 111 ManagePasswordsBubbleView::CloseCurrentBubble(); | 138 ManagePasswordsBubbleView::CloseCurrentBubble(); |
| 112 EXPECT_FALSE(IsBubbleShowing()); | 139 EXPECT_FALSE(IsBubbleShowing()); |
| 113 } | 140 } |
| 114 | 141 |
| 115 IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, | 142 IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, |
| 116 CommandExecutionInManagingState) { | 143 CommandExecutionInManagingState) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 samples->GetCount( | 186 samples->GetCount( |
| 160 metrics_util::MANUAL_MANAGE_PASSWORDS)); | 187 metrics_util::MANUAL_MANAGE_PASSWORDS)); |
| 161 } | 188 } |
| 162 | 189 |
| 163 IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, | 190 IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, |
| 164 CommandExecutionInPendingState) { | 191 CommandExecutionInPendingState) { |
| 165 // Open once with pending password: automagical! | 192 // Open once with pending password: automagical! |
| 166 SetupPendingPassword(); | 193 SetupPendingPassword(); |
| 167 EXPECT_TRUE(IsBubbleShowing()); | 194 EXPECT_TRUE(IsBubbleShowing()); |
| 168 ManagePasswordsBubbleView::CloseCurrentBubble(); | 195 ManagePasswordsBubbleView::CloseCurrentBubble(); |
| 196 // Drain message pump to ensure the bubble view is cleared so that it can be | |
| 197 // created again (it is checked on Mac to prevent re-opening the bubble when | |
| 198 // clicking the location bar button repeatedly). | |
| 199 content::RunAllPendingInMessageLoop(); | |
| 200 | |
| 169 // This opening should be measured as manual. | 201 // This opening should be measured as manual. |
| 170 ExecuteManagePasswordsCommand(); | 202 ExecuteManagePasswordsCommand(); |
| 171 EXPECT_TRUE(IsBubbleShowing()); | 203 EXPECT_TRUE(IsBubbleShowing()); |
| 172 | 204 |
| 173 std::unique_ptr<base::HistogramSamples> samples( | 205 std::unique_ptr<base::HistogramSamples> samples( |
| 174 GetSamples(kDisplayDispositionMetric)); | 206 GetSamples(kDisplayDispositionMetric)); |
| 175 EXPECT_EQ( | 207 EXPECT_EQ( |
| 176 1, | 208 1, |
| 177 samples->GetCount( | 209 samples->GetCount( |
| 178 metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING)); | 210 metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING)); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 310 test_form()->origin = GURL("https://example.com"); | 342 test_form()->origin = GURL("https://example.com"); |
| 311 test_form()->display_name = base::ASCIIToUTF16("Peter"); | 343 test_form()->display_name = base::ASCIIToUTF16("Peter"); |
| 312 test_form()->username_value = base::ASCIIToUTF16("pet12@gmail.com"); | 344 test_form()->username_value = base::ASCIIToUTF16("pet12@gmail.com"); |
| 313 std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials; | 345 std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials; |
| 314 local_credentials.push_back( | 346 local_credentials.push_back( |
| 315 base::MakeUnique<autofill::PasswordForm>(*test_form())); | 347 base::MakeUnique<autofill::PasswordForm>(*test_form())); |
| 316 | 348 |
| 317 // Open another window with focus. | 349 // Open another window with focus. |
| 318 Browser* focused_window = CreateBrowser(browser()->profile()); | 350 Browser* focused_window = CreateBrowser(browser()->profile()); |
| 319 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(focused_window)); | 351 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(focused_window)); |
| 320 content::RunAllPendingInMessageLoop(); | |
| 321 | 352 |
| 322 gfx::NativeWindow window = browser()->window()->GetNativeWindow(); | |
| 323 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); | |
| 324 ASSERT_NE(nullptr, widget); | |
| 325 | |
| 326 views::test::WidgetActivationWaiter inactive_waiter(widget, false); | |
| 327 inactive_waiter.Wait(); | |
| 328 ManagePasswordsBubbleView::set_auto_signin_toast_timeout(0); | 353 ManagePasswordsBubbleView::set_auto_signin_toast_timeout(0); |
| 329 SetupAutoSignin(std::move(local_credentials)); | 354 SetupAutoSignin(std::move(local_credentials)); |
| 330 content::RunAllPendingInMessageLoop(); | |
| 331 EXPECT_TRUE(IsBubbleShowing()); | 355 EXPECT_TRUE(IsBubbleShowing()); |
| 332 | 356 |
| 333 // Bring the first window back. The toast closes by timeout. | 357 // Bring the first window back. The toast closes by timeout. |
| 334 focused_window->window()->Close(); | 358 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 335 browser()->window()->Activate(); | |
| 336 content::RunAllPendingInMessageLoop(); | 359 content::RunAllPendingInMessageLoop(); |
| 337 views::test::WidgetActivationWaiter active_waiter(widget, true); | 360 |
| 338 active_waiter.Wait(); | 361 // Auto-close of the auto-sign-in dialog is not implemented for a Cocoa |
|
msw
2017/04/19 18:23:17
ditto: should it be implemented or is not auto-clo
varkha
2017/04/20 04:14:20
Done.
| |
| 362 // browser. | |
| 363 #if !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER) | |
| 339 EXPECT_FALSE(IsBubbleShowing()); | 364 EXPECT_FALSE(IsBubbleShowing()); |
| 365 #else | |
| 366 EXPECT_TRUE(IsBubbleShowing()); | |
| 367 #endif | |
| 340 } | 368 } |
| OLD | NEW |