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

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

Issue 7582005: Add chrome.loadAsync capability to ChromeDriver, which allows the user not to (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ... 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
« no previous file with comments | « chrome/test/webdriver/automation.h ('k') | chrome/test/webdriver/commands/create_session.cc » ('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) 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/automation.h" 5 #include "chrome/test/webdriver/automation.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #endif 9 #endif
10 10
11 #include "base/base_paths.h" 11 #include "base/base_paths.h"
12 #include "base/basictypes.h"
12 #include "base/callback.h" 13 #include "base/callback.h"
13 #include "base/command_line.h" 14 #include "base/command_line.h"
14 #include "base/environment.h" 15 #include "base/environment.h"
15 #include "base/file_path.h" 16 #include "base/file_path.h"
16 #include "base/file_util.h" 17 #include "base/file_util.h"
17 #include "base/json/json_writer.h" 18 #include "base/json/json_writer.h"
18 #include "base/logging.h" 19 #include "base/logging.h"
20 #include "base/memory/ref_counted.h"
19 #include "base/path_service.h" 21 #include "base/path_service.h"
20 #include "base/string_number_conversions.h" 22 #include "base/string_number_conversions.h"
21 #include "base/string_split.h" 23 #include "base/string_split.h"
22 #include "base/stringprintf.h" 24 #include "base/stringprintf.h"
23 #include "base/synchronization/waitable_event.h" 25 #include "base/synchronization/waitable_event.h"
24 #include "base/utf_string_conversions.h" 26 #include "base/utf_string_conversions.h"
25 #include "base/values.h" 27 #include "base/values.h"
26 #include "chrome/common/automation_constants.h" 28 #include "chrome/common/automation_constants.h"
27 #include "chrome/common/chrome_constants.h" 29 #include "chrome/common/chrome_constants.h"
28 #include "chrome/common/chrome_switches.h" 30 #include "chrome/common/chrome_switches.h"
29 #include "chrome/common/url_constants.h" 31 #include "chrome/common/url_constants.h"
30 #include "chrome/test/automation/automation_json_requests.h" 32 #include "chrome/test/automation/automation_json_requests.h"
31 #include "chrome/test/automation/automation_proxy.h" 33 #include "chrome/test/automation/automation_proxy.h"
34 #include "chrome/test/automation/browser_proxy.h"
32 #include "chrome/test/automation/extension_proxy.h" 35 #include "chrome/test/automation/extension_proxy.h"
33 #include "chrome/test/automation/proxy_launcher.h" 36 #include "chrome/test/automation/proxy_launcher.h"
37 #include "chrome/test/automation/tab_proxy.h"
34 #include "chrome/test/webdriver/frame_path.h" 38 #include "chrome/test/webdriver/frame_path.h"
35 #include "chrome/test/webdriver/webdriver_error.h" 39 #include "chrome/test/webdriver/webdriver_error.h"
36 #include "ui/gfx/point.h" 40 #include "ui/gfx/point.h"
37 41
38 #if defined(OS_WIN) 42 #if defined(OS_WIN)
39 #include "base/win/registry.h" 43 #include "base/win/registry.h"
40 #include "base/win/windows_version.h" 44 #include "base/win/windows_version.h"
41 #endif 45 #endif
42 46
43 namespace { 47 namespace {
44 48
45 // Gets the path to the default Chrome executable. Returns true on success. 49 // Gets the path to the default Chrome executable. Returns true on success.
46 bool GetDefaultChromeExe(FilePath* browser_exe) { 50 bool GetDefaultChromeExe(FilePath* browser_exe) {
51 // Instead of using chrome constants, we hardcode these constants here so
52 // that we can locate chrome or chromium regardless of the branding
53 // chromedriver is built with. It may be argued that then we need to keep
54 // these in sync with chrome constants. However, if chrome constants changes,
55 // we need to look for the previous and new versions to support some
56 // backwards compatibility.
57 #if defined(OS_WIN)
58 FilePath browser_exes[] = {
59 FilePath(L"chrome.exe")
60 };
61 #elif defined(OS_MACOSX)
62 FilePath browser_exes[] = {
63 FilePath("Google Chrome.app/Contents/MacOS/Google Chrome"),
64 FilePath("Chromium.app/Contents/MacOS/Chromium")
65 };
66 #elif defined(OS_LINUX)
67 FilePath browser_exes[] = {
68 FilePath("google-chrome"),
69 FilePath("chrome"),
70 FilePath("chromium"),
71 FilePath("chromium-browser")
72 };
73 #endif
74
75 // Check the directory which this module resides in.
76 FilePath module_dir;
77 if (PathService::Get(base::DIR_MODULE, &module_dir)) {
78 for (size_t j = 0; j < arraysize(browser_exes); ++j) {
79 FilePath path = module_dir.Append(browser_exes[j]);
80 if (file_util::PathExists(path)) {
81 *browser_exe = path;
82 return true;
83 }
84 }
85 }
86
47 std::vector<FilePath> locations; 87 std::vector<FilePath> locations;
48 // Add the directory which this module resides in. 88 std::vector<FilePath> chromium_locations;
49 FilePath module_dir;
50 if (PathService::Get(base::DIR_MODULE, &module_dir))
51 locations.push_back(module_dir);
52
53 #if defined(OS_WIN) 89 #if defined(OS_WIN)
54 // Add the App Paths registry key location. 90 // Add the App Paths registry key location.
55 const wchar_t kSubKey[] = 91 const wchar_t kSubKey[] =
56 L"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\chrome.exe"; 92 L"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\chrome.exe";
57 base::win::RegKey key(HKEY_CURRENT_USER, kSubKey, KEY_READ); 93 base::win::RegKey key(HKEY_CURRENT_USER, kSubKey, KEY_READ);
58 std::wstring path; 94 std::wstring path;
59 if (key.ReadValue(L"path", &path) == ERROR_SUCCESS) 95 if (key.ReadValue(L"path", &path) == ERROR_SUCCESS)
60 locations.push_back(FilePath(path)); 96 locations.push_back(FilePath(path));
61 base::win::RegKey sys_key(HKEY_LOCAL_MACHINE, kSubKey, KEY_READ); 97 base::win::RegKey sys_key(HKEY_LOCAL_MACHINE, kSubKey, KEY_READ);
62 if (sys_key.ReadValue(L"path", &path) == ERROR_SUCCESS) 98 if (sys_key.ReadValue(L"path", &path) == ERROR_SUCCESS)
63 locations.push_back(FilePath(path)); 99 locations.push_back(FilePath(path));
64 100
65 // Add the user-level location for Chrome. 101 // Add the user-level location for Chrome.
66 FilePath app_from_google(L"Google\\Chrome\\Application"); 102 FilePath app_from_google(L"Google\\Chrome\\Application");
103 FilePath app_from_chromium(L"Chromium\\Application");
67 scoped_ptr<base::Environment> env(base::Environment::Create()); 104 scoped_ptr<base::Environment> env(base::Environment::Create());
68 std::string home_dir; 105 std::string home_dir;
69 if (env->GetVar("userprofile", &home_dir)) { 106 if (env->GetVar("userprofile", &home_dir)) {
70 FilePath default_location(UTF8ToWide(home_dir)); 107 FilePath default_location(UTF8ToWide(home_dir));
71 if (base::win::GetVersion() < base::win::VERSION_VISTA) { 108 if (base::win::GetVersion() < base::win::VERSION_VISTA) {
72 default_location = default_location.Append( 109 default_location = default_location.Append(
73 L"Local Settings\\Application Data"); 110 L"Local Settings\\Application Data");
74 } else { 111 } else {
75 default_location = default_location.Append(L"AppData\\Local"); 112 default_location = default_location.Append(L"AppData\\Local");
76 } 113 }
77 locations.push_back(default_location.Append(app_from_google)); 114 locations.push_back(default_location.Append(app_from_google));
115 chromium_locations.push_back(default_location.Append(app_from_chromium));
78 } 116 }
79 117
80 // Add the system-level location for Chrome. 118 // Add the system-level location for Chrome.
81 std::string program_dir; 119 std::string program_dir;
82 if (env->GetVar("ProgramFiles", &program_dir)) { 120 if (env->GetVar("ProgramFiles", &program_dir)) {
83 locations.push_back(FilePath(UTF8ToWide(program_dir)) 121 locations.push_back(FilePath(UTF8ToWide(program_dir))
84 .Append(app_from_google)); 122 .Append(app_from_google));
123 chromium_locations.push_back(FilePath(UTF8ToWide(program_dir))
124 .Append(app_from_chromium));
85 } 125 }
86 if (env->GetVar("ProgramFiles(x86)", &program_dir)) { 126 if (env->GetVar("ProgramFiles(x86)", &program_dir)) {
87 locations.push_back(FilePath(UTF8ToWide(program_dir)) 127 locations.push_back(FilePath(UTF8ToWide(program_dir))
88 .Append(app_from_google)); 128 .Append(app_from_google));
129 chromium_locations.push_back(FilePath(UTF8ToWide(program_dir))
130 .Append(app_from_chromium));
89 } 131 }
90 #elif defined(OS_MACOSX) 132 #elif defined(OS_MACOSX)
133 locations.push_back(file_util::GetHomeDir().AppendASCII("Applications"));
91 locations.push_back(FilePath("/Applications")); 134 locations.push_back(FilePath("/Applications"));
92 #elif defined(OS_LINUX) 135 #elif defined(OS_LINUX)
93 // Proxy launcher doesn't check for google-chrome, only chrome. 136 locations.push_back(FilePath("/opt/google/chrome"));
94 FilePath chrome_sym_link("/usr/bin/google-chrome"); 137 locations.push_back(FilePath("/usr/local/bin"));
95 if (file_util::PathExists(chrome_sym_link)) { 138 locations.push_back(FilePath("/usr/local/sbin"));
96 FilePath chrome; 139 locations.push_back(FilePath("/usr/bin"));
97 if (file_util::ReadSymbolicLink(chrome_sym_link, &chrome)) { 140 locations.push_back(FilePath("/usr/sbin"));
98 locations.push_back(chrome.DirName()); 141 locations.push_back(FilePath("/bin"));
99 } 142 locations.push_back(FilePath("/sbin"));
100 }
101 #endif 143 #endif
102 144
103 // Add the current directory. 145 // Add the current directory.
104 FilePath current_dir; 146 FilePath current_dir;
105 if (file_util::GetCurrentDirectory(&current_dir)) 147 if (file_util::GetCurrentDirectory(&current_dir))
106 locations.push_back(current_dir); 148 locations.push_back(current_dir);
107 149
108 // Determine the default directory. 150 // Determine the default exe.
109 for (size_t i = 0; i < locations.size(); ++i) { 151
110 FilePath path = locations[i].Append(chrome::kBrowserProcessExecutablePath); 152 // Loop through the browser executable paths (|browser_exes|). For each
111 if (file_util::PathExists(path)) { 153 // path, see if any of the locations have such a filename.
112 *browser_exe = path; 154 for (size_t j = 0; j < arraysize(browser_exes); ++j) {
113 return true; 155 for (size_t i = 0; i < locations.size(); ++i) {
156 FilePath path = locations[i].Append(browser_exes[j]);
157 if (file_util::PathExists(path)) {
158 *browser_exe = path;
159 return true;
160 }
161 }
162 }
163
164 // Loop through the browser executable paths (|browser_exes|). For each
Huyen 2011/08/08 17:53:12 Code above is similar, maybe move it into a method
165 // path, see if any of the chromium locations have such a filename.
166 for (size_t j = 0; j < arraysize(browser_exes); ++j) {
167 for (size_t i = 0; i < chromium_locations.size(); ++i) {
168 FilePath path = chromium_locations[i].Append(browser_exes[j]);
169 if (file_util::PathExists(path)) {
170 *browser_exe = path;
171 return true;
172 }
114 } 173 }
115 } 174 }
116 return false; 175 return false;
117 } 176 }
118 177
119 } // namespace 178 } // namespace
120 179
121 namespace webdriver { 180 namespace webdriver {
122 181
123 Automation::Automation() {} 182 Automation::Automation() {}
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 url, 1, &navigate_response, 482 url, 1, &navigate_response,
424 &error_msg)) { 483 &error_msg)) {
425 *error = new Error(kUnknownError, error_msg); 484 *error = new Error(kUnknownError, error_msg);
426 return; 485 return;
427 } 486 }
428 // TODO(kkania): Do not rely on this enum. 487 // TODO(kkania): Do not rely on this enum.
429 if (navigate_response == AUTOMATION_MSG_NAVIGATION_ERROR) 488 if (navigate_response == AUTOMATION_MSG_NAVIGATION_ERROR)
430 *error = new Error(kUnknownError, "Navigation error occurred"); 489 *error = new Error(kUnknownError, "Navigation error occurred");
431 } 490 }
432 491
492 void Automation::NavigateToURLAsync(int tab_id,
493 const std::string& url,
494 Error** error) {
495 int windex = 0, tab_index = 0;
496 *error = GetIndicesForTab(tab_id, &windex, &tab_index);
497 if (*error)
498 return;
499
500 scoped_refptr<BrowserProxy> browser = automation()->GetBrowserWindow(windex);
501 if (!browser) {
502 *error = new Error(kUnknownError, "Couldn't obtain browser proxy");
503 return;
504 }
505 scoped_refptr<TabProxy> tab = browser->GetTab(tab_index);
506 if (!tab) {
507 *error = new Error(kUnknownError, "Couldn't obtain tab proxy");
508 return;
509 }
510 if (!tab->NavigateToURLAsync(GURL(url))) {
511 *error = new Error(kUnknownError, "Unable to navigate to url");
512 return;
513 }
514 }
515
433 void Automation::GoForward(int tab_id, Error** error) { 516 void Automation::GoForward(int tab_id, Error** error) {
434 int windex = 0, tab_index = 0; 517 int windex = 0, tab_index = 0;
435 *error = GetIndicesForTab(tab_id, &windex, &tab_index); 518 *error = GetIndicesForTab(tab_id, &windex, &tab_index);
436 if (*error) 519 if (*error)
437 return; 520 return;
438 521
439 std::string error_msg; 522 std::string error_msg;
440 if (!SendGoForwardJSONRequest( 523 if (!SendGoForwardJSONRequest(
441 automation(), windex, tab_index, &error_msg)) { 524 automation(), windex, tab_index, &error_msg)) {
442 *error = new Error(kUnknownError, error_msg); 525 *error = new Error(kUnknownError, error_msg);
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 768, 0, "Alerts are not supported for this version of Chrome"); 715 768, 0, "Alerts are not supported for this version of Chrome");
633 } 716 }
634 717
635 Error* Automation::CheckAdvancedInteractionsSupported() { 718 Error* Automation::CheckAdvancedInteractionsSupported() {
636 const char* message = 719 const char* message =
637 "Advanced user interactions are not supported for this version of Chrome"; 720 "Advanced user interactions are not supported for this version of Chrome";
638 return CheckVersion(750, 0, message); 721 return CheckVersion(750, 0, message);
639 } 722 }
640 723
641 } // namespace webdriver 724 } // namespace webdriver
OLDNEW
« no previous file with comments | « chrome/test/webdriver/automation.h ('k') | chrome/test/webdriver/commands/create_session.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698