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

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

Powered by Google App Engine
This is Rietveld 408576698