Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / passwords / manage_passwords_bubble_blacklist_view_controller_unittest.mm
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 #import "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_blacklist_view_controller.h"
6
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"
13
14 // Helper delegate for testing the blacklist view of the password management
15 // bubble.
16 @interface ManagePasswordsBubbleBlacklistViewTestDelegate
17     : NSObject<ManagePasswordsBubbleContentViewDelegate> {
18   BOOL dismissed_;
19 }
20 @property(readonly) BOOL dismissed;
21 @end
22
23 @implementation ManagePasswordsBubbleBlacklistViewTestDelegate
24
25 @synthesize dismissed = dismissed_;
26
27 - (void)viewShouldDismiss {
28   dismissed_ = YES;
29 }
30
31 @end
32
33 namespace {
34
35 // Tests for the blacklist view of the password management bubble.
36 class ManagePasswordsBubbleBlacklistViewControllerTest
37     : public ManagePasswordsControllerTest {
38  public:
39   ManagePasswordsBubbleBlacklistViewControllerTest() : controller_(nil) {}
40
41   virtual void SetUp() OVERRIDE {
42     ManagePasswordsControllerTest::SetUp();
43     delegate_.reset(
44         [[ManagePasswordsBubbleBlacklistViewTestDelegate alloc] init]);
45   }
46
47   ManagePasswordsBubbleBlacklistViewTestDelegate* delegate() {
48     return delegate_.get();
49   }
50
51   ManagePasswordsBubbleBlacklistViewController* controller() {
52     if (!controller_) {
53       controller_.reset([[ManagePasswordsBubbleBlacklistViewController alloc]
54           initWithModel:model()
55                delegate:delegate()]);
56       [controller_ loadView];
57     }
58     return controller_.get();
59   }
60
61  private:
62   base::scoped_nsobject<ManagePasswordsBubbleBlacklistViewController>
63       controller_;
64   base::scoped_nsobject<ManagePasswordsBubbleBlacklistViewTestDelegate>
65       delegate_;
66 };
67
68 TEST_F(ManagePasswordsBubbleBlacklistViewControllerTest,
69        ShouldDismissWhenDoneClicked) {
70   NSButton* doneButton = controller().doneButton;
71   [doneButton performClick:nil];
72   EXPECT_TRUE(delegate().dismissed);
73 }
74
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);
85
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());
91 }
92
93 }  // namespace