OLD | NEW |
| (Empty) |
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/passwords/manage_passwords_test.h" | |
6 | |
7 #include "base/strings/utf_string_conversions.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/browser_window.h" | |
12 #include "chrome/browser/ui/passwords/manage_passwords_icon.h" | |
13 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller_mock.h" | |
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
15 #include "chrome/test/base/in_process_browser_test.h" | |
16 #include "chrome/test/base/interactive_test_utils.h" | |
17 #include "components/autofill/core/common/password_form.h" | |
18 #include "components/password_manager/core/browser/password_form_manager.h" | |
19 #include "components/password_manager/core/browser/password_manager_metrics_util
.h" | |
20 #include "components/password_manager/core/browser/stub_password_manager_client.
h" | |
21 #include "components/password_manager/core/browser/stub_password_manager_driver.
h" | |
22 #include "testing/gtest/include/gtest/gtest.h" | |
23 | |
24 void ManagePasswordsTest::SetUpOnMainThread() { | |
25 AddTabAtIndex(0, GURL("http://example.com/"), content::PAGE_TRANSITION_TYPED); | |
26 // Create the test UIController here so that it's bound to the currently | |
27 // active WebContents. | |
28 new ManagePasswordsUIControllerMock( | |
29 browser()->tab_strip_model()->GetActiveWebContents()); | |
30 } | |
31 | |
32 ManagePasswordsUIControllerMock* ManagePasswordsTest::controller() { | |
33 return static_cast<ManagePasswordsUIControllerMock*>( | |
34 ManagePasswordsUIController::FromWebContents( | |
35 browser()->tab_strip_model()->GetActiveWebContents())); | |
36 } | |
37 | |
38 void ManagePasswordsTest::ExecuteManagePasswordsCommand() { | |
39 // Show the window to ensure that it's active. | |
40 browser()->window()->Show(); | |
41 | |
42 CommandUpdater* updater = browser()->command_controller()->command_updater(); | |
43 EXPECT_TRUE(updater->IsCommandEnabled(IDC_MANAGE_PASSWORDS_FOR_PAGE)); | |
44 EXPECT_TRUE(updater->ExecuteCommand(IDC_MANAGE_PASSWORDS_FOR_PAGE)); | |
45 | |
46 // Wait for the command execution to pop up the bubble. | |
47 content::RunAllPendingInMessageLoop(); | |
48 } | |
49 | |
50 void ManagePasswordsTest::SetupManagingPasswords() { | |
51 base::string16 kTestUsername = base::ASCIIToUTF16("test_username"); | |
52 autofill::PasswordFormMap map; | |
53 map[kTestUsername] = test_form(); | |
54 controller()->OnPasswordAutofilled(map); | |
55 controller()->UpdateIconAndBubbleState(view()); | |
56 } | |
57 | |
58 void ManagePasswordsTest::SetupPendingPassword() { | |
59 password_manager::StubPasswordManagerClient client; | |
60 password_manager::StubPasswordManagerDriver driver; | |
61 scoped_ptr<password_manager::PasswordFormManager> test_form_manager( | |
62 new password_manager::PasswordFormManager( | |
63 NULL, &client, &driver, *test_form(), false)); | |
64 controller()->OnPasswordSubmitted(test_form_manager.Pass()); | |
65 | |
66 // Wait for the command execution triggered by the automatic popup to pop up | |
67 // the bubble. | |
68 content::RunAllPendingInMessageLoop(); | |
69 controller()->UpdateIconAndBubbleState(view()); | |
70 } | |
71 | |
72 void ManagePasswordsTest::SetupAutomaticPassword() { | |
73 password_manager::StubPasswordManagerClient client; | |
74 password_manager::StubPasswordManagerDriver driver; | |
75 scoped_ptr<password_manager::PasswordFormManager> test_form_manager( | |
76 new password_manager::PasswordFormManager( | |
77 NULL, &client, &driver, *test_form(), false)); | |
78 controller()->OnAutomaticPasswordSave(test_form_manager.Pass()); | |
79 | |
80 // Wait for the command execution triggered by the automatic popup to pop up | |
81 // the bubble. | |
82 content::RunAllPendingInMessageLoop(); | |
83 controller()->UpdateIconAndBubbleState(view()); | |
84 } | |
85 | |
86 void ManagePasswordsTest::SetupBlackistedPassword() { | |
87 base::string16 kTestUsername = base::ASCIIToUTF16("test_username"); | |
88 autofill::PasswordFormMap map; | |
89 map[kTestUsername] = test_form(); | |
90 controller()->OnBlacklistBlockedAutofill(map); | |
91 controller()->UpdateIconAndBubbleState(view()); | |
92 } | |
93 | |
94 base::HistogramSamples* ManagePasswordsTest::GetSamples( | |
95 const char* histogram) { | |
96 // Ensure that everything has been properly recorded before pulling samples. | |
97 content::RunAllPendingInMessageLoop(); | |
98 return histogram_tester_.GetHistogramSamplesSinceCreation(histogram) | |
99 .release(); | |
100 } | |
OLD | NEW |