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 | 6 |
7 #import "base/mac/scoped_nsobject.h" | 7 #import "base/mac/scoped_nsobject.h" |
8 #import "base/strings/string_util.h" | 8 #import "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #import "chrome/app/chrome_command_ids.h" // For translate menu command ids. | |
11 #include "chrome/browser/infobars/infobar_service.h" | 10 #include "chrome/browser/infobars/infobar_service.h" |
12 #import "chrome/browser/translate/translate_infobar_delegate.h" | |
13 #import "chrome/browser/translate/translate_tab_helper.h" | 11 #import "chrome/browser/translate/translate_tab_helper.h" |
14 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" | 12 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" |
15 #import "chrome/browser/ui/cocoa/infobars/before_translate_infobar_controller.h" | 13 #import "chrome/browser/ui/cocoa/infobars/before_translate_infobar_controller.h" |
16 #import "chrome/browser/ui/cocoa/infobars/infobar_cocoa.h" | 14 #import "chrome/browser/ui/cocoa/infobars/infobar_cocoa.h" |
17 #import "chrome/browser/ui/cocoa/infobars/translate_infobar_base.h" | 15 #import "chrome/browser/ui/cocoa/infobars/translate_infobar_base.h" |
18 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
| 17 #import "components/translate/core/browser/options_menu_model.h" |
| 18 #import "components/translate/core/browser/translate_infobar_delegate.h" |
19 #include "components/translate/core/browser/translate_language_list.h" | 19 #include "components/translate/core/browser/translate_language_list.h" |
20 #include "components/translate/core/browser/translate_manager.h" | 20 #include "components/translate/core/browser/translate_manager.h" |
21 #import "content/public/browser/web_contents.h" | 21 #import "content/public/browser/web_contents.h" |
22 #include "ipc/ipc_message.h" | 22 #include "ipc/ipc_message.h" |
23 #import "testing/gmock/include/gmock/gmock.h" | 23 #import "testing/gmock/include/gmock/gmock.h" |
24 #import "testing/gtest/include/gtest/gtest.h" | 24 #import "testing/gtest/include/gtest/gtest.h" |
25 #import "testing/platform_test.h" | 25 #import "testing/platform_test.h" |
26 | 26 |
27 using content::WebContents; | 27 using content::WebContents; |
28 | 28 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 } | 89 } |
90 CocoaProfileTest::TearDown(); | 90 CocoaProfileTest::TearDown(); |
91 } | 91 } |
92 | 92 |
93 void CreateInfoBar(translate::TranslateStep type) { | 93 void CreateInfoBar(translate::TranslateStep type) { |
94 TranslateErrors::Type error = TranslateErrors::NONE; | 94 TranslateErrors::Type error = TranslateErrors::NONE; |
95 if (type == translate::TRANSLATE_STEP_TRANSLATE_ERROR) | 95 if (type == translate::TRANSLATE_STEP_TRANSLATE_ERROR) |
96 error = TranslateErrors::NETWORK; | 96 error = TranslateErrors::NETWORK; |
97 [[infobar_controller_ view] removeFromSuperview]; | 97 [[infobar_controller_ view] removeFromSuperview]; |
98 | 98 |
| 99 TranslateTabHelper* translate_tab_helper = |
| 100 TranslateTabHelper::FromWebContents(web_contents_.get()); |
99 scoped_ptr<TranslateInfoBarDelegate> delegate( | 101 scoped_ptr<TranslateInfoBarDelegate> delegate( |
100 new MockTranslateInfoBarDelegate(web_contents_.get(), type, error)); | 102 new MockTranslateInfoBarDelegate(web_contents_.get(), type, error)); |
101 scoped_ptr<infobars::InfoBar> infobar( | 103 scoped_ptr<infobars::InfoBar> infobar( |
102 TranslateInfoBarDelegate::CreateInfoBar(delegate.Pass())); | 104 translate_tab_helper->CreateInfoBar(delegate.Pass())); |
103 if (infobar_) | 105 if (infobar_) |
104 infobar_->CloseSoon(); | 106 infobar_->CloseSoon(); |
105 infobar_ = static_cast<InfoBarCocoa*>(infobar.release()); | 107 infobar_ = static_cast<InfoBarCocoa*>(infobar.release()); |
106 infobar_->SetOwner(InfoBarService::FromWebContents(web_contents_.get())); | 108 infobar_->SetOwner(InfoBarService::FromWebContents(web_contents_.get())); |
107 | 109 |
108 infobar_controller_.reset([static_cast<TranslateInfoBarControllerBase*>( | 110 infobar_controller_.reset([static_cast<TranslateInfoBarControllerBase*>( |
109 infobar_->controller()) retain]); | 111 infobar_->controller()) retain]); |
110 | 112 |
111 // We need to set the window to be wide so that the options button | 113 // We need to set the window to be wide so that the options button |
112 // doesn't overlap the other buttons. | 114 // doesn't overlap the other buttons. |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 | 198 |
197 { | 199 { |
198 EXPECT_CALL(*infobar_delegate(), ToggleSiteBlacklist()) | 200 EXPECT_CALL(*infobar_delegate(), ToggleSiteBlacklist()) |
199 .Times(1); | 201 .Times(1); |
200 [infobar_controller_ optionsMenuChanged:neverTranslateSiteItem]; | 202 [infobar_controller_ optionsMenuChanged:neverTranslateSiteItem]; |
201 } | 203 } |
202 | 204 |
203 { | 205 { |
204 // Can't mock these effectively, so just check that the tag is set | 206 // Can't mock these effectively, so just check that the tag is set |
205 // correctly. | 207 // correctly. |
206 EXPECT_EQ(IDC_TRANSLATE_REPORT_BAD_LANGUAGE_DETECTION, | 208 EXPECT_EQ(OptionsMenuModel::REPORT_BAD_DETECTION, |
207 [reportBadLanguageItem tag]); | 209 [reportBadLanguageItem tag]); |
208 EXPECT_EQ(IDC_TRANSLATE_OPTIONS_ABOUT, [aboutTranslateItem tag]); | 210 EXPECT_EQ(OptionsMenuModel::ABOUT_TRANSLATE, [aboutTranslateItem tag]); |
209 } | 211 } |
210 } | 212 } |
211 | 213 |
212 // Check that selecting a new item from the "Source Language" popup in "before | 214 // Check that selecting a new item from the "Source Language" popup in "before |
213 // translate" mode doesn't trigger a translation or change state. | 215 // translate" mode doesn't trigger a translation or change state. |
214 // http://crbug.com/36666 | 216 // http://crbug.com/36666 |
215 TEST_F(TranslationInfoBarTest, Bug36666) { | 217 TEST_F(TranslationInfoBarTest, Bug36666) { |
216 CreateInfoBar(translate::TRANSLATE_STEP_BEFORE_TRANSLATE); | 218 CreateInfoBar(translate::TRANSLATE_STEP_BEFORE_TRANSLATE); |
217 EXPECT_CALL(*infobar_delegate(), Translate()) | 219 EXPECT_CALL(*infobar_delegate(), Translate()) |
218 .Times(0); | 220 .Times(0); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 translate_prefs->ResetTranslationDeniedCount("en"); | 262 translate_prefs->ResetTranslationDeniedCount("en"); |
261 for (int i = 0; i < 4; ++i) { | 263 for (int i = 0; i < 4; ++i) { |
262 translate_prefs->IncrementTranslationDeniedCount("en"); | 264 translate_prefs->IncrementTranslationDeniedCount("en"); |
263 } | 265 } |
264 CreateInfoBar(translate::TRANSLATE_STEP_BEFORE_TRANSLATE); | 266 CreateInfoBar(translate::TRANSLATE_STEP_BEFORE_TRANSLATE); |
265 BeforeTranslateInfobarController* controller = | 267 BeforeTranslateInfobarController* controller = |
266 (BeforeTranslateInfobarController*)infobar_controller_.get(); | 268 (BeforeTranslateInfobarController*)infobar_controller_.get(); |
267 EXPECT_TRUE([[controller alwaysTranslateButton] superview] == nil); | 269 EXPECT_TRUE([[controller alwaysTranslateButton] superview] == nil); |
268 EXPECT_TRUE([[controller neverTranslateButton] superview] != nil); | 270 EXPECT_TRUE([[controller neverTranslateButton] superview] != nil); |
269 } | 271 } |
OLD | NEW |