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

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

Issue 9372120: Implementation of AutomationEventQueue and associated framework to support generic non-blocking aut… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Made CompareEventId predicate class private to AutomationEventQueue. Created 8 years, 9 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/testing_automation_provider.h" 5 #include "chrome/browser/automation/testing_automation_provider.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 2298 matching lines...) Expand 10 before | Expand all | Expand 10 after
2309 handler_map["NavigateToURL"] = 2309 handler_map["NavigateToURL"] =
2310 &TestingAutomationProvider::NavigateToURL; 2310 &TestingAutomationProvider::NavigateToURL;
2311 handler_map["GetLocalStatePrefsInfo"] = 2311 handler_map["GetLocalStatePrefsInfo"] =
2312 &TestingAutomationProvider::GetLocalStatePrefsInfo; 2312 &TestingAutomationProvider::GetLocalStatePrefsInfo;
2313 handler_map["SetLocalStatePrefs"] = 2313 handler_map["SetLocalStatePrefs"] =
2314 &TestingAutomationProvider::SetLocalStatePrefs; 2314 &TestingAutomationProvider::SetLocalStatePrefs;
2315 handler_map["GetPrefsInfo"] = &TestingAutomationProvider::GetPrefsInfo; 2315 handler_map["GetPrefsInfo"] = &TestingAutomationProvider::GetPrefsInfo;
2316 handler_map["SetPrefs"] = &TestingAutomationProvider::SetPrefs; 2316 handler_map["SetPrefs"] = &TestingAutomationProvider::SetPrefs;
2317 handler_map["ExecuteJavascript"] = 2317 handler_map["ExecuteJavascript"] =
2318 &TestingAutomationProvider::ExecuteJavascriptJSON; 2318 &TestingAutomationProvider::ExecuteJavascriptJSON;
2319 handler_map["AddDomRaisedEventObserver"] =
Nirnimesh 2012/03/01 10:34:12 See corresponding comment in pyauto.py
2320 &TestingAutomationProvider::AddDomRaisedEventObserver;
2321 handler_map["RemoveEventObserver"] =
2322 &TestingAutomationProvider::RemoveEventObserver;
2323 handler_map["GetNextEvent"] =
2324 &TestingAutomationProvider::GetNextEvent;
2325 handler_map["ClearEventQueue"] =
2326 &TestingAutomationProvider::ClearEventQueue;
2319 handler_map["ExecuteJavascriptInRenderView"] = 2327 handler_map["ExecuteJavascriptInRenderView"] =
2320 &TestingAutomationProvider::ExecuteJavascriptInRenderView; 2328 &TestingAutomationProvider::ExecuteJavascriptInRenderView;
2321 handler_map["GoForward"] = 2329 handler_map["GoForward"] =
2322 &TestingAutomationProvider::GoForward; 2330 &TestingAutomationProvider::GoForward;
2323 handler_map["GoBack"] = 2331 handler_map["GoBack"] =
2324 &TestingAutomationProvider::GoBack; 2332 &TestingAutomationProvider::GoBack;
2325 handler_map["Reload"] = 2333 handler_map["Reload"] =
2326 &TestingAutomationProvider::ReloadJSON; 2334 &TestingAutomationProvider::ReloadJSON;
2327 handler_map["CaptureEntirePage"] = 2335 handler_map["CaptureEntirePage"] =
2328 &TestingAutomationProvider::CaptureEntirePageJSON; 2336 &TestingAutomationProvider::CaptureEntirePageJSON;
(...skipping 4107 matching lines...) Expand 10 before | Expand all | Expand 10 after
6436 AutomationJSONReply(this, reply_message).SendError( 6444 AutomationJSONReply(this, reply_message).SendError(
6437 "A RenderViewHost object was not found with the given view ID."); 6445 "A RenderViewHost object was not found with the given view ID.");
6438 return; 6446 return;
6439 } 6447 }
6440 6448
6441 new DomOperationMessageSender(this, reply_message, true); 6449 new DomOperationMessageSender(this, reply_message, true);
6442 ExecuteJavascriptInRenderViewFrame(frame_xpath, javascript, reply_message, 6450 ExecuteJavascriptInRenderViewFrame(frame_xpath, javascript, reply_message,
6443 rvh); 6451 rvh);
6444 } 6452 }
6445 6453
6454 void TestingAutomationProvider::AddDomRaisedEventObserver(
Nirnimesh 2012/03/01 10:34:12 you pass a lot of other args from the python side,
craigdh 2012/03/01 21:34:18 Those are left over from some point in the design
6455 DictionaryValue* args,
6456 IPC::Message* reply_message) {
6457 if (SendErrorIfModalDialogActive(this, reply_message))
6458 return;
6459
6460 AutomationJSONReply reply(this, reply_message);
6461 std::string event_name;
6462 if (!args->GetString("event_name", &event_name)) {
6463 reply.SendError("'event_name' missing or invalid");
6464 return;
6465 }
6466
6467 if (!automation_event_queue_.get())
6468 automation_event_queue_.reset(new AutomationEventQueue);
6469
6470 int observer_id = automation_event_queue_->AddObserver(
6471 new DomRaisedEventObserver(automation_event_queue_.get(), event_name));
6472 scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
6473 return_value->SetInteger("observer_id", observer_id);
6474 reply.SendSuccess(return_value.get());
6475 }
6476
6477 void TestingAutomationProvider::RemoveEventObserver(
6478 DictionaryValue* args,
6479 IPC::Message* reply_message) {
6480 AutomationJSONReply reply(this, reply_message);
6481 int observer_id;
6482 if (!args->GetInteger("observer_id", &observer_id)) {
6483 reply.SendError("'observer_id' missing or invalid");
6484 return;
6485 }
6486 if (automation_event_queue_->RemoveObserver(observer_id)) {
6487 reply.SendSuccess(NULL);
6488 return;
6489 }
6490 if (!automation_event_queue_.get()) {
Nirnimesh 2012/03/01 10:34:12 The if in line 6486 implies that this if will neve
craigdh 2012/03/01 21:34:18 Done.
6491 reply.SendError("No observers have been created.");
6492 return;
6493 }
6494 reply.SendError("Invalid observer id.");
6495 }
6496
6497 void TestingAutomationProvider::ClearEventQueue(
6498 DictionaryValue* args,
6499 IPC::Message* reply_message) {
6500 AutomationJSONReply reply(this, reply_message);
Nirnimesh 2012/03/01 10:34:12 remove
craigdh 2012/03/01 21:34:18 Done.
6501 if (automation_event_queue_.get())
6502 automation_event_queue_->Clear();
Nirnimesh 2012/03/01 10:34:12 Also free up automation_event_queue_?
craigdh 2012/03/01 21:34:18 Changed to just automation_event_queue_.reset() wh
6503 reply.SendSuccess(NULL);
Nirnimesh 2012/03/01 10:34:12 AutomationJSONReply reply(this, reply_message).Sen
craigdh 2012/03/01 21:34:18 Done.
6504 }
6505
6506 void TestingAutomationProvider::GetNextEvent(
6507 DictionaryValue* args,
6508 IPC::Message* reply_message) {
6509 scoped_ptr<AutomationJSONReply> reply(
6510 new AutomationJSONReply(this, reply_message));
6511 int observer_id;
6512 bool blocking;
6513 if (!args->GetInteger("observer_id", &observer_id)) {
6514 reply->SendError("'observer_id' missing or invalid");
6515 return;
6516 }
6517 if (!args->GetBoolean("blocking", &blocking)) {
6518 reply->SendError("'blocking' missing or invalid");
6519 return;
6520 }
6521 if (!automation_event_queue_.get()) {
6522 reply->SendError("No observers have been created.");
Nirnimesh 2012/03/01 10:34:12 Add: "Did you call AddDomRaisedEventObserver?"
craigdh 2012/03/01 21:34:18 Done. Added a comment to the same effect but a lit
6523 return;
6524 }
6525
6526 automation_event_queue_->GetNextEvent(reply.release(), observer_id, blocking);
Nirnimesh 2012/03/01 10:34:12 AutomationEventQueue::GetNextEvent takes Automatio
craigdh 2012/03/01 21:34:18 When a matching event is added to the queue and th
6527 }
6528
6446 void TestingAutomationProvider::GoForward( 6529 void TestingAutomationProvider::GoForward(
6447 DictionaryValue* args, 6530 DictionaryValue* args,
6448 IPC::Message* reply_message) { 6531 IPC::Message* reply_message) {
6449 if (SendErrorIfModalDialogActive(this, reply_message)) 6532 if (SendErrorIfModalDialogActive(this, reply_message))
6450 return; 6533 return;
6451 6534
6452 WebContents* web_contents; 6535 WebContents* web_contents;
6453 std::string error; 6536 std::string error;
6454 if (!GetTabFromJSONArgs(args, &web_contents, &error)) { 6537 if (!GetTabFromJSONArgs(args, &web_contents, &error)) {
6455 AutomationJSONReply(this, reply_message).SendError(error); 6538 AutomationJSONReply(this, reply_message).SendError(error);
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after
6973 7056
6974 Send(reply_message_); 7057 Send(reply_message_);
6975 redirect_query_ = 0; 7058 redirect_query_ = 0;
6976 reply_message_ = NULL; 7059 reply_message_ = NULL;
6977 } 7060 }
6978 7061
6979 void TestingAutomationProvider::OnRemoveProvider() { 7062 void TestingAutomationProvider::OnRemoveProvider() {
6980 if (g_browser_process) 7063 if (g_browser_process)
6981 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); 7064 g_browser_process->GetAutomationProviderList()->RemoveProvider(this);
6982 } 7065 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698