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

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

Issue 13185004: [chromedriver] Implement proxy capability. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments & Rebase. Created 7 years, 8 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/test/chromedriver/commands.h" 5 #include "chrome/test/chromedriver/commands.h"
6 6
7 #include "base/bind.h"
7 #include "base/callback.h" 8 #include "base/callback.h"
chrisgao (Use stgao instead) 2013/04/02 15:37:17 unused
chrisgao (Use stgao instead) 2013/04/03 18:51:43 Done.
8 #include "base/file_util.h" 9 #include "base/file_util.h"
9 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
10 #include "base/sys_info.h" 11 #include "base/sys_info.h"
11 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/test/chromedriver/capabilities_parser.h"
12 #include "chrome/test/chromedriver/chrome/chrome.h" 14 #include "chrome/test/chromedriver/chrome/chrome.h"
13 #include "chrome/test/chromedriver/chrome/chrome_android_impl.h" 15 #include "chrome/test/chromedriver/chrome/chrome_android_impl.h"
14 #include "chrome/test/chromedriver/chrome/chrome_desktop_impl.h" 16 #include "chrome/test/chromedriver/chrome/chrome_desktop_impl.h"
15 #include "chrome/test/chromedriver/chrome/status.h" 17 #include "chrome/test/chromedriver/chrome/status.h"
16 #include "chrome/test/chromedriver/chrome/version.h" 18 #include "chrome/test/chromedriver/chrome/version.h"
17 #include "chrome/test/chromedriver/chrome/web_view.h" 19 #include "chrome/test/chromedriver/chrome/web_view.h"
18 #include "chrome/test/chromedriver/net/net_util.h" 20 #include "chrome/test/chromedriver/net/net_util.h"
19 #include "chrome/test/chromedriver/net/url_request_context_getter.h" 21 #include "chrome/test/chromedriver/net/url_request_context_getter.h"
20 #include "chrome/test/chromedriver/session.h" 22 #include "chrome/test/chromedriver/session.h"
21 #include "chrome/test/chromedriver/session_map.h" 23 #include "chrome/test/chromedriver/session_map.h"
(...skipping 28 matching lines...) Expand all
50 scoped_ptr<base::Value>* out_value, 52 scoped_ptr<base::Value>* out_value,
51 std::string* out_session_id) { 53 std::string* out_session_id) {
52 int port; 54 int port;
53 if (!FindOpenPort(&port)) 55 if (!FindOpenPort(&port))
54 return Status(kUnknownError, "failed to find an open port for Chrome"); 56 return Status(kUnknownError, "failed to find an open port for Chrome");
55 57
56 const base::DictionaryValue* desired_caps; 58 const base::DictionaryValue* desired_caps;
57 if (!params.GetDictionary("desiredCapabilities", &desired_caps)) 59 if (!params.GetDictionary("desiredCapabilities", &desired_caps))
58 return Status(kUnknownError, "cannot find dict 'desiredCapabilities'"); 60 return Status(kUnknownError, "cannot find dict 'desiredCapabilities'");
59 61
62 Capabilities capabilities;
63 Status status = ParseCapabilities(
64 *desired_caps, & capabilities, base::Bind(&file_util::PathExists));
65 if (status.IsError())
66 return status;
67
60 scoped_ptr<Chrome> chrome; 68 scoped_ptr<Chrome> chrome;
61 Status status(kOk); 69 if (capabilities.HasAndroidPackage()) {
62 std::string android_package;
63 if (desired_caps->GetString("chromeOptions.android_package",
64 &android_package)) {
65 scoped_ptr<ChromeAndroidImpl> chrome_android(new ChromeAndroidImpl( 70 scoped_ptr<ChromeAndroidImpl> chrome_android(new ChromeAndroidImpl(
66 context_getter, port, socket_factory)); 71 context_getter, port, socket_factory));
67 status = chrome_android->Launch(android_package); 72 status = chrome_android->Launch(capabilities.android_package);
68 chrome.reset(chrome_android.release()); 73 chrome.reset(chrome_android.release());
69 } else { 74 } else {
70 base::FilePath::StringType path_str;
71 base::FilePath chrome_exe;
72 if (desired_caps->GetString("chromeOptions.binary", &path_str)) {
73 chrome_exe = base::FilePath(path_str);
74 if (!file_util::PathExists(chrome_exe)) {
75 std::string message = base::StringPrintf(
76 "no chrome binary at %" PRFilePath,
77 path_str.c_str());
78 return Status(kUnknownError, message);
79 }
80 }
81
82 const base::Value* args = NULL;
83 const base::ListValue* args_list = NULL;
84 if (desired_caps->Get("chromeOptions.args", &args) &&
85 !args->GetAsList(&args_list)) {
86 return Status(kUnknownError,
87 "command line arguments for chrome must be a list");
88 }
89
90 const base::Value* prefs = NULL;
91 const base::DictionaryValue* prefs_dict = NULL;
92 if (desired_caps->Get("chromeOptions.prefs", &prefs) &&
93 !prefs->GetAsDictionary(&prefs_dict)) {
94 return Status(kUnknownError, "'prefs' must be a dictionary");
95 }
96
97 const base::Value* local_state = NULL;
98 const base::DictionaryValue* local_state_dict = NULL;
99 if (desired_caps->Get("chromeOptions.localState", &local_state) &&
100 !prefs->GetAsDictionary(&prefs_dict)) {
101 return Status(kUnknownError, "'localState' must be a dictionary");
102 }
103
104 const base::Value* extensions = NULL;
105 const base::ListValue* extensions_list = NULL;
106 if (desired_caps->Get("chromeOptions.extensions", &extensions)
107 && !extensions->GetAsList(&extensions_list)) {
108 return Status(kUnknownError,
109 "chrome extensions must be a list");
110 }
111
112 const base::Value* log_path = NULL;
113 std::string chrome_log_path;
114 if (desired_caps->Get("chromeOptions.logPath", &log_path) &&
115 !log_path->GetAsString(&chrome_log_path)) {
116 return Status(kUnknownError,
117 "chrome log path must be a string");
118 }
119
120 scoped_ptr<ChromeDesktopImpl> chrome_desktop(new ChromeDesktopImpl( 75 scoped_ptr<ChromeDesktopImpl> chrome_desktop(new ChromeDesktopImpl(
121 context_getter, port, socket_factory)); 76 context_getter, port, socket_factory));
122 status = chrome_desktop->Launch(chrome_exe, args_list, extensions_list, 77 status = chrome_desktop->Launch(
123 prefs_dict, local_state_dict, 78 capabilities.chrome_exe, &capabilities.args_list,
124 chrome_log_path); 79 capabilities.extensions_list, capabilities.prefs_dict,
80 capabilities.local_state_dict, capabilities.log_path);
125 chrome.reset(chrome_desktop.release()); 81 chrome.reset(chrome_desktop.release());
126 } 82 }
127 if (status.IsError()) 83 if (status.IsError())
128 return Status(kSessionNotCreatedException, status.message()); 84 return Status(kSessionNotCreatedException, status.message());
129 85
130 std::list<std::string> web_view_ids; 86 std::list<std::string> web_view_ids;
131 status = chrome->GetWebViewIds(&web_view_ids); 87 status = chrome->GetWebViewIds(&web_view_ids);
132 if (status.IsError() || web_view_ids.empty()) { 88 if (status.IsError() || web_view_ids.empty()) {
133 chrome->Quit(); 89 chrome->Quit();
134 return status.IsError() ? status : 90 return status.IsError() ? status :
(...skipping 29 matching lines...) Expand all
164 std::string* out_session_id) { 120 std::string* out_session_id) {
165 std::vector<std::string> session_ids; 121 std::vector<std::string> session_ids;
166 session_map->GetKeys(&session_ids); 122 session_map->GetKeys(&session_ids);
167 for (size_t i = 0; i < session_ids.size(); ++i) { 123 for (size_t i = 0; i < session_ids.size(); ++i) {
168 scoped_ptr<base::Value> unused_value; 124 scoped_ptr<base::Value> unused_value;
169 std::string unused_session_id; 125 std::string unused_session_id;
170 quit_command.Run(params, session_ids[i], &unused_value, &unused_session_id); 126 quit_command.Run(params, session_ids[i], &unused_value, &unused_session_id);
171 } 127 }
172 return Status(kOk); 128 return Status(kOk);
173 } 129 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698