Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: chrome/browser/translate/translate_manager_render_view_host_unittest.cc

Issue 240193003: Move Infobars core files to the Infobars component (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix nib name on mac Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include <algorithm> 5 #include <algorithm>
6 #include <set> 6 #include <set>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/prefs/pref_change_registrar.h" 10 #include "base/prefs/pref_change_registrar.h"
11 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "chrome/app/chrome_command_ids.h" 13 #include "chrome/app/chrome_command_ids.h"
14 #include "chrome/browser/chrome_notification_types.h" 14 #include "chrome/browser/chrome_notification_types.h"
15 #include "chrome/browser/extensions/test_extension_system.h" 15 #include "chrome/browser/extensions/test_extension_system.h"
16 #include "chrome/browser/infobars/infobar.h"
17 #include "chrome/browser/infobars/infobar_service.h" 16 #include "chrome/browser/infobars/infobar_service.h"
18 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h" 17 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h"
19 #include "chrome/browser/translate/translate_infobar_delegate.h" 18 #include "chrome/browser/translate/translate_infobar_delegate.h"
20 #include "chrome/browser/translate/translate_service.h" 19 #include "chrome/browser/translate/translate_service.h"
21 #include "chrome/browser/translate/translate_tab_helper.h" 20 #include "chrome/browser/translate/translate_tab_helper.h"
22 #include "chrome/browser/ui/translate/translate_bubble_factory.h" 21 #include "chrome/browser/ui/translate/translate_bubble_factory.h"
23 #include "chrome/browser/ui/translate/translate_bubble_model.h" 22 #include "chrome/browser/ui/translate/translate_bubble_model.h"
24 #include "chrome/browser/ui/translate/translate_bubble_model_impl.h" 23 #include "chrome/browser/ui/translate/translate_bubble_model_impl.h"
25 #include "chrome/common/chrome_switches.h" 24 #include "chrome/common/chrome_switches.h"
26 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
27 #include "chrome/common/url_constants.h" 26 #include "chrome/common/url_constants.h"
28 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 27 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
29 #include "chrome/test/base/testing_browser_process.h" 28 #include "chrome/test/base/testing_browser_process.h"
30 #include "chrome/test/base/testing_profile.h" 29 #include "chrome/test/base/testing_profile.h"
30 #include "components/infobars/core/infobar.h"
31 #include "components/translate/content/common/translate_messages.h" 31 #include "components/translate/content/common/translate_messages.h"
32 #include "components/translate/core/browser/translate_accept_languages.h" 32 #include "components/translate/core/browser/translate_accept_languages.h"
33 #include "components/translate/core/browser/translate_download_manager.h" 33 #include "components/translate/core/browser/translate_download_manager.h"
34 #include "components/translate/core/browser/translate_language_list.h" 34 #include "components/translate/core/browser/translate_language_list.h"
35 #include "components/translate/core/browser/translate_manager.h" 35 #include "components/translate/core/browser/translate_manager.h"
36 #include "components/translate/core/browser/translate_prefs.h" 36 #include "components/translate/core/browser/translate_prefs.h"
37 #include "components/translate/core/browser/translate_script.h" 37 #include "components/translate/core/browser/translate_script.h"
38 #include "components/translate/core/common/language_detection_details.h" 38 #include "components/translate/core/common/language_detection_details.h"
39 #include "components/translate/core/common/translate_pref_names.h" 39 #include "components/translate/core/common/translate_pref_names.h"
40 #include "content/public/browser/navigation_details.h" 40 #include "content/public/browser/navigation_details.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 TranslateInfoBarDelegate* GetTranslateInfoBar() { 152 TranslateInfoBarDelegate* GetTranslateInfoBar() {
153 return (infobar_service()->infobar_count() == 1) ? 153 return (infobar_service()->infobar_count() == 1) ?
154 infobar_service()->infobar_at(0)->delegate()-> 154 infobar_service()->infobar_at(0)->delegate()->
155 AsTranslateInfoBarDelegate() : 155 AsTranslateInfoBarDelegate() :
156 NULL; 156 NULL;
157 } 157 }
158 158
159 // If there is 1 infobar and it is a translate infobar, closes it and returns 159 // If there is 1 infobar and it is a translate infobar, closes it and returns
160 // true. Returns false otherwise. 160 // true. Returns false otherwise.
161 bool CloseTranslateInfoBar() { 161 bool CloseTranslateInfoBar() {
162 InfoBarDelegate* infobar = GetTranslateInfoBar(); 162 infobars::InfoBarDelegate* infobar = GetTranslateInfoBar();
163 if (!infobar) 163 if (!infobar)
164 return false; 164 return false;
165 infobar->InfoBarDismissed(); // Simulates closing the infobar. 165 infobar->InfoBarDismissed(); // Simulates closing the infobar.
166 infobar_service()->RemoveInfoBar(infobar_service()->infobar_at(0)); 166 infobar_service()->RemoveInfoBar(infobar_service()->infobar_at(0));
167 return true; 167 return true;
168 } 168 }
169 169
170 // Checks whether |infobar| has been removed and clears the removed infobar 170 // Checks whether |infobar| has been removed and clears the removed infobar
171 // list. 171 // list.
172 bool CheckInfoBarRemovedAndReset(InfoBarDelegate* delegate) { 172 bool CheckInfoBarRemovedAndReset(infobars::InfoBarDelegate* delegate) {
173 bool found = removed_infobars_.count(delegate) != 0; 173 bool found = removed_infobars_.count(delegate) != 0;
174 removed_infobars_.clear(); 174 removed_infobars_.clear();
175 return found; 175 return found;
176 } 176 }
177 177
178 void ExpireTranslateScriptImmediately() { 178 void ExpireTranslateScriptImmediately() {
179 TranslateDownloadManager::GetInstance()->SetTranslateScriptExpirationDelay( 179 TranslateDownloadManager::GetInstance()->SetTranslateScriptExpirationDelay(
180 0); 180 0);
181 } 181 }
182 182
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 params.edit_flags = blink::WebContextMenuData::CanTranslate; 228 params.edit_flags = blink::WebContextMenuData::CanTranslate;
229 return new TestRenderViewContextMenu(web_contents()->GetMainFrame(), 229 return new TestRenderViewContextMenu(web_contents()->GetMainFrame(),
230 params); 230 params);
231 } 231 }
232 232
233 virtual void Observe(int type, 233 virtual void Observe(int type,
234 const content::NotificationSource& source, 234 const content::NotificationSource& source,
235 const content::NotificationDetails& details) { 235 const content::NotificationDetails& details) {
236 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type); 236 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type);
237 removed_infobars_.insert( 237 removed_infobars_.insert(
238 content::Details<InfoBar::RemovedDetails>(details)->first->delegate()); 238 content::Details<infobars::InfoBar::RemovedDetails>(
239 details)->first->delegate());
239 } 240 }
240 241
241 MOCK_METHOD1(OnPreferenceChanged, void(const std::string&)); 242 MOCK_METHOD1(OnPreferenceChanged, void(const std::string&));
242 243
243 protected: 244 protected:
244 virtual void SetUp() { 245 virtual void SetUp() {
245 TranslateService::InitializeForTesting(); 246 TranslateService::InitializeForTesting();
246 TranslateService::SetUseInfobar(true); 247 TranslateService::SetUseInfobar(true);
247 248
248 // Clears the translate script so it is fetched everytime and sets the 249 // Clears the translate script so it is fetched everytime and sets the
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 } 349 }
349 350
350 PrefChangeRegistrar::NamedChangeCallback pref_callback_; 351 PrefChangeRegistrar::NamedChangeCallback pref_callback_;
351 352
352 private: 353 private:
353 content::NotificationRegistrar notification_registrar_; 354 content::NotificationRegistrar notification_registrar_;
354 net::TestURLFetcherFactory url_fetcher_factory_; 355 net::TestURLFetcherFactory url_fetcher_factory_;
355 356
356 // The infobars that have been removed. 357 // The infobars that have been removed.
357 // WARNING: the pointers point to deleted objects, use only for comparison. 358 // WARNING: the pointers point to deleted objects, use only for comparison.
358 std::set<InfoBarDelegate*> removed_infobars_; 359 std::set<infobars::InfoBarDelegate*> removed_infobars_;
359 360
360 DISALLOW_COPY_AND_ASSIGN(TranslateManagerRenderViewHostTest); 361 DISALLOW_COPY_AND_ASSIGN(TranslateManagerRenderViewHostTest);
361 }; 362 };
362 363
363 class MockTranslateBubbleFactory : public TranslateBubbleFactory { 364 class MockTranslateBubbleFactory : public TranslateBubbleFactory {
364 public: 365 public:
365 MockTranslateBubbleFactory() {} 366 MockTranslateBubbleFactory() {}
366 367
367 virtual void ShowImplementation(BrowserWindow* window, 368 virtual void ShowImplementation(BrowserWindow* window,
368 content::WebContents* web_contents, 369 content::WebContents* web_contents,
(...skipping 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1543 // Check the bubble exists instead of the infobar. 1544 // Check the bubble exists instead of the infobar.
1544 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); 1545 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
1545 ASSERT_TRUE(infobar == NULL); 1546 ASSERT_TRUE(infobar == NULL);
1546 TranslateBubbleModel* bubble = factory->model(); 1547 TranslateBubbleModel* bubble = factory->model();
1547 ASSERT_TRUE(bubble != NULL); 1548 ASSERT_TRUE(bubble != NULL);
1548 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_TRANSLATING, 1549 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_TRANSLATING,
1549 bubble->GetViewState()); 1550 bubble->GetViewState());
1550 } 1551 }
1551 1552
1552 #endif // defined(USE_AURA) 1553 #endif // defined(USE_AURA)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698