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

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

Issue 22694006: Infobar system refactor. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/command_line.h" 9 #include "base/command_line.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 } 146 }
147 147
148 InfoBarService* infobar_service() { 148 InfoBarService* infobar_service() {
149 return InfoBarService::FromWebContents(web_contents()); 149 return InfoBarService::FromWebContents(web_contents());
150 } 150 }
151 151
152 // Returns the translate infobar if there is 1 infobar and it is a translate 152 // Returns the translate infobar if there is 1 infobar and it is a translate
153 // infobar. 153 // infobar.
154 TranslateInfoBarDelegate* GetTranslateInfoBar() { 154 TranslateInfoBarDelegate* GetTranslateInfoBar() {
155 return (infobar_service()->infobar_count() == 1) ? 155 return (infobar_service()->infobar_count() == 1) ?
156 infobar_service()->infobar_at(0)->AsTranslateInfoBarDelegate() : NULL; 156 infobar_service()->infobar_at(0)->delegate()->
157 AsTranslateInfoBarDelegate() : NULL;
157 } 158 }
158 159
159 // If there is 1 infobar and it is a translate infobar, closes it and returns 160 // If there is 1 infobar and it is a translate infobar, closes it and returns
160 // true. Returns false otherwise. 161 // true. Returns false otherwise.
161 bool CloseTranslateInfoBar() { 162 bool CloseTranslateInfoBar() {
162 InfoBarDelegate* infobar = GetTranslateInfoBar(); 163 InfoBarDelegate* infobar = GetTranslateInfoBar();
163 if (!infobar) 164 if (!infobar)
164 return false; 165 return false;
165 infobar->InfoBarDismissed(); // Simulates closing the infobar. 166 infobar->InfoBarDismissed(); // Simulates closing the infobar.
166 infobar_service()->RemoveInfoBar(infobar); 167 infobar_service()->RemoveInfoBar(infobar_service()->infobar_at(0));
167 return true; 168 return true;
168 } 169 }
169 170
170 // Checks whether |infobar| has been removed and clears the removed infobar 171 // Checks whether |infobar| has been removed and clears the removed infobar
171 // list. 172 // list.
172 bool CheckInfoBarRemovedAndReset(InfoBarDelegate* delegate) { 173 bool CheckInfoBarRemovedAndReset(InfoBarDelegate* delegate) {
173 bool found = removed_infobars_.count(delegate) != 0; 174 bool found = removed_infobars_.count(delegate) != 0;
174 removed_infobars_.clear(); 175 removed_infobars_.clear();
175 return found; 176 return found;
176 } 177 }
177 178
178 void ExpireTranslateScriptImmediately() { 179 void ExpireTranslateScriptImmediately() {
179 TranslateManager::GetInstance()->SetTranslateScriptExpirationDelay(0); 180 TranslateManager::GetInstance()->SetTranslateScriptExpirationDelay(0);
180 } 181 }
181 182
182 // If there is 1 infobar and it is a translate infobar, deny translation and 183 // If there is 1 infobar and it is a translate infobar, deny translation and
183 // returns true. Returns false otherwise. 184 // returns true. Returns false otherwise.
184 bool DenyTranslation() { 185 bool DenyTranslation() {
185 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); 186 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
186 if (!infobar) 187 if (!infobar)
187 return false; 188 return false;
188 infobar->TranslationDeclined(); 189 infobar->TranslationDeclined();
189 infobar_service()->RemoveInfoBar(infobar); 190 infobar_service()->RemoveInfoBar(infobar_service()->infobar_at(0));
190 return true; 191 return true;
191 } 192 }
192 193
193 void ReloadAndWait(bool successful_reload) { 194 void ReloadAndWait(bool successful_reload) {
194 NavEntryCommittedObserver nav_observer(web_contents()); 195 NavEntryCommittedObserver nav_observer(web_contents());
195 if (successful_reload) 196 if (successful_reload)
196 Reload(); 197 Reload();
197 else 198 else
198 FailedReload(); 199 FailedReload();
199 200
200 // Ensures it is really handled a reload. 201 // Ensures it is really handled a reload.
201 const content::LoadCommittedDetails& nav_details = 202 const content::LoadCommittedDetails& nav_details =
202 nav_observer.load_committed_details(); 203 nav_observer.load_committed_details();
203 EXPECT_TRUE(nav_details.entry != NULL); // There was a navigation. 204 EXPECT_TRUE(nav_details.entry != NULL); // There was a navigation.
204 EXPECT_EQ(content::NAVIGATION_TYPE_EXISTING_PAGE, nav_details.type); 205 EXPECT_EQ(content::NAVIGATION_TYPE_EXISTING_PAGE, nav_details.type);
205 206
206 // The TranslateManager class processes the navigation entry committed 207 // The TranslateManager class processes the navigation entry committed
207 // notification in a posted task; process that task. 208 // notification in a posted task; process that task.
208 base::MessageLoop::current()->RunUntilIdle(); 209 base::MessageLoop::current()->RunUntilIdle();
209 } 210 }
210 211
211 virtual void Observe(int type, 212 virtual void Observe(int type,
212 const content::NotificationSource& source, 213 const content::NotificationSource& source,
213 const content::NotificationDetails& details) { 214 const content::NotificationDetails& details) {
214 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type); 215 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type);
215 removed_infobars_.insert( 216 removed_infobars_.insert(
216 content::Details<InfoBar::RemovedDetails>(details)->first); 217 content::Details<InfoBar::RemovedDetails>(details)->first->delegate());
217 } 218 }
218 219
219 MOCK_METHOD1(OnPreferenceChanged, void(const std::string&)); 220 MOCK_METHOD1(OnPreferenceChanged, void(const std::string&));
220 221
221 protected: 222 protected:
222 virtual void SetUp() { 223 virtual void SetUp() {
223 // Access the TranslateManager singleton so it is created before we call 224 // Access the TranslateManager singleton so it is created before we call
224 // ChromeRenderViewHostTestHarness::SetUp() to match what's done in Chrome, 225 // ChromeRenderViewHostTestHarness::SetUp() to match what's done in Chrome,
225 // where the TranslateManager is created before the WebContents. This 226 // where the TranslateManager is created before the WebContents. This
226 // matters as they both register for similar events and we want the 227 // matters as they both register for similar events and we want the
(...skipping 1382 matching lines...) Expand 10 before | Expand all | Expand 10 after
1609 content::WebContents* current_web_contents = 1610 content::WebContents* current_web_contents =
1610 browser()->tab_strip_model()->GetActiveWebContents(); 1611 browser()->tab_strip_model()->GetActiveWebContents();
1611 content::Source<content::WebContents> source(current_web_contents); 1612 content::Source<content::WebContents> source(current_web_contents);
1612 1613
1613 ui_test_utils::WindowedNotificationObserverWithDetails< 1614 ui_test_utils::WindowedNotificationObserverWithDetails<
1614 LanguageDetectionDetails> 1615 LanguageDetectionDetails>
1615 fr_language_detected_signal(chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED, 1616 fr_language_detected_signal(chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED,
1616 source); 1617 source);
1617 fr_language_detected_signal.Wait(); 1618 fr_language_detected_signal.Wait();
1618 } 1619 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698