Skip to content

Commit 3f50b3e

Browse files
committed
Fixed custom commands check; add /shutdown command
1 parent 695c260 commit 3f50b3e

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

inc/webdriver_route_patterns.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ class CommandRoutes {
104104
static const char kVisualizerShowPoint[];
105105
static const char kTouchPinchZoom[];
106106
static const char kTouchPinchRotate[];
107+
static const char kShutdown[];
107108

108109
private:
109110
static std::set<std::string> standardCommandRoutes;

src/Test/main.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ std::string tests::testDataFolder;
5454
#include "versioninfo.h"
5555
#include "webdriver_route_table.h"
5656
#include "shutdown_command.h"
57+
#include "webdriver_route_patterns.h"
5758

5859
#ifndef OS_IOS
5960
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
@@ -259,6 +260,7 @@ int main(int argc, char *argv[])
259260
webdriver::RouteTable *routeTableWithShutdownCommand = new webdriver::RouteTable(wd_server->GetRouteTable());
260261
const char shutdownCommandRoute[] = "/-cisco-shutdown";
261262
routeTableWithShutdownCommand->Add<webdriver::ShutdownCommand>(shutdownCommandRoute);
263+
routeTableWithShutdownCommand->Add<webdriver::ShutdownCommand>(webdriver::CommandRoutes::kShutdown);
262264
wd_server->SetRouteTable(routeTableWithShutdownCommand);
263265

264266
InitVNCClient();

src/webdriver/webdriver_route_patterns.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ bool CommandRoutes::IsStandardRoute(const std::string& pattern) {
8989
standardCommandRoutes.insert(kCiscoPlayerState);
9090
standardCommandRoutes.insert(kCiscoPlayerVolume);
9191
standardCommandRoutes.insert(kCiscoPlayingPosition);
92+
standardCommandRoutes.insert(kShutdown);
9293
}
9394

9495
// check if paatern is presence in set
@@ -183,5 +184,6 @@ const char CommandRoutes::kVisualizerSource[] = "/session/*/-cisco-vis
183184
const char CommandRoutes::kVisualizerShowPoint[] = "/session/*/-cisco-visualizer_show_point";
184185
const char CommandRoutes::kTouchPinchZoom[] = "/session/*/touch/-cisco-pinch-zoom";
185186
const char CommandRoutes::kTouchPinchRotate[] = "/session/*/touch/-cisco-pinch-rotate";
187+
const char CommandRoutes::kShutdown[] = "/shutdown";
186188

187189
} // namespace webdriver

src/webdriver/webdriver_route_table.cc

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ CommandCreatorPtr RouteTable::GetRouteForURL(const std::string& url, std::string
120120
bool RouteTable::AddRoute(const std::string& uri_pattern,
121121
const CommandCreatorPtr& creator) {
122122
// custom command check
123-
if (false){//!CommandRoutes::IsStandardRoute(uri_pattern)) {
123+
if (!CommandRoutes::IsStandardRoute(uri_pattern)) {
124124
std::vector<std::string> url_segments;
125125
base::SplitString(uri_pattern, '/', &url_segments);
126126

@@ -129,17 +129,16 @@ bool RouteTable::AddRoute(const std::string& uri_pattern,
129129
GlobalLogger::Log(kWarningLogLevel, "Custom commands too short");
130130
return false;
131131
}
132-
if (url_segments.size() >= 2
133-
&& url_segments[0].empty() && url_segments[1] != "session") {
134-
if (!CheckCustomPrefix(url_segments[1]))
135-
return false;
136-
} else if (url_segments.size() < 4 || !url_segments[0].empty()
137-
|| url_segments[1] != "session" || url_segments[2] != "*") {
138-
GlobalLogger::Log(kWarningLogLevel, "Invalid custom commands");
132+
bool hasCustomPrefix = false;
133+
for ( uint i = 0; i < url_segments.size(); i++ )
134+
{
135+
hasCustomPrefix = CheckCustomPrefix(url_segments[i]);
136+
if (hasCustomPrefix)
137+
break;
138+
}
139+
if (!hasCustomPrefix) {
140+
GlobalLogger::Log(kWarningLogLevel, "Comand " + uri_pattern +" has no valid custom prefix");
139141
return false;
140-
} else {
141-
if (!CheckCustomPrefix(url_segments[3]))
142-
return false;
143142
}
144143
}
145144
std::vector<webdriver::internal::RouteDetails>::iterator route;
@@ -175,8 +174,6 @@ bool RouteTable::CheckCustomPrefix(const std::string& prefix) {
175174
if (prefix_segments.size() < 3 || !prefix_segments[0].empty() || prefix_segments[2].empty()
176175
|| prefix_segments[1].empty() || !std::isalpha(prefix_segments[1].at(0))) {
177176
#endif //OS_WIN
178-
179-
GlobalLogger::Log(kWarningLogLevel, "Custom prefix invalid");
180177
return false;
181178
}
182179
return true;

0 commit comments

Comments
 (0)