OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "chrome/browser/ui/cocoa/profiles/profile_signin_confirmation_view_contr
oller.h" | 5 #import "chrome/browser/ui/cocoa/profiles/profile_signin_confirmation_view_contr
oller.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #include "base/mac/scoped_nsobject.h" | 9 #include "base/mac/scoped_nsobject.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/browser/ui/sync/profile_signin_confirmation_helper.h" | 14 #include "chrome/browser/ui/sync/profile_signin_confirmation_helper.h" |
15 #include "chrome/grit/chromium_strings.h" | 15 #include "chrome/grit/chromium_strings.h" |
16 #include "chrome/grit/generated_resources.h" | 16 #include "chrome/grit/generated_resources.h" |
17 #include "chrome/test/base/in_process_browser_test.h" | 17 #include "chrome/test/base/in_process_browser_test.h" |
18 #import "testing/gtest_mac.h" | 18 #import "testing/gtest_mac.h" |
19 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
20 | 20 |
21 @interface ProfileSigninConfirmationViewController (TestingAPI) | 21 class ProfileSigninConfirmationViewControllerTest |
| 22 : public InProcessBrowserTest, |
| 23 public ui::ProfileSigninConfirmationDelegate { |
22 | 24 |
23 @property(readonly, nonatomic) ui::ProfileSigninConfirmationDelegate* delegate; | |
24 @property(readonly, nonatomic) NSButton* createProfileButton; | |
25 @property(readonly, nonatomic) NSTextView* explanationField; | |
26 | |
27 @end | |
28 | |
29 @implementation ProfileSigninConfirmationViewController (TestingAPI) | |
30 | |
31 - (ui::ProfileSigninConfirmationDelegate*)delegate { | |
32 return delegate_.get(); | |
33 } | |
34 | |
35 - (NSButton*)createProfileButton { | |
36 return createProfileButton_.get(); | |
37 } | |
38 | |
39 - (NSTextView*)explanationField { | |
40 return explanationField_.get(); | |
41 } | |
42 | |
43 @end | |
44 | |
45 class ProfileSigninConfirmationViewControllerTest | |
46 : public InProcessBrowserTest { | |
47 public: | 25 public: |
48 ProfileSigninConfirmationViewControllerTest() | 26 ProfileSigninConfirmationViewControllerTest() |
49 : window_(nil), | 27 : window_(nil), |
50 continued_(false), | 28 continued_(false), |
51 cancelled_(false), | 29 cancelled_(false), |
52 created_(false), | 30 created_(false), |
53 closed_(false) { | 31 closed_(false) { |
54 } | 32 } |
55 | 33 |
56 protected: | 34 protected: |
57 void SetUpOnMainThread() override {} | 35 void SetUpOnMainThread() override {} |
58 | 36 |
59 void SetupDialog(bool offerProfileCreation = true) { | 37 void SetupDialog(bool offerProfileCreation = true) { |
60 window_.reset( | 38 window_.reset( |
61 [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 400, 600) | 39 [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 400, 600) |
62 styleMask:NSBorderlessWindowMask | 40 styleMask:NSBorderlessWindowMask |
63 backing:NSBackingStoreBuffered | 41 backing:NSBackingStoreBuffered |
64 defer:NO]); | 42 defer:NO]); |
65 base::Closure close = base::Bind( | 43 base::Closure close = base::Bind( |
66 &ProfileSigninConfirmationViewControllerTest::OnClose, | 44 &ProfileSigninConfirmationViewControllerTest::OnClose, |
67 base::Unretained(this)); | 45 base::Unretained(this)); |
68 controller_.reset([[ProfileSigninConfirmationViewController alloc] | 46 controller_.reset([[ProfileSigninConfirmationViewController alloc] |
69 initWithBrowser:browser() | 47 initWithBrowser:browser() |
70 username:username() | 48 username:username() |
71 delegate:base::MakeUnique<TestSigninDelegate>(this) | 49 delegate:this |
72 closeDialogCallback:close | 50 closeDialogCallback:close |
73 offerProfileCreation:offerProfileCreation]); | 51 offerProfileCreation:offerProfileCreation]); |
74 [[window_ contentView] addSubview:[controller_ view]]; | 52 [[window_ contentView] addSubview:[controller_ view]]; |
75 [window_ makeKeyAndOrderFront:NSApp]; | 53 [window_ makeKeyAndOrderFront:NSApp]; |
76 ASSERT_TRUE([window_ isVisible]); | 54 ASSERT_TRUE([window_ isVisible]); |
77 } | 55 } |
78 | 56 |
79 // Test helpers. | 57 // Test helpers. |
80 std::string username() { | 58 std::string username() { |
81 return "foo@bar.com"; | 59 return "foo@bar.com"; |
82 } | 60 } |
83 base::string16 learn_more() { | 61 base::string16 learn_more() { |
84 return l10n_util::GetStringUTF16( | 62 return l10n_util::GetStringUTF16( |
85 IDS_ENTERPRISE_SIGNIN_PROFILE_LINK_LEARN_MORE); | 63 IDS_ENTERPRISE_SIGNIN_PROFILE_LINK_LEARN_MORE); |
86 } | 64 } |
87 | 65 |
| 66 // ui::ProfileSigninConfirmationDelegate: |
| 67 void OnContinueSignin() override { continued_ = true; } |
| 68 void OnCancelSignin() override { cancelled_ = true; } |
| 69 void OnSigninWithNewProfile() override { created_ = true; } |
88 void OnClose() { closed_ = true; } | 70 void OnClose() { closed_ = true; } |
89 | 71 |
90 // The window containing the dialog. | 72 // The window containing the dialog. |
91 base::scoped_nsobject<NSWindow> window_; | 73 base::scoped_nsobject<NSWindow> window_; |
92 | 74 |
93 // Dialog under test. | 75 // Dialog under test. |
94 base::scoped_nsobject<ProfileSigninConfirmationViewController> controller_; | 76 base::scoped_nsobject<ProfileSigninConfirmationViewController> controller_; |
95 | 77 |
96 // Visible for testing UI interactions. | 78 // Visible for testing UI interactions. |
97 bool continued_; | 79 bool continued_; |
98 bool cancelled_; | 80 bool cancelled_; |
99 bool created_; | 81 bool created_; |
100 bool closed_; | 82 bool closed_; |
101 | 83 |
102 private: | 84 private: |
103 class TestSigninDelegate : public ui::ProfileSigninConfirmationDelegate { | |
104 public: | |
105 explicit TestSigninDelegate( | |
106 ProfileSigninConfirmationViewControllerTest* client) | |
107 : client_(client) {} | |
108 | |
109 // ui::ProfileSigninConfirmationDelegate: | |
110 void OnContinueSignin() override { client_->continued_ = true; } | |
111 void OnCancelSignin() override { client_->cancelled_ = true; } | |
112 void OnSigninWithNewProfile() override { client_->created_ = true; } | |
113 | |
114 private: | |
115 ProfileSigninConfirmationViewControllerTest* client_; | |
116 | |
117 DISALLOW_COPY_AND_ASSIGN(TestSigninDelegate); | |
118 }; | |
119 | |
120 DISALLOW_COPY_AND_ASSIGN(ProfileSigninConfirmationViewControllerTest); | 85 DISALLOW_COPY_AND_ASSIGN(ProfileSigninConfirmationViewControllerTest); |
121 }; | 86 }; |
122 | 87 |
123 IN_PROC_BROWSER_TEST_F(ProfileSigninConfirmationViewControllerTest, | 88 IN_PROC_BROWSER_TEST_F(ProfileSigninConfirmationViewControllerTest, |
124 ContinueClicked) { | 89 ContinueClicked) { |
125 SetupDialog(); | 90 SetupDialog(); |
126 | 91 |
127 // Click should invoke and clear delegate and close the dialog. | 92 // Click should invoke and clear delegate and close the dialog. |
128 [controller_ ok:nil]; | 93 [controller_ ok:nil]; |
129 EXPECT_TRUE(continued_); | 94 EXPECT_TRUE(continued_); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 EXPECT_NSNE(nil, [controller_ createProfileButton]); | 178 EXPECT_NSNE(nil, [controller_ createProfileButton]); |
214 EXPECT_TRUE([[[controller_ view] subviews] | 179 EXPECT_TRUE([[[controller_ view] subviews] |
215 containsObject:[controller_ createProfileButton]]); | 180 containsObject:[controller_ createProfileButton]]); |
216 NSString* explanationWithCreateProfile = base::SysUTF16ToNSString( | 181 NSString* explanationWithCreateProfile = base::SysUTF16ToNSString( |
217 l10n_util::GetStringFUTF16( | 182 l10n_util::GetStringFUTF16( |
218 IDS_ENTERPRISE_SIGNIN_EXPLANATION_WITH_PROFILE_CREATION, | 183 IDS_ENTERPRISE_SIGNIN_EXPLANATION_WITH_PROFILE_CREATION, |
219 base::UTF8ToUTF16(username()), learn_more())); | 184 base::UTF8ToUTF16(username()), learn_more())); |
220 EXPECT_NSEQ(explanationWithCreateProfile, | 185 EXPECT_NSEQ(explanationWithCreateProfile, |
221 [[[controller_ explanationField] textStorage] string]); | 186 [[[controller_ explanationField] textStorage] string]); |
222 } | 187 } |
OLD | NEW |