SCBrowserSimulator


SeasideTesting-Core

Comment:



Hierarchy:

ProtoObject
Object
SCBrowserSimulator

Summary:

instance variables:

cookies history responseSema

methods:

instance class
accessing private request/response no messages

Detail:

instance variables:

cookies
InitialValue:
a Dictionary()
inferredType:
Dictionary
history
InitialValue:
an OrderedCollection()
inferredType:
OrderedCollection
responseSema
inferredType:
UndefinedObject

instance methods:

accessing
cookies

	^ cookies ifNil: [cookies _ Dictionary new]
history

	^history ifNil: [history _ OrderedCollection new]
responseSemaphore: s

	responseSema _ s

private
cookieString

	| out |
	self cookies isEmpty
		ifTrue: [^ ''].
	out _ WriteStream on: String new.
	out nextPutAll: 'Cookie:'.
	self cookies values
		do: [:cookie | out nextPutAll: ' ' , cookie key , '=' , cookie value]
		separatedBy: [out nextPut: $;].
	out nextPutAll: String crlf.
	^ out contents
httpGetRequestStreamFor: url
 
	^ ('GET ' , url , ' HTTP/1.0' , String crlf , self cookieString , String crlf) readStream
httpPostRequestStreamForUrl: url data: postData
 
	^ ('POST ' , url , ' HTTP/1.0 ' , String crlf , 'Content-Length: ' , postData size printString , String crlf , 'Content-type: application/x-www-form-urlencoded' , String crlf , self cookieString , String crlf , postData) readStream
parseCookieString: s
 
	| parts keyAndValue result |
	parts _ s findTokens: ';'.
	keyAndValue _ parts first findTokens: '='.
	result _ WACookie key: keyAndValue first value: keyAndValue second.
	^result
privateIssueRequest: anHttpRequest
 
	| response cookie |
	response := SeasidePlatformSupport
		issueRequest: anHttpRequest
		responseSemaphore: responseSema.
	response
		ifNil: [^ self error: 'What do I do here?'].
	response cookies
		ifNotNilDo: [:col | col
				do: [:cookieString | 
					cookie := self parseCookieString: cookieString.
					self cookies at: cookie key put: cookie]].
	^ response

request/response
back

	self history removeLast.
	^ self history last value
establishSessionAtBase: baseUrlString

	| req |
	req _ HttpRequest
				readFromStream: (self httpGetRequestStreamFor: baseUrlString).
	^ self issueRequestUntilNotMoved: req
followAnchor: anAnchor
 
	| req |
	anAnchor ifNil: [self error: 'Anchor cannot be nil'].
	req _ HttpRequest
				readFromStream: (self httpGetRequestStreamFor: anAnchor asString).
	^ self issueRequestUntilNotMoved: req
issueRequestUntilNotMoved: anHttpRequest
 
	| response req newUrl doc |
	req _ anHttpRequest.
	[response _ self privateIssueRequest: req.
	response status = #tempMoved]
		whileTrue: [newUrl _ response fields at: 'Location'.
			req _ HttpRequest
						readFromStream: (self httpGetRequestStreamFor: newUrl)].
	doc _ SCSeasideResponse fromResponse: response.
	self history add: req -> doc.
	^ doc
lastResponse

	^self history last value
refresh

	^ self issueRequestUntilNotMoved: self history last key
submitForm: form pressingButton: button
 
	| req url |
	form isNil | button isNil ifTrue: [self error: 'Neither form nor button should be nil'].
	url _ form actionUrl.
	req _ HttpRequest
				readFromStream: (self
						httpPostRequestStreamForUrl: url
						data: (form httpDataWithButton: button)).
	^ self issueRequestUntilNotMoved: req

class methods:

^top


- made by Dandelion -