Skip to content

Commit 3dcce88

Browse files
committed
Merge branch 'WD_1.X_dev' of https://portal-ua.globallogic.com/git/wd into WD_1.X_dev
2 parents 9db27dc + 677df05 commit 3dcce88

11 files changed

+154
-79
lines changed

generate_wdversion.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
versionfile = open (filename, 'w')
99
versionfile.write("namespace webdriver {\n")
1010
versionfile.write("extern const char kProductName[] = \"WebDriver-cisco-cmt\";\n")
11-
versionfile.write("extern const char kVersionNumber[] = \"1.3.0\";\n")
11+
versionfile.write("extern const char kVersionNumber[] = \"1.2.1\";\n")
1212
versionfile.write("extern const char kBuildTime[] = __TIME__;\n")
1313
versionfile.write("extern const char kBuildDate[] = __DATE__;\n")
1414
versionfile.write("extern const char kLastChanges[] = \"" + data.strip() + "\";\n")

inc/extension_qt/web_view_executor.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef WEBDRIVER_QT_WEB_VIEW_EXECUTOR_H_
22
#define WEBDRIVER_QT_WEB_VIEW_EXECUTOR_H_
33

4+
#include "base/yasper.h"
45
#include "extension_qt/q_view_executor.h"
56
#include "webdriver_logging.h"
67

@@ -133,7 +134,7 @@ class QWebViewCmdExecutor : public QViewCmdExecutor {
133134
QWebView* getView(const ViewId& viewId, Error** error);
134135

135136
private:
136-
scoped_ptr<QWebkitProxy> webkitProxy_;
137+
yasper::ptr<QWebkitProxy> webkitProxy_;
137138
QWebView* view_;
138139

139140
DISALLOW_COPY_AND_ASSIGN(QWebViewCmdExecutor);

inc/webdriver_server.h

+2
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ class Server {
183183

184184
int ParseConfigToOptions();
185185

186+
int ParseMongooseConfig();
187+
186188
DISALLOW_COPY_AND_ASSIGN(Server);
187189
};
188190

inc/webdriver_switches.h

+10
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ class Switches {
8888

8989
static const char kWhiteList[];
9090

91+
/// \page page_webdriver_switches WD Server switches
92+
/// - <b>webserver-cfg</b><br>
93+
/// The path to mongoose config file (e.g. config.json) in
94+
/// JSON format with specified mongoose start option
95+
/// (extra-mime-types, listening_ports, etc.)
96+
/// Option from webserver config file will have more priority than
97+
/// commandline param that specify the same option.
98+
99+
static const char kWebServerCfg[];
100+
91101
};
92102

93103
} // namespace webdriver

src/webdriver/extension_qt/qwebkit_proxy.cc

+49-52
Large diffs are not rendered by default.

