Skip to content

Commit

Permalink
LukeIS: iphone driver adding 'Status' response in order to attach to …
Browse files Browse the repository at this point in the history
…a Grid. Adding settings to specify where Grid is located in order to attach to the Grid on startup of app. Removing and ignoring iphone/.../atoms.h as it is autogenerated, updated script to detect for existance of atoms.h as to not rebuild every time. Adding new DesiredCapabilities.IPAD, had to add '/status' to DriverCommand and HttpCommandExecutor to easily test status command. fixes issue 1882

r14831
  • Loading branch information
lukeis committed Nov 20, 2011
1 parent a79985d commit 18a4c0d
Show file tree
Hide file tree
Showing 18 changed files with 318 additions and 4,437 deletions.
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ desc 'Clean build artifacts.'
task :clean do
rm_rf 'build/'
rm_rf 'iphone/build/'
rm_rf 'iphone/src/objc/atoms.h'
rm_rf 'android/app/bin/'
rm_rf 'android/app/build/'
rm_rf 'android/app/libs/'
Expand Down
42 changes: 42 additions & 0 deletions iphone/Settings.bundle/Root.plist
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,48 @@
<key>AutocorrectionType</key>
<string>No</string>
</dict>
<dict>
<key>Type</key>
<string>PSGroupSpecifier</string>
<key>Title</key>
<string>Grid</string>
</dict>
<dict>
<key>Type</key>
<string>PSTextFieldSpecifier</string>
<key>Title</key>
<string>GridHost</string>
<key>Key</key>
<string>preference_grid_mode_host</string>
<key>DefaultValue</key>
<string></string>
<key>IsSecure</key>
<false/>
<key>KeyboardType</key>
<string>URL</string>
<key>AutocapitalizationType</key>
<string>None</string>
<key>AutocorrectionType</key>
<string>No</string>
</dict>
<dict>
<key>Type</key>
<string>PSTextFieldSpecifier</string>
<key>Title</key>
<string>GridPort</string>
<key>Key</key>
<string>preference_grid_mode_port</string>
<key>DefaultValue</key>
<string>4444</string>
<key>IsSecure</key>
<false/>
<key>KeyboardType</key>
<string>NumberPad</string>
<key>AutocapitalizationType</key>
<string>None</string>
<key>AutocorrectionType</key>
<string>No</string>
</dict>
</array>
</dict>
</plist>
3 changes: 3 additions & 0 deletions iphone/Settings.bundle/en.lproj/Root.strings
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@

