Use uh to fake windows in cucumber test suite

This commit is contained in:
Thibault Jouan 2015-04-16 15:35:04 +00:00
parent 0ef0e47036
commit 1903ba166b
2 changed files with 47 additions and 6 deletions

View File

@ -21,7 +21,7 @@ end
After do
uhwm_ensure_stop
x_windows_ensure_stop
x_clients_ensure_stop
end
Around '@other_wm_running' do |_, block|

View File

@ -1,3 +1,5 @@
require 'uh'
module Uh
module WM
module Testing
@ -56,6 +58,10 @@ module Uh
@other_wm
end
def x_client
@x_client ||= XClient.new
end
def x_key key
fail "cannot simulate X key `#{key}'" unless system "xdotool key #{key}"
end
@ -70,16 +76,51 @@ module Uh
end
def x_window_name
'Event Tester'
@x_client.window_name
end
def x_window_map
@x_window = ChildProcess.build(*%w[xev -event owner_grab_button])
@x_window.start
x_client.map.sync
end
def x_windows_ensure_stop
@x_window and @x_window.stop
def x_clients_ensure_stop
@x_client and @x_client.terminate
end
private
class XClient
attr_reader :name
def initialize
@name = "#{self.class.name.split('::').last}/#{object_id}"
@geo = Geo.new(0, 0, 640, 480)
@display = Display.new.tap { |o| o.open }
end
def terminate
@display.close
end
def sync
@display.sync false
end
def window
@window ||= @display.create_window(@geo).tap do |o|
o.name = @name
end
end
def window_name
@name
end
def map
window.map
self
end
end
end
end