| 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. | 10 #import "chrome/app/chrome_command_ids.h" // For translate menu command ids. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 translate::TranslateStep kTranslateToolbarStates[] = { | 32 translate::TranslateStep kTranslateToolbarStates[] = { |
| 33 translate::TRANSLATE_STEP_BEFORE_TRANSLATE, | 33 translate::TRANSLATE_STEP_BEFORE_TRANSLATE, |
| 34 translate::TRANSLATE_STEP_AFTER_TRANSLATE, | 34 translate::TRANSLATE_STEP_AFTER_TRANSLATE, |
| 35 translate::TRANSLATE_STEP_TRANSLATING, | 35 translate::TRANSLATE_STEP_TRANSLATING, |
| 36 translate::TRANSLATE_STEP_TRANSLATE_ERROR}; | 36 translate::TRANSLATE_STEP_TRANSLATE_ERROR}; |
| 37 | 37 |
| 38 class MockTranslateInfoBarDelegate : public TranslateInfoBarDelegate { | 38 class MockTranslateInfoBarDelegate : public TranslateInfoBarDelegate { |
| 39 public: | 39 public: |
| 40 MockTranslateInfoBarDelegate(content::WebContents* web_contents, | 40 MockTranslateInfoBarDelegate(content::WebContents* web_contents, |
| 41 translate::TranslateStep step, | 41 translate::TranslateStep step, |
| 42 TranslateErrors::Type error, | 42 TranslateErrors::Type error) |
| 43 PrefService* prefs) | |
| 44 : TranslateInfoBarDelegate( | 43 : TranslateInfoBarDelegate( |
| 45 TranslateTabHelper::GetManagerFromWebContents( | 44 TranslateTabHelper::GetManagerFromWebContents( |
| 46 web_contents)->GetWeakPtr(), | 45 web_contents)->GetWeakPtr(), |
| 47 false, | 46 false, |
| 48 step, | 47 step, |
| 49 NULL, | 48 NULL, |
| 50 "en", | 49 "en", |
| 51 "es", | 50 "es", |
| 52 error, | 51 error, |
| 53 prefs, | |
| 54 false) {} | 52 false) {} |
| 55 | 53 |
| 56 MOCK_METHOD0(Translate, void()); | 54 MOCK_METHOD0(Translate, void()); |
| 57 MOCK_METHOD0(RevertTranslation, void()); | 55 MOCK_METHOD0(RevertTranslation, void()); |
| 58 | 56 |
| 59 MOCK_METHOD0(TranslationDeclined, void()); | 57 MOCK_METHOD0(TranslationDeclined, void()); |
| 60 | 58 |
| 61 virtual bool IsTranslatableLanguageByPrefs() OVERRIDE { return true; } | 59 virtual bool IsTranslatableLanguageByPrefs() OVERRIDE { return true; } |
| 62 MOCK_METHOD0(ToggleTranslatableLanguageByPrefs, void()); | 60 MOCK_METHOD0(ToggleTranslatableLanguageByPrefs, void()); |
| 63 virtual bool IsSiteBlacklisted() OVERRIDE { return false; } | 61 virtual bool IsSiteBlacklisted() OVERRIDE { return false; } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 89 infobar_->CloseSoon(); | 87 infobar_->CloseSoon(); |
| 90 infobar_ = NULL; | 88 infobar_ = NULL; |
| 91 } | 89 } |
| 92 CocoaProfileTest::TearDown(); | 90 CocoaProfileTest::TearDown(); |
| 93 } | 91 } |
| 94 | 92 |
| 95 void CreateInfoBar(translate::TranslateStep type) { | 93 void CreateInfoBar(translate::TranslateStep type) { |
| 96 TranslateErrors::Type error = TranslateErrors::NONE; | 94 TranslateErrors::Type error = TranslateErrors::NONE; |
| 97 if (type == translate::TRANSLATE_STEP_TRANSLATE_ERROR) | 95 if (type == translate::TRANSLATE_STEP_TRANSLATE_ERROR) |
| 98 error = TranslateErrors::NETWORK; | 96 error = TranslateErrors::NETWORK; |
| 99 Profile* profile = | |
| 100 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | |
| 101 [[infobar_controller_ view] removeFromSuperview]; | 97 [[infobar_controller_ view] removeFromSuperview]; |
| 102 | 98 |
| 103 scoped_ptr<TranslateInfoBarDelegate> delegate( | 99 scoped_ptr<TranslateInfoBarDelegate> delegate( |
| 104 new MockTranslateInfoBarDelegate(web_contents_.get(), type, error, | 100 new MockTranslateInfoBarDelegate(web_contents_.get(), type, error)); |
| 105 profile->GetPrefs())); | |
| 106 scoped_ptr<infobars::InfoBar> infobar( | 101 scoped_ptr<infobars::InfoBar> infobar( |
| 107 TranslateInfoBarDelegate::CreateInfoBar(delegate.Pass())); | 102 TranslateInfoBarDelegate::CreateInfoBar(delegate.Pass())); |
| 108 if (infobar_) | 103 if (infobar_) |
| 109 infobar_->CloseSoon(); | 104 infobar_->CloseSoon(); |
| 110 infobar_ = static_cast<InfoBarCocoa*>(infobar.release()); | 105 infobar_ = static_cast<InfoBarCocoa*>(infobar.release()); |
| 111 infobar_->SetOwner(InfoBarService::FromWebContents(web_contents_.get())); | 106 infobar_->SetOwner(InfoBarService::FromWebContents(web_contents_.get())); |
| 112 | 107 |
| 113 infobar_controller_.reset([static_cast<TranslateInfoBarControllerBase*>( | 108 infobar_controller_.reset([static_cast<TranslateInfoBarControllerBase*>( |
| 114 infobar_->controller()) retain]); | 109 infobar_->controller()) retain]); |
| 115 | 110 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 translate_prefs->ResetTranslationDeniedCount("en"); | 260 translate_prefs->ResetTranslationDeniedCount("en"); |
| 266 for (int i = 0; i < 4; ++i) { | 261 for (int i = 0; i < 4; ++i) { |
| 267 translate_prefs->IncrementTranslationDeniedCount("en"); | 262 translate_prefs->IncrementTranslationDeniedCount("en"); |
| 268 } | 263 } |
| 269 CreateInfoBar(translate::TRANSLATE_STEP_BEFORE_TRANSLATE); | 264 CreateInfoBar(translate::TRANSLATE_STEP_BEFORE_TRANSLATE); |
| 270 BeforeTranslateInfobarController* controller = | 265 BeforeTranslateInfobarController* controller = |
| 271 (BeforeTranslateInfobarController*)infobar_controller_.get(); | 266 (BeforeTranslateInfobarController*)infobar_controller_.get(); |
| 272 EXPECT_TRUE([[controller alwaysTranslateButton] superview] == nil); | 267 EXPECT_TRUE([[controller alwaysTranslateButton] superview] == nil); |
| 273 EXPECT_TRUE([[controller neverTranslateButton] superview] != nil); | 268 EXPECT_TRUE([[controller neverTranslateButton] superview] != nil); |
| 274 } | 269 } |
| OLD | NEW |