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

Side by Side Diff: chrome/test/chromedriver/session_commands.cc

Issue 23467010: [chromedriver] Logging tweaks and fixes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/chromedriver/session_commands.h" 5 #include "chrome/test/chromedriver/session_commands.h"
6 6
7 #include <list> 7 #include <list>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/logging.h" // For CHECK macros. 12 #include "base/logging.h" // For CHECK macros.
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/message_loop/message_loop_proxy.h" 14 #include "base/message_loop/message_loop_proxy.h"
15 #include "base/synchronization/lock.h" 15 #include "base/synchronization/lock.h"
16 #include "base/synchronization/waitable_event.h" 16 #include "base/synchronization/waitable_event.h"
17 #include "base/values.h" 17 #include "base/values.h"
18 #include "chrome/test/chromedriver/basic_types.h" 18 #include "chrome/test/chromedriver/basic_types.h"
19 #include "chrome/test/chromedriver/capabilities.h"
19 #include "chrome/test/chromedriver/chrome/automation_extension.h" 20 #include "chrome/test/chromedriver/chrome/automation_extension.h"
20 #include "chrome/test/chromedriver/chrome/chrome.h" 21 #include "chrome/test/chromedriver/chrome/chrome.h"
22 #include "chrome/test/chromedriver/chrome/chrome_android_impl.h"
23 #include "chrome/test/chromedriver/chrome/chrome_desktop_impl.h"
24 #include "chrome/test/chromedriver/chrome/device_manager.h"
25 #include "chrome/test/chromedriver/chrome/devtools_event_listener.h"
21 #include "chrome/test/chromedriver/chrome/geoposition.h" 26 #include "chrome/test/chromedriver/chrome/geoposition.h"
22 #include "chrome/test/chromedriver/chrome/status.h" 27 #include "chrome/test/chromedriver/chrome/status.h"
28 #include "chrome/test/chromedriver/chrome/version.h"
23 #include "chrome/test/chromedriver/chrome/web_view.h" 29 #include "chrome/test/chromedriver/chrome/web_view.h"
30 #include "chrome/test/chromedriver/chrome_launcher.h"
24 #include "chrome/test/chromedriver/logging.h" 31 #include "chrome/test/chromedriver/logging.h"
32 #include "chrome/test/chromedriver/net/url_request_context_getter.h"
25 #include "chrome/test/chromedriver/session.h" 33 #include "chrome/test/chromedriver/session.h"
26 #include "chrome/test/chromedriver/util.h" 34 #include "chrome/test/chromedriver/util.h"
27 35
28 namespace { 36 namespace {
29 37
30 const char kWindowHandlePrefix[] = "CDwindow-"; 38 const char kWindowHandlePrefix[] = "CDwindow-";
31 39
32 std::string WebViewIdToWindowHandle(const std::string& web_view_id) { 40 std::string WebViewIdToWindowHandle(const std::string& web_view_id) {
33 return kWindowHandlePrefix + web_view_id; 41 return kWindowHandlePrefix + web_view_id;
34 } 42 }
35 43
36 bool WindowHandleToWebViewId(const std::string& window_handle, 44 bool WindowHandleToWebViewId(const std::string& window_handle,
37 std::string* web_view_id) { 45 std::string* web_view_id) {
38 if (window_handle.find(kWindowHandlePrefix) != 0u) 46 if (window_handle.find(kWindowHandlePrefix) != 0u)
39 return false; 47 return false;
40 *web_view_id = window_handle.substr( 48 *web_view_id = window_handle.substr(
41 std::string(kWindowHandlePrefix).length()); 49 std::string(kWindowHandlePrefix).length());
42 return true; 50 return true;
43 } 51 }
44 52
45 } // namespace 53 } // namespace
46 54
55 InitSessionParams::InitSessionParams(
56 scoped_refptr<URLRequestContextGetter> context_getter,
57 const SyncWebSocketFactory& socket_factory,
58 DeviceManager* device_manager)
59 : context_getter(context_getter),
60 socket_factory(socket_factory),
61 device_manager(device_manager) {}
62
63 InitSessionParams::~InitSessionParams() {}
64
65 namespace {
66
67 scoped_ptr<base::DictionaryValue> CreateCapabilities(Chrome* chrome) {
68 scoped_ptr<base::DictionaryValue> caps(new base::DictionaryValue());
69 caps->SetString("browserName", "chrome");
70 caps->SetString("version", chrome->GetVersion());
71 caps->SetString("chrome.chromedriverVersion", kChromeDriverVersion);
72 caps->SetString("platform", chrome->GetOperatingSystemName());
73 caps->SetBoolean("javascriptEnabled", true);
74 caps->SetBoolean("takesScreenshot", true);
75 caps->SetBoolean("handlesAlerts", true);
76 caps->SetBoolean("databaseEnabled", true);
77 caps->SetBoolean("locationContextEnabled", true);
78 caps->SetBoolean("applicationCacheEnabled", false);
79 caps->SetBoolean("browserConnectionEnabled", false);
80 caps->SetBoolean("cssSelectorsEnabled", true);
81 caps->SetBoolean("webStorageEnabled", true);
82 caps->SetBoolean("rotatable", false);
83 caps->SetBoolean("acceptSslCerts", true);
84 caps->SetBoolean("nativeEvents", true);
85 return caps.Pass();
86 }
87
88
89 Status InitSessionHelper(
90 const InitSessionParams& bound_params,
91 Session* session,
92 const base::DictionaryValue& params,
93 scoped_ptr<base::Value>* value) {
94 const base::DictionaryValue* desired_caps;
95 if (!params.GetDictionary("desiredCapabilities", &desired_caps))
96 return Status(kUnknownError, "cannot find dict 'desiredCapabilities'");
97
98 Capabilities capabilities;
99 Status status = capabilities.Parse(*desired_caps);
chrisgao (Use stgao instead) 2013/09/06 21:20:13 If there is some warning during parsing like "load
kkania 2013/09/06 23:09:29 OK
100 if (status.IsError())
101 return status;
102
103 // Create Log's and DevToolsEventListener's for ones that are DevTools-based.
104 // Session will own the Log's, Chrome will own the listeners.
105 ScopedVector<DevToolsEventListener> devtools_event_listeners;
106 status = CreateLogs(capabilities,
107 &session->devtools_logs,
108 &session->driver_log,
109 &devtools_event_listeners);
110 if (status.IsError())
111 return status;
112
113 status = LaunchChrome(bound_params.context_getter.get(),
114 bound_params.socket_factory,
115 bound_params.device_manager,
116 capabilities,
117 devtools_event_listeners,
118 &session->chrome);
119 if (status.IsError())
120 return status;
121
122 std::list<std::string> web_view_ids;
123 status = session->chrome->GetWebViewIds(&web_view_ids);
124 if (status.IsError() || web_view_ids.empty()) {
125 return status.IsError() ? status :
126 Status(kUnknownError, "unable to discover open window in chrome");
127 }
128
129 session->window = web_view_ids.front();
130 session->detach = capabilities.detach;
131 session->force_devtools_screenshot = capabilities.force_devtools_screenshot;
132 session->capabilities = CreateCapabilities(session->chrome.get());
133 value->reset(session->capabilities->DeepCopy());
134 return Status(kOk);
135 }
136
137 } // namespace
138
139 Status ExecuteInitSession(
140 const InitSessionParams& bound_params,
141 Session* session,
142 const base::DictionaryValue& params,
143 scoped_ptr<base::Value>* value) {
144 Status status = InitSessionHelper(bound_params, session, params, value);
145 if (status.IsError())
146 session->quit = true;
147 return status;
148 }
149
47 Status ExecuteQuit( 150 Status ExecuteQuit(
48 bool allow_detach, 151 bool allow_detach,
49 Session* session, 152 Session* session,
50 const base::DictionaryValue& params, 153 const base::DictionaryValue& params,
51 scoped_ptr<base::Value>* value) { 154 scoped_ptr<base::Value>* value) {
52 if (allow_detach && session->detach) { 155 if (allow_detach && session->detach) {
53 return Status(kOk); 156 return Status(kOk);
54 } else { 157 } else {
55 session->quit = true; 158 session->quit = true;
56 return session->chrome->Quit(); 159 return session->chrome->Quit();
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 return status; 482 return status;
380 483
381 return extension->MaximizeWindow(); 484 return extension->MaximizeWindow();
382 } 485 }
383 486
384 Status ExecuteGetAvailableLogTypes( 487 Status ExecuteGetAvailableLogTypes(
385 Session* session, 488 Session* session,
386 const base::DictionaryValue& params, 489 const base::DictionaryValue& params,
387 scoped_ptr<base::Value>* value) { 490 scoped_ptr<base::Value>* value) {
388 scoped_ptr<base::ListValue> types(new base::ListValue()); 491 scoped_ptr<base::ListValue> types(new base::ListValue());
389 for (ScopedVector<WebDriverLog>::const_iterator log 492 std::vector<WebDriverLog*> logs = session->GetAllLogs();
390 = session->devtools_logs.begin(); 493 for (std::vector<WebDriverLog*>::const_iterator log = logs.begin();
391 log != session->devtools_logs.end(); ++log) { 494 log != logs.end();
495 ++log) {
392 types->AppendString((*log)->type()); 496 types->AppendString((*log)->type());
393 } 497 }
394 value->reset(types.release()); 498 *value = types.Pass();
395 return Status(kOk); 499 return Status(kOk);
396 } 500 }
397 501
398 Status ExecuteGetLog( 502 Status ExecuteGetLog(
399 Session* session, 503 Session* session,
400 const base::DictionaryValue& params, 504 const base::DictionaryValue& params,
401 scoped_ptr<base::Value>* value) { 505 scoped_ptr<base::Value>* value) {
402 std::string log_type; 506 std::string log_type;
403 if (!params.GetString("type", &log_type)) { 507 if (!params.GetString("type", &log_type)) {
404 return Status(kUnknownError, "missing or invalid 'type'"); 508 return Status(kUnknownError, "missing or invalid 'type'");
405 } 509 }
406 for (ScopedVector<WebDriverLog>::const_iterator log 510 std::vector<WebDriverLog*> logs = session->GetAllLogs();
407 = session->devtools_logs.begin(); 511 for (std::vector<WebDriverLog*>::const_iterator log = logs.begin();
408 log != session->devtools_logs.end(); ++log) { 512 log != logs.end();
513 ++log) {
409 if (log_type == (*log)->type()) { 514 if (log_type == (*log)->type()) {
410 scoped_ptr<base::ListValue> log_entries = (*log)->GetAndClearEntries(); 515 *value = (*log)->GetAndClearEntries();
411 value->reset(log_entries.release());
412 return Status(kOk); 516 return Status(kOk);
413 } 517 }
414 } 518 }
415 return Status(kUnknownError, "log type '" + log_type + "' not found"); 519 return Status(kUnknownError, "log type '" + log_type + "' not found");
416 } 520 }
417 521
418 Status ExecuteUploadFile( 522 Status ExecuteUploadFile(
419 Session* session, 523 Session* session,
420 const base::DictionaryValue& params, 524 const base::DictionaryValue& params,
421 scoped_ptr<base::Value>* value) { 525 scoped_ptr<base::Value>* value) {
(...skipping 15 matching lines...) Expand all
437 } 541 }
438 std::string error_msg; 542 std::string error_msg;
439 base::FilePath upload; 543 base::FilePath upload;
440 Status status = UnzipSoleFile(upload_dir, zip_data, &upload); 544 Status status = UnzipSoleFile(upload_dir, zip_data, &upload);
441 if (status.IsError()) 545 if (status.IsError())
442 return Status(kUnknownError, "unable to unzip 'file'", status); 546 return Status(kUnknownError, "unable to unzip 'file'", status);
443 547
444 value->reset(new base::StringValue(upload.value())); 548 value->reset(new base::StringValue(upload.value()));
445 return Status(kOk); 549 return Status(kOk);
446 } 550 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698