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

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

Issue 211273007: Split InfoBarService core code into InfoBarManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase + comments 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" 16 #include "chrome/browser/infobars/infobar.h"
17 #include "chrome/browser/infobars/infobar_manager.h"
17 #include "chrome/browser/infobars/infobar_service.h" 18 #include "chrome/browser/infobars/infobar_service.h"
18 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h" 19 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h"
19 #include "chrome/browser/translate/translate_infobar_delegate.h" 20 #include "chrome/browser/translate/translate_infobar_delegate.h"
20 #include "chrome/browser/translate/translate_manager.h" 21 #include "chrome/browser/translate/translate_manager.h"
21 #include "chrome/browser/translate/translate_service.h" 22 #include "chrome/browser/translate/translate_service.h"
22 #include "chrome/browser/translate/translate_tab_helper.h" 23 #include "chrome/browser/translate/translate_tab_helper.h"
23 #include "chrome/browser/ui/translate/translate_bubble_factory.h" 24 #include "chrome/browser/ui/translate/translate_bubble_factory.h"
24 #include "chrome/browser/ui/translate/translate_bubble_model.h" 25 #include "chrome/browser/ui/translate/translate_bubble_model.h"
25 #include "chrome/browser/ui/translate/translate_bubble_model_impl.h" 26 #include "chrome/browser/ui/translate/translate_bubble_model_impl.h"
26 #include "chrome/common/chrome_switches.h" 27 #include "chrome/common/chrome_switches.h"
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 *original_lang = translate_param.c; 141 *original_lang = translate_param.c;
141 if (target_lang) 142 if (target_lang)
142 *target_lang = translate_param.d; 143 *target_lang = translate_param.d;
143 return true; 144 return true;
144 } 145 }
145 146
146 InfoBarService* infobar_service() { 147 InfoBarService* infobar_service() {
147 return InfoBarService::FromWebContents(web_contents()); 148 return InfoBarService::FromWebContents(web_contents());
148 } 149 }
149 150
151 InfoBarManager* infobar_manager() {
152 return infobar_service()->infobar_manager();
153 }
154
150 // Returns the translate infobar if there is 1 infobar and it is a translate 155 // Returns the translate infobar if there is 1 infobar and it is a translate
151 // infobar. 156 // infobar.
152 TranslateInfoBarDelegate* GetTranslateInfoBar() { 157 TranslateInfoBarDelegate* GetTranslateInfoBar() {
153 return (infobar_service()->infobar_count() == 1) 158 return (infobar_manager()->infobar_count() == 1)
154 ? infobar_service() 159 ? infobar_manager()
155 ->infobar_at(0) 160 ->infobar_at(0)
156 ->delegate() 161 ->delegate()
157 ->AsTranslateInfoBarDelegate() 162 ->AsTranslateInfoBarDelegate()
158 : NULL; 163 : NULL;
159 } 164 }
160 165
161 // If there is 1 infobar and it is a translate infobar, closes it and returns 166 // If there is 1 infobar and it is a translate infobar, closes it and returns
162 // true. Returns false otherwise. 167 // true. Returns false otherwise.
163 bool CloseTranslateInfoBar() { 168 bool CloseTranslateInfoBar() {
164 InfoBarDelegate* infobar = GetTranslateInfoBar(); 169 InfoBarDelegate* infobar = GetTranslateInfoBar();
165 if (!infobar) 170 if (!infobar)
166 return false; 171 return false;
167 infobar->InfoBarDismissed(); // Simulates closing the infobar. 172 infobar->InfoBarDismissed(); // Simulates closing the infobar.
168 infobar_service()->RemoveInfoBar(infobar_service()->infobar_at(0)); 173 infobar_manager()->RemoveInfoBar(infobar_manager()->infobar_at(0));
169 return true; 174 return true;
170 } 175 }
171 176
172 // Checks whether |infobar| has been removed and clears the removed infobar 177 // Checks whether |infobar| has been removed and clears the removed infobar
173 // list. 178 // list.
174 bool CheckInfoBarRemovedAndReset(InfoBarDelegate* delegate) { 179 bool CheckInfoBarRemovedAndReset(InfoBarDelegate* delegate) {
175 bool found = removed_infobars_.count(delegate) != 0; 180 bool found = removed_infobars_.count(delegate) != 0;
176 removed_infobars_.clear(); 181 removed_infobars_.clear();
177 return found; 182 return found;
178 } 183 }
179 184
180 void ExpireTranslateScriptImmediately() { 185 void ExpireTranslateScriptImmediately() {
181 TranslateDownloadManager::GetInstance()->SetTranslateScriptExpirationDelay( 186 TranslateDownloadManager::GetInstance()->SetTranslateScriptExpirationDelay(
182 0); 187 0);
183 } 188 }
184 189
185 // If there is 1 infobar and it is a translate infobar, deny translation and 190 // If there is 1 infobar and it is a translate infobar, deny translation and
186 // returns true. Returns false otherwise. 191 // returns true. Returns false otherwise.
187 bool DenyTranslation() { 192 bool DenyTranslation() {
188 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); 193 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
189 if (!infobar) 194 if (!infobar)
190 return false; 195 return false;
191 infobar->TranslationDeclined(); 196 infobar->TranslationDeclined();
192 infobar_service()->RemoveInfoBar(infobar_service()->infobar_at(0)); 197 infobar_manager()->RemoveInfoBar(infobar_manager()->infobar_at(0));
193 return true; 198 return true;
194 } 199 }
195 200
196 void ReloadAndWait(bool successful_reload) { 201 void ReloadAndWait(bool successful_reload) {
197 NavEntryCommittedObserver nav_observer(web_contents()); 202 NavEntryCommittedObserver nav_observer(web_contents());
198 if (successful_reload) 203 if (successful_reload)
199 Reload(); 204 Reload();
200 else 205 else
201 FailedReload(); 206 FailedReload();
202 207
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 // This should not have triggered a translate. 731 // This should not have triggered a translate.
727 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); 732 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang));
728 } 733 }
729 734
730 // Tests that multiple OnPageContents do not cause multiple infobars. 735 // Tests that multiple OnPageContents do not cause multiple infobars.
731 TEST_F(TranslateManagerRenderViewHostTest, MultipleOnPageContents) { 736 TEST_F(TranslateManagerRenderViewHostTest, MultipleOnPageContents) {
732 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); 737 SimulateNavigation(GURL("http://www.google.fr"), "fr", true);
733 738
734 // Simulate clicking 'Nope' (don't translate). 739 // Simulate clicking 'Nope' (don't translate).
735 EXPECT_TRUE(DenyTranslation()); 740 EXPECT_TRUE(DenyTranslation());
736 EXPECT_EQ(0U, infobar_service()->infobar_count()); 741 EXPECT_EQ(0U, infobar_manager()->infobar_count());
737 742
738 // Send a new PageContents, we should not show an infobar. 743 // Send a new PageContents, we should not show an infobar.
739 SimulateOnTranslateLanguageDetermined("fr", true); 744 SimulateOnTranslateLanguageDetermined("fr", true);
740 EXPECT_EQ(0U, infobar_service()->infobar_count()); 745 EXPECT_EQ(0U, infobar_manager()->infobar_count());
741 746
742 // Do the same steps but simulate closing the infobar this time. 747 // Do the same steps but simulate closing the infobar this time.
743 SimulateNavigation(GURL("http://www.youtube.fr"), "fr", true); 748 SimulateNavigation(GURL("http://www.youtube.fr"), "fr", true);
744 EXPECT_TRUE(CloseTranslateInfoBar()); 749 EXPECT_TRUE(CloseTranslateInfoBar());
745 EXPECT_EQ(0U, infobar_service()->infobar_count()); 750 EXPECT_EQ(0U, infobar_manager()->infobar_count());
746 SimulateOnTranslateLanguageDetermined("fr", true); 751 SimulateOnTranslateLanguageDetermined("fr", true);
747 EXPECT_EQ(0U, infobar_service()->infobar_count()); 752 EXPECT_EQ(0U, infobar_manager()->infobar_count());
748 } 753 }
749 754
750 // Test that reloading the page brings back the infobar if the 755 // Test that reloading the page brings back the infobar if the
751 // reload succeeded and does not bring it back the reload fails. 756 // reload succeeded and does not bring it back the reload fails.
752 TEST_F(TranslateManagerRenderViewHostTest, Reload) { 757 TEST_F(TranslateManagerRenderViewHostTest, Reload) {
753 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); 758 SimulateNavigation(GURL("http://www.google.fr"), "fr", true);
754 759
755 EXPECT_TRUE(CloseTranslateInfoBar()); 760 EXPECT_TRUE(CloseTranslateInfoBar());
756 761
757 // Reload should bring back the infobar if the reload succeeds. 762 // Reload should bring back the infobar if the reload succeeds.
(...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after
1531 // Check the bubble exists instead of the infobar. 1536 // Check the bubble exists instead of the infobar.
1532 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); 1537 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
1533 ASSERT_TRUE(infobar == NULL); 1538 ASSERT_TRUE(infobar == NULL);
1534 TranslateBubbleModel* bubble = factory->model(); 1539 TranslateBubbleModel* bubble = factory->model();
1535 ASSERT_TRUE(bubble != NULL); 1540 ASSERT_TRUE(bubble != NULL);
1536 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_TRANSLATING, 1541 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_TRANSLATING,
1537 bubble->GetViewState()); 1542 bubble->GetViewState());
1538 } 1543 }
1539 1544
1540 #endif // defined(USE_AURA) 1545 #endif // defined(USE_AURA)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698