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 scoped_ptr<base::HistogramSamples> samples( 84 GetSamples(kDisplayDispositionMetric)); 85 EXPECT_EQ( 86 1, 87 samples->GetCount( 88 password_manager::metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING)); 89 EXPECT_EQ(0, 90 samples->GetCount( 91 password_manager::metrics_util::MANUAL_WITH_PASSWORD_PENDING)); 92 EXPECT_EQ(0, 93 samples->GetCount( 94 password_manager::metrics_util::MANUAL_MANAGE_PASSWORDS)); 95} 96 97IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, 98 CommandExecutionInPendingState) { 99 // Open once with pending password: automagical! 100 SetupPendingPassword(); 101 ManagePasswordsBubbleView::CloseBubble(); 102 // This opening should be measured as manual. 103 ExecuteManagePasswordsCommand(); 104 105 scoped_ptr<base::HistogramSamples> samples( 106 GetSamples(kDisplayDispositionMetric)); 107 EXPECT_EQ( 108 1, 109 samples->GetCount( 110 password_manager::metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING)); 111 EXPECT_EQ(1, 112 samples->GetCount( 113 password_manager::metrics_util::MANUAL_WITH_PASSWORD_PENDING)); 114 EXPECT_EQ(0, 115 samples->GetCount( 116 password_manager::metrics_util::MANUAL_MANAGE_PASSWORDS)); 117} 118