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 #include "chrome/browser/infobars/infobar_tab_helper.h" | 11 #include "chrome/browser/infobars/infobar_tab_helper.h" |
12 #import "chrome/browser/translate/translate_infobar_delegate.h" | 12 #import "chrome/browser/translate/translate_infobar_delegate.h" |
13 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" | 13 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" |
14 #import "chrome/browser/ui/cocoa/infobars/before_translate_infobar_controller.h" | 14 #import "chrome/browser/ui/cocoa/infobars/before_translate_infobar_controller.h" |
15 #import "chrome/browser/ui/cocoa/infobars/infobar.h" | 15 #import "chrome/browser/ui/cocoa/infobars/infobar.h" |
16 #import "chrome/browser/ui/cocoa/infobars/translate_infobar_base.h" | 16 #import "chrome/browser/ui/cocoa/infobars/translate_infobar_base.h" |
17 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 17 #include "chrome/browser/ui/tab_contents/tab_contents.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 // TODO(avi): Kill this when TabContents goes away. |
| 27 class TranslationInfoBarTestContentsCreator { |
| 28 public: |
| 29 static TabContents* CreateTabContents(content::WebContents* contents) { |
| 30 return TabContents::Factory::CreateTabContents(contents); |
| 31 } |
| 32 }; |
| 33 |
26 namespace { | 34 namespace { |
27 | 35 |
28 // All states the translate toolbar can assume. | 36 // All states the translate toolbar can assume. |
29 TranslateInfoBarDelegate::Type kTranslateToolbarStates[] = { | 37 TranslateInfoBarDelegate::Type kTranslateToolbarStates[] = { |
30 TranslateInfoBarDelegate::BEFORE_TRANSLATE, | 38 TranslateInfoBarDelegate::BEFORE_TRANSLATE, |
31 TranslateInfoBarDelegate::AFTER_TRANSLATE, | 39 TranslateInfoBarDelegate::AFTER_TRANSLATE, |
32 TranslateInfoBarDelegate::TRANSLATING, | 40 TranslateInfoBarDelegate::TRANSLATING, |
33 TranslateInfoBarDelegate::TRANSLATION_ERROR | 41 TranslateInfoBarDelegate::TRANSLATION_ERROR |
34 }; | 42 }; |
35 | 43 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 MOCK_METHOD0(ToggleSiteBlacklist, void()); | 77 MOCK_METHOD0(ToggleSiteBlacklist, void()); |
70 MOCK_METHOD0(ToggleAlwaysTranslate, void()); | 78 MOCK_METHOD0(ToggleAlwaysTranslate, void()); |
71 }; | 79 }; |
72 | 80 |
73 class TranslationInfoBarTest : public CocoaProfileTest { | 81 class TranslationInfoBarTest : public CocoaProfileTest { |
74 public: | 82 public: |
75 // Each test gets a single Mock translate delegate for the lifetime of | 83 // Each test gets a single Mock translate delegate for the lifetime of |
76 // the test. | 84 // the test. |
77 virtual void SetUp() { | 85 virtual void SetUp() { |
78 CocoaProfileTest::SetUp(); | 86 CocoaProfileTest::SetUp(); |
79 tab_contents_.reset(new TabContents(WebContents::Create( | 87 tab_contents_.reset( |
80 profile(), NULL, MSG_ROUTING_NONE, NULL))); | 88 TranslationInfoBarTestContentsCreator::CreateTabContents( |
| 89 WebContents::Create(profile(), NULL, MSG_ROUTING_NONE, NULL))); |
81 CreateInfoBar(); | 90 CreateInfoBar(); |
82 } | 91 } |
83 | 92 |
84 void CreateInfoBar() { | 93 void CreateInfoBar() { |
85 CreateInfoBar(TranslateInfoBarDelegate::BEFORE_TRANSLATE); | 94 CreateInfoBar(TranslateInfoBarDelegate::BEFORE_TRANSLATE); |
86 } | 95 } |
87 | 96 |
88 void CreateInfoBar(TranslateInfoBarDelegate::Type type) { | 97 void CreateInfoBar(TranslateInfoBarDelegate::Type type) { |
89 TranslateErrors::Type error = TranslateErrors::NONE; | 98 TranslateErrors::Type error = TranslateErrors::NONE; |
90 if (type == TranslateInfoBarDelegate::TRANSLATION_ERROR) | 99 if (type == TranslateInfoBarDelegate::TRANSLATION_ERROR) |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 translate_prefs.IncrementTranslationDeniedCount("en"); | 258 translate_prefs.IncrementTranslationDeniedCount("en"); |
250 } | 259 } |
251 CreateInfoBar(TranslateInfoBarDelegate::BEFORE_TRANSLATE); | 260 CreateInfoBar(TranslateInfoBarDelegate::BEFORE_TRANSLATE); |
252 BeforeTranslateInfobarController* controller = | 261 BeforeTranslateInfobarController* controller = |
253 (BeforeTranslateInfobarController*)infobar_controller_.get(); | 262 (BeforeTranslateInfobarController*)infobar_controller_.get(); |
254 EXPECT_TRUE([[controller alwaysTranslateButton] superview] == nil); | 263 EXPECT_TRUE([[controller alwaysTranslateButton] superview] == nil); |
255 EXPECT_TRUE([[controller neverTranslateButton] superview] != nil); | 264 EXPECT_TRUE([[controller neverTranslateButton] superview] != nil); |
256 } | 265 } |
257 | 266 |
258 } // namespace | 267 } // namespace |
OLD | NEW |