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