OLD | NEW |
| (Empty) |
1 // Copyright 2013 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 "ui/app_list/cocoa/signin_view_controller.h" | |
6 | |
7 #include "base/mac/foundation_util.h" | |
8 #include "base/mac/scoped_nsobject.h" | |
9 #include "base/strings/utf_string_conversions.h" | |
10 #import "testing/gtest_mac.h" | |
11 #include "ui/app_list/signin_delegate.h" | |
12 #include "ui/app_list/test/app_list_test_view_delegate.h" | |
13 #import "ui/gfx/test/ui_cocoa_test_helper.h" | |
14 | |
15 @class TestSigninViewDelegate; | |
16 | |
17 namespace { | |
18 | |
19 // Helper function to cycle through the responder chain created implicitly | |
20 // from subviews, without having to interact with the event system. | |
21 NSControl* NextControl(NSControl* control) { | |
22 NSArray* siblings = [[control superview] subviews]; | |
23 for (NSUInteger index = [siblings indexOfObject:control] + 1; | |
24 index < [siblings count] ; ++index) { | |
25 if ([[siblings objectAtIndex:index] acceptsFirstResponder]) | |
26 return [siblings objectAtIndex:index]; | |
27 } | |
28 return nil; | |
29 } | |
30 | |
31 } // namespace | |
32 | |
33 namespace app_list { | |
34 namespace test { | |
35 | |
36 class SigninViewControllerTest : public ui::CocoaTest, | |
37 public SigninDelegate { | |
38 public: | |
39 SigninViewControllerTest() | |
40 : test_text_(base::ASCIIToUTF16("Sign in")), | |
41 needs_signin_(true), | |
42 show_signin_count_(0), | |
43 open_learn_more_count_(0), | |
44 open_settings_count_(0) {} | |
45 | |
46 // ui::CocoaTest override: | |
47 virtual void SetUp() OVERRIDE; | |
48 | |
49 // SigninDelegate overrides: | |
50 virtual bool NeedSignin() OVERRIDE { return needs_signin_; } | |
51 virtual void ShowSignin() OVERRIDE { ++show_signin_count_; } | |
52 virtual void OpenLearnMore() OVERRIDE { ++open_learn_more_count_; } | |
53 virtual void OpenSettings() OVERRIDE { ++open_settings_count_; } | |
54 | |
55 virtual base::string16 GetSigninHeading() OVERRIDE { return test_text_; } | |
56 virtual base::string16 GetSigninText() OVERRIDE { return test_text_; } | |
57 virtual base::string16 GetSigninButtonText() OVERRIDE { return test_text_; } | |
58 virtual base::string16 GetLearnMoreLinkText() OVERRIDE { return test_text_; } | |
59 virtual base::string16 GetSettingsLinkText() OVERRIDE { return test_text_; } | |
60 | |
61 protected: | |
62 const base::string16 test_text_; | |
63 base::scoped_nsobject<SigninViewController> signin_view_controller_; | |
64 bool needs_signin_; | |
65 int show_signin_count_; | |
66 int open_learn_more_count_; | |
67 int open_settings_count_; | |
68 | |
69 private: | |
70 DISALLOW_COPY_AND_ASSIGN(SigninViewControllerTest); | |
71 }; | |
72 | |
73 void SigninViewControllerTest::SetUp() { | |
74 NSRect frame = NSMakeRect(0, 0, 400, 500); | |
75 signin_view_controller_.reset( | |
76 [[SigninViewController alloc] initWithFrame:frame | |
77 cornerRadius:3 | |
78 delegate:this]); | |
79 | |
80 ui::CocoaTest::SetUp(); | |
81 [[test_window() contentView] addSubview:[signin_view_controller_ view]]; | |
82 } | |
83 | |
84 TEST_VIEW(SigninViewControllerTest, [signin_view_controller_ view]); | |
85 | |
86 TEST_F(SigninViewControllerTest, NotSignedIn) { | |
87 NSArray* content_subviews = [[test_window() contentView] subviews]; | |
88 EXPECT_EQ(1u, [content_subviews count]); | |
89 NSArray* subviews = [[content_subviews objectAtIndex:0] subviews]; | |
90 EXPECT_LT(0u, [subviews count]); | |
91 | |
92 // The first subview that acceptFirstResponder should be the signin button, | |
93 // and performing its action should show the signin dialog. Then "Learn more", | |
94 // followed by "Settings". | |
95 NSControl* control = NextControl([subviews objectAtIndex:0]); | |
96 EXPECT_EQ(0, show_signin_count_); | |
97 EXPECT_TRUE([[control target] performSelector:[control action] | |
98 withObject:control]); | |
99 EXPECT_EQ(1, show_signin_count_); | |
100 | |
101 control = NextControl(control); | |
102 EXPECT_EQ(0, open_learn_more_count_); | |
103 EXPECT_TRUE([[control target] performSelector:[control action] | |
104 withObject:control]); | |
105 EXPECT_EQ(1, open_learn_more_count_); | |
106 | |
107 control = NextControl(control); | |
108 EXPECT_EQ(0, open_settings_count_); | |
109 EXPECT_TRUE([[control target] performSelector:[control action] | |
110 withObject:control]); | |
111 EXPECT_EQ(1, open_settings_count_); | |
112 } | |
113 | |
114 } // namespace test | |
115 } // namespace app_list | |
OLD | NEW |