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

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

Issue 7327007: Moving notification types which are chrome specific to a new header file chrome_notification_type... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 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 <algorithm> 6 #include <algorithm>
7 #include <set> 7 #include <set>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "base/stringprintf.h" 11 #include "base/stringprintf.h"
12 #include "chrome/app/chrome_command_ids.h" 12 #include "chrome/app/chrome_command_ids.h"
13 #include "chrome/browser/prefs/pref_change_registrar.h" 13 #include "chrome/browser/prefs/pref_change_registrar.h"
14 #include "chrome/browser/prefs/pref_service.h" 14 #include "chrome/browser/prefs/pref_service.h"
15 #include "chrome/browser/tab_contents/infobar.h" 15 #include "chrome/browser/tab_contents/infobar.h"
16 #include "chrome/browser/tab_contents/render_view_context_menu.h" 16 #include "chrome/browser/tab_contents/render_view_context_menu.h"
17 #include "chrome/browser/translate/translate_infobar_delegate.h" 17 #include "chrome/browser/translate/translate_infobar_delegate.h"
18 #include "chrome/browser/translate/translate_manager.h" 18 #include "chrome/browser/translate/translate_manager.h"
19 #include "chrome/browser/translate/translate_prefs.h" 19 #include "chrome/browser/translate/translate_prefs.h"
20 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" 20 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h"
21 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 21 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
22 #include "chrome/common/chrome_notification_types.h"
22 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
23 #include "chrome/common/render_messages.h" 24 #include "chrome/common/render_messages.h"
24 #include "chrome/test/testing_browser_process.h" 25 #include "chrome/test/testing_browser_process.h"
25 #include "chrome/test/testing_profile.h" 26 #include "chrome/test/testing_profile.h"
26 #include "content/browser/browser_thread.h" 27 #include "content/browser/browser_thread.h"
27 #include "content/browser/renderer_host/mock_render_process_host.h" 28 #include "content/browser/renderer_host/mock_render_process_host.h"
28 #include "content/browser/renderer_host/test_render_view_host.h" 29 #include "content/browser/renderer_host/test_render_view_host.h"
29 #include "content/browser/tab_contents/navigation_details.h" 30 #include "content/browser/tab_contents/navigation_details.h"
30 #include "content/browser/tab_contents/test_tab_contents.h" 31 #include "content/browser/tab_contents/test_tab_contents.h"
31 #include "content/common/notification_details.h" 32 #include "content/common/notification_details.h"
32 #include "content/common/notification_observer_mock.h" 33 #include "content/common/notification_observer_mock.h"
33 #include "content/common/notification_registrar.h" 34 #include "content/common/notification_registrar.h"
34 #include "content/common/notification_type.h"
35 #include "content/common/test_url_fetcher_factory.h" 35 #include "content/common/test_url_fetcher_factory.h"
36 #include "content/common/view_messages.h" 36 #include "content/common/view_messages.h"
37 #include "grit/generated_resources.h" 37 #include "grit/generated_resources.h"
38 #include "ipc/ipc_test_sink.h" 38 #include "ipc/ipc_test_sink.h"
39 #include "testing/gmock/include/gmock/gmock.h" 39 #include "testing/gmock/include/gmock/gmock.h"
40 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" 40 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h"
41 #include "third_party/cld/languages/public/languages.h" 41 #include "third_party/cld/languages/public/languages.h"
42 42
43 using testing::_; 43 using testing::_;
44 using testing::Pointee; 44 using testing::Pointee;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 // returns true. Returns false otherwise. 131 // returns true. Returns false otherwise.
132 bool DenyTranslation() { 132 bool DenyTranslation() {
133 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); 133 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
134 if (!infobar) 134 if (!infobar)
135 return false; 135 return false;
136 infobar->TranslationDeclined(); 136 infobar->TranslationDeclined();
137 contents_wrapper()->RemoveInfoBar(infobar); 137 contents_wrapper()->RemoveInfoBar(infobar);
138 return true; 138 return true;
139 } 139 }
140 140
141 virtual void Observe(NotificationType type, 141 virtual void Observe(int type,
142 const NotificationSource& source, 142 const NotificationSource& source,
143 const NotificationDetails& details) { 143 const NotificationDetails& details) {
144 DCHECK_EQ(NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, type.value); 144 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type);
145 removed_infobars_.insert(Details<InfoBarRemovedDetails>(details)->first); 145 removed_infobars_.insert(Details<InfoBarRemovedDetails>(details)->first);
146 } 146 }
147 147
148 protected: 148 protected:
149 virtual void SetUp() { 149 virtual void SetUp() {
150 URLFetcher::set_factory(&url_fetcher_factory_); 150 URLFetcher::set_factory(&url_fetcher_factory_);
151 151
152 // Access the TranslateManager singleton so it is created before we call 152 // Access the TranslateManager singleton so it is created before we call
153 // RenderViewHostTestHarness::SetUp() to match what's done in Chrome, where 153 // RenderViewHostTestHarness::SetUp() to match what's done in Chrome, where
154 // the TranslateManager is created before the TabContents. This matters as 154 // the TranslateManager is created before the TabContents. This matters as
155 // they both register for similar events and we want the notifications to 155 // they both register for similar events and we want the notifications to
156 // happen in the same sequence (TranslateManager first, TabContents second). 156 // happen in the same sequence (TranslateManager first, TabContents second).
157 // Also clears the translate script so it is fetched everytime and sets the 157 // Also clears the translate script so it is fetched everytime and sets the
158 // expiration delay to a large value by default (in case it was zeroed in 158 // expiration delay to a large value by default (in case it was zeroed in
159 // a previous test). 159 // a previous test).
160 TranslateManager::GetInstance()->ClearTranslateScript(); 160 TranslateManager::GetInstance()->ClearTranslateScript();
161 TranslateManager::GetInstance()-> 161 TranslateManager::GetInstance()->
162 set_translate_script_expiration_delay(60 * 60 * 1000); 162 set_translate_script_expiration_delay(60 * 60 * 1000);
163 163
164 TabContentsWrapperTestHarness::SetUp(); 164 TabContentsWrapperTestHarness::SetUp();
165 165
166 notification_registrar_.Add(this, 166 notification_registrar_.Add(this,
167 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, 167 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
168 Source<TabContentsWrapper>(contents_wrapper())); 168 Source<TabContentsWrapper>(contents_wrapper()));
169 } 169 }
170 170
171 virtual void TearDown() { 171 virtual void TearDown() {
172 process()->sink().ClearMessages(); 172 process()->sink().ClearMessages();
173 173
174 notification_registrar_.Remove(this, 174 notification_registrar_.Remove(this,
175 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, 175 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
176 Source<TabContentsWrapper>(contents_wrapper())); 176 Source<TabContentsWrapper>(contents_wrapper()));
177 177
178 TabContentsWrapperTestHarness::TearDown(); 178 TabContentsWrapperTestHarness::TearDown();
179 179
180 URLFetcher::set_factory(NULL); 180 URLFetcher::set_factory(NULL);
181 } 181 }
182 182
183 void SimulateTranslateScriptURLFetch(bool success) { 183 void SimulateTranslateScriptURLFetch(bool success) {
184 TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); 184 TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0);
185 ASSERT_TRUE(fetcher); 185 ASSERT_TRUE(fetcher);
(...skipping 30 matching lines...) Expand all
216 } 216 }
217 fetcher->delegate()->OnURLFetchComplete(fetcher, fetcher->original_url(), 217 fetcher->delegate()->OnURLFetchComplete(fetcher, fetcher->original_url(),
218 status, success ? 200 : 500, 218 status, success ? 200 : 500,
219 net::ResponseCookies(), 219 net::ResponseCookies(),
220 data); 220 data);
221 } 221 }
222 222
223 void SetPrefObserverExpectation(const char* path) { 223 void SetPrefObserverExpectation(const char* path) {
224 EXPECT_CALL( 224 EXPECT_CALL(
225 pref_observer_, 225 pref_observer_,
226 Observe(NotificationType(NotificationType::PREF_CHANGED), 226 Observe(int(chrome::NOTIFICATION_PREF_CHANGED),
227 _, 227 _,
228 Property(&Details<std::string>::ptr, Pointee(path)))); 228 Property(&Details<std::string>::ptr, Pointee(path))));
229 } 229 }
230 230
231 NotificationObserverMock pref_observer_; 231 NotificationObserverMock pref_observer_;
232 ScopedTestingBrowserProcess testing_browser_process_; 232 ScopedTestingBrowserProcess testing_browser_process_;
233 233
234 private: 234 private:
235 NotificationRegistrar notification_registrar_; 235 NotificationRegistrar notification_registrar_;
236 TestURLFetcherFactory url_fetcher_factory_; 236 TestURLFetcherFactory url_fetcher_factory_;
237 BrowserThread ui_thread_; 237 BrowserThread ui_thread_;
238 238
239 // The infobars that have been removed. 239 // The infobars that have been removed.
240 // WARNING: the pointers point to deleted objects, use only for comparison. 240 // WARNING: the pointers point to deleted objects, use only for comparison.
241 std::set<InfoBarDelegate*> removed_infobars_; 241 std::set<InfoBarDelegate*> removed_infobars_;
242 242
243 DISALLOW_COPY_AND_ASSIGN(TranslateManagerTest); 243 DISALLOW_COPY_AND_ASSIGN(TranslateManagerTest);
244 }; 244 };
245 245
246 // An observer that keeps track of whether a navigation entry was committed. 246 // An observer that keeps track of whether a navigation entry was committed.
247 class NavEntryCommittedObserver : public NotificationObserver { 247 class NavEntryCommittedObserver : public NotificationObserver {
248 public: 248 public:
249 explicit NavEntryCommittedObserver(TabContents* tab_contents) { 249 explicit NavEntryCommittedObserver(TabContents* tab_contents) {
250 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, 250 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
251 Source<NavigationController>(&tab_contents->controller())); 251 Source<NavigationController>(&tab_contents->controller()));
252 } 252 }
253 253
254 virtual void Observe(NotificationType type, 254 virtual void Observe(int type,
255 const NotificationSource& source, 255 const NotificationSource& source,
256 const NotificationDetails& details) { 256 const NotificationDetails& details) {
257 DCHECK(type == NotificationType::NAV_ENTRY_COMMITTED); 257 DCHECK(type == content::NOTIFICATION_NAV_ENTRY_COMMITTED);
258 details_ = 258 details_ =
259 *(Details<content::LoadCommittedDetails>(details).ptr()); 259 *(Details<content::LoadCommittedDetails>(details).ptr());
260 } 260 }
261 261
262 const content::LoadCommittedDetails& 262 const content::LoadCommittedDetails&
263 get_load_commited_details() const { 263 get_load_commited_details() const {
264 return details_; 264 return details_;
265 } 265 }
266 266
267 private: 267 private:
(...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after
1288 NULL); 1288 NULL);
1289 // Now simulate the URL fetch. 1289 // Now simulate the URL fetch.
1290 SimulateTranslateScriptURLFetch(true); 1290 SimulateTranslateScriptURLFetch(true);
1291 // Now the message should have been sent. 1291 // Now the message should have been sent.
1292 int page_id = 0; 1292 int page_id = 0;
1293 std::string original_lang, target_lang; 1293 std::string original_lang, target_lang;
1294 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); 1294 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang));
1295 EXPECT_EQ("es", original_lang); 1295 EXPECT_EQ("es", original_lang);
1296 EXPECT_EQ("en", target_lang); 1296 EXPECT_EQ("en", target_lang);
1297 } 1297 }
OLDNEW
« no previous file with comments | « chrome/browser/translate/translate_manager.cc ('k') | chrome/browser/translate/translate_tab_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698