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

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: rebase 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
« no previous file with comments | « chrome/test/chromedriver/session_commands.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 session->driver_log.reset(
95 new WebDriverLog(WebDriverLog::kDriverType, Log::kAll));
96 const base::DictionaryValue* desired_caps;
97 if (!params.GetDictionary("desiredCapabilities", &desired_caps))
98 return Status(kUnknownError, "cannot find dict 'desiredCapabilities'");
99
100 Capabilities capabilities;
101 Status status = capabilities.Parse(*desired_caps);
102 if (status.IsError())
103 return status;
104
105 if (capabilities.logging_prefs.count(WebDriverLog::kDriverType)) {
106 session->driver_log->set_min_level(
107 capabilities.logging_prefs[WebDriverLog::kDriverType]);
108 }
109
110 // Create Log's and DevToolsEventListener's for ones that are DevTools-based.
111 // Session will own the Log's, Chrome will own the listeners.
112 ScopedVector<DevToolsEventListener> devtools_event_listeners;
113 status = CreateLogs(capabilities,
114 &session->devtools_logs,
115 &devtools_event_listeners);
116 if (status.IsError())
117 return status;
118
119 status = LaunchChrome(bound_params.context_getter.get(),
120 bound_params.socket_factory,
121 bound_params.device_manager,
122 capabilities,
123 devtools_event_listeners,
124 &session->chrome);
125 if (status.IsError())
126 return status;
127
128 std::list<std::string> web_view_ids;
129 status = session->chrome->GetWebViewIds(&web_view_ids);
130 if (status.IsError() || web_view_ids.empty()) {
131 return status.IsError() ? status :
132 Status(kUnknownError, "unable to discover open window in chrome");
133 }
134
135 session->window = web_view_ids.front();
136 session->detach = capabilities.detach;
137 session->force_devtools_screenshot = capabilities.force_devtools_screenshot;
138 session->capabilities = CreateCapabilities(session->chrome.get());
139 value->reset(session->capabilities->DeepCopy());
140 return Status(kOk);
141 }
142
143 } // namespace
144
145 Status ExecuteInitSession(
146 const InitSessionParams& bound_params,
147 Session* session,
148 const base::DictionaryValue& params,
149 scoped_ptr<base::Value>* value) {
150 Status status = InitSessionHelper(bound_params, session, params, value);
151 if (status.IsError())
152 session->quit = true;
153 return status;
154 }
155
47 Status ExecuteQuit( 156 Status ExecuteQuit(
48 bool allow_detach, 157 bool allow_detach,
49 Session* session, 158 Session* session,
50 const base::DictionaryValue& params, 159 const base::DictionaryValue& params,
51 scoped_ptr<base::Value>* value) { 160 scoped_ptr<base::Value>* value) {
52 if (allow_detach && session->detach) { 161 if (allow_detach && session->detach) {
53 return Status(kOk); 162 return Status(kOk);
54 } else { 163 } else {
55 session->quit = true; 164 session->quit = true;
56 return session->chrome->Quit(); 165 return session->chrome->Quit();
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 return status; 488 return status;
380 489
381 return extension->MaximizeWindow(); 490 return extension->MaximizeWindow();
382 } 491 }
383 492
384 Status ExecuteGetAvailableLogTypes( 493 Status ExecuteGetAvailableLogTypes(
385 Session* session, 494 Session* session,
386 const base::DictionaryValue& params, 495 const base::DictionaryValue& params,
387 scoped_ptr<base::Value>* value) { 496 scoped_ptr<base::Value>* value) {
388 scoped_ptr<base::ListValue> types(new base::ListValue()); 497 scoped_ptr<base::ListValue> types(new base::ListValue());
389 for (ScopedVector<WebDriverLog>::const_iterator log 498 std::vector<WebDriverLog*> logs = session->GetAllLogs();
390 = session->devtools_logs.begin(); 499 for (std::vector<WebDriverLog*>::const_iterator log = logs.begin();
391 log != session->devtools_logs.end(); ++log) { 500 log != logs.end();
501 ++log) {
392 types->AppendString((*log)->type()); 502 types->AppendString((*log)->type());
393 } 503 }
394 value->reset(types.release()); 504 *value = types.Pass();
395 return Status(kOk); 505 return Status(kOk);
396 } 506 }
397 507
398 Status ExecuteGetLog( 508 Status ExecuteGetLog(
399 Session* session, 509 Session* session,
400 const base::DictionaryValue& params, 510 const base::DictionaryValue& params,
401 scoped_ptr<base::Value>* value) { 511 scoped_ptr<base::Value>* value) {
402 std::string log_type; 512 std::string log_type;
403 if (!params.GetString("type", &log_type)) { 513 if (!params.GetString("type", &log_type)) {
404 return Status(kUnknownError, "missing or invalid 'type'"); 514 return Status(kUnknownError, "missing or invalid 'type'");
405 } 515 }
406 for (ScopedVector<WebDriverLog>::const_iterator log 516 std::vector<WebDriverLog*> logs = session->GetAllLogs();
407 = session->devtools_logs.begin(); 517 for (std::vector<WebDriverLog*>::const_iterator log = logs.begin();
408 log != session->devtools_logs.end(); ++log) { 518 log != logs.end();
519 ++log) {
409 if (log_type == (*log)->type()) { 520 if (log_type == (*log)->type()) {
410 scoped_ptr<base::ListValue> log_entries = (*log)->GetAndClearEntries(); 521 *value = (*log)->GetAndClearEntries();
411 value->reset(log_entries.release());
412 return Status(kOk); 522 return Status(kOk);
413 } 523 }
414 } 524 }
415 return Status(kUnknownError, "log type '" + log_type + "' not found"); 525 return Status(kUnknownError, "log type '" + log_type + "' not found");
416 } 526 }
417 527
418 Status ExecuteUploadFile( 528 Status ExecuteUploadFile(
419 Session* session, 529 Session* session,
420 const base::DictionaryValue& params, 530 const base::DictionaryValue& params,
421 scoped_ptr<base::Value>* value) { 531 scoped_ptr<base::Value>* value) {
(...skipping 15 matching lines...) Expand all
437 } 547 }
438 std::string error_msg; 548 std::string error_msg;
439 base::FilePath upload; 549 base::FilePath upload;
440 Status status = UnzipSoleFile(upload_dir, zip_data, &upload); 550 Status status = UnzipSoleFile(upload_dir, zip_data, &upload);
441 if (status.IsError()) 551 if (status.IsError())
442 return Status(kUnknownError, "unable to unzip 'file'", status); 552 return Status(kUnknownError, "unable to unzip 'file'", status);
443 553
444 value->reset(new base::StringValue(upload.value())); 554 value->reset(new base::StringValue(upload.value()));
445 return Status(kOk); 555 return Status(kOk);
446 } 556 }
OLDNEW
« no previous file with comments | « chrome/test/chromedriver/session_commands.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698