"Server" = "Server";
"Port" = "Port";
"Grid" = "Grid";
"GridHost" = "Host";
"GridPort" = "Port";
14 changes: 11 additions & 3 deletions iphone/iWebDriver.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
289233AE0DB2D0DB0083E9F9 /* MainViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 289233A90DB2D0DB0083E9F9 /* MainViewController.m */; };
289233AF0DB2D0DB0083E9F9 /* RootViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 289233AB0DB2D0DB0083E9F9 /* RootViewController.m */; };
289233B00DB2D0DB0083E9F9 /* FlipsideViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 289233AD0DB2D0DB0083E9F9 /* FlipsideViewController.m */; };
40BE09AB147714580042C6DA /* Status.m in Sources */ = {isa = PBXBuildFile; fileRef = 40BE09AA147714580042C6DA /* Status.m */; };
40BE09AC147715AA0042C6DA /* Status.m in Sources */ = {isa = PBXBuildFile; fileRef = 40BE09AA147714580042C6DA /* Status.m */; };
64084BF312B6C6A10049D2FB /* Storage.m in Sources */ = {isa = PBXBuildFile; fileRef = 731C4510128BBF4000261249 /* Storage.m */; };
64084BF412B6C6C90049D2FB /* Database.m in Sources */ = {isa = PBXBuildFile; fileRef = 73D14FCC1289B6540074E63B /* Database.m */; };
64084BF512B6C6C90049D2FB /* GeoLocation.m in Sources */ = {isa = PBXBuildFile; fileRef = 731C450E128BBF4000261249 /* GeoLocation.m */; };
Expand Down Expand Up @@ -172,6 +174,8 @@
289233AD0DB2D0DB0083E9F9 /* FlipsideViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FlipsideViewController.m; path = Classes/FlipsideViewController.m; sourceTree = "<group>"; };
29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
32CA4F630368D1EE00C91783 /* iWebDriver_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = iWebDriver_Prefix.pch; sourceTree = "<group>"; };
40BE09A9147714580042C6DA /* Status.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Status.h; sourceTree = "<group>"; };
40BE09AA147714580042C6DA /* Status.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Status.m; sourceTree = "<group>"; };
642C489E112260150064EB9C /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
642C48A3112260480064EB9C /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
643822E812C0305900F0C7CC /* atoms.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = atoms.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -466,6 +470,8 @@
648EB1FC137C63B800DEFD44 /* Css.m */,
731C450D128BBF4000261249 /* GeoLocation.h */,
731C450E128BBF4000261249 /* GeoLocation.m */,
40BE09A9147714580042C6DA /* Status.h */,
40BE09AA147714580042C6DA /* Status.m */,
731C450F128BBF4000261249 /* Storage.h */,
731C4510128BBF4000261249 /* Storage.m */,
64D8AA411120B94D001649CC /* SessionRoot.h */,
Expand Down Expand Up @@ -718,7 +724,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if [ -e ${PROJECT_DIR}/../go ]; then\n cd ${PROJECT_DIR}/..\n echo \"Regenerating iPhone atoms header file\"\n\n HEADER=\"${PROJECT_DIR}/src/objc/atoms.h\"\n BACKUP=\"${HEADER}.orig\"\n\n if [ -e ${HEADER} ]; then\n mv ${HEADER} ${BACKUP}\n fi\n\n ./go iphone_atoms\n BUILD_RESULT=$?\n if [ $BUILD_RESULT -ne 0 ]; then\n echo \"Failed to regenerate header file; restoring original\"\n if [ -e ${BACKUP} ]; then\n mv ${BACKUP} ${HEADER}\n fi\n exit $BUILD_RESULT\n else\n if [ -e ${BACKUP} ]; then\n rm ${BACKUP}\n fi\n fi\nelse\n echo \"Unable to locate \"go\" script; using existing atoms header snapshot\"\nfi\n";
shellScript = "if [ ! -e ${PROJECT_DIR}/src/objc/atoms.h ]; then\n if [ -e ${PROJECT_DIR}/../go ]; then\n cd ${PROJECT_DIR}/..\n echo \"Regenerating iPhone atoms header file\"\n\n ./go iphone_atoms\n BUILD_RESULT=$?\n if [ $BUILD_RESULT -ne 0 ]; then\n echo \"Failed to regenerate header file\"; exit $BUILD_RESULT\n fi\nelse\n echo \"Unable to locate \\\"go\\\" script;\"\nfi\nfi\n";
};
8399890A0EE605A30074D106 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
Expand Down Expand Up @@ -787,13 +793,15 @@
643822F712C032F600F0C7CC /* Element.mm in Sources */,
64A2262E12C1828000537E73 /* NSData+Base64.m in Sources */,
648EB1FD137C63B800DEFD44 /* Css.m in Sources */,
40BE09AB147714580042C6DA /* Status.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
839988DC0EE6052D0074D106 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
40BE09AC147715AA0042C6DA /* Status.m in Sources */,
64BFFCBC12B6EC0D00FEB710 /* NSObject+SBJSON.m in Sources */,
64BFFCBD12B6EC0D00FEB710 /* NSString+SBJSON.m in Sources */,
64BFFCBE12B6EC0D00FEB710 /* SBJSON.m in Sources */,
Expand Down Expand Up @@ -876,7 +884,7 @@
GCC_PREFIX_HEADER = src/objc/iWebDriver_Prefix.pch;
HEADER_SEARCH_PATHS = "$(COCOAHTTPSERVER_HEADERS)/**";
INFOPLIST_FILE = Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 3.0;
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)/iphoneos.sdk/usr/local/lib\"",
Expand Down Expand Up @@ -909,7 +917,7 @@
GCC_PREFIX_HEADER = src/objc/iWebDriver_Prefix.pch;
HEADER_SEARCH_PATHS = "$(COCOAHTTPSERVER_HEADERS)/**";
INFOPLIST_FILE = Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 3.0;
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)/iphoneos.sdk/usr/local/lib\"",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@
PATCHED_CODE = "$(PROJECT_DIR)/extensions/patched";
PREBINDING = NO;
PRODUCT_NAME = CocoaHTTPServer;
SDKROOT = iphoneos5.0;
};
name = Debug;
};
Expand All @@ -312,6 +313,7 @@
PATCHED_CODE = "$(PROJECT_DIR)/extensions/patched";
PREBINDING = NO;
PRODUCT_NAME = CocoaHTTPServer;
SDKROOT = iphoneos5.0;
ZERO_LINK = NO;
};
name = Release;
Expand Down
71 changes: 70 additions & 1 deletion iphone/src/objc/HTTPServerController.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#import "WebDriverHTTPConnection.h"
#import "RESTServiceMapping.h"
#import "WebDriverPreferences.h"
#import "Status.h"

