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

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

Issue 2315363003: [chromedriver] Ensure GetLog works even if the current tab is closed. (Closed)
Patch Set: rebase and remove unused variable Created 4 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
« no previous file with comments | « no previous file | chrome/test/chromedriver/test/run_py_tests.py » ('j') | 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 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 bool WindowHandleToWebViewId(const std::string& window_handle, 64 bool WindowHandleToWebViewId(const std::string& window_handle,
65 std::string* web_view_id) { 65 std::string* web_view_id) {
66 if (!base::StartsWith(window_handle, kWindowHandlePrefix, 66 if (!base::StartsWith(window_handle, kWindowHandlePrefix,
67 base::CompareCase::SENSITIVE)) { 67 base::CompareCase::SENSITIVE)) {
68 return false; 68 return false;
69 } 69 }
70 *web_view_id = window_handle.substr(sizeof(kWindowHandlePrefix) - 1); 70 *web_view_id = window_handle.substr(sizeof(kWindowHandlePrefix) - 1);
71 return true; 71 return true;
72 } 72 }
73 73
74 Status EvaluateScriptAndIgnoreResult(Session* session, std::string expression) {
75 WebView* web_view = nullptr;
76 Status status = session->GetTargetWindow(&web_view);
77 if (status.IsError())
78 return status;
79 std::string frame_id = session->GetCurrentFrameId();
80 std::unique_ptr<base::Value> result;
81 return web_view->EvaluateScript(frame_id, expression, &result);
82 }
83
74 } // namespace 84 } // namespace
75 85
76 InitSessionParams::InitSessionParams( 86 InitSessionParams::InitSessionParams(
77 scoped_refptr<URLRequestContextGetter> context_getter, 87 scoped_refptr<URLRequestContextGetter> context_getter,
78 const SyncWebSocketFactory& socket_factory, 88 const SyncWebSocketFactory& socket_factory,
79 DeviceManager* device_manager, 89 DeviceManager* device_manager,
80 PortServer* port_server, 90 PortServer* port_server,
81 PortManager* port_manager) 91 PortManager* port_manager)
82 : context_getter(context_getter), 92 : context_getter(context_getter),
83 socket_factory(socket_factory), 93 socket_factory(socket_factory),
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 } 748 }
739 749
740 Status ExecuteGetLog(Session* session, 750 Status ExecuteGetLog(Session* session,
741 const base::DictionaryValue& params, 751 const base::DictionaryValue& params,
742 std::unique_ptr<base::Value>* value) { 752 std::unique_ptr<base::Value>* value) {
743 std::string log_type; 753 std::string log_type;
744 if (!params.GetString("type", &log_type)) { 754 if (!params.GetString("type", &log_type)) {
745 return Status(kUnknownError, "missing or invalid 'type'"); 755 return Status(kUnknownError, "missing or invalid 'type'");
746 } 756 }
747 757
748 WebView* web_view = NULL; 758 // Evaluate a JavaScript in the renderer process for the current tab, to flush
749 Status status = session->GetTargetWindow(&web_view); 759 // out any pending logging-related events.
750 if (status.IsError()) 760 Status status = EvaluateScriptAndIgnoreResult(session, "1");
751 return status; 761 if (status.IsError()) {
752 762 // Sometimes a WebDriver client fetches logs to diagnose an error that has
753 base::ListValue args; 763 // occurred. It's possible that in the case of an error, the renderer is no
754 std::unique_ptr<base::Value> result; 764 // be longer available, but we should return the logs anyway. So log (but
755 status = web_view->CallFunction(session->GetCurrentFrameId(), 765 // don't fail on) any error that we get while evaluating the script.
756 "function(s) { return 1; }", args, &result); 766 LOG(WARNING) << "Unable to evaluate script: " << status.message();
757 if (status.IsError()) 767 }
758 return status;
759
760 int response;
761 if (!result->GetAsInteger(&response) || response != 1)
762 return Status(kUnknownError, "unexpected response from browser");
763 768
764 std::vector<WebDriverLog*> logs = session->GetAllLogs(); 769 std::vector<WebDriverLog*> logs = session->GetAllLogs();
765 for (std::vector<WebDriverLog*>::const_iterator log = logs.begin(); 770 for (std::vector<WebDriverLog*>::const_iterator log = logs.begin();
766 log != logs.end(); 771 log != logs.end();
767 ++log) { 772 ++log) {
768 if (log_type == (*log)->type()) { 773 if (log_type == (*log)->type()) {
769 *value = (*log)->GetAndClearEntries(); 774 *value = (*log)->GetAndClearEntries();
770 return Status(kOk); 775 return Status(kOk);
771 } 776 }
772 } 777 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 std::unique_ptr<base::Value>* value) { 871 std::unique_ptr<base::Value>* value) {
867 WebView* web_view = nullptr; 872 WebView* web_view = nullptr;
868 Status status = session->GetTargetWindow(&web_view); 873 Status status = session->GetTargetWindow(&web_view);
869 if (status.IsError()) 874 if (status.IsError())
870 return status; 875 return status;
871 status = web_view->DeleteScreenOrientation(); 876 status = web_view->DeleteScreenOrientation();
872 if (status.IsError()) 877 if (status.IsError())
873 return status; 878 return status;
874 return Status(kOk); 879 return Status(kOk);
875 } 880 }
OLDNEW
« no previous file with comments | « no previous file | chrome/test/chromedriver/test/run_py_tests.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698