| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/scoped_nsobject.h" | 7 #import "base/scoped_nsobject.h" |
| 8 #import "base/string_util.h" | 8 #import "base/string_util.h" |
| 9 #import "chrome/app/chrome_dll_resource.h" // For translate menu command ids. | 9 #import "chrome/app/chrome_dll_resource.h" // For translate menu command ids. |
| 10 #import "chrome/browser/cocoa/browser_test_helper.h" | 10 #import "chrome/browser/cocoa/browser_test_helper.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 TranslateErrors::Type error = TranslateErrors::NONE; | 96 TranslateErrors::Type error = TranslateErrors::NONE; |
| 97 if (type == TranslateInfoBarDelegate::kTranslationError) | 97 if (type == TranslateInfoBarDelegate::kTranslationError) |
| 98 error = TranslateErrors::NETWORK; | 98 error = TranslateErrors::NETWORK; |
| 99 infobar_delegate.reset( | 99 infobar_delegate.reset( |
| 100 new MockTranslateInfoBarDelegate(type, error, tab_contents.get())); | 100 new MockTranslateInfoBarDelegate(type, error, tab_contents.get())); |
| 101 [[infobar_controller view] removeFromSuperview]; | 101 [[infobar_controller view] removeFromSuperview]; |
| 102 scoped_ptr<InfoBar> infobar(infobar_delegate->CreateInfoBar()); | 102 scoped_ptr<InfoBar> infobar(infobar_delegate->CreateInfoBar()); |
| 103 infobar_controller.reset( | 103 infobar_controller.reset( |
| 104 reinterpret_cast<TranslateInfoBarControllerBase*>( | 104 reinterpret_cast<TranslateInfoBarControllerBase*>( |
| 105 infobar->controller())); | 105 infobar->controller())); |
| 106 // Need to call this to get the view to load from nib. | 106 // We need to set the window to be wide so that the options button |
| 107 // doesn't overlap the other buttons. |
| 108 [test_window() setContentSize:NSMakeSize(2000, 500)]; |
| 109 [[infobar_controller view] setFrame:NSMakeRect(0, 0, 2000, 500)]; |
| 107 [[test_window() contentView] addSubview:[infobar_controller view]]; | 110 [[test_window() contentView] addSubview:[infobar_controller view]]; |
| 108 } | 111 } |
| 109 }; | 112 }; |
| 110 | 113 |
| 111 // Check that we can instantiate a Translate Infobar correctly. | 114 // Check that we can instantiate a Translate Infobar correctly. |
| 112 TEST_F(TranslationInfoBarTest, Instantiate) { | 115 TEST_F(TranslationInfoBarTest, Instantiate) { |
| 113 CreateInfoBar(); | 116 CreateInfoBar(); |
| 114 ASSERT_TRUE(infobar_controller.get()); | 117 ASSERT_TRUE(infobar_controller.get()); |
| 115 } | 118 } |
| 116 | 119 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 138 | 141 |
| 139 EXPECT_CALL(*infobar_delegate, RevertTranslation()).Times(1); | 142 EXPECT_CALL(*infobar_delegate, RevertTranslation()).Times(1); |
| 140 [infobar_controller showOriginal:nil]; | 143 [infobar_controller showOriginal:nil]; |
| 141 } | 144 } |
| 142 | 145 |
| 143 // Check that items in the options menu are hooked up correctly. | 146 // Check that items in the options menu are hooked up correctly. |
| 144 TEST_F(TranslationInfoBarTest, OptionsMenuItemsHookedUp) { | 147 TEST_F(TranslationInfoBarTest, OptionsMenuItemsHookedUp) { |
| 145 EXPECT_CALL(*infobar_delegate, Translate()) | 148 EXPECT_CALL(*infobar_delegate, Translate()) |
| 146 .Times(0); | 149 .Times(0); |
| 147 | 150 |
| 148 [infobar_controller rebuildOptionsMenu]; | 151 [infobar_controller rebuildOptionsMenu:NO]; |
| 149 NSMenu* optionsMenu = [infobar_controller optionsMenu]; | 152 NSMenu* optionsMenu = [infobar_controller optionsMenu]; |
| 150 NSArray* optionsMenuItems = [optionsMenu itemArray]; | 153 NSArray* optionsMenuItems = [optionsMenu itemArray]; |
| 151 | 154 |
| 152 EXPECT_EQ([optionsMenuItems count], 5U); | 155 EXPECT_EQ([optionsMenuItems count], 5U); |
| 153 | 156 |
| 154 // First item is the options menu button's title, so there's no need to test | 157 // First item is the options menu button's title, so there's no need to test |
| 155 // that the target on that is setup correctly. | 158 // that the target on that is setup correctly. |
| 156 for (NSUInteger i = 1; i < [optionsMenuItems count]; ++i) { | 159 for (NSUInteger i = 1; i < [optionsMenuItems count]; ++i) { |
| 157 NSMenuItem* item = [optionsMenuItems objectAtIndex:i]; | 160 NSMenuItem* item = [optionsMenuItems objectAtIndex:i]; |
| 158 EXPECT_EQ([item target], infobar_controller.get()); | 161 EXPECT_EQ([item target], infobar_controller.get()); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 .Times(0); | 211 .Times(0); |
| 209 | 212 |
| 210 for (size_t i = 0; i < arraysize(kTranslateToolbarStates); ++i) { | 213 for (size_t i = 0; i < arraysize(kTranslateToolbarStates); ++i) { |
| 211 CreateInfoBar(kTranslateToolbarStates[i]); | 214 CreateInfoBar(kTranslateToolbarStates[i]); |
| 212 EXPECT_TRUE( | 215 EXPECT_TRUE( |
| 213 [infobar_controller verifyLayout]) << "Layout wrong, for state #" << i; | 216 [infobar_controller verifyLayout]) << "Layout wrong, for state #" << i; |
| 214 } | 217 } |
| 215 } | 218 } |
| 216 | 219 |
| 217 } // namespace | 220 } // namespace |
| OLD | NEW |