manage_passwords_bubble_view_browsertest.cc revision 116680a4aac90f2aa7413d9095a592090648e557
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 3// found in the LICENSE file. 4 5#include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h" 6 7#include "base/metrics/histogram_samples.h" 8#include "chrome/browser/ui/browser.h" 9#include "chrome/browser/ui/tabs/tab_strip_model.h" 10#include "chrome/browser/ui/views/passwords/manage_passwords_view_test.h" 11#include "components/password_manager/core/browser/password_manager_metrics_util.h" 12#include "components/password_manager/core/browser/stub_password_manager_client.h" 13#include "testing/gtest/include/gtest/gtest.h" 14 15namespace { 16 17const char kDisplayDispositionMetric[] = "PasswordBubble.DisplayDisposition"; 18 19} // namespace 20 21typedef ManagePasswordsViewTest ManagePasswordsBubbleViewTest; 22 23IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, BasicOpenAndClose) { 24 EXPECT_FALSE(ManagePasswordsBubbleView::IsShowing()); 25 ManagePasswordsBubbleView::ShowBubble( 26 browser()->tab_strip_model()->GetActiveWebContents(), 27 ManagePasswordsBubble::USER_ACTION); 28 EXPECT_TRUE(ManagePasswordsBubbleView::IsShowing()); 29 ManagePasswordsBubbleView::CloseBubble(); 30 EXPECT_FALSE(ManagePasswordsBubbleView::IsShowing()); 31 32 // And, just for grins, ensure that we can re-open the bubble. 33 ManagePasswordsBubbleView::ShowBubble( 34 browser()->tab_strip_model()->GetActiveWebContents(), 35 ManagePasswordsBubble::USER_ACTION); 36 EXPECT_TRUE(ManagePasswordsBubbleView::IsShowing()); 37 ManagePasswordsBubbleView::CloseBubble(); 38 EXPECT_FALSE(ManagePasswordsBubbleView::IsShowing()); 39} 40 41// Same as 'BasicOpenAndClose', but use the command rather than the static 42// method directly. 43IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, CommandControlsBubble) { 44 // The command only works if the icon is visible, so get into management mode. 45 SetupManagingPasswords(); 46 EXPECT_FALSE(ManagePasswordsBubbleView::IsShowing()); 47 ExecuteManagePasswordsCommand(); 48 EXPECT_TRUE(ManagePasswordsBubbleView::IsShowing()); 49 ManagePasswordsBubbleView::CloseBubble(); 50 EXPECT_FALSE(ManagePasswordsBubbleView::IsShowing()); 51 52 // And, just for grins, ensure that we can re-open the bubble. 53 ExecuteManagePasswordsCommand(); 54 EXPECT_TRUE(ManagePasswordsBubbleView::IsShowing()); 55 ManagePasswordsBubbleView::CloseBubble(); 56 EXPECT_FALSE(ManagePasswordsBubbleView::IsShowing()); 57} 58 59IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, 60 CommandExecutionInManagingState) { 61 SetupManagingPasswords(); 62 ExecuteManagePasswordsCommand(); 63 64 scoped_ptr<base::HistogramSamples> samples( 65 GetSamples(kDisplayDispositionMetric)); 66 EXPECT_EQ( 67 0, 68 samples->GetCount( 69 password_manager::metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING)); 70 EXPECT_EQ(0, 71 samples->GetCount( 72 password_manager::metrics_util::MANUAL_WITH_PASSWORD_PENDING)); 73 EXPECT_EQ(1, 74 samples->GetCount( 75 password_manager::metrics_util::MANUAL_MANAGE_PASSWORDS)); 76} 77 78IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, 79 CommandExecutionInAutomaticState) { 80 // Open with pending password: automagical! 81 SetupPendingPassword(); 82 83 // Bubble should not be focused by default. 84 EXPECT_FALSE( 85 ManagePasswordsBubbleView::Bubble()->GetFocusManager()->GetFocusedView()); 86 // Bubble can be active if user clicks it. 87 EXPECT_TRUE(ManagePasswordsBubbleView::Bubble()->CanActivate()); 88 89 scoped_ptr<base::HistogramSamples> samples( 90 GetSamples(kDisplayDispositionMetric)); 91 EXPECT_EQ( 92 1, 93 samples->GetCount( 94 password_manager::metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING)); 95 EXPECT_EQ(0, 96 samples->GetCount( 97 password_manager::metrics_util::MANUAL_WITH_PASSWORD_PENDING)); 98 EXPECT_EQ(0, 99 samples->GetCount( 100 password_manager::metrics_util::MANUAL_MANAGE_PASSWORDS)); 101} 102 103IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, 104 CommandExecutionInPendingState) { 105 // Open once with pending password: automagical! 106 SetupPendingPassword(); 107 ManagePasswordsBubbleView::CloseBubble(); 108 // This opening should be measured as manual. 109 ExecuteManagePasswordsCommand(); 110 111 scoped_ptr<base::HistogramSamples> samples( 112 GetSamples(kDisplayDispositionMetric)); 113 EXPECT_EQ( 114 1, 115 samples->GetCount( 116 password_manager::metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING)); 117 EXPECT_EQ(1, 118 samples->GetCount( 119 password_manager::metrics_util::MANUAL_WITH_PASSWORD_PENDING)); 120 EXPECT_EQ(0, 121 samples->GetCount( 122 password_manager::metrics_util::MANUAL_MANAGE_PASSWORDS)); 123} 124