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

Side by Side Diff: chrome/test/webdriver/session.cc

Issue 7523060: Let pyauto create an attached webdriver instance to manipulate web pages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address nirnimesh' latest comments Created 9 years, 4 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 #include "chrome/test/webdriver/session.h" 5 #include "chrome/test/webdriver/session.h"
6 6
7 #include <sstream> 7 #include <sstream>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 screenshot_on_error_(false), 63 screenshot_on_error_(false),
64 use_native_events_(false), 64 use_native_events_(false),
65 has_alert_prompt_text_(false) { 65 has_alert_prompt_text_(false) {
66 SessionManager::GetInstance()->Add(this); 66 SessionManager::GetInstance()->Add(this);
67 } 67 }
68 68
69 Session::~Session() { 69 Session::~Session() {
70 SessionManager::GetInstance()->Remove(id_); 70 SessionManager::GetInstance()->Remove(id_);
71 } 71 }
72 72
73 Error* Session::Init(const FilePath& browser_exe, 73 Error* Session::Init(const Automation::InitOptions& options) {
74 const FilePath& user_data_dir,
75 const CommandLine& options) {
76 if (!thread_.Start()) { 74 if (!thread_.Start()) {
77 delete this; 75 delete this;
78 return new Error(kUnknownError, "Cannot start session thread"); 76 return new Error(kUnknownError, "Cannot start session thread");
79 } 77 }
80 78
81 Error* error = NULL; 79 Error* error = NULL;
82 RunSessionTask(NewRunnableMethod( 80 RunSessionTask(NewRunnableMethod(
83 this, 81 this,
84 &Session::InitOnSessionThread, 82 &Session::InitOnSessionThread,
85 browser_exe,
86 user_data_dir,
87 options, 83 options,
88 &error)); 84 &error));
89 if (error) 85 if (error)
90 Terminate(); 86 Terminate();
91 return error; 87 return error;
92 } 88 }
93 89
94 void Session::Terminate() { 90 void Session::Terminate() {
95 RunSessionTask(NewRunnableMethod( 91 RunSessionTask(NewRunnableMethod(
96 this, 92 this,
(...skipping 971 matching lines...) Expand 10 before | Expand all | Expand 10 after
1068 done_event.Wait(); 1064 done_event.Wait();
1069 } 1065 }
1070 1066
1071 void Session::RunSessionTaskOnSessionThread(Task* task, 1067 void Session::RunSessionTaskOnSessionThread(Task* task,
1072 base::WaitableEvent* done_event) { 1068 base::WaitableEvent* done_event) {
1073 task->Run(); 1069 task->Run();
1074 delete task; 1070 delete task;
1075 done_event->Signal(); 1071 done_event->Signal();
1076 } 1072 }
1077 1073
1078 void Session::InitOnSessionThread(const FilePath& browser_exe, 1074
1079 const FilePath& user_data_dir, 1075 void Session::InitOnSessionThread(const Automation::InitOptions& options,
1080 const CommandLine& options,
1081 Error** error) { 1076 Error** error) {
1082 automation_.reset(new Automation()); 1077 automation_.reset(new Automation());
1083 if (browser_exe.empty()) { 1078 automation_->Init(options, error);
1084 automation_->Init(options, user_data_dir, error);
1085 } else {
1086 automation_->InitWithBrowserPath(
1087 browser_exe, user_data_dir, options, error);
1088 }
1089
1090 if (*error) 1079 if (*error)
1091 return; 1080 return;
1092 1081
1093 std::vector<int> tab_ids; 1082 std::vector<int> tab_ids;
1094 automation_->GetTabIds(&tab_ids, error); 1083 automation_->GetTabIds(&tab_ids, error);
1095 if (*error) 1084 if (*error)
1096 return; 1085 return;
1097 if (tab_ids.empty()) { 1086 if (tab_ids.empty()) {
1098 *error = new Error(kUnknownError, "No tab ids after initialization"); 1087 *error = new Error(kUnknownError, "No tab ids after initialization");
1099 return; 1088 return;
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
1442 path, 1431 path,
1443 &error)); 1432 &error));
1444 if (error) 1433 if (error)
1445 return error; 1434 return error;
1446 if (!file_util::ReadFileToString(path, png)) 1435 if (!file_util::ReadFileToString(path, png))
1447 return new Error(kUnknownError, "Could not read screenshot file"); 1436 return new Error(kUnknownError, "Could not read screenshot file");
1448 return NULL; 1437 return NULL;
1449 } 1438 }
1450 1439
1451 } // namespace webdriver 1440 } // namespace webdriver
OLDNEW
« chrome/browser/automation/automation_provider.cc ('K') | « chrome/test/webdriver/session.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698