lib/selenium/webdriver/safari/server.rb in selenium-webdriver-2.27.2 vs lib/selenium/webdriver/safari/server.rb in selenium-webdriver-2.29.0

- old
+ new

@@ -4,11 +4,10 @@ class Server def initialize(port, command_timeout) @port = port @command_timeout = command_timeout - @frame = LibWebSocket::Frame.new end def start @server = TCPServer.new(Platform.localhost, @port) end @@ -20,17 +19,19 @@ def send(command) json = WebDriver.json_dump(command) puts ">>> #{json}" if $DEBUG - frame = LibWebSocket::Frame.new(json).to_s + frame = WebSocket::Frame::Outgoing::Server.new(:version => @version, :data => json, :type => :text) - @ws.write frame + @ws.write frame.to_s @ws.flush end def receive + @frame ||= WebSocket::Frame::Incoming::Server.new(:version => @version) + until msg = @frame.next end_time = Time.now + @command_timeout begin data = @ws.read_nonblock(1) @@ -42,16 +43,16 @@ IO.select([@ws], nil, nil, end_time - now) retry end - @frame.append(data) + @frame << data end puts "<<< #{msg}" if $DEBUG - WebDriver.json_load msg + WebDriver.json_load msg.to_s end def ws_uri "ws://#{Platform.localhost}:#{@port}/wd" end @@ -105,32 +106,35 @@ http.close end def process_handshake @ws = @server.accept - hs = LibWebSocket::OpeningHandshake::Server.new + hs = WebSocket::Handshake::Server.new req = '' - until hs.done? + until hs.finished? data = @ws.getc || next + req << data.chr + hs << data + end - unless hs.parse(data.chr) - if req.include? "favicon.ico" - @ws.close - process_handshake - return - else - raise Error::WebDriverError, "#{hs.error}: #{req}" - end + unless hs.valid? + if req.include? "favicon.ico" + @ws.close + process_handshake + return + else + raise Error::WebDriverError, "#{hs.error}: #{req}" end end @ws.write(hs.to_s) @ws.flush - puts "handshake complete" if $DEBUG + puts "handshake complete, v#{hs.version}" if $DEBUG @server.close + @version = hs.version end end end end