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