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/memory/scoped_nsobject.h" | 7 #import "base/memory/scoped_nsobject.h" |
8 #import "base/string_util.h" | 8 #import "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/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 #import "chrome/browser/translate/translate_infobar_delegate.h" | 11 #import "chrome/browser/translate/translate_infobar_delegate.h" |
12 #import "chrome/browser/ui/cocoa/browser_test_helper.h" | 12 #import "chrome/browser/ui/cocoa/browser_test_helper.h" |
13 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 13 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
14 #import "chrome/browser/ui/cocoa/infobars/infobar.h" | 14 #import "chrome/browser/ui/cocoa/infobars/infobar.h" |
15 #import "chrome/browser/ui/cocoa/translate/translate_infobar_base.h" | 15 #import "chrome/browser/ui/cocoa/translate/translate_infobar_base.h" |
16 #import "chrome/browser/ui/cocoa/translate/before_translate_infobar_controller.h
" | 16 #import "chrome/browser/ui/cocoa/translate/before_translate_infobar_controller.h
" |
| 17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
17 #import "content/browser/site_instance.h" | 18 #import "content/browser/site_instance.h" |
18 #import "content/browser/tab_contents/tab_contents.h" | 19 #import "content/browser/tab_contents/tab_contents.h" |
19 #import "testing/gmock/include/gmock/gmock.h" | 20 #import "testing/gmock/include/gmock/gmock.h" |
20 #import "testing/gtest/include/gtest/gtest.h" | 21 #import "testing/gtest/include/gtest/gtest.h" |
21 #import "testing/platform_test.h" | 22 #import "testing/platform_test.h" |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 // All states the translate toolbar can assume. | 26 // All states the translate toolbar can assume. |
26 TranslateInfoBarDelegate::Type kTranslateToolbarStates[] = { | 27 TranslateInfoBarDelegate::Type kTranslateToolbarStates[] = { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 MOCK_METHOD0(RevertTranslation, void()); | 62 MOCK_METHOD0(RevertTranslation, void()); |
62 MOCK_METHOD0(TranslationDeclined, void()); | 63 MOCK_METHOD0(TranslationDeclined, void()); |
63 MOCK_METHOD0(ToggleLanguageBlacklist, void()); | 64 MOCK_METHOD0(ToggleLanguageBlacklist, void()); |
64 MOCK_METHOD0(ToggleSiteBlacklist, void()); | 65 MOCK_METHOD0(ToggleSiteBlacklist, void()); |
65 MOCK_METHOD0(ToggleAlwaysTranslate, void()); | 66 MOCK_METHOD0(ToggleAlwaysTranslate, void()); |
66 }; | 67 }; |
67 | 68 |
68 class TranslationInfoBarTest : public CocoaTest { | 69 class TranslationInfoBarTest : public CocoaTest { |
69 public: | 70 public: |
70 BrowserTestHelper browser_helper_; | 71 BrowserTestHelper browser_helper_; |
71 scoped_ptr<TabContents> tab_contents; | 72 scoped_ptr<TabContentsWrapper> tab_contents; |
72 scoped_ptr<MockTranslateInfoBarDelegate> infobar_delegate; | 73 scoped_ptr<MockTranslateInfoBarDelegate> infobar_delegate; |
73 scoped_nsobject<TranslateInfoBarControllerBase> infobar_controller; | 74 scoped_nsobject<TranslateInfoBarControllerBase> infobar_controller; |
74 | 75 |
75 public: | 76 public: |
76 // Each test gets a single Mock translate delegate for the lifetime of | 77 // Each test gets a single Mock translate delegate for the lifetime of |
77 // the test. | 78 // the test. |
78 virtual void SetUp() { | 79 virtual void SetUp() { |
79 CocoaTest::SetUp(); | 80 CocoaTest::SetUp(); |
80 tab_contents.reset( | 81 tab_contents.reset(new TabContentsWrapper(new TabContents( |
81 new TabContents(browser_helper_.profile(), | 82 browser_helper_.profile(), NULL, MSG_ROUTING_NONE, NULL, NULL))); |
82 NULL, | |
83 MSG_ROUTING_NONE, | |
84 NULL, | |
85 NULL)); | |
86 CreateInfoBar(); | 83 CreateInfoBar(); |
87 } | 84 } |
88 | 85 |
89 void CreateInfoBar() { | 86 void CreateInfoBar() { |
90 CreateInfoBar(TranslateInfoBarDelegate::BEFORE_TRANSLATE); | 87 CreateInfoBar(TranslateInfoBarDelegate::BEFORE_TRANSLATE); |
91 } | 88 } |
92 | 89 |
93 void CreateInfoBar(TranslateInfoBarDelegate::Type type) { | 90 void CreateInfoBar(TranslateInfoBarDelegate::Type type) { |
94 TranslateErrors::Type error = TranslateErrors::NONE; | 91 TranslateErrors::Type error = TranslateErrors::NONE; |
95 if (type == TranslateInfoBarDelegate::TRANSLATION_ERROR) | 92 if (type == TranslateInfoBarDelegate::TRANSLATION_ERROR) |
96 error = TranslateErrors::NETWORK; | 93 error = TranslateErrors::NETWORK; |
97 infobar_delegate.reset( | 94 infobar_delegate.reset(new MockTranslateInfoBarDelegate(type, error, |
98 new MockTranslateInfoBarDelegate(type, error, tab_contents.get())); | 95 tab_contents->tab_contents())); |
99 [[infobar_controller view] removeFromSuperview]; | 96 [[infobar_controller view] removeFromSuperview]; |
100 scoped_ptr<InfoBar> infobar( | 97 scoped_ptr<InfoBar> infobar( |
101 static_cast<InfoBarDelegate*>(infobar_delegate.get())->CreateInfoBar()); | 98 static_cast<InfoBarDelegate*>(infobar_delegate.get())-> |
| 99 CreateInfoBar(tab_contents.get())); |
102 infobar_controller.reset( | 100 infobar_controller.reset( |
103 reinterpret_cast<TranslateInfoBarControllerBase*>( | 101 reinterpret_cast<TranslateInfoBarControllerBase*>( |
104 infobar->controller())); | 102 infobar->controller())); |
105 // We need to set the window to be wide so that the options button | 103 // We need to set the window to be wide so that the options button |
106 // doesn't overlap the other buttons. | 104 // doesn't overlap the other buttons. |
107 [test_window() setContentSize:NSMakeSize(2000, 500)]; | 105 [test_window() setContentSize:NSMakeSize(2000, 500)]; |
108 [[infobar_controller view] setFrame:NSMakeRect(0, 0, 2000, 500)]; | 106 [[infobar_controller view] setFrame:NSMakeRect(0, 0, 2000, 500)]; |
109 [[test_window() contentView] addSubview:[infobar_controller view]]; | 107 [[test_window() contentView] addSubview:[infobar_controller view]]; |
110 } | 108 } |
111 }; | 109 }; |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 translate_prefs.IncrementTranslationDeniedCount("en"); | 244 translate_prefs.IncrementTranslationDeniedCount("en"); |
247 } | 245 } |
248 CreateInfoBar(TranslateInfoBarDelegate::BEFORE_TRANSLATE); | 246 CreateInfoBar(TranslateInfoBarDelegate::BEFORE_TRANSLATE); |
249 BeforeTranslateInfobarController* controller = | 247 BeforeTranslateInfobarController* controller = |
250 (BeforeTranslateInfobarController*)infobar_controller.get(); | 248 (BeforeTranslateInfobarController*)infobar_controller.get(); |
251 EXPECT_TRUE([[controller alwaysTranslateButton] superview] == nil); | 249 EXPECT_TRUE([[controller alwaysTranslateButton] superview] == nil); |
252 EXPECT_TRUE([[controller neverTranslateButton] superview] != nil); | 250 EXPECT_TRUE([[controller neverTranslateButton] superview] != nil); |
253 } | 251 } |
254 | 252 |
255 } // namespace | 253 } // namespace |
OLD | NEW |