| OLD | NEW |
| 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/session.h" | 5 #include "chrome/test/chromedriver/session.h" |
| 6 | 6 |
| 7 #include <list> | 7 #include <list> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" |
| 10 #include "base/threading/thread_local.h" |
| 9 #include "base/values.h" | 11 #include "base/values.h" |
| 10 #include "chrome/test/chromedriver/chrome/chrome.h" | 12 #include "chrome/test/chromedriver/chrome/chrome.h" |
| 11 #include "chrome/test/chromedriver/chrome/status.h" | 13 #include "chrome/test/chromedriver/chrome/status.h" |
| 12 #include "chrome/test/chromedriver/chrome/version.h" | 14 #include "chrome/test/chromedriver/chrome/version.h" |
| 13 #include "chrome/test/chromedriver/chrome/web_view.h" | 15 #include "chrome/test/chromedriver/chrome/web_view.h" |
| 14 #include "chrome/test/chromedriver/logging.h" | 16 #include "chrome/test/chromedriver/logging.h" |
| 15 | 17 |
| 18 namespace { |
| 19 |
| 20 base::LazyInstance<base::ThreadLocalPointer<Session> > |
| 21 lazy_tls_session = LAZY_INSTANCE_INITIALIZER; |
| 22 |
| 23 } // namespace |
| 24 |
| 16 FrameInfo::FrameInfo(const std::string& parent_frame_id, | 25 FrameInfo::FrameInfo(const std::string& parent_frame_id, |
| 17 const std::string& frame_id, | 26 const std::string& frame_id, |
| 18 const std::string& chromedriver_frame_id) | 27 const std::string& chromedriver_frame_id) |
| 19 : parent_frame_id(parent_frame_id), | 28 : parent_frame_id(parent_frame_id), |
| 20 frame_id(frame_id), | 29 frame_id(frame_id), |
| 21 chromedriver_frame_id(chromedriver_frame_id) {} | 30 chromedriver_frame_id(chromedriver_frame_id) {} |
| 22 | 31 |
| 23 const base::TimeDelta Session::kDefaultPageLoadTimeout = | 32 const base::TimeDelta Session::kDefaultPageLoadTimeout = |
| 24 base::TimeDelta::FromMinutes(5); | 33 base::TimeDelta::FromMinutes(5); |
| 25 | 34 |
| 26 Session::Session(const std::string& id) | 35 Session::Session(const std::string& id) |
| 27 : id(id), | 36 : id(id), |
| 28 quit(false), | 37 quit(false), |
| 29 detach(false), | 38 detach(false), |
| 30 force_devtools_screenshot(false), | 39 force_devtools_screenshot(false), |
| 31 sticky_modifiers(0), | 40 sticky_modifiers(0), |
| 32 mouse_position(0, 0), | 41 mouse_position(0, 0), |
| 33 page_load_timeout(kDefaultPageLoadTimeout) {} | 42 page_load_timeout(kDefaultPageLoadTimeout) {} |
| 34 | 43 |
| 35 Session::Session(const std::string& id, scoped_ptr<Chrome> chrome) | 44 Session::Session(const std::string& id, scoped_ptr<Chrome> chrome) |
| 36 : id(id), | 45 : id(id) |
| 37 quit(false), | 46 quit(false), |
| 38 detach(false), | 47 detach(false), |
| 39 force_devtools_screenshot(false), | 48 force_devtools_screenshot(false), |
| 40 chrome(chrome.Pass()), | 49 chrome(chrome.Pass()), |
| 41 sticky_modifiers(0), | 50 sticky_modifiers(0), |
| 42 mouse_position(0, 0), | 51 mouse_position(0, 0), |
| 43 page_load_timeout(kDefaultPageLoadTimeout), | 52 page_load_timeout(kDefaultPageLoadTimeout) {} |
| 44 capabilities(CreateCapabilities()) {} | |
| 45 | 53 |
| 46 Session::~Session() {} | 54 Session::~Session() {} |
| 47 | 55 |
| 48 Status Session::GetTargetWindow(WebView** web_view) { | 56 Status Session::GetTargetWindow(WebView** web_view) { |
| 49 if (!chrome) | 57 if (!chrome) |
| 50 return Status(kNoSuchWindow, "no chrome started in this session"); | 58 return Status(kNoSuchWindow, "no chrome started in this session"); |
| 51 | 59 |
| 52 Status status = chrome->GetWebViewById(window, web_view); | 60 Status status = chrome->GetWebViewById(window, web_view); |
| 53 if (status.IsError()) | 61 if (status.IsError()) |
| 54 status = Status(kNoSuchWindow, "target window already closed", status); | 62 status = Status(kNoSuchWindow, "target window already closed", status); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 66 parent_frame_id = frames.back().frame_id; | 74 parent_frame_id = frames.back().frame_id; |
| 67 frames.push_back(FrameInfo(parent_frame_id, frame_id, chromedriver_frame_id)); | 75 frames.push_back(FrameInfo(parent_frame_id, frame_id, chromedriver_frame_id)); |
| 68 } | 76 } |
| 69 | 77 |
| 70 std::string Session::GetCurrentFrameId() const { | 78 std::string Session::GetCurrentFrameId() const { |
| 71 if (frames.empty()) | 79 if (frames.empty()) |
| 72 return std::string(); | 80 return std::string(); |
| 73 return frames.back().frame_id; | 81 return frames.back().frame_id; |
| 74 } | 82 } |
| 75 | 83 |
| 76 scoped_ptr<base::DictionaryValue> Session::CreateCapabilities() { | 84 std::vector<WebDriverLog*> Session::GetAllLogs() const { |
| 77 scoped_ptr<base::DictionaryValue> caps(new base::DictionaryValue()); | 85 std::vector<WebDriverLog*> logs; |
| 78 caps->SetString("browserName", "chrome"); | 86 for (ScopedVector<WebDriverLog>::const_iterator log = devtools_logs.begin(); |
| 79 caps->SetString("version", chrome->GetVersion()); | 87 log != devtools_logs.end(); |
| 80 caps->SetString("chrome.chromedriverVersion", kChromeDriverVersion); | 88 ++log) { |
| 81 caps->SetString("platform", chrome->GetOperatingSystemName()); | 89 logs.push_back(*log); |
| 82 caps->SetBoolean("javascriptEnabled", true); | 90 } |
| 83 caps->SetBoolean("takesScreenshot", true); | 91 if (driver_log) |
| 84 caps->SetBoolean("handlesAlerts", true); | 92 logs.push_back(driver_log.get()); |
| 85 caps->SetBoolean("databaseEnabled", true); | 93 return logs; |
| 86 caps->SetBoolean("locationContextEnabled", true); | |
| 87 caps->SetBoolean("applicationCacheEnabled", false); | |
| 88 caps->SetBoolean("browserConnectionEnabled", false); | |
| 89 caps->SetBoolean("cssSelectorsEnabled", true); | |
| 90 caps->SetBoolean("webStorageEnabled", true); | |
| 91 caps->SetBoolean("rotatable", false); | |
| 92 caps->SetBoolean("acceptSslCerts", true); | |
| 93 caps->SetBoolean("nativeEvents", true); | |
| 94 return caps.Pass(); | |
| 95 } | 94 } |
| 95 |
| 96 Session* GetThreadLocalSession() { |
| 97 return lazy_tls_session.Pointer()->Get(); |
| 98 } |
| 99 |
| 100 void SetThreadLocalSession(scoped_ptr<Session> session) { |
| 101 lazy_tls_session.Pointer()->Set(session.release()); |
| 102 } |
| OLD | NEW |