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" |
29 #include "ui/views/test/widget_test.h" | 30 #include "ui/base/ui_base_switches.h" |
31 #include "ui/base/ui_features.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 |
39 // A helper class that will create FakeURLFetcher and record the requested URLs. | 41 // A helper class that will create FakeURLFetcher and record the requested URLs. |
(...skipping 16 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())); | |
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()); |
95 // Drain message pump to ensure the bubble view is cleared so that it can be | |
96 // created again (it is checked on Mac to prevent re-opening the bubble when | |
97 // clicking the location bar button repeatedly). | |
98 content::RunAllPendingInMessageLoop(); | |
78 | 99 |
79 // And, just for grins, ensure that we can re-open the bubble. | 100 // And, just for grins, ensure that we can re-open the bubble. |
80 ManagePasswordsBubbleView::ShowBubble( | 101 TabDialogs::FromWebContents( |
81 browser()->tab_strip_model()->GetActiveWebContents(), | 102 browser()->tab_strip_model()->GetActiveWebContents()) |
82 ManagePasswordsBubbleView::USER_GESTURE); | 103 ->ShowManagePasswordsBubble(true /* user_action */); |
83 EXPECT_TRUE(IsBubbleShowing()); | 104 EXPECT_TRUE(IsBubbleShowing()); |
84 bubble = ManagePasswordsBubbleView::manage_password_bubble(); | 105 bubble = ManagePasswordsBubbleView::manage_password_bubble(); |
85 EXPECT_TRUE(bubble->initially_focused_view()); | 106 EXPECT_TRUE(bubble->initially_focused_view()); |
86 EXPECT_EQ(bubble->initially_focused_view(), | 107 EXPECT_EQ(bubble->initially_focused_view(), |
87 bubble->GetFocusManager()->GetFocusedView()); | 108 bubble->GetFocusManager()->GetFocusedView()); |
88 ManagePasswordsBubbleView::CloseCurrentBubble(); | 109 ManagePasswordsBubbleView::CloseCurrentBubble(); |
89 EXPECT_FALSE(IsBubbleShowing()); | 110 EXPECT_FALSE(IsBubbleShowing()); |
90 } | 111 } |
91 | 112 |
92 // Same as 'BasicOpenAndClose', but use the command rather than the static | 113 // Same as 'BasicOpenAndClose', but use the command rather than the static |
93 // method directly. | 114 // method directly. |
94 IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, CommandControlsBubble) { | 115 IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, CommandControlsBubble) { |
116 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | |
95 // The command only works if the icon is visible, so get into management mode. | 117 // The command only works if the icon is visible, so get into management mode. |
96 SetupManagingPasswords(); | 118 SetupManagingPasswords(); |
97 EXPECT_FALSE(IsBubbleShowing()); | 119 EXPECT_FALSE(IsBubbleShowing()); |
98 ExecuteManagePasswordsCommand(); | 120 ExecuteManagePasswordsCommand(); |
99 EXPECT_TRUE(IsBubbleShowing()); | 121 EXPECT_TRUE(IsBubbleShowing()); |
100 const ManagePasswordsBubbleView* bubble = | 122 const ManagePasswordsBubbleView* bubble = |
101 ManagePasswordsBubbleView::manage_password_bubble(); | 123 ManagePasswordsBubbleView::manage_password_bubble(); |
102 EXPECT_TRUE(bubble->initially_focused_view()); | 124 EXPECT_TRUE(bubble->initially_focused_view()); |
103 EXPECT_EQ(bubble->initially_focused_view(), | 125 EXPECT_EQ(bubble->initially_focused_view(), |
104 bubble->GetFocusManager()->GetFocusedView()); | 126 bubble->GetFocusManager()->GetFocusedView()); |
105 ManagePasswordsBubbleView::CloseCurrentBubble(); | 127 ManagePasswordsBubbleView::CloseCurrentBubble(); |
106 EXPECT_FALSE(IsBubbleShowing()); | 128 EXPECT_FALSE(IsBubbleShowing()); |
129 // Drain message pump to ensure the bubble view is cleared so that it can be | |
130 // created again (it is checked on Mac to prevent re-opening the bubble when | |
131 // clicking the location bar button repeatedly). | |
132 content::RunAllPendingInMessageLoop(); | |
107 | 133 |
108 // And, just for grins, ensure that we can re-open the bubble. | 134 // And, just for grins, ensure that we can re-open the bubble. |
109 ExecuteManagePasswordsCommand(); | 135 ExecuteManagePasswordsCommand(); |
110 EXPECT_TRUE(IsBubbleShowing()); | 136 EXPECT_TRUE(IsBubbleShowing()); |
111 ManagePasswordsBubbleView::CloseCurrentBubble(); | 137 ManagePasswordsBubbleView::CloseCurrentBubble(); |
112 EXPECT_FALSE(IsBubbleShowing()); | 138 EXPECT_FALSE(IsBubbleShowing()); |
113 } | 139 } |
114 | 140 |
115 IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, | 141 IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, |
116 CommandExecutionInManagingState) { | 142 CommandExecutionInManagingState) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
159 samples->GetCount( | 185 samples->GetCount( |
160 metrics_util::MANUAL_MANAGE_PASSWORDS)); | 186 metrics_util::MANUAL_MANAGE_PASSWORDS)); |
161 } | 187 } |
162 | 188 |
163 IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, | 189 IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, |
164 CommandExecutionInPendingState) { | 190 CommandExecutionInPendingState) { |
165 // Open once with pending password: automagical! | 191 // Open once with pending password: automagical! |
166 SetupPendingPassword(); | 192 SetupPendingPassword(); |
167 EXPECT_TRUE(IsBubbleShowing()); | 193 EXPECT_TRUE(IsBubbleShowing()); |
168 ManagePasswordsBubbleView::CloseCurrentBubble(); | 194 ManagePasswordsBubbleView::CloseCurrentBubble(); |
195 // Drain message pump to ensure the bubble view is cleared so that it can be | |
196 // created again (it is checked on Mac to prevent re-opening the bubble when | |
197 // clicking the location bar button repeatedly). | |
198 content::RunAllPendingInMessageLoop(); | |
199 | |
169 // This opening should be measured as manual. | 200 // This opening should be measured as manual. |
170 ExecuteManagePasswordsCommand(); | 201 ExecuteManagePasswordsCommand(); |
171 EXPECT_TRUE(IsBubbleShowing()); | 202 EXPECT_TRUE(IsBubbleShowing()); |
172 | 203 |
173 std::unique_ptr<base::HistogramSamples> samples( | 204 std::unique_ptr<base::HistogramSamples> samples( |
174 GetSamples(kDisplayDispositionMetric)); | 205 GetSamples(kDisplayDispositionMetric)); |
175 EXPECT_EQ( | 206 EXPECT_EQ( |
176 1, | 207 1, |
177 samples->GetCount( | 208 samples->GetCount( |
178 metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING)); | 209 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"); | 341 test_form()->origin = GURL("https://example.com"); |
311 test_form()->display_name = base::ASCIIToUTF16("Peter"); | 342 test_form()->display_name = base::ASCIIToUTF16("Peter"); |
312 test_form()->username_value = base::ASCIIToUTF16("pet12@gmail.com"); | 343 test_form()->username_value = base::ASCIIToUTF16("pet12@gmail.com"); |
313 std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials; | 344 std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials; |
314 local_credentials.push_back( | 345 local_credentials.push_back( |
315 base::MakeUnique<autofill::PasswordForm>(*test_form())); | 346 base::MakeUnique<autofill::PasswordForm>(*test_form())); |
316 | 347 |
317 // Open another window with focus. | 348 // Open another window with focus. |
318 Browser* focused_window = CreateBrowser(browser()->profile()); | 349 Browser* focused_window = CreateBrowser(browser()->profile()); |
319 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(focused_window)); | 350 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(focused_window)); |
320 content::RunAllPendingInMessageLoop(); | |
321 | 351 |
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); | 352 ManagePasswordsBubbleView::set_auto_signin_toast_timeout(0); |
329 SetupAutoSignin(std::move(local_credentials)); | 353 SetupAutoSignin(std::move(local_credentials)); |
330 content::RunAllPendingInMessageLoop(); | |
331 EXPECT_TRUE(IsBubbleShowing()); | 354 EXPECT_TRUE(IsBubbleShowing()); |
332 | 355 |
333 // Bring the first window back. The toast closes by timeout. | 356 // Bring the first window back. The toast closes by timeout. |
334 focused_window->window()->Close(); | 357 focused_window->window()->Close(); |
msw
2017/04/20 17:41:16
Why isn't BringBrowserWindowToFront sufficient? Co
varkha
2017/04/20 21:21:24
I didn't comment in code here because I ended not
| |
335 browser()->window()->Activate(); | 358 browser()->window()->Activate(); |
336 content::RunAllPendingInMessageLoop(); | 359 content::RunAllPendingInMessageLoop(); |
337 views::test::WidgetActivationWaiter active_waiter(widget, true); | 360 ui_test_utils::BrowserActivationWaiter waiter(browser()); |
338 active_waiter.Wait(); | 361 waiter.WaitForActivation(); |
362 | |
363 // Sign-in dialogs opened for inactive browser windows do not auto-close on | |
364 // MacOS. This matches existing Cocoa bubble behavior. | |
365 // TODO(varkha): Remove the limitation as part of http://crbug/671916 . | |
366 #if !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER) | |
339 EXPECT_FALSE(IsBubbleShowing()); | 367 EXPECT_FALSE(IsBubbleShowing()); |
368 #else | |
369 EXPECT_TRUE(IsBubbleShowing()); | |
370 #endif | |
340 } | 371 } |
OLD | NEW |