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

Side by Side Diff: chrome/browser/automation/automation_provider_observers.cc

Issue 10922002: Remove the translate pyauto test to chrome tests and all the supporting automation hooks. I've adde… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: take out data files so patch applies, will remove separately Created 8 years, 3 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) 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 "chrome/browser/automation/automation_provider_observers.h" 5 #include "chrome/browser/automation/automation_provider_observers.h"
6 6
7 #include <deque> 7 #include <deque>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 #include "chrome/browser/notifications/notification_ui_manager.h" 46 #include "chrome/browser/notifications/notification_ui_manager.h"
47 #include "chrome/browser/password_manager/password_store_change.h" 47 #include "chrome/browser/password_manager/password_store_change.h"
48 #include "chrome/browser/profiles/profile.h" 48 #include "chrome/browser/profiles/profile.h"
49 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" 49 #include "chrome/browser/renderer_host/chrome_render_message_filter.h"
50 #include "chrome/browser/search_engines/template_url_service.h" 50 #include "chrome/browser/search_engines/template_url_service.h"
51 #include "chrome/browser/search_engines/template_url_service_factory.h" 51 #include "chrome/browser/search_engines/template_url_service_factory.h"
52 #include "chrome/browser/sessions/session_tab_helper.h" 52 #include "chrome/browser/sessions/session_tab_helper.h"
53 #include "chrome/browser/sessions/tab_restore_service.h" 53 #include "chrome/browser/sessions/tab_restore_service.h"
54 #include "chrome/browser/sessions/tab_restore_service_factory.h" 54 #include "chrome/browser/sessions/tab_restore_service_factory.h"
55 #include "chrome/browser/tab_contents/thumbnail_generator.h" 55 #include "chrome/browser/tab_contents/thumbnail_generator.h"
56 #include "chrome/browser/translate/page_translated_details.h"
57 #include "chrome/browser/translate/translate_infobar_delegate.h"
58 #include "chrome/browser/translate/translate_tab_helper.h"
59 #include "chrome/browser/ui/browser.h" 56 #include "chrome/browser/ui/browser.h"
60 #include "chrome/browser/ui/browser_list.h" 57 #include "chrome/browser/ui/browser_list.h"
61 #include "chrome/browser/ui/browser_tabstrip.h" 58 #include "chrome/browser/ui/browser_tabstrip.h"
62 #include "chrome/browser/ui/browser_window.h" 59 #include "chrome/browser/ui/browser_window.h"
63 #include "chrome/browser/ui/find_bar/find_notification_details.h" 60 #include "chrome/browser/ui/find_bar/find_notification_details.h"
64 #include "chrome/browser/ui/login/login_prompt.h" 61 #include "chrome/browser/ui/login/login_prompt.h"
65 #include "chrome/browser/ui/tab_contents/tab_contents.h" 62 #include "chrome/browser/ui/tab_contents/tab_contents.h"
66 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" 63 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h"
67 #include "chrome/browser/ui/webui/ntp/most_visited_handler.h" 64 #include "chrome/browser/ui/webui/ntp/most_visited_handler.h"
68 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" 65 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
(...skipping 1185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1254 if (type != chrome::NOTIFICATION_METRIC_EVENT_DURATION) { 1251 if (type != chrome::NOTIFICATION_METRIC_EVENT_DURATION) {
1255 NOTREACHED(); 1252 NOTREACHED();
1256 return; 1253 return;
1257 } 1254 }
1258 MetricEventDurationDetails* metric_event_duration = 1255 MetricEventDurationDetails* metric_event_duration =
1259 content::Details<MetricEventDurationDetails>(details).ptr(); 1256 content::Details<MetricEventDurationDetails>(details).ptr();
1260 durations_[metric_event_duration->event_name] = 1257 durations_[metric_event_duration->event_name] =
1261 metric_event_duration->duration_ms; 1258 metric_event_duration->duration_ms;
1262 } 1259 }
1263 1260
1264 PageTranslatedObserver::PageTranslatedObserver(AutomationProvider* automation,
1265 IPC::Message* reply_message,
1266 WebContents* web_contents)
1267 : automation_(automation->AsWeakPtr()),
1268 reply_message_(reply_message) {
1269 registrar_.Add(this, chrome::NOTIFICATION_PAGE_TRANSLATED,
1270 content::Source<WebContents>(web_contents));
1271 }
1272
1273 PageTranslatedObserver::~PageTranslatedObserver() {}
1274
1275 void PageTranslatedObserver::Observe(
1276 int type,
1277 const content::NotificationSource& source,
1278 const content::NotificationDetails& details) {
1279 if (!automation_) {
1280 delete this;
1281 return;
1282 }
1283
1284 DCHECK(type == chrome::NOTIFICATION_PAGE_TRANSLATED);
1285 AutomationJSONReply reply(automation_, reply_message_.release());
1286
1287 PageTranslatedDetails* translated_details =
1288 content::Details<PageTranslatedDetails>(details).ptr();
1289 scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
1290 return_value->SetBoolean(
1291 "translation_success",
1292 translated_details->error_type == TranslateErrors::NONE);
1293 reply.SendSuccess(return_value.get());
1294 delete this;
1295 }
1296
1297 TabLanguageDeterminedObserver::TabLanguageDeterminedObserver(
1298 AutomationProvider* automation, IPC::Message* reply_message,
1299 WebContents* web_contents, TranslateInfoBarDelegate* translate_bar)
1300 : automation_(automation->AsWeakPtr()),
1301 reply_message_(reply_message),
1302 web_contents_(web_contents),
1303 translate_bar_(translate_bar) {
1304 registrar_.Add(this, chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED,
1305 content::Source<WebContents>(web_contents_));
1306 }
1307
1308 TabLanguageDeterminedObserver::~TabLanguageDeterminedObserver() {}
1309
1310 void TabLanguageDeterminedObserver::Observe(
1311 int type, const content::NotificationSource& source,
1312 const content::NotificationDetails& details) {
1313 DCHECK(type == chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED);
1314
1315 if (!automation_) {
1316 delete this;
1317 return;
1318 }
1319
1320 TranslateTabHelper* helper =
1321 TabContents::FromWebContents(web_contents_)->translate_tab_helper();
1322 scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
1323 return_value->SetBoolean("page_translated",
1324 helper->language_state().IsPageTranslated());
1325 return_value->SetBoolean(
1326 "can_translate_page", TranslatePrefs::CanTranslate(
1327 automation_->profile()->GetPrefs(),
1328 helper->language_state().original_language(),
1329 web_contents_->GetURL()));
1330 return_value->SetString("original_language",
1331 helper->language_state().original_language());
1332 if (translate_bar_) {
1333 DictionaryValue* bar_info = new DictionaryValue;
1334 std::map<TranslateInfoBarDelegate::Type, std::string> type_to_string;
1335 type_to_string[TranslateInfoBarDelegate::BEFORE_TRANSLATE] =
1336 "BEFORE_TRANSLATE";
1337 type_to_string[TranslateInfoBarDelegate::TRANSLATING] =
1338 "TRANSLATING";
1339 type_to_string[TranslateInfoBarDelegate::AFTER_TRANSLATE] =
1340 "AFTER_TRANSLATE";
1341 type_to_string[TranslateInfoBarDelegate::TRANSLATION_ERROR] =
1342 "TRANSLATION_ERROR";
1343
1344 if (translate_bar_->type() == TranslateInfoBarDelegate::BEFORE_TRANSLATE) {
1345 bar_info->SetBoolean("always_translate_lang_button_showing",
1346 translate_bar_->ShouldShowAlwaysTranslateButton());
1347 bar_info->SetBoolean("never_translate_lang_button_showing",
1348 translate_bar_->ShouldShowNeverTranslateButton());
1349 }
1350 bar_info->SetString("bar_state", type_to_string[translate_bar_->type()]);
1351 bar_info->SetString("target_lang_code",
1352 translate_bar_->GetTargetLanguageCode());
1353 bar_info->SetString("original_lang_code",
1354 translate_bar_->GetOriginalLanguageCode());
1355 return_value->Set("translate_bar", bar_info);
1356 }
1357 AutomationJSONReply(automation_, reply_message_.release())
1358 .SendSuccess(return_value.get());
1359 delete this;
1360 }
1361
1362 InfoBarCountObserver::InfoBarCountObserver(AutomationProvider* automation, 1261 InfoBarCountObserver::InfoBarCountObserver(AutomationProvider* automation,
1363 IPC::Message* reply_message, 1262 IPC::Message* reply_message,
1364 TabContents* tab_contents, 1263 TabContents* tab_contents,
1365 size_t target_count) 1264 size_t target_count)
1366 : automation_(automation->AsWeakPtr()), 1265 : automation_(automation->AsWeakPtr()),
1367 reply_message_(reply_message), 1266 reply_message_(reply_message),
1368 tab_contents_(tab_contents), 1267 tab_contents_(tab_contents),
1369 target_count_(target_count) { 1268 target_count_(target_count) {
1370 content::Source<InfoBarTabHelper> source(tab_contents->infobar_tab_helper()); 1269 content::Source<InfoBarTabHelper> source(tab_contents->infobar_tab_helper());
1371 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, 1270 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED,
(...skipping 1607 matching lines...) Expand 10 before | Expand all | Expand 10 after
2979 if (automation_) { 2878 if (automation_) {
2980 AutomationJSONReply(automation_, reply_message_.release()) 2879 AutomationJSONReply(automation_, reply_message_.release())
2981 .SendSuccess(NULL); 2880 .SendSuccess(NULL);
2982 } 2881 }
2983 delete this; 2882 delete this;
2984 } 2883 }
2985 } else { 2884 } else {
2986 NOTREACHED(); 2885 NOTREACHED();
2987 } 2886 }
2988 } 2887 }
OLDNEW
« no previous file with comments | « chrome/browser/automation/automation_provider_observers.h ('k') | chrome/browser/automation/testing_automation_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698