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

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

Issue 7006010: Change InfoBar-related notifications to be sourced from a TabContentsWrapper, not a TabContents. ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 5
6 #include <set> 6 #include <set>
7 7
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/app/chrome_command_ids.h" 9 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/browser/prefs/pref_change_registrar.h" 10 #include "chrome/browser/prefs/pref_change_registrar.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 return false; 131 return false;
132 infobar->TranslationDeclined(); 132 infobar->TranslationDeclined();
133 contents_wrapper()->RemoveInfoBar(infobar); 133 contents_wrapper()->RemoveInfoBar(infobar);
134 return true; 134 return true;
135 } 135 }
136 136
137 virtual void Observe(NotificationType type, 137 virtual void Observe(NotificationType type,
138 const NotificationSource& source, 138 const NotificationSource& source,
139 const NotificationDetails& details) { 139 const NotificationDetails& details) {
140 DCHECK_EQ(NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, type.value); 140 DCHECK_EQ(NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, type.value);
141 removed_infobars_.insert(Details<InfoBarDelegate>(details).ptr()); 141 removed_infobars_.insert(
142 Details<std::pair<InfoBarDelegate*, bool> >(details)->first);
142 } 143 }
143 144
144 protected: 145 protected:
145 virtual void SetUp() { 146 virtual void SetUp() {
146 URLFetcher::set_factory(&url_fetcher_factory_); 147 URLFetcher::set_factory(&url_fetcher_factory_);
147 148
148 // Access the TranslateManager singleton so it is created before we call 149 // Access the TranslateManager singleton so it is created before we call
149 // RenderViewHostTestHarness::SetUp() to match what's done in Chrome, where 150 // RenderViewHostTestHarness::SetUp() to match what's done in Chrome, where
150 // the TranslateManager is created before the TabContents. This matters as 151 // the TranslateManager is created before the TabContents. This matters as
151 // they both register for similar events and we want the notifications to 152 // they both register for similar events and we want the notifications to
152 // happen in the same sequence (TranslateManager first, TabContents second). 153 // happen in the same sequence (TranslateManager first, TabContents second).
153 // Also clears the translate script so it is fetched everytime and sets the 154 // Also clears the translate script so it is fetched everytime and sets the
154 // expiration delay to a large value by default (in case it was zeroed in 155 // expiration delay to a large value by default (in case it was zeroed in
155 // a previous test). 156 // a previous test).
156 TranslateManager::GetInstance()->ClearTranslateScript(); 157 TranslateManager::GetInstance()->ClearTranslateScript();
157 TranslateManager::GetInstance()-> 158 TranslateManager::GetInstance()->
158 set_translate_script_expiration_delay(60 * 60 * 1000); 159 set_translate_script_expiration_delay(60 * 60 * 1000);
159 160
160 TabContentsWrapperTestHarness::SetUp(); 161 TabContentsWrapperTestHarness::SetUp();
161 162
162 notification_registrar_.Add(this, 163 notification_registrar_.Add(this,
163 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, 164 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
164 Source<TabContents>(contents())); 165 Source<TabContentsWrapper>(contents_wrapper()));
165 } 166 }
166 167
167 virtual void TearDown() { 168 virtual void TearDown() {
168 process()->sink().ClearMessages(); 169 process()->sink().ClearMessages();
169 170
170 notification_registrar_.Remove(this, 171 notification_registrar_.Remove(this,
171 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, 172 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
172 Source<TabContents>(contents())); 173 Source<TabContentsWrapper>(contents_wrapper()));
173 174
174 TabContentsWrapperTestHarness::TearDown(); 175 TabContentsWrapperTestHarness::TearDown();
175 176
176 URLFetcher::set_factory(NULL); 177 URLFetcher::set_factory(NULL);
177 } 178 }
178 179
179 void SimulateURLFetch(bool success) { 180 void SimulateURLFetch(bool success) {
180 TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); 181 TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0);
181 ASSERT_TRUE(fetcher); 182 ASSERT_TRUE(fetcher);
182 net::URLRequestStatus status; 183 net::URLRequestStatus status;
(...skipping 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after
1198 NULL); 1199 NULL);
1199 // Now simulate the URL fetch. 1200 // Now simulate the URL fetch.
1200 SimulateURLFetch(true); 1201 SimulateURLFetch(true);
1201 // Now the message should have been sent. 1202 // Now the message should have been sent.
1202 int page_id = 0; 1203 int page_id = 0;
1203 std::string original_lang, target_lang; 1204 std::string original_lang, target_lang;
1204 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); 1205 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang));
1205 EXPECT_EQ("es", original_lang); 1206 EXPECT_EQ("es", original_lang);
1206 EXPECT_EQ("en", target_lang); 1207 EXPECT_EQ("en", target_lang);
1207 } 1208 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698