Implement nacl_irt_memory for non-sfi mode.
[chromium-blink-merge.git] / chrome / test / chromedriver / session.cc
blob91370da1d3b451059eb45ffad274af78f9a86e53
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
3 // found in the LICENSE file.
5 #include "chrome/test/chromedriver/session.h"
7 #include <list>
9 #include "base/lazy_instance.h"
10 #include "base/threading/thread_local.h"
11 #include "base/values.h"
12 #include "chrome/test/chromedriver/chrome/chrome.h"
13 #include "chrome/test/chromedriver/chrome/status.h"
14 #include "chrome/test/chromedriver/chrome/version.h"
15 #include "chrome/test/chromedriver/chrome/web_view.h"
16 #include "chrome/test/chromedriver/logging.h"
18 namespace {
20 base::LazyInstance<base::ThreadLocalPointer<Session> >
21 lazy_tls_session = LAZY_INSTANCE_INITIALIZER;
23 } // namespace
25 FrameInfo::FrameInfo(const std::string& parent_frame_id,
26 const std::string& frame_id,
27 const std::string& chromedriver_frame_id)
28 : parent_frame_id(parent_frame_id),
29 frame_id(frame_id),
30 chromedriver_frame_id(chromedriver_frame_id) {}
32 const base::TimeDelta Session::kDefaultPageLoadTimeout =
33 base::TimeDelta::FromMinutes(5);
35 Session::Session(const std::string& id)
36 : id(id),
37 quit(false),
38 detach(false),
39 force_devtools_screenshot(false),
40 sticky_modifiers(0),
41 mouse_position(0, 0),
42 page_load_timeout(kDefaultPageLoadTimeout),
43 auto_reporting_enabled(false) {}
45 Session::Session(const std::string& id, scoped_ptr<Chrome> chrome)
46 : id(id),
47 quit(false),
48 detach(false),
49 force_devtools_screenshot(false),
50 chrome(chrome.Pass()),
51 sticky_modifiers(0),
52 mouse_position(0, 0),
53 page_load_timeout(kDefaultPageLoadTimeout),
54 auto_reporting_enabled(false) {}
56 Session::~Session() {}
58 Status Session::GetTargetWindow(WebView** web_view) {
59 if (!chrome)
60 return Status(kNoSuchWindow, "no chrome started in this session");
62 Status status = chrome->GetWebViewById(window, web_view);
63 if (status.IsError())
64 status = Status(kNoSuchWindow, "target window already closed", status);
65 return status;
68 void Session::SwitchToTopFrame() {
69 frames.clear();
72 void Session::SwitchToSubFrame(const std::string& frame_id,
73 const std::string& chromedriver_frame_id) {
74 std::string parent_frame_id;
75 if (!frames.empty())
76 parent_frame_id = frames.back().frame_id;
77 frames.push_back(FrameInfo(parent_frame_id, frame_id, chromedriver_frame_id));
80 std::string Session::GetCurrentFrameId() const {
81 if (frames.empty())
82 return std::string();
83 return frames.back().frame_id;
86 std::vector<WebDriverLog*> Session::GetAllLogs() const {
87 std::vector<WebDriverLog*> logs;
88 for (ScopedVector<WebDriverLog>::const_iterator log = devtools_logs.begin();
89 log != devtools_logs.end();
90 ++log) {
91 logs.push_back(*log);
93 if (driver_log)
94 logs.push_back(driver_log.get());
95 return logs;
98 std::string Session::GetFirstBrowserError() const {
99 for (ScopedVector<WebDriverLog>::const_iterator it = devtools_logs.begin();
100 it != devtools_logs.end();
101 ++it) {
102 if ((*it)->type() == WebDriverLog::kBrowserType) {
103 std::string message = (*it)->GetFirstErrorMessage();
104 if (!message.empty())
105 return message;
108 return std::string();
111 Session* GetThreadLocalSession() {
112 return lazy_tls_session.Pointer()->Get();
115 void SetThreadLocalSession(scoped_ptr<Session> session) {
116 lazy_tls_session.Pointer()->Set(session.release());