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/views/passwords/manage_passwords_view_test.h" | |
6 | |
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/password_form_manager.h" | |
22 #include "components/password_manager/core/browser/password_manager_metrics_util
.h" | |
23 #include "components/password_manager/core/browser/stub_password_manager_client.
h" | |
24 #include "components/password_manager/core/browser/stub_password_manager_driver.
h" | |
25 #include "testing/gtest/include/gtest/gtest.h" | |
26 | |
27 void ManagePasswordsViewTest::SetUpOnMainThread() { | |
28 AddTabAtIndex(0, GURL("http://example.com/"), content::PAGE_TRANSITION_TYPED); | |
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()); | |
33 } | |
34 | |
35 ManagePasswordsUIControllerMock* ManagePasswordsViewTest::controller() { | |
36 return static_cast<ManagePasswordsUIControllerMock*>( | |
37 ManagePasswordsUIController::FromWebContents( | |
38 browser()->tab_strip_model()->GetActiveWebContents())); | |
39 } | |
40 | |
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(); | |
45 } | |
46 | |
47 void ManagePasswordsViewTest::ExecuteManagePasswordsCommand() { | |
48 // Show the window to ensure that it's active. | |
49 browser()->window()->Show(); | |
50 | |
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)); | |
54 | |
55 // Wait for the command execution to pop up the bubble. | |
56 content::RunAllPendingInMessageLoop(); | |
57 } | |
58 | |
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()); | |
65 } | |
66 | |
67 void ManagePasswordsViewTest::SetupPendingPassword() { | |
68 password_manager::StubPasswordManagerClient client; | |
69 password_manager::StubPasswordManagerDriver 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.Pass()); | |
74 | |
75 // Wait for the command execution triggered by the automatic popup to pop up | |
76 // the bubble. | |
77 content::RunAllPendingInMessageLoop(); | |
78 controller()->UpdateIconAndBubbleState(view()); | |
79 } | |
80 | |
81 void ManagePasswordsViewTest::SetupAutomaticPassword() { | |
82 password_manager::StubPasswordManagerClient client; | |
83 password_manager::StubPasswordManagerDriver driver; | |
84 scoped_ptr<password_manager::PasswordFormManager> test_form_manager( | |
85 new password_manager::PasswordFormManager( | |
86 NULL, &client, &driver, *test_form(), false)); | |
87 controller()->OnAutomaticPasswordSave(test_form_manager.Pass()); | |
88 | |
89 // Wait for the command execution triggered by the automatic popup to pop up | |
90 // the bubble. | |
91 content::RunAllPendingInMessageLoop(); | |
92 controller()->UpdateIconAndBubbleState(view()); | |
93 } | |
94 | |
95 void ManagePasswordsViewTest::SetupBlackistedPassword() { | |
96 base::string16 kTestUsername = base::ASCIIToUTF16("test_username"); | |
97 autofill::PasswordFormMap map; | |
98 map[kTestUsername] = test_form(); | |
99 controller()->OnBlacklistBlockedAutofill(map); | |
100 controller()->UpdateIconAndBubbleState(view()); | |
101 } | |
102 | |
103 base::HistogramSamples* ManagePasswordsViewTest::GetSamples( | |
104 const char* histogram) { | |
105 // Ensure that everything has been properly recorded before pulling samples. | |
106 content::RunAllPendingInMessageLoop(); | |
107 return statistics_reader_.GetHistogramSamplesSinceCreation( | |
108 histogram).release(); | |
109 } | |
OLD | NEW |