1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/test/chromedriver/session.h"
#include <list>
#include "base/values.h"
#include "chrome/test/chromedriver/chrome/chrome.h"
#include "chrome/test/chromedriver/chrome/status.h"
#include "chrome/test/chromedriver/chrome/version.h"
#include "chrome/test/chromedriver/chrome/web_view.h"
FrameInfo::FrameInfo(const std::string& parent_frame_id,
const std::string& frame_id,
const std::string& chromedriver_frame_id)
: parent_frame_id(parent_frame_id),
frame_id(frame_id),
chromedriver_frame_id(chromedriver_frame_id) {}
Session::Session(const std::string& id)
: id(id),
thread(("SessionThread_" + id).c_str()),
sticky_modifiers(0),
mouse_position(0, 0),
implicit_wait(0),
page_load_timeout(0),
script_timeout(0) {
}
Session::Session(const std::string& id, scoped_ptr<Chrome> chrome)
: id(id),
thread(("SessionThread_" + id).c_str()),
chrome(chrome.Pass()),
sticky_modifiers(0),
mouse_position(0, 0),
implicit_wait(0),
page_load_timeout(0),
script_timeout(0),
capabilities(CreateCapabilities()) {
}
Session::~Session() {}
Status Session::GetTargetWindow(WebView** web_view) {
if (!chrome)
return Status(kNoSuchWindow, "no chrome started in this session");
Status status = chrome->GetWebViewById(window, web_view);
if (status.IsError())
status = Status(kNoSuchWindow, "target window already closed", status);
return status;
}
void Session::SwitchToTopFrame() {
frames.clear();
}
void Session::SwitchToSubFrame(const std::string& frame_id,
const std::string& chromedriver_frame_id) {
std::string parent_frame_id;
if (!frames.empty())
parent_frame_id = frames.back().frame_id;
frames.push_back(FrameInfo(parent_frame_id, frame_id, chromedriver_frame_id));
}
std::string Session::GetCurrentFrameId() const {
if (frames.empty())
return std::string();
return frames.back().frame_id;
}
scoped_ptr<base::DictionaryValue> Session::CreateCapabilities() {
scoped_ptr<base::DictionaryValue> caps(new base::DictionaryValue());
caps->SetString("browserName", "chrome");
caps->SetString("version", chrome->GetVersion());
caps->SetString("driverVersion", kChromeDriverVersion);
caps->SetString("platform", chrome->GetOperatingSystemName());
caps->SetBoolean("javascriptEnabled", true);
caps->SetBoolean("takesScreenshot", true);
caps->SetBoolean("handlesAlerts", true);
caps->SetBoolean("databaseEnabled", true);
caps->SetBoolean("locationContextEnabled", true);
caps->SetBoolean("applicationCacheEnabled", false);
caps->SetBoolean("browserConnectionEnabled", false);
caps->SetBoolean("cssSelectorsEnabled", true);
caps->SetBoolean("webStorageEnabled", true);
caps->SetBoolean("rotatable", false);
caps->SetBoolean("acceptSslCerts", true);
caps->SetBoolean("nativeEvents", true);
return caps.Pass();
}
SessionAccessorImpl::SessionAccessorImpl(scoped_ptr<Session> session)
: session_(session.Pass()) {}
Session* SessionAccessorImpl::Access(scoped_ptr<base::AutoLock>* lock) {
lock->reset(new base::AutoLock(session_lock_));
return session_.get();
}
void SessionAccessorImpl::DeleteSession() {
session_.reset();
}
SessionAccessorImpl::~SessionAccessorImpl() {}
|