cf4c6f5c54f5dc6cdf849d0e4a5b843c7069da10
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / passwords / manage_passwords_bubble_confirmation_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_confirmation_view_controller.h"
6
7 #include "base/mac/scoped_nsobject.h"
8 #include "base/strings/string16.h"
9 #include "base/strings/utf_string_conversions.h"
10 #import "chrome/browser/ui/cocoa/bubble_combobox.h"
11 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h"
12 #include "chrome/browser/ui/cocoa/passwords/manage_passwords_controller_test.h"
13 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
14 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller_mock.h"
15 #include "chrome/browser/ui/passwords/save_password_refusal_combobox_model.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "testing/gtest_mac.h"
18
19 @interface ManagePasswordsBubbleContentViewTestDelegate
20     : NSObject<ManagePasswordsBubbleContentViewDelegate> {
21   BOOL dismissed_;
22 }
23 @property(readonly) BOOL dismissed;
24 @end
25
26 @implementation ManagePasswordsBubbleContentViewTestDelegate
27
28 @synthesize dismissed = dismissed_;
29
30 - (void)viewShouldDismiss {
31   dismissed_ = YES;
32 }
33
34 @end
35
36 namespace {
37
38 class ManagePasswordsBubbleConfirmationViewControllerTest
39     : public ManagePasswordsControllerTest {
40  public:
41   ManagePasswordsBubbleConfirmationViewControllerTest() : controller_(nil) {}
42
43   virtual void SetUp() OVERRIDE {
44     ManagePasswordsControllerTest::SetUp();
45     delegate_.reset(
46         [[ManagePasswordsBubbleContentViewTestDelegate alloc] init]);
47   }
48
49   ManagePasswordsBubbleContentViewTestDelegate* delegate() {
50     return delegate_.get();
51   }
52
53   ManagePasswordsBubbleConfirmationViewController* controller() {
54     if (!controller_) {
55       controller_.reset([[ManagePasswordsBubbleConfirmationViewController alloc]
56           initWithModel:model()
57                delegate:delegate()]);
58       [controller_ loadView];
59     }
60     return controller_.get();
61   }
62
63  private:
64   base::scoped_nsobject<ManagePasswordsBubbleConfirmationViewController>
65       controller_;
66   base::scoped_nsobject<ManagePasswordsBubbleContentViewTestDelegate> delegate_;
67 };
68
69 TEST_F(ManagePasswordsBubbleConfirmationViewControllerTest,
70        ShouldDismissWhenOKClicked) {
71   [controller().okButton performClick:nil];
72   EXPECT_TRUE([delegate() dismissed]);
73 }
74
75 TEST_F(ManagePasswordsBubbleConfirmationViewControllerTest,
76        ShouldOpenPasswordsAndDismissWhenLinkClicked) {
77   [controller().confirmationText clickedOnLink:nil atIndex:0];
78   EXPECT_TRUE([delegate() dismissed]);
79   EXPECT_TRUE(ui_controller()->navigated_to_settings_page());
80 }
81
82 }  // namespace