[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / views / passwords / manage_passwords_view_test.cc
bloba8198c778d8b1379cfd01fb1f2fa8358ca013b7a
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.
5 #include "chrome/browser/ui/views/passwords/manage_passwords_view_test.h"
7 #include "base/test/statistics_delta_reader.h"
8 #include "chrome/app/chrome_command_ids.h"
9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/browser_command_controller.h"
11 #include "chrome/browser/ui/passwords/manage_passwords_icon.h"
12 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller_mock.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model.h"
14 #include "chrome/browser/ui/views/frame/browser_view.h"
15 #include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h"
16 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h"
17 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
18 #include "chrome/test/base/in_process_browser_test.h"
19 #include "chrome/test/base/interactive_test_utils.h"
20 #include "components/autofill/core/common/password_form.h"
21 #include "components/password_manager/core/browser/mock_password_manager_driver.h"
22 #include "components/password_manager/core/browser/password_form_manager.h"
23 #include "components/password_manager/core/browser/password_manager_driver.h"
24 #include "components/password_manager/core/browser/password_manager_metrics_util.h"
25 #include "components/password_manager/core/browser/stub_password_manager_client.h"
26 #include "testing/gtest/include/gtest/gtest.h"
28 void ManagePasswordsViewTest::SetUpOnMainThread() {
29 // Create the test UIController here so that it's bound to the currently
30 // active WebContents.
31 new ManagePasswordsUIControllerMock(
32 browser()->tab_strip_model()->GetActiveWebContents());
35 ManagePasswordsUIControllerMock* ManagePasswordsViewTest::controller() {
36 return static_cast<ManagePasswordsUIControllerMock*>(
37 ManagePasswordsUIController::FromWebContents(
38 browser()->tab_strip_model()->GetActiveWebContents()));
41 ManagePasswordsIconView* ManagePasswordsViewTest::view() {
42 BrowserView* browser_view = static_cast<BrowserView*>(browser()->window());
43 return browser_view->GetToolbarView()->location_bar()->
44 manage_passwords_icon_view();
47 void ManagePasswordsViewTest::ExecuteManagePasswordsCommand() {
48 // Show the window to ensure that it's active.
49 browser()->window()->Show();
51 CommandUpdater* updater = browser()->command_controller()->command_updater();
52 EXPECT_TRUE(updater->IsCommandEnabled(IDC_MANAGE_PASSWORDS_FOR_PAGE));
53 EXPECT_TRUE(updater->ExecuteCommand(IDC_MANAGE_PASSWORDS_FOR_PAGE));
55 // Wait for the command execution to pop up the bubble.
56 content::RunAllPendingInMessageLoop();
59 void ManagePasswordsViewTest::SetupManagingPasswords() {
60 base::string16 kTestUsername = base::ASCIIToUTF16("test_username");
61 autofill::PasswordFormMap map;
62 map[kTestUsername] = test_form();
63 controller()->OnPasswordAutofilled(map);
64 controller()->UpdateIconAndBubbleState(view());
67 void ManagePasswordsViewTest::SetupPendingPassword() {
68 password_manager::StubPasswordManagerClient client;
69 password_manager::MockPasswordManagerDriver driver;
70 scoped_ptr<password_manager::PasswordFormManager> test_form_manager(
71 new password_manager::PasswordFormManager(
72 NULL, &client, &driver, *test_form(), false));
73 controller()->OnPasswordSubmitted(test_form_manager.release());
75 // Wait for the command execution triggered by the automatic popup to pop up
76 // the bubble.
77 content::RunAllPendingInMessageLoop();
78 controller()->UpdateIconAndBubbleState(view());
81 void ManagePasswordsViewTest::SetupBlackistedPassword() {
82 base::string16 kTestUsername = base::ASCIIToUTF16("test_username");
83 autofill::PasswordFormMap map;
84 map[kTestUsername] = test_form();
85 controller()->OnBlacklistBlockedAutofill(map);
86 controller()->UpdateIconAndBubbleState(view());
89 base::HistogramSamples* ManagePasswordsViewTest::GetSamples(
90 const char* histogram) {
91 // Ensure that everything has been properly recorded before pulling samples.
92 content::RunAllPendingInMessageLoop();
93 return statistics_reader_.GetHistogramSamplesSinceCreation(
94 histogram).release();