From 8e2760957820f629d90277635ce4900d69f5b73b Mon Sep 17 00:00:00 2001 From: David Burns Date: Fri, 14 Dec 2012 16:11:02 +0000 Subject: [PATCH] Bug 819351: move import script file creation/deletion to marionette actor and have it deleted on session delete. r=jgriffin --- .../tests/unit/test_import_script.py | 4 +-- .../tests/unit/test_import_script_content.py | 28 +++++++++++++++++++ .../marionette/tests/unit/unit-tests.ini | 2 ++ testing/marionette/marionette-actors.js | 9 +++--- testing/marionette/marionette-listener.js | 10 ++----- 5 files changed, 40 insertions(+), 13 deletions(-) create mode 100644 testing/marionette/client/marionette/tests/unit/test_import_script_content.py diff --git a/testing/marionette/client/marionette/tests/unit/test_import_script.py b/testing/marionette/client/marionette/tests/unit/test_import_script.py index 2f884272d7b..8b93d7b3ac5 100644 --- a/testing/marionette/client/marionette/tests/unit/test_import_script.py +++ b/testing/marionette/client/marionette/tests/unit/test_import_script.py @@ -18,13 +18,13 @@ class TestImportScript(MarionetteTestCase): os.path.join(__file__, os.path.pardir, "importscript.js")) secondjs = os.path.abspath( os.path.join(__file__, os.path.pardir, "importanotherscript.js")) - + self.marionette.import_script(firstjs) self.marionette.import_script(secondjs) self.assertEqual("i'm a test function!", self.marionette.execute_script("return testFunc();")) - + self.assertEqual("i'm yet another test function!", self.marionette.execute_script("return testAnotherFunc();")) diff --git a/testing/marionette/client/marionette/tests/unit/test_import_script_content.py b/testing/marionette/client/marionette/tests/unit/test_import_script_content.py new file mode 100644 index 00000000000..6e95e72dc3f --- /dev/null +++ b/testing/marionette/client/marionette/tests/unit/test_import_script_content.py @@ -0,0 +1,28 @@ + +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import os +from marionette_test import MarionetteTestCase + +class TestImportScriptContent(MarionetteTestCase): + + def test_importing_script_then_reusing_it(self): + test_html = self.marionette.absolute_url("test_windows.html") + self.marionette.navigate(test_html) + js = os.path.abspath(os.path.join(__file__, os.path.pardir, "importscript.js")) + self.current_window = self.marionette.current_window_handle + link = self.marionette.find_element("link text", "Open new window") + link.click() + + windows = self.marionette.window_handles + windows.remove(self.current_window) + self.marionette.switch_to_window(windows[0]) + + self.marionette.import_script(js) + self.marionette.close() + + self.marionette.switch_to_window(self.current_window) + self.assertEqual("i'm a test function!", self.marionette.execute_script("return testFunc();")) + diff --git a/testing/marionette/client/marionette/tests/unit/unit-tests.ini b/testing/marionette/client/marionette/tests/unit/unit-tests.ini index b091f5c6e14..19155c53e34 100644 --- a/testing/marionette/client/marionette/tests/unit/unit-tests.ini +++ b/testing/marionette/client/marionette/tests/unit/unit-tests.ini @@ -13,6 +13,8 @@ skip = false [test_getstatus.py] [test_import_script.py] +[test_import_script_content.py.py] +b2g = false [test_click.py] b2g = false [test_selected.py] diff --git a/testing/marionette/marionette-actors.js b/testing/marionette/marionette-actors.js index 38de3ea8c12..92ec0922b83 100644 --- a/testing/marionette/marionette-actors.js +++ b/testing/marionette/marionette-actors.js @@ -1880,16 +1880,17 @@ MarionetteDriverActor.prototype = { } catch (ex) { // browserType remains undefined. } - let reg; + let reg = {}; if (!browserType || browserType != "content") { - reg = this.curBrowser.register(this.generateFrameId(message.json.value), + reg.id = this.curBrowser.register(this.generateFrameId(message.json.value), message.json.href); } - this.curBrowser.elementManager.seenItems[reg] = listenerWindow; //add to seenItems + this.curBrowser.elementManager.seenItems[reg.id] = listenerWindow; //add to seenItems + reg.importedScripts = this.importedScripts.path; if (nullPrevious && (this.curBrowser.curFrameId != null)) { this.sendAsync("newSession", {B2G: (appName == "B2G")}); if (this.curBrowser.newSession) { - this.sendResponse(reg); + this.sendResponse(reg.id); } } return reg; diff --git a/testing/marionette/marionette-listener.js b/testing/marionette/marionette-listener.js index bb6a29d1287..3f36f8a1bc6 100644 --- a/testing/marionette/marionette-listener.js +++ b/testing/marionette/marionette-listener.js @@ -40,7 +40,7 @@ let listenerId = null; //unique ID of this listener let activeFrame = null; let curWindow = content; let elementManager = new ElementManager([]); -let importedScripts = FileUtils.getFile('TmpD', ['marionettescript']); +let importedScripts = null; // The sandbox we execute test scripts in. Gets lazily created in // createExecuteContentSandbox(). @@ -65,7 +65,8 @@ function registerSelf() { let register = sendSyncMessage("Marionette:register", msg); if (register[0]) { - listenerId = register[0]; + listenerId = register[0].id; + importedScripts = FileUtils.File(register[0].importedScripts); startListeners(); } } @@ -215,11 +216,6 @@ function deleteSession(msg) { // reset frame to the top-most frame curWindow = content; curWindow.focus(); - try { - importedScripts.remove(false); - } - catch (e) { - } } /*