| 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 18 matching lines...) Expand all Loading... |
| 29 // All states the translate toolbar can assume. | 29 // All states the translate toolbar can assume. |
| 30 TranslateInfoBarDelegate::Type kTranslateToolbarStates[] = { | 30 TranslateInfoBarDelegate::Type kTranslateToolbarStates[] = { |
| 31 TranslateInfoBarDelegate::BEFORE_TRANSLATE, | 31 TranslateInfoBarDelegate::BEFORE_TRANSLATE, |
| 32 TranslateInfoBarDelegate::AFTER_TRANSLATE, | 32 TranslateInfoBarDelegate::AFTER_TRANSLATE, |
| 33 TranslateInfoBarDelegate::TRANSLATING, | 33 TranslateInfoBarDelegate::TRANSLATING, |
| 34 TranslateInfoBarDelegate::TRANSLATION_ERROR | 34 TranslateInfoBarDelegate::TRANSLATION_ERROR |
| 35 }; | 35 }; |
| 36 | 36 |
| 37 class MockTranslateInfoBarDelegate : public TranslateInfoBarDelegate { | 37 class MockTranslateInfoBarDelegate : public TranslateInfoBarDelegate { |
| 38 public: | 38 public: |
| 39 MockTranslateInfoBarDelegate(TranslateInfoBarDelegate::Type type, | 39 MockTranslateInfoBarDelegate(content::WebContents* web_contents, |
| 40 TranslateInfoBarDelegate::Type type, |
| 40 TranslateErrors::Type error, | 41 TranslateErrors::Type error, |
| 41 PrefService* prefs, | 42 PrefService* prefs, |
| 42 ShortcutConfiguration config) | 43 ShortcutConfiguration config) |
| 43 : TranslateInfoBarDelegate(type, NULL, "en", "es", error, prefs, config) { | 44 : TranslateInfoBarDelegate(web_contents, type, NULL, "en", "es", error, |
| 45 prefs, config) { |
| 44 } | 46 } |
| 45 | 47 |
| 46 MOCK_METHOD0(Translate, void()); | 48 MOCK_METHOD0(Translate, void()); |
| 47 MOCK_METHOD0(RevertTranslation, void()); | 49 MOCK_METHOD0(RevertTranslation, void()); |
| 48 | 50 |
| 49 MOCK_METHOD0(TranslationDeclined, void()); | 51 MOCK_METHOD0(TranslationDeclined, void()); |
| 50 | 52 |
| 51 virtual bool IsTranslatableLanguageByPrefs() OVERRIDE { return true; } | 53 virtual bool IsTranslatableLanguageByPrefs() OVERRIDE { return true; } |
| 52 MOCK_METHOD0(ToggleTranslatableLanguageByPrefs, void()); | 54 MOCK_METHOD0(ToggleTranslatableLanguageByPrefs, void()); |
| 53 virtual bool IsSiteBlacklisted() OVERRIDE { return false; } | 55 virtual bool IsSiteBlacklisted() OVERRIDE { return false; } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 if (type == TranslateInfoBarDelegate::TRANSLATION_ERROR) | 88 if (type == TranslateInfoBarDelegate::TRANSLATION_ERROR) |
| 87 error = TranslateErrors::NETWORK; | 89 error = TranslateErrors::NETWORK; |
| 88 Profile* profile = | 90 Profile* profile = |
| 89 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | 91 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
| 90 ShortcutConfiguration config; | 92 ShortcutConfiguration config; |
| 91 config.never_translate_min_count = 3; | 93 config.never_translate_min_count = 3; |
| 92 config.always_translate_min_count = 3; | 94 config.always_translate_min_count = 3; |
| 93 [[infobar_controller_ view] removeFromSuperview]; | 95 [[infobar_controller_ view] removeFromSuperview]; |
| 94 | 96 |
| 95 scoped_ptr<TranslateInfoBarDelegate> delegate( | 97 scoped_ptr<TranslateInfoBarDelegate> delegate( |
| 96 new MockTranslateInfoBarDelegate(type, error, profile->GetPrefs(), | 98 new MockTranslateInfoBarDelegate(web_contents_.get(), type, error, |
| 97 config)); | 99 profile->GetPrefs(), config)); |
| 98 scoped_ptr<InfoBar> infobar( | 100 scoped_ptr<InfoBar> infobar( |
| 99 TranslateInfoBarDelegate::CreateInfoBar(delegate.Pass())); | 101 TranslateInfoBarDelegate::CreateInfoBar(delegate.Pass())); |
| 100 if (infobar_) | 102 if (infobar_) |
| 101 infobar_->CloseSoon(); | 103 infobar_->CloseSoon(); |
| 102 infobar_ = static_cast<InfoBarCocoa*>(infobar.release()); | 104 infobar_ = static_cast<InfoBarCocoa*>(infobar.release()); |
| 103 infobar_->SetOwner(InfoBarService::FromWebContents(web_contents_.get())); | 105 infobar_->SetOwner(InfoBarService::FromWebContents(web_contents_.get())); |
| 104 | 106 |
| 105 infobar_controller_.reset([static_cast<TranslateInfoBarControllerBase*>( | 107 infobar_controller_.reset([static_cast<TranslateInfoBarControllerBase*>( |
| 106 infobar_->controller()) retain]); | 108 infobar_->controller()) retain]); |
| 107 | 109 |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 translate_prefs.ResetTranslationDeniedCount("en"); | 257 translate_prefs.ResetTranslationDeniedCount("en"); |
| 256 for (int i = 0; i < 4; ++i) { | 258 for (int i = 0; i < 4; ++i) { |
| 257 translate_prefs.IncrementTranslationDeniedCount("en"); | 259 translate_prefs.IncrementTranslationDeniedCount("en"); |
| 258 } | 260 } |
| 259 CreateInfoBar(TranslateInfoBarDelegate::BEFORE_TRANSLATE); | 261 CreateInfoBar(TranslateInfoBarDelegate::BEFORE_TRANSLATE); |
| 260 BeforeTranslateInfobarController* controller = | 262 BeforeTranslateInfobarController* controller = |
| 261 (BeforeTranslateInfobarController*)infobar_controller_.get(); | 263 (BeforeTranslateInfobarController*)infobar_controller_.get(); |
| 262 EXPECT_TRUE([[controller alwaysTranslateButton] superview] == nil); | 264 EXPECT_TRUE([[controller alwaysTranslateButton] superview] == nil); |
| 263 EXPECT_TRUE([[controller neverTranslateButton] superview] != nil); | 265 EXPECT_TRUE([[controller neverTranslateButton] superview] != nil); |
| 264 } | 266 } |
| OLD | NEW |