Class: Vapir::Firefox::ModalDialog

Inherits:
Object
  • Object
show all
Includes:
Firefox::Window, ModalDialog
Defined in:
lib/vapir-firefox/modal_dialog.rb

Overview

represents a window which is modal to a parent window

Instance Method Summary collapse

Instance Method Details

#browser_window_objectObject



73
74
75
76
# File 'lib/vapir-firefox/modal_dialog.rb', line 73

def browser_window_object
  assert_exists
  modal_window
end

#click_button(button_text, options = {}) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/vapir-firefox/modal_dialog.rb', line 48

def click_button(button_text, options={})
  assert_exists
  options=handle_options(options, :timeout => nil) # we don't actually use timeout here. maybe should error on it? 
  # raise if no anonymous nodes are found (this is where the buttons are) 
  anonymous_dialog_nodes=@modal_window.document.getAnonymousNodes(@modal_window.document.documentElement) || raise("Could not find anonymous nodes on which to look for buttons")
  xul_buttons=[]
  anonymous_dialog_nodes.to_array.each do |node|
    xul_buttons+=node.getElementsByTagName('xul:button').to_array.select do |button|
      Vapir::fuzzy_match(button.label, button_text)
    end
  end
  raise("Found #{xul_buttons.size} buttons which match #{button_text} - expected to find 1") unless xul_buttons.size==1
  xul_button=xul_buttons.first
  xul_button.disabled=false # get around firefox's stupid thing where the default button is disabled for a few seconds or something, god knows why
  xul_button.click
end

#closeObject



65
66
67
# File 'lib/vapir-firefox/modal_dialog.rb', line 65

def close
  @modal_window.close
end

#documentObject



69
70
71
72
# File 'lib/vapir-firefox/modal_dialog.rb', line 69

def document
  assert_exists
  Firefox::ModalDialogDocument.new(self)
end

#exists?Boolean

Returns:

  • (Boolean)


33
34
35
36
# File 'lib/vapir-firefox/modal_dialog.rb', line 33

def exists?
  # jssh_socket may be nil if the window has closed 
  @modal_window && @browser.jssh_socket && @browser.jssh_socket.object('getWindows()').to_js_array.include(@modal_window)
end

#locateObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/vapir-firefox/modal_dialog.rb', line 10

def locate
  candidates=[]
  Vapir::Firefox.each_window_object do |win|
    opener=win.attr(:opener)
    opener=nil unless opener.type=='object'
    content=win.attr(:content)
    if content.type=='object'
      content_opener=content.attr(:opener)
      content_opener=nil unless content_opener.type=='object'
    end
    if [@browser.browser_window_object, @browser.content_window_object].any?{|_w| [opener, content_opener].compact.include?(_w) }
      candidates << win 
    end
  end
  if candidates.size==0
    nil
  elsif candidates.size==1
    @modal_window=candidates.first
  else
    raise "Multiple windows found which this is a parent of - cannot determine which is the expected modal dialog"
  end
end

#mozilla_window_class_nameObject



77
78
79
# File 'lib/vapir-firefox/modal_dialog.rb', line 77

def mozilla_window_class_name
  'MozillaDialogClass'
end

#set_text_field(value) ⇒ Object

Raises:

  • (NotImplementedError)


43
44
45
46
# File 'lib/vapir-firefox/modal_dialog.rb', line 43

def set_text_field(value)
  assert_exists
  raise NotImplementedError
end

#textObject



38
39
40
41
# File 'lib/vapir-firefox/modal_dialog.rb', line 38

def text
  assert_exists
  @modal_window.document.documentElement.textContent
end