src/webdriver/extension_qt/qwebkit_proxy.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ class QWebkitProxy {
185185
Session* session_;
186186
QWebPage* page_;
187187

188-
QWebFrame* GetFrame(QWebPage* page, const FramePath& frame_path);
188+
QWebFrame* GetFrame(const FramePath& frame_path);
189189
QWebFrame* FindFrameByMeta(QWebFrame* parent, const FramePath &frame_path);
190190
QWebFrame* FindFrameByPath(QWebFrame* parent, const FramePath &frame_path);
191191

@@ -246,7 +246,6 @@ class QWebkitProxy {
246246
Point* location);
247247

248248
Error* GetElementRegionInView(
249-
QWebPage* page,
250249
const ElementId& element,
251250
const Rect& region,
252251
bool center,

src/webdriver/extension_qt/web_view_executor.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ namespace webdriver {
4242
*error = new Error(kNoSuchWindow); \
4343
return; \
4444
} \
45-
webkitProxy_.reset(new QWebkitProxy(session_, (view_)?view_->page():NULL));
45+
webkitProxy_ = yasper::ptr<QWebkitProxy>(new QWebkitProxy(session_, (view_)?view_->page():NULL));
4646

4747
const ViewType QWebViewCmdExecutorCreator::WEB_VIEW_TYPE = 0x13f0;
4848

@@ -977,14 +977,14 @@ void QWebViewCmdExecutor::GetMute(const ElementId &element, bool *mute, Error **
977977
void QWebViewCmdExecutor::VisualizerSource(std::string* source, Error** error) {
978978
CHECK_VIEW_EXISTANCE
979979

980-
QWebViewVisualizerSourceCommand command(this, session_, view_);
980+
QWebViewVisualizerSourceCommand command(webkitProxy_, session_, view_);
981981
command.Execute(source, error);
982982
}
983983

984984
void QWebViewCmdExecutor::VisualizerShowPoint(Error** error) {
985985
CHECK_VIEW_EXISTANCE
986986

987-
QWebViewVisualizerShowPointCommand command(this, session_, view_);
987+
QWebViewVisualizerShowPointCommand command(webkitProxy_, session_, view_);
988988
command.Execute(error);
989989
}
990990

src/webdriver/extension_qt/web_view_visualizer.cc

+27-12
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
namespace webdriver {
1616

17-
QWebViewVisualizerSourceCommand::QWebViewVisualizerSourceCommand(QWebViewCmdExecutor* executor, Session* session, QWebView* view)
18-
: executor_(executor), session_(session), view_(view)
17+
QWebViewVisualizerSourceCommand::QWebViewVisualizerSourceCommand(yasper::ptr<QWebkitProxy> webkitProxy, Session* session, QWebView* view)
18+
: webkitProxy_(webkitProxy), session_(session), view_(view)
1919
{}
2020

2121
void QWebViewVisualizerSourceCommand::Execute(std::string* source, Error** error) {
@@ -36,11 +36,10 @@ void QWebViewVisualizerSourceCommand::Execute(std::string* source, Error** error
3636
"return new XMLSerializer().serializeToString(root);";
3737

3838
Value* unscoped_value = NULL;
39-
executor_->ExecuteScript(
39+
*error = webkitProxy_->ExecuteScript(
4040
kSource,
4141
new ListValue(),
42-
&unscoped_value,
43-
error);
42+
&unscoped_value);
4443
if (*error) {
4544
(*error)->AddDetails("getSource execution failed");
4645
return;
@@ -230,15 +229,27 @@ void QWebViewVisualizerSourceCommand::AssembleImg(pugi::xml_node element) const
230229

231230
void QWebViewVisualizerSourceCommand::AssembleStyle(pugi::xml_node element) const {
232231
pugi::xml_attribute type = element.attribute("type");
233-
if (type.empty() != 0 &&
232+
if (!type.empty() &&
234233
std::string(type.value()) != "text/css") {
235234
return;
236235
}
237236

238-
QString value = QString::fromUtf8(element.text().as_string());
239-
value = AssembleStyle(value);
240-
clearChildren(element);
241-
element.append_child(pugi::node_pcdata).set_value(value.toStdString().c_str());
237+
if (len(element.children()) == 1 &&
238+
element.first_child().type() == pugi::node_cdata) {
239+
pugi::xml_node cdata = element.first_child();
240+
element.remove_child(cdata);
241+
QString value = QString::fromUtf8(cdata.value());
242+
value = AssembleStyle(value);
243+
element.append_child(pugi::node_pcdata).set_value(value.toStdString().c_str());
244+
} else {
245+
for (pugi::xml_node_iterator childIt = element.begin(); childIt != element.end(); childIt++) {
246+
if (childIt->type() == pugi::node_pcdata) {
247+
QString value = QString::fromUtf8(childIt->value());
248+
value = AssembleStyle(value);
249+
childIt->set_value(value.toStdString().c_str());
250+
}
251+
}
252+
}
242253
}
243254

244255
void QWebViewVisualizerSourceCommand::AssembleStyle(pugi::xml_attribute attribute) const {
@@ -353,6 +364,10 @@ bool QWebViewVisualizerSourceCommand::isEmpty(const pugi::xml_object_range<pugi:
353364
return range.begin() == range.end();
354365
}
355366

367+
int QWebViewVisualizerSourceCommand::len(const pugi::xml_object_range<pugi::xml_node_iterator>& range) {
368+
return std::distance(range.begin(), range.end());
369+
}
370+
356371
void QWebViewVisualizerSourceCommand::clearChildren(pugi::xml_node element) {
357372
std::vector<pugi::xml_node> children;
358373
for (pugi::xml_node_iterator it = element.children().begin(); it != element.children().end(); it++) {
@@ -390,8 +405,8 @@ class QCursorMark : public QWidget
390405
static const int RADIUS = 5;
391406
};
392407

393-
QWebViewVisualizerShowPointCommand::QWebViewVisualizerShowPointCommand(QWebViewCmdExecutor* executor, Session* session, QWebView* view)
394-
: executor_(executor), session_(session), view_(view)
408+
QWebViewVisualizerShowPointCommand::QWebViewVisualizerShowPointCommand(yasper::ptr<QWebkitProxy> webkitProxy, Session* session, QWebView* view)
409+
: webkitProxy_(webkitProxy), session_(session), view_(view)
395410
{}
396411

397412
void QWebViewVisualizerShowPointCommand::Execute(Error** error) {

src/webdriver/extension_qt/web_view_visualizer.h

+7-5
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,20 @@
99
#include <QtWebKit/QtWebKit>
1010
#endif
1111

12+
#include "base/yasper.h"
13+
#include "qwebkit_proxy.h"
1214
#include "third_party/pugixml/pugixml.hpp"
1315

1416
namespace webdriver {
1517

16-
class QWebViewCmdExecutor;
1718
class Error;
1819
class Session;
1920

2021
class QWebViewVisualizerSourceCommand : public QObject {
2122
Q_OBJECT
2223

2324
public:
24-
QWebViewVisualizerSourceCommand(QWebViewCmdExecutor* executor, Session* session, QWebView* view);
25+
QWebViewVisualizerSourceCommand(yasper::ptr<QWebkitProxy> webkitProxy, Session* session, QWebView* view);
2526

2627
void Execute(std::string* source, Error** error);
2728

@@ -47,22 +48,23 @@ private Q_SLOTS:
4748

4849
private:
4950
static bool isEmpty(const pugi::xml_object_range<pugi::xml_node_iterator>& range);
51+
static int len(const pugi::xml_object_range<pugi::xml_node_iterator>& range);
5052
static void clearChildren(pugi::xml_node element);
5153
static const char DATA_PROTOCOL[];
5254

53-
QWebViewCmdExecutor* executor_;
55+
yasper::ptr<QWebkitProxy> webkitProxy_;
5456
Session* session_;
5557
QWebView* view_;
5658
};
5759

5860
class QWebViewVisualizerShowPointCommand {
5961
public:
60-
QWebViewVisualizerShowPointCommand(QWebViewCmdExecutor* executor, Session* session, QWebView* view);
62+
QWebViewVisualizerShowPointCommand(yasper::ptr<QWebkitProxy> webkitProxy, Session* session, QWebView* view);
6163

6264
void Execute(Error** error);
6365

6466
private:
65-
QWebViewCmdExecutor* executor_;
67+
yasper::ptr<QWebkitProxy> webkitProxy_;
6668
Session* session_;
6769
QWebView* view_;
6870
};

src/webdriver/webdriver_server.cc

+50-3
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,9 @@ int Server::InitMongooseOptions() {
607607
}
608608
}
609609
mg_options_.push_back("extra_mime_types");
610-
mg_options_.push_back(".xhtml=application/xhtml+xml");
610+
mg_options_.push_back(".xhtml=application/xhtml+xml,.qml=text/x-qml");
611+
612+
ParseMongooseConfig();
611613

612614
return 0;
613615
}
@@ -674,7 +676,7 @@ int Server::ParseConfigToOptions() {
674676

675677
if (value->GetType() != Value::TYPE_DICTIONARY)
676678
{
677-
std::cerr << "Execute script returned non-dict: " + JsonStringify(value.get()) << std::endl;
679+
std::cerr << "Config file: result of parsing json is not a dictionary " + JsonStringify(value.get()) << std::endl;
678680
return 2;
679681
}
680682

@@ -700,7 +702,52 @@ int Server::ParseConfigToOptions() {
700702
}
701703
else
702704
{
703-
std::cerr << "can't read file" << std::endl;
705+
std::cerr << "can't read config file" << std::endl;
706+
return 1;
707+
}
708+
}
709+
710+
return 0;
711+
}
712+
713+
int Server::ParseMongooseConfig() {
714+
if (options_->HasSwitch(webdriver::Switches::kWebServerCfg))
715+
{
716+
//parse json config file and set value
717+
std::string mongoose_cfg;
718+
FilePath configPath(options_->GetSwitchValueNative(webdriver::Switches::kWebServerCfg));
719+
720+
if (file_util::ReadFileToString(configPath, &mongoose_cfg))
721+
{
722+
scoped_ptr<Value> value(base::JSONReader::ReadAndReturnError(
723+
mongoose_cfg, base::JSON_ALLOW_TRAILING_COMMAS, NULL, NULL));
724+
if (!value.get())
725+
{
726+
std::cout << "Failed to parse webserver config file" << std::endl;
727+
return 1;
728+
}
729+
730+
if (value->GetType() != Value::TYPE_DICTIONARY)
731+
{
732+
std::cerr << "Webserver config: result of parsing json is not a dictionary " + JsonStringify(value.get()) << std::endl;
733+
return 2;
734+
}
735+
736+
DictionaryValue* result_dict = static_cast<DictionaryValue*>(value.get());
737+
738+
DictionaryValue::key_iterator key_iter = result_dict->begin_keys();
739+
for (; key_iter != result_dict->end_keys(); ++key_iter) {
740+
std::string value;
741+
result_dict->GetStringWithoutPathExpansion(*key_iter, &value);
742+
mg_options_.push_back(*key_iter);
743+
mg_options_.push_back(value.c_str());
744+
}
745+
746+
return 0;
747+
}
748+
else
749+
{
750+
std::cerr << "can't read webserver confifg file" << std::endl;
704751
return 1;
705752
}
706753
}

src/webdriver/webdriver_switches.cc

+2
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,6 @@ const char Switches::kUserInputDevice[] = "uinput";
2828

2929
const char Switches::kWhiteList[] = "white-list";
3030

31+
const char Switches::kWebServerCfg[] = "webserver-cfg";
32+
3133
} // namespace webdriver

0 commit comments

Comments
 (0)