| 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) |
| 22 |
| 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 |
| 21 class ProfileSigninConfirmationViewControllerTest | 45 class ProfileSigninConfirmationViewControllerTest |
| 22 : public InProcessBrowserTest, | 46 : public InProcessBrowserTest { |
| 23 public ui::ProfileSigninConfirmationDelegate { | |
| 24 | |
| 25 public: | 47 public: |
| 26 ProfileSigninConfirmationViewControllerTest() | 48 ProfileSigninConfirmationViewControllerTest() |
| 27 : window_(nil), | 49 : window_(nil), |
| 28 continued_(false), | 50 continued_(false), |
| 29 cancelled_(false), | 51 cancelled_(false), |
| 30 created_(false), | 52 created_(false), |
| 31 closed_(false) { | 53 closed_(false) { |
| 32 } | 54 } |
| 33 | 55 |
| 34 protected: | 56 protected: |
| 35 void SetUpOnMainThread() override {} | 57 void SetUpOnMainThread() override {} |
| 36 | 58 |
| 37 void SetupDialog(bool offerProfileCreation = true) { | 59 void SetupDialog(bool offerProfileCreation = true) { |
| 38 window_.reset( | 60 window_.reset( |
| 39 [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 400, 600) | 61 [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 400, 600) |
| 40 styleMask:NSBorderlessWindowMask | 62 styleMask:NSBorderlessWindowMask |
| 41 backing:NSBackingStoreBuffered | 63 backing:NSBackingStoreBuffered |
| 42 defer:NO]); | 64 defer:NO]); |
| 43 base::Closure close = base::Bind( | 65 base::Closure close = base::Bind( |
| 44 &ProfileSigninConfirmationViewControllerTest::OnClose, | 66 &ProfileSigninConfirmationViewControllerTest::OnClose, |
| 45 base::Unretained(this)); | 67 base::Unretained(this)); |
| 46 controller_.reset([[ProfileSigninConfirmationViewController alloc] | 68 controller_.reset([[ProfileSigninConfirmationViewController alloc] |
| 47 initWithBrowser:browser() | 69 initWithBrowser:browser() |
| 48 username:username() | 70 username:username() |
| 49 delegate:this | 71 delegate:base::MakeUnique<TestSigninDelegate>(this) |
| 50 closeDialogCallback:close | 72 closeDialogCallback:close |
| 51 offerProfileCreation:offerProfileCreation]); | 73 offerProfileCreation:offerProfileCreation]); |
| 52 [[window_ contentView] addSubview:[controller_ view]]; | 74 [[window_ contentView] addSubview:[controller_ view]]; |
| 53 [window_ makeKeyAndOrderFront:NSApp]; | 75 [window_ makeKeyAndOrderFront:NSApp]; |
| 54 ASSERT_TRUE([window_ isVisible]); | 76 ASSERT_TRUE([window_ isVisible]); |
| 55 } | 77 } |
| 56 | 78 |
| 57 // Test helpers. | 79 // Test helpers. |
| 58 std::string username() { | 80 std::string username() { |
| 59 return "foo@bar.com"; | 81 return "foo@bar.com"; |
| 60 } | 82 } |
| 61 base::string16 learn_more() { | 83 base::string16 learn_more() { |
| 62 return l10n_util::GetStringUTF16( | 84 return l10n_util::GetStringUTF16( |
| 63 IDS_ENTERPRISE_SIGNIN_PROFILE_LINK_LEARN_MORE); | 85 IDS_ENTERPRISE_SIGNIN_PROFILE_LINK_LEARN_MORE); |
| 64 } | 86 } |
| 65 | 87 |
| 66 // ui::ProfileSigninConfirmationDelegate: | |
| 67 void OnContinueSignin() override { continued_ = true; } | |
| 68 void OnCancelSignin() override { cancelled_ = true; } | |
| 69 void OnSigninWithNewProfile() override { created_ = true; } | |
| 70 void OnClose() { closed_ = true; } | 88 void OnClose() { closed_ = true; } |
| 71 | 89 |
| 72 // The window containing the dialog. | 90 // The window containing the dialog. |
| 73 base::scoped_nsobject<NSWindow> window_; | 91 base::scoped_nsobject<NSWindow> window_; |
| 74 | 92 |
| 75 // Dialog under test. | 93 // Dialog under test. |
| 76 base::scoped_nsobject<ProfileSigninConfirmationViewController> controller_; | 94 base::scoped_nsobject<ProfileSigninConfirmationViewController> controller_; |
| 77 | 95 |
| 78 // Visible for testing UI interactions. | 96 // Visible for testing UI interactions. |
| 79 bool continued_; | 97 bool continued_; |
| 80 bool cancelled_; | 98 bool cancelled_; |
| 81 bool created_; | 99 bool created_; |
| 82 bool closed_; | 100 bool closed_; |
| 83 | 101 |
| 84 private: | 102 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 |
| 85 DISALLOW_COPY_AND_ASSIGN(ProfileSigninConfirmationViewControllerTest); | 120 DISALLOW_COPY_AND_ASSIGN(ProfileSigninConfirmationViewControllerTest); |
| 86 }; | 121 }; |
| 87 | 122 |
| 88 IN_PROC_BROWSER_TEST_F(ProfileSigninConfirmationViewControllerTest, | 123 IN_PROC_BROWSER_TEST_F(ProfileSigninConfirmationViewControllerTest, |
| 89 ContinueClicked) { | 124 ContinueClicked) { |
| 90 SetupDialog(); | 125 SetupDialog(); |
| 91 | 126 |
| 92 // Click should invoke and clear delegate and close the dialog. | 127 // Click should invoke and clear delegate and close the dialog. |
| 93 [controller_ ok:nil]; | 128 [controller_ ok:nil]; |
| 94 EXPECT_TRUE(continued_); | 129 EXPECT_TRUE(continued_); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 EXPECT_NSNE(nil, [controller_ createProfileButton]); | 213 EXPECT_NSNE(nil, [controller_ createProfileButton]); |
| 179 EXPECT_TRUE([[[controller_ view] subviews] | 214 EXPECT_TRUE([[[controller_ view] subviews] |
| 180 containsObject:[controller_ createProfileButton]]); | 215 containsObject:[controller_ createProfileButton]]); |
| 181 NSString* explanationWithCreateProfile = base::SysUTF16ToNSString( | 216 NSString* explanationWithCreateProfile = base::SysUTF16ToNSString( |
| 182 l10n_util::GetStringFUTF16( | 217 l10n_util::GetStringFUTF16( |
| 183 IDS_ENTERPRISE_SIGNIN_EXPLANATION_WITH_PROFILE_CREATION, | 218 IDS_ENTERPRISE_SIGNIN_EXPLANATION_WITH_PROFILE_CREATION, |
| 184 base::UTF8ToUTF16(username()), learn_more())); | 219 base::UTF8ToUTF16(username()), learn_more())); |
| 185 EXPECT_NSEQ(explanationWithCreateProfile, | 220 EXPECT_NSEQ(explanationWithCreateProfile, |
| 186 [[[controller_ explanationField] textStorage] string]); | 221 [[[controller_ explanationField] textStorage] string]); |
| 187 } | 222 } |
| OLD | NEW |