Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: chrome/browser/ui/passwords/manage_passwords_test.cc

Issue 444603003: Hook up the Mac password bubble to the browser and add browser tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix views build Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/passwords/manage_passwords_view_test.h" 5 #include "chrome/browser/ui/passwords/manage_passwords_test.h"
6 6
7 #include "base/strings/utf_string_conversions.h"
7 #include "chrome/app/chrome_command_ids.h" 8 #include "chrome/app/chrome_command_ids.h"
8 #include "chrome/browser/ui/browser.h" 9 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/browser_command_controller.h" 10 #include "chrome/browser/ui/browser_command_controller.h"
11 #include "chrome/browser/ui/browser_window.h"
10 #include "chrome/browser/ui/passwords/manage_passwords_icon.h" 12 #include "chrome/browser/ui/passwords/manage_passwords_icon.h"
11 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller_mock.h" 13 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller_mock.h"
12 #include "chrome/browser/ui/tabs/tab_strip_model.h" 14 #include "chrome/browser/ui/tabs/tab_strip_model.h"
13 #include "chrome/browser/ui/views/frame/browser_view.h"
14 #include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h"
15 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h"
16 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
17 #include "chrome/test/base/in_process_browser_test.h" 15 #include "chrome/test/base/in_process_browser_test.h"
18 #include "chrome/test/base/interactive_test_utils.h" 16 #include "chrome/test/base/interactive_test_utils.h"
19 #include "components/autofill/core/common/password_form.h" 17 #include "components/autofill/core/common/password_form.h"
20 #include "components/password_manager/core/browser/password_form_manager.h" 18 #include "components/password_manager/core/browser/password_form_manager.h"
21 #include "components/password_manager/core/browser/password_manager_metrics_util .h" 19 #include "components/password_manager/core/browser/password_manager_metrics_util .h"
22 #include "components/password_manager/core/browser/stub_password_manager_client. h" 20 #include "components/password_manager/core/browser/stub_password_manager_client. h"
23 #include "components/password_manager/core/browser/stub_password_manager_driver. h" 21 #include "components/password_manager/core/browser/stub_password_manager_driver. h"
24 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
25 23
26 void ManagePasswordsViewTest::SetUpOnMainThread() { 24 void ManagePasswordsTest::SetUpOnMainThread() {
27 AddTabAtIndex(0, GURL("http://example.com/"), content::PAGE_TRANSITION_TYPED); 25 AddTabAtIndex(0, GURL("http://example.com/"), content::PAGE_TRANSITION_TYPED);
28 // Create the test UIController here so that it's bound to the currently 26 // Create the test UIController here so that it's bound to the currently
29 // active WebContents. 27 // active WebContents.
30 new ManagePasswordsUIControllerMock( 28 new ManagePasswordsUIControllerMock(
31 browser()->tab_strip_model()->GetActiveWebContents()); 29 browser()->tab_strip_model()->GetActiveWebContents());
32 } 30 }
33 31
34 ManagePasswordsUIControllerMock* ManagePasswordsViewTest::controller() { 32 ManagePasswordsUIControllerMock* ManagePasswordsTest::controller() {
35 return static_cast<ManagePasswordsUIControllerMock*>( 33 return static_cast<ManagePasswordsUIControllerMock*>(
36 ManagePasswordsUIController::FromWebContents( 34 ManagePasswordsUIController::FromWebContents(
37 browser()->tab_strip_model()->GetActiveWebContents())); 35 browser()->tab_strip_model()->GetActiveWebContents()));
38 } 36 }
39 37
40 ManagePasswordsIconView* ManagePasswordsViewTest::view() { 38 void ManagePasswordsTest::ExecuteManagePasswordsCommand() {
41 BrowserView* browser_view = static_cast<BrowserView*>(browser()->window());
42 return browser_view->GetToolbarView()->location_bar()->
43 manage_passwords_icon_view();
44 }
45
46 void ManagePasswordsViewTest::ExecuteManagePasswordsCommand() {
47 // Show the window to ensure that it's active. 39 // Show the window to ensure that it's active.
48 browser()->window()->Show(); 40 browser()->window()->Show();
49 41
50 CommandUpdater* updater = browser()->command_controller()->command_updater(); 42 CommandUpdater* updater = browser()->command_controller()->command_updater();
51 EXPECT_TRUE(updater->IsCommandEnabled(IDC_MANAGE_PASSWORDS_FOR_PAGE)); 43 EXPECT_TRUE(updater->IsCommandEnabled(IDC_MANAGE_PASSWORDS_FOR_PAGE));
52 EXPECT_TRUE(updater->ExecuteCommand(IDC_MANAGE_PASSWORDS_FOR_PAGE)); 44 EXPECT_TRUE(updater->ExecuteCommand(IDC_MANAGE_PASSWORDS_FOR_PAGE));
53 45
54 // Wait for the command execution to pop up the bubble. 46 // Wait for the command execution to pop up the bubble.
55 content::RunAllPendingInMessageLoop(); 47 content::RunAllPendingInMessageLoop();
56 } 48 }
57 49
58 void ManagePasswordsViewTest::SetupManagingPasswords() { 50 void ManagePasswordsTest::SetupManagingPasswords() {
59 base::string16 kTestUsername = base::ASCIIToUTF16("test_username"); 51 base::string16 kTestUsername = base::ASCIIToUTF16("test_username");
60 autofill::PasswordFormMap map; 52 autofill::PasswordFormMap map;
61 map[kTestUsername] = test_form(); 53 map[kTestUsername] = test_form();
62 controller()->OnPasswordAutofilled(map); 54 controller()->OnPasswordAutofilled(map);
63 controller()->UpdateIconAndBubbleState(view()); 55 controller()->UpdateIconAndBubbleState(view());
64 } 56 }
65 57
66 void ManagePasswordsViewTest::SetupPendingPassword() { 58 void ManagePasswordsTest::SetupPendingPassword() {
67 password_manager::StubPasswordManagerClient client; 59 password_manager::StubPasswordManagerClient client;
68 password_manager::StubPasswordManagerDriver driver; 60 password_manager::StubPasswordManagerDriver driver;
69 scoped_ptr<password_manager::PasswordFormManager> test_form_manager( 61 scoped_ptr<password_manager::PasswordFormManager> test_form_manager(
70 new password_manager::PasswordFormManager( 62 new password_manager::PasswordFormManager(
71 NULL, &client, &driver, *test_form(), false)); 63 NULL, &client, &driver, *test_form(), false));
72 controller()->OnPasswordSubmitted(test_form_manager.Pass()); 64 controller()->OnPasswordSubmitted(test_form_manager.Pass());
73 65
74 // Wait for the command execution triggered by the automatic popup to pop up 66 // Wait for the command execution triggered by the automatic popup to pop up
75 // the bubble. 67 // the bubble.
76 content::RunAllPendingInMessageLoop(); 68 content::RunAllPendingInMessageLoop();
77 controller()->UpdateIconAndBubbleState(view()); 69 controller()->UpdateIconAndBubbleState(view());
78 } 70 }
79 71
80 void ManagePasswordsViewTest::SetupAutomaticPassword() { 72 void ManagePasswordsTest::SetupAutomaticPassword() {
81 password_manager::StubPasswordManagerClient client; 73 password_manager::StubPasswordManagerClient client;
82 password_manager::StubPasswordManagerDriver driver; 74 password_manager::StubPasswordManagerDriver driver;
83 scoped_ptr<password_manager::PasswordFormManager> test_form_manager( 75 scoped_ptr<password_manager::PasswordFormManager> test_form_manager(
84 new password_manager::PasswordFormManager( 76 new password_manager::PasswordFormManager(
85 NULL, &client, &driver, *test_form(), false)); 77 NULL, &client, &driver, *test_form(), false));
86 controller()->OnAutomaticPasswordSave(test_form_manager.Pass()); 78 controller()->OnAutomaticPasswordSave(test_form_manager.Pass());
87 79
88 // Wait for the command execution triggered by the automatic popup to pop up 80 // Wait for the command execution triggered by the automatic popup to pop up
89 // the bubble. 81 // the bubble.
90 content::RunAllPendingInMessageLoop(); 82 content::RunAllPendingInMessageLoop();
91 controller()->UpdateIconAndBubbleState(view()); 83 controller()->UpdateIconAndBubbleState(view());
92 } 84 }
93 85
94 void ManagePasswordsViewTest::SetupBlackistedPassword() { 86 void ManagePasswordsTest::SetupBlackistedPassword() {
95 base::string16 kTestUsername = base::ASCIIToUTF16("test_username"); 87 base::string16 kTestUsername = base::ASCIIToUTF16("test_username");
96 autofill::PasswordFormMap map; 88 autofill::PasswordFormMap map;
97 map[kTestUsername] = test_form(); 89 map[kTestUsername] = test_form();
98 controller()->OnBlacklistBlockedAutofill(map); 90 controller()->OnBlacklistBlockedAutofill(map);
99 controller()->UpdateIconAndBubbleState(view()); 91 controller()->UpdateIconAndBubbleState(view());
100 } 92 }
101 93
102 base::HistogramSamples* ManagePasswordsViewTest::GetSamples( 94 base::HistogramSamples* ManagePasswordsTest::GetSamples(
103 const char* histogram) { 95 const char* histogram) {
104 // Ensure that everything has been properly recorded before pulling samples. 96 // Ensure that everything has been properly recorded before pulling samples.
105 content::RunAllPendingInMessageLoop(); 97 content::RunAllPendingInMessageLoop();
106 return histogram_tester_.GetHistogramSamplesSinceCreation(histogram) 98 return histogram_tester_.GetHistogramSamplesSinceCreation(histogram)
107 .release(); 99 .release();
108 } 100 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698