OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
6 #include <stddef.h> | 6 #include <stddef.h> |
7 | 7 |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #import "base/mac/scoped_nsobject.h" | 10 #import "base/mac/scoped_nsobject.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 } | 96 } |
97 | 97 |
98 void CreateInfoBar(translate::TranslateStep type) { | 98 void CreateInfoBar(translate::TranslateStep type) { |
99 translate::TranslateErrors::Type error = translate::TranslateErrors::NONE; | 99 translate::TranslateErrors::Type error = translate::TranslateErrors::NONE; |
100 if (type == translate::TRANSLATE_STEP_TRANSLATE_ERROR) | 100 if (type == translate::TRANSLATE_STEP_TRANSLATE_ERROR) |
101 error = translate::TranslateErrors::NETWORK; | 101 error = translate::TranslateErrors::NETWORK; |
102 [[infobar_controller_ view] removeFromSuperview]; | 102 [[infobar_controller_ view] removeFromSuperview]; |
103 | 103 |
104 ChromeTranslateClient* chrome_translate_client = | 104 ChromeTranslateClient* chrome_translate_client = |
105 ChromeTranslateClient::FromWebContents(web_contents_.get()); | 105 ChromeTranslateClient::FromWebContents(web_contents_.get()); |
106 scoped_ptr<translate::TranslateInfoBarDelegate> delegate( | 106 std::unique_ptr<translate::TranslateInfoBarDelegate> delegate( |
107 new MockTranslateInfoBarDelegate(web_contents_.get(), type, error)); | 107 new MockTranslateInfoBarDelegate(web_contents_.get(), type, error)); |
108 scoped_ptr<infobars::InfoBar> infobar( | 108 std::unique_ptr<infobars::InfoBar> infobar( |
109 chrome_translate_client->CreateInfoBar(std::move(delegate))); | 109 chrome_translate_client->CreateInfoBar(std::move(delegate))); |
110 if (infobar_) | 110 if (infobar_) |
111 infobar_->CloseSoon(); | 111 infobar_->CloseSoon(); |
112 infobar_ = static_cast<InfoBarCocoa*>(infobar.release()); | 112 infobar_ = static_cast<InfoBarCocoa*>(infobar.release()); |
113 infobar_->SetOwner(InfoBarService::FromWebContents(web_contents_.get())); | 113 infobar_->SetOwner(InfoBarService::FromWebContents(web_contents_.get())); |
114 | 114 |
115 infobar_controller_.reset([static_cast<TranslateInfoBarControllerBase*>( | 115 infobar_controller_.reset([static_cast<TranslateInfoBarControllerBase*>( |
116 infobar_->controller()) retain]); | 116 infobar_->controller()) retain]); |
117 | 117 |
118 // We need to set the window to be wide so that the options button | 118 // We need to set the window to be wide so that the options button |
119 // doesn't overlap the other buttons. | 119 // doesn't overlap the other buttons. |
120 [test_window() setContentSize:NSMakeSize(2000, 500)]; | 120 [test_window() setContentSize:NSMakeSize(2000, 500)]; |
121 [[infobar_controller_ view] setFrame:NSMakeRect(0, 0, 2000, 500)]; | 121 [[infobar_controller_ view] setFrame:NSMakeRect(0, 0, 2000, 500)]; |
122 [[test_window() contentView] addSubview:[infobar_controller_ view]]; | 122 [[test_window() contentView] addSubview:[infobar_controller_ view]]; |
123 } | 123 } |
124 | 124 |
125 MockTranslateInfoBarDelegate* infobar_delegate() const { | 125 MockTranslateInfoBarDelegate* infobar_delegate() const { |
126 return static_cast<MockTranslateInfoBarDelegate*>(infobar_->delegate()); | 126 return static_cast<MockTranslateInfoBarDelegate*>(infobar_->delegate()); |
127 } | 127 } |
128 | 128 |
129 scoped_ptr<WebContents> web_contents_; | 129 std::unique_ptr<WebContents> web_contents_; |
130 InfoBarCocoa* infobar_; // weak, deletes itself | 130 InfoBarCocoa* infobar_; // weak, deletes itself |
131 base::scoped_nsobject<TranslateInfoBarControllerBase> infobar_controller_; | 131 base::scoped_nsobject<TranslateInfoBarControllerBase> infobar_controller_; |
132 }; | 132 }; |
133 | 133 |
134 // Check that we can instantiate a Translate Infobar correctly. | 134 // Check that we can instantiate a Translate Infobar correctly. |
135 TEST_F(TranslationInfoBarTest, Instantiate) { | 135 TEST_F(TranslationInfoBarTest, Instantiate) { |
136 CreateInfoBar(translate::TRANSLATE_STEP_BEFORE_TRANSLATE); | 136 CreateInfoBar(translate::TRANSLATE_STEP_BEFORE_TRANSLATE); |
137 ASSERT_TRUE(infobar_controller_.get()); | 137 ASSERT_TRUE(infobar_controller_.get()); |
138 } | 138 } |
139 | 139 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 EXPECT_CALL(*infobar_delegate(), Translate()) | 242 EXPECT_CALL(*infobar_delegate(), Translate()) |
243 .Times(0); | 243 .Times(0); |
244 EXPECT_TRUE( | 244 EXPECT_TRUE( |
245 [infobar_controller_ verifyLayout]) << "Layout wrong, for state #" << i; | 245 [infobar_controller_ verifyLayout]) << "Layout wrong, for state #" << i; |
246 } | 246 } |
247 } | 247 } |
248 | 248 |
249 // Verify that the infobar shows the "Always translate this language" button | 249 // Verify that the infobar shows the "Always translate this language" button |
250 // after doing 3 translations. | 250 // after doing 3 translations. |
251 TEST_F(TranslationInfoBarTest, TriggerShowAlwaysTranslateButton) { | 251 TEST_F(TranslationInfoBarTest, TriggerShowAlwaysTranslateButton) { |
252 scoped_ptr<translate::TranslatePrefs> translate_prefs( | 252 std::unique_ptr<translate::TranslatePrefs> translate_prefs( |
253 ChromeTranslateClient::CreateTranslatePrefs(profile()->GetPrefs())); | 253 ChromeTranslateClient::CreateTranslatePrefs(profile()->GetPrefs())); |
254 translate_prefs->ResetTranslationAcceptedCount("en"); | 254 translate_prefs->ResetTranslationAcceptedCount("en"); |
255 for (int i = 0; i < 4; ++i) { | 255 for (int i = 0; i < 4; ++i) { |
256 translate_prefs->IncrementTranslationAcceptedCount("en"); | 256 translate_prefs->IncrementTranslationAcceptedCount("en"); |
257 } | 257 } |
258 CreateInfoBar(translate::TRANSLATE_STEP_BEFORE_TRANSLATE); | 258 CreateInfoBar(translate::TRANSLATE_STEP_BEFORE_TRANSLATE); |
259 BeforeTranslateInfobarController* controller = | 259 BeforeTranslateInfobarController* controller = |
260 (BeforeTranslateInfobarController*)infobar_controller_.get(); | 260 (BeforeTranslateInfobarController*)infobar_controller_.get(); |
261 EXPECT_TRUE([[controller alwaysTranslateButton] superview] != nil); | 261 EXPECT_TRUE([[controller alwaysTranslateButton] superview] != nil); |
262 EXPECT_TRUE([[controller neverTranslateButton] superview] == nil); | 262 EXPECT_TRUE([[controller neverTranslateButton] superview] == nil); |
263 } | 263 } |
264 | 264 |
265 // Verify that the infobar shows the "Never translate this language" button | 265 // Verify that the infobar shows the "Never translate this language" button |
266 // after denying 3 translations. | 266 // after denying 3 translations. |
267 TEST_F(TranslationInfoBarTest, TriggerShowNeverTranslateButton) { | 267 TEST_F(TranslationInfoBarTest, TriggerShowNeverTranslateButton) { |
268 scoped_ptr<translate::TranslatePrefs> translate_prefs( | 268 std::unique_ptr<translate::TranslatePrefs> translate_prefs( |
269 ChromeTranslateClient::CreateTranslatePrefs(profile()->GetPrefs())); | 269 ChromeTranslateClient::CreateTranslatePrefs(profile()->GetPrefs())); |
270 translate_prefs->ResetTranslationDeniedCount("en"); | 270 translate_prefs->ResetTranslationDeniedCount("en"); |
271 for (int i = 0; i < 4; ++i) { | 271 for (int i = 0; i < 4; ++i) { |
272 translate_prefs->IncrementTranslationDeniedCount("en"); | 272 translate_prefs->IncrementTranslationDeniedCount("en"); |
273 } | 273 } |
274 CreateInfoBar(translate::TRANSLATE_STEP_BEFORE_TRANSLATE); | 274 CreateInfoBar(translate::TRANSLATE_STEP_BEFORE_TRANSLATE); |
275 BeforeTranslateInfobarController* controller = | 275 BeforeTranslateInfobarController* controller = |
276 (BeforeTranslateInfobarController*)infobar_controller_.get(); | 276 (BeforeTranslateInfobarController*)infobar_controller_.get(); |
277 EXPECT_TRUE([[controller alwaysTranslateButton] superview] == nil); | 277 EXPECT_TRUE([[controller alwaysTranslateButton] superview] == nil); |
278 EXPECT_TRUE([[controller neverTranslateButton] superview] != nil); | 278 EXPECT_TRUE([[controller neverTranslateButton] superview] != nil); |
279 } | 279 } |
OLD | NEW |