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.
5 #import "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_blacklist_view_controller.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h"
9 #import "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_blacklist_view_controller.h"
10 #include "chrome/browser/ui/cocoa/passwords/manage_passwords_controller_test.h"
11 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller_mock.h"
12 #include "components/password_manager/core/common/password_manager_ui.h"
14 // Helper delegate for testing the blacklist view of the password management
16 @interface ManagePasswordsBubbleBlacklistViewTestDelegate
17 : NSObject<ManagePasswordsBubbleContentViewDelegate> {
20 @property(readonly) BOOL dismissed;
23 @implementation ManagePasswordsBubbleBlacklistViewTestDelegate
25 @synthesize dismissed = dismissed_;
27 - (void)viewShouldDismiss {
35 // Tests for the blacklist view of the password management bubble.
36 class ManagePasswordsBubbleBlacklistViewControllerTest
37 : public ManagePasswordsControllerTest {
39 ManagePasswordsBubbleBlacklistViewControllerTest() : controller_(nil) {}
41 virtual void SetUp() OVERRIDE {
42 ManagePasswordsControllerTest::SetUp();
44 [[ManagePasswordsBubbleBlacklistViewTestDelegate alloc] init]);
47 ManagePasswordsBubbleBlacklistViewTestDelegate* delegate() {
48 return delegate_.get();
51 ManagePasswordsBubbleBlacklistViewController* controller() {
53 controller_.reset([[ManagePasswordsBubbleBlacklistViewController alloc]
55 delegate:delegate()]);
56 [controller_ loadView];
58 return controller_.get();
62 base::scoped_nsobject<ManagePasswordsBubbleBlacklistViewController>
64 base::scoped_nsobject<ManagePasswordsBubbleBlacklistViewTestDelegate>
68 TEST_F(ManagePasswordsBubbleBlacklistViewControllerTest,
69 ShouldDismissWhenDoneClicked) {
70 NSButton* doneButton = controller().doneButton;
71 [doneButton performClick:nil];
72 EXPECT_TRUE(delegate().dismissed);
75 TEST_F(ManagePasswordsBubbleBlacklistViewControllerTest,
76 ShouldDismissAndUnblacklistWhenUnblacklistClicked) {
77 ui_controller()->SetState(password_manager::ui::BLACKLIST_STATE);
78 // Unblacklisting requires passwords to exist for the site.
79 autofill::PasswordForm form;
80 form.username_value = base::ASCIIToUTF16("username");
81 form.password_value = base::ASCIIToUTF16("password");
82 autofill::ConstPasswordFormMap map;
83 map[base::ASCIIToUTF16("username")] = &form;
84 ui_controller()->SetPasswordFormMap(map);
86 EXPECT_EQ(password_manager::ui::BLACKLIST_STATE, ui_controller()->state());
87 NSButton* undoButton = controller().undoBlacklistButton;
88 [undoButton performClick:nil];
89 EXPECT_TRUE(delegate().dismissed);
90 EXPECT_NE(password_manager::ui::BLACKLIST_STATE, ui_controller()->state());