#import <sys/types.h>
#import <sys/socket.h>
Expand All @@ -33,6 +34,8 @@ @implementation HTTPServerController
@synthesize viewController = viewController_;
@synthesize serviceMapping = serviceMapping_;

static NSMutableData *webData;

-(NSString *)getAddress {

struct ifaddrs *head;
Expand Down Expand Up @@ -74,6 +77,7 @@ -(id) init {
if (![super init])
return nil;
UInt16 portNumber = [[WebDriverPreferences sharedInstance] serverPortNumber];
NSString* grid = [[WebDriverPreferences sharedInstance] gridLocation];

server_ = [[WebDriverHTTPServer alloc] init];

Expand All @@ -93,14 +97,79 @@ -(id) init {
[self getAddress],
[server_ port]);

status_ = [[NSString alloc] initWithFormat:@"Started at http://%@:%d/hub/",
status_ = [[NSString alloc] initWithFormat:@"Started at http://%@:%d/wd/hub/",
[self getAddress],
[server_ port]];

if([grid length] > 0) {
NSString *device;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
device = DEVICE_IPAD;
} else {
device = DEVICE_IPHONE;
}
NSString* gridPort = [[WebDriverPreferences sharedInstance] gridPort];

NSString *registerUrlStr = [NSString stringWithFormat:@"http://%@:%@/grid/register", grid, gridPort];

// make http request to grid host registering self as a single node with just safari to test.
NSString *json = [NSString stringWithFormat:@"{'class':'org.openqa.grid.common.RegistrationRequest',"
"'capabilities':[{'seleniumProtocol':'WebDriver','browserName':'%@','maxInstances':1,'platform':'MAC'}],"
"'configuration':{'port':%d"
",'register':True,'host':%@"
",'proxy':'org.openqa.grid.selenium.proxy.DefaultRemoteProxy','maxSession':1,"
"'hubHost':'%@','hubPort':'%@','role':'wd','registerCycle':5000,"
"'hub':'%@','remoteHost':'http://%@:%d'"
"}}", device, [server_ port], [self getAddress], grid, gridPort, registerUrlStr, [self getAddress], [server_ port] ];


NSURL *registerUrl = [NSURL URLWithString:registerUrlStr];

NSMutableURLRequest *gridRegister = [NSMutableURLRequest requestWithURL:registerUrl];

NSString *msgLength = [NSString stringWithFormat:@"%d", [json length]];

[gridRegister addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[gridRegister setHTTPMethod:@"POST"];
[gridRegister setHTTPBody: [json dataUsingEncoding:NSUTF8StringEncoding]];

NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:gridRegister delegate:self];

if (theConnection) {
// Create the NSMutableData to hold the received data.
// receivedData is an instance variable declared elsewhere.
webData = [[NSMutableData data] retain];
} else {
// Inform the user that the connection failed.
}

}

serviceMapping_ = [[RESTServiceMapping alloc] init];

return self;
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[webData setLength: 0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[webData appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(@"ERROR with theConenction");
[connection release];
[webData release];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"DONE. Received Bytes: %d", [webData length]);
NSString *theXML = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
NSLog(@"%@",theXML);
[theXML release];
}

// Singleton

Expand Down
14 changes: 10 additions & 4 deletions iphone/src/objc/RESTServiceMapping.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#import "JSONRESTResource.h"
#import "Session.h"
#import "SessionRoot.h"
#import "Status.h"
#import "HTTPResponse+Utility.h"
#import "RootViewController.h"

Expand All @@ -45,6 +46,9 @@ - (id)init {
// The root of our REST service.
HTTPVirtualDirectory *restRoot = [[[HTTPVirtualDirectory alloc] init] autorelease];
[serverRoot_ setResource:restRoot withName:@"hub"];

// Respond to /status
[restRoot setResource:[[[Status alloc] init] autorelease] withName:@"status"];

// Make the root also accessible from /wd/hub. This will allow clients hard
// coded for the java Selenium server to also work with us.
Expand All @@ -71,6 +75,7 @@ - (id)init {
// Pass nil in the |query|, |method| or |data| arguments to ignore.
+ (void)propertiesOfHTTPMessage:(CFHTTPMessageRef)request
toQuery:(NSString **)query
toUri:(NSURL **)uri
method:(NSString **)method
data:(NSData **)data {
// Extract method
Expand All @@ -81,8 +86,8 @@ + (void)propertiesOfHTTPMessage:(CFHTTPMessageRef)request

// Extract requested URI
if (query != nil) {
NSURL *uri = [(NSURL *)CFHTTPMessageCopyRequestURL(request) autorelease];
*query = [uri relativeString];
*uri = [(NSURL *)CFHTTPMessageCopyRequestURL(request) autorelease];
*query = [*uri relativeString];
}

// Extract POST data
Expand All @@ -95,11 +100,13 @@ + (void)propertiesOfHTTPMessage:(CFHTTPMessageRef)request
- (NSObject<HTTPResponse> *)httpResponseForRequest:(CFHTTPMessageRef)request {

NSString *query;
NSURL *uri;
NSString *method;
NSData *data;

[RESTServiceMapping propertiesOfHTTPMessage:request
toQuery:&query
toUri:&uri
method:&method
data:&data];

Expand All @@ -119,10 +126,9 @@ + (void)propertiesOfHTTPMessage:(CFHTTPMessageRef)request
// Unfortunately, WebDriver only supports absolute redirects (r733). We need
// to expand all relative redirects to absolute redirects.
if ([response isKindOfClass:[HTTPRedirectResponse class]]) {
NSURL *uri = [(NSURL *)CFHTTPMessageCopyRequestURL(request) autorelease];
[(HTTPRedirectResponse *)response expandRelativeUrlWithBase:uri];
}
if (response == nil) {
NSLog(@"404 - could not create response for request at %@", query);
}
Expand Down
29 changes: 29 additions & 0 deletions iphone/src/objc/Status.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// Status.h
// iWebDriver
//
// Created by Luke Inman-Semerau on 11/17/11.
// Copyright (c) 2011 Free Software Conservancy. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import <Foundation/Foundation.h>
#import "HTTPVirtualDirectory.h"

static NSString * const DEVICE_IPHONE = @"iphone";
static NSString * const DEVICE_IPAD = @"ipad";

@interface Status : HTTPVirtualDirectory

@end
Loading

0 comments on commit 18a4c0d

Please sign in to comment.