Bug 772995: Implementing close() for closing windows with marionette; r=mdas

This commit is contained in:
David Burns 2012-07-16 16:06:04 -07:00
Родитель 7761fe0d8e
Коммит 5e6f4b8272
3 изменённых файлов: 77 добавлений и 2 удалений

Просмотреть файл

@ -256,7 +256,7 @@ class Marionette(object):
response = self._send_message('getWindows', 'value')
return response
def close_window(self, window_id=None):
def close(self, window_id=None):
if not window_id:
window_id = self.current_window_handle
response = self._send_message('closeWindow', 'ok', value=window_id)

Просмотреть файл

@ -55,6 +55,41 @@ class TestSwitchWindow(MarionetteTestCase):
self.assertEqual(self.marionette.current_window_handle, orig_win)
self.assertEqual(len(self.marionette.window_handles), len(orig_available))
def testShouldLoadAWindowAndThenCloseIt(self):
test_html = self.marionette.absolute_url("test_windows.html")
self.marionette.navigate(test_html)
current = self.marionette.current_window_handle
self.marionette.find_element('link text',"Open new window").click()
window_handles = self.marionette.window_handles
window_handles.remove(current)
self.marionette.switch_to_window(window_handles[0])
self.assertEqual(self.marionette.title, "We Arrive Here")
handle = self.marionette.current_window_handle
self.assertEqual(self.marionette.current_window_handle, handle)
self.assertEqual(2, len(self.marionette.window_handles))
# Let's close and check
self.marionette.close()
self.marionette.switch_to_window(current)
self.assertEqual(1, len(self.marionette.window_handles))
def testShouldCauseAWindowToLoadAndCheckItIsOpenThenCloseIt(self):
test_html = self.marionette.absolute_url("test_windows.html")
self.marionette.navigate(test_html)
current = self.marionette.current_window_handle
self.marionette.find_element('link text',"Open new window").click()
self.assertEqual(2, len(self.marionette.window_handles))
# Let's close and check
self.marionette.close()
self.marionette.switch_to_window(current)
self.assertEqual(1, len(self.marionette.window_handles))
def tearDown(self):
#ensure that we close the window, regardless of pass/failure
self.close_new_window()

Просмотреть файл

@ -1192,6 +1192,45 @@ MarionetteDriverActor.prototype = {
}
},
/**
* Closes the Browser Window.
*
* If it is B2G it returns straight away and does not do anything
*
* If is desktop it calculates how many windows are open and if there is only
* 1 then it deletes the session otherwise it closes the window
*/
closeWindow: function MDA_closeWindow() {
if (appName == "B2G") {
// We can't close windows so just return
this.sendOk();
}
else {
// Get the total number of windows
let numOpenWindows = 0;
let winEnum = this.getWinEnumerator();
while (winEnum.hasMoreElements()) {
numOpenWindows += 1;
winEnum.getNext();
}
// if there is only 1 window left, delete the session
if (numOpenWindows === 1){
this.deleteSession();
return;
}
try{
this.messageManager.removeDelayedFrameScript("chrome://marionette/content/marionette-listener.js");
this.getCurrentWindow().close();
this.sendOk();
}
catch (e) {
this.sendError("Could not close window: " + e.message, 13, e.stack);
}
}
},
/**
* Deletes the session.
*
@ -1393,7 +1432,8 @@ MarionetteDriverActor.prototype.requestTypes = {
"switchToWindow": MarionetteDriverActor.prototype.switchToWindow,
"deleteSession": MarionetteDriverActor.prototype.deleteSession,
"emulatorCmdResult": MarionetteDriverActor.prototype.emulatorCmdResult,
"importScript": MarionetteDriverActor.prototype.importScript
"importScript": MarionetteDriverActor.prototype.importScript,
"closeWindow": MarionetteDriverActor.prototype.closeWindow
};
/**