| 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. |
| 11 #include "chrome/browser/infobars/infobar_service.h" | 11 #include "chrome/browser/infobars/infobar_service.h" |
| 12 #import "chrome/browser/translate/translate_infobar_delegate.h" | 12 #import "chrome/browser/translate/translate_infobar_delegate.h" |
| 13 #include "chrome/browser/translate/translate_language_list.h" | 13 #include "chrome/browser/translate/translate_language_list.h" |
| 14 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" | 14 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" |
| 15 #import "chrome/browser/ui/cocoa/infobars/before_translate_infobar_controller.h" | 15 #import "chrome/browser/ui/cocoa/infobars/before_translate_infobar_controller.h" |
| 16 #import "chrome/browser/ui/cocoa/infobars/infobar.h" | 16 #import "chrome/browser/ui/cocoa/infobars/infobar_cocoa.h" |
| 17 #import "chrome/browser/ui/cocoa/infobars/translate_infobar_base.h" | 17 #import "chrome/browser/ui/cocoa/infobars/translate_infobar_base.h" |
| 18 #import "content/public/browser/web_contents.h" | 18 #import "content/public/browser/web_contents.h" |
| 19 #include "ipc/ipc_message.h" | 19 #include "ipc/ipc_message.h" |
| 20 #import "testing/gmock/include/gmock/gmock.h" | 20 #import "testing/gmock/include/gmock/gmock.h" |
| 21 #import "testing/gtest/include/gtest/gtest.h" | 21 #import "testing/gtest/include/gtest/gtest.h" |
| 22 #import "testing/platform_test.h" | 22 #import "testing/platform_test.h" |
| 23 | 23 |
| 24 using content::WebContents; | 24 using content::WebContents; |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 InfoBarService* infobar_service = | 81 InfoBarService* infobar_service = |
| 82 InfoBarService::FromWebContents(web_contents_.get()); | 82 InfoBarService::FromWebContents(web_contents_.get()); |
| 83 Profile* profile = | 83 Profile* profile = |
| 84 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | 84 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
| 85 ShortcutConfiguration config; | 85 ShortcutConfiguration config; |
| 86 config.never_translate_min_count = 3; | 86 config.never_translate_min_count = 3; |
| 87 config.always_translate_min_count = 3; | 87 config.always_translate_min_count = 3; |
| 88 infobar_delegate_.reset(new MockTranslateInfoBarDelegate( | 88 infobar_delegate_.reset(new MockTranslateInfoBarDelegate( |
| 89 infobar_service, type, error, profile->GetPrefs(), config)); | 89 infobar_service, type, error, profile->GetPrefs(), config)); |
| 90 [[infobar_controller_ view] removeFromSuperview]; | 90 [[infobar_controller_ view] removeFromSuperview]; |
| 91 scoped_ptr<InfoBar> infobar(static_cast<InfoBarDelegate*>( | 91 |
| 92 infobar_delegate_.get())->CreateInfoBar(infobar_service)); | 92 InfoBarDelegate* base = |
| 93 infobar_controller_.reset(reinterpret_cast<TranslateInfoBarControllerBase*>( | 93 static_cast<InfoBarDelegate*>(infobar_delegate_.get()); |
| 94 infobar->controller())); | 94 infobar_.reset( |
| 95 static_cast<InfoBarCocoa*>(base->CreateInfoBar(infobar_service))); |
| 96 infobar_controller_.reset([static_cast<TranslateInfoBarControllerBase*>( |
| 97 infobar_->controller()) retain]); |
| 98 |
| 95 // We need to set the window to be wide so that the options button | 99 // We need to set the window to be wide so that the options button |
| 96 // doesn't overlap the other buttons. | 100 // doesn't overlap the other buttons. |
| 97 [test_window() setContentSize:NSMakeSize(2000, 500)]; | 101 [test_window() setContentSize:NSMakeSize(2000, 500)]; |
| 98 [[infobar_controller_ view] setFrame:NSMakeRect(0, 0, 2000, 500)]; | 102 [[infobar_controller_ view] setFrame:NSMakeRect(0, 0, 2000, 500)]; |
| 99 [[test_window() contentView] addSubview:[infobar_controller_ view]]; | 103 [[test_window() contentView] addSubview:[infobar_controller_ view]]; |
| 100 } | 104 } |
| 101 | 105 |
| 102 scoped_ptr<WebContents> web_contents_; | 106 scoped_ptr<WebContents> web_contents_; |
| 103 scoped_ptr<MockTranslateInfoBarDelegate> infobar_delegate_; | 107 scoped_ptr<MockTranslateInfoBarDelegate> infobar_delegate_; |
| 108 scoped_ptr<InfoBarCocoa> infobar_; |
| 104 base::scoped_nsobject<TranslateInfoBarControllerBase> infobar_controller_; | 109 base::scoped_nsobject<TranslateInfoBarControllerBase> infobar_controller_; |
| 105 }; | 110 }; |
| 106 | 111 |
| 107 // Check that we can instantiate a Translate Infobar correctly. | 112 // Check that we can instantiate a Translate Infobar correctly. |
| 108 TEST_F(TranslationInfoBarTest, Instantiate) { | 113 TEST_F(TranslationInfoBarTest, Instantiate) { |
| 109 CreateInfoBar(); | 114 CreateInfoBar(); |
| 110 ASSERT_TRUE(infobar_controller_.get()); | 115 ASSERT_TRUE(infobar_controller_.get()); |
| 111 } | 116 } |
| 112 | 117 |
| 113 // Check that clicking the Translate button calls Translate(). | 118 // Check that clicking the Translate button calls Translate(). |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 translate_prefs.IncrementTranslationDeniedCount("en"); | 245 translate_prefs.IncrementTranslationDeniedCount("en"); |
| 241 } | 246 } |
| 242 CreateInfoBar(TranslateInfoBarDelegate::BEFORE_TRANSLATE); | 247 CreateInfoBar(TranslateInfoBarDelegate::BEFORE_TRANSLATE); |
| 243 BeforeTranslateInfobarController* controller = | 248 BeforeTranslateInfobarController* controller = |
| 244 (BeforeTranslateInfobarController*)infobar_controller_.get(); | 249 (BeforeTranslateInfobarController*)infobar_controller_.get(); |
| 245 EXPECT_TRUE([[controller alwaysTranslateButton] superview] == nil); | 250 EXPECT_TRUE([[controller alwaysTranslateButton] superview] == nil); |
| 246 EXPECT_TRUE([[controller neverTranslateButton] superview] != nil); | 251 EXPECT_TRUE([[controller neverTranslateButton] superview] != nil); |
| 247 } | 252 } |
| 248 | 253 |
| 249 } // namespace | 254 } // namespace |
| OLD | NEW |