Bug 765239: allow marionette to reuse script file when importing scripts. r=mdas
authorDavid Burns <dburns@mozilla.com>
Mon, 18 Jun 2012 11:59:39 -0700
changeset 96982 373e6f9264e62452b6f56f9cc3fbbacfb40c58a9
parent 96981 515c5d751c5e2d729fa62d48a018cf8935353c2b
child 96983 50a969a82733e75577d79fcb4df5a2cb889d9ddf
push id10801
push userryanvm@gmail.com
push dateTue, 19 Jun 2012 00:59:28 +0000
treeherdermozilla-inbound@50a969a82733 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmdas
bugs765239
milestone16.0a1
first release with
nightly linux32
373e6f9264e6 / 16.0a1 / 20120619030538 / files
nightly linux64
373e6f9264e6 / 16.0a1 / 20120619030538 / files
nightly mac
373e6f9264e6 / 16.0a1 / 20120619030538 / files
nightly win32
373e6f9264e6 / 16.0a1 / 20120619030538 / files
nightly win64
373e6f9264e6 / 16.0a1 / 20120619030538 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 765239: allow marionette to reuse script file when importing scripts. r=mdas
testing/marionette/client/marionette/tests/unit/importanotherscript.js
testing/marionette/client/marionette/tests/unit/test_import_script.py
testing/marionette/marionette-actors.js
testing/marionette/marionette-listener.js
new file mode 100644
--- /dev/null
+++ b/testing/marionette/client/marionette/tests/unit/importanotherscript.js
@@ -0,0 +1,1 @@
+let testAnotherFunc = function() { return "i'm yet another test function!";};
--- a/testing/marionette/client/marionette/tests/unit/test_import_script.py
+++ b/testing/marionette/client/marionette/tests/unit/test_import_script.py
@@ -8,12 +8,27 @@ from marionette_test import MarionetteTe
 
 class TestImportScript(MarionetteTestCase):
     def test_import_script(self):
         js = os.path.abspath(os.path.join(__file__, os.path.pardir, "importscript.js"))
         self.marionette.import_script(js)
         self.assertEqual("i'm a test function!", self.marionette.execute_script("return testFunc();"))
         self.assertEqual("i'm a test function!", self.marionette.execute_async_script("marionetteScriptFinished(testFunc());"))
 
+    def test_importing_another_script_and_check_they_append(self):
+        firstjs = os.path.abspath(
+                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();"))
+
 class TestImportScriptChrome(TestImportScript):
     def setUp(self):
         MarionetteTestCase.setUp(self)
         self.marionette.set_context("chrome")
--- a/testing/marionette/marionette-actors.js
+++ b/testing/marionette/marionette-actors.js
@@ -1266,17 +1266,17 @@ MarionetteDriverActor.prototype = {
       return;
     }
   },
   
   importScript: function MDA_importScript(aRequest) {
     if (this.context == "chrome") {
       let file;
       if (this.importedScripts.exists()) {
-        file = FileUtils.openFileOutputStream(this.importedScripts, FileUtils.MODE_APPEND);
+        file = FileUtils.openFileOutputStream(this.importedScripts, FileUtils.MODE_APPEND | FileUtils.MODE_WRONLY);
       }
       else {
         file = FileUtils.openFileOutputStream(this.importedScripts, FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE);
       }
       file.write(aRequest.script, aRequest.script.length);
       file.close();
       this.sendOk();
     }
--- a/testing/marionette/marionette-listener.js
+++ b/testing/marionette/marionette-listener.js
@@ -762,17 +762,17 @@ function emulatorCmdResult(msg) {
     sendError(e.message, e.num, e.stack);
     return;
   }
 }
 
 function importScript(msg) {
   let file;
   if (importedScripts.exists()) {
-    file = FileUtils.openFileOutputStream(importedScripts, FielUtils.MODE_APPEND);
+    file = FileUtils.openFileOutputStream(importedScripts, FileUtils.MODE_APPEND | FileUtils.MODE_WRONLY);
   }
   else {
     file = FileUtils.openFileOutputStream(importedScripts, FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE);
   }
   file.write(msg.json.script, msg.json.script.length);
   file.close();
   sendOk();
 }