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

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

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

Powered by Google App Engine
This is Rietveld 408576698