From 58b95498e0c6ac00c1941262afeaa566c88c861b Mon Sep 17 00:00:00 2001 From: David Burns Date: Tue, 30 May 2017 13:51:02 +0100 Subject: [PATCH] Bug 1368674 - Remove simpleTest functionality from Marionette. r=whimboo This is a remanent of the B2G code for injecting Mochitest style tests into Gecko. This is no longer used by anything and is now dead code. MozReview-Commit-ID: 4qaB3vxQzon --HG-- extra : rebase_source : b4b7e66452b7ce7335ef5f509957121f403d7043 --- testing/marionette/driver.js | 44 ----- .../tests/unit/test_execute_script.py | 13 -- .../tests/unit/test_simpletest_chrome.js | 12 -- .../tests/unit/test_simpletest_fail.js | 16 -- .../tests/unit/test_simpletest_pass.js | 12 -- .../tests/unit/test_simpletest_sanity.py | 107 ----------- .../tests/unit/test_simpletest_timeout.js | 16 -- .../marionette_harness/tests/unit/unit-tests.ini | 5 - testing/marionette/listener.js | 29 --- testing/marionette/simpletest.js | 208 --------------------- 10 files changed, 462 deletions(-) delete mode 100644 testing/marionette/harness/marionette_harness/tests/unit/test_simpletest_chrome.js delete mode 100644 testing/marionette/harness/marionette_harness/tests/unit/test_simpletest_fail.js delete mode 100644 testing/marionette/harness/marionette_harness/tests/unit/test_simpletest_pass.js delete mode 100644 testing/marionette/harness/marionette_harness/tests/unit/test_simpletest_sanity.py delete mode 100644 testing/marionette/harness/marionette_harness/tests/unit/test_simpletest_timeout.js delete mode 100644 testing/marionette/simpletest.js diff --git a/testing/marionette/driver.js b/testing/marionette/driver.js index 4d96bc933848..fe68784355fb 100644 --- a/testing/marionette/driver.js +++ b/testing/marionette/driver.js @@ -35,7 +35,6 @@ Cu.import("chrome://marionette/content/logging.js"); Cu.import("chrome://marionette/content/modal.js"); Cu.import("chrome://marionette/content/proxy.js"); Cu.import("chrome://marionette/content/session.js"); -Cu.import("chrome://marionette/content/simpletest.js"); Cu.import("chrome://marionette/content/wait.js"); this.EXPORTED_SYMBOLS = ["GeckoDriver", "Context"]; @@ -894,49 +893,6 @@ GeckoDriver.prototype.execute_ = function (script, args, timeout, opts = {}) { }; /** - * Execute pure JavaScript. Used to execute simpletest harness tests, - * which are like mochitests only injected using Marionette. - * - * Scripts are expected to call the {@code finish} global when done. - */ -GeckoDriver.prototype.executeJSScript = function* (cmd, resp) { - let win = assert.window(this.getCurrentWindow()); - - let {script, args, scriptTimeout} = cmd.parameters; - scriptTimeout = scriptTimeout || this.timeouts.script; - - let opts = { - filename: cmd.parameters.filename, - line: cmd.parameters.line, - async: cmd.parameters.async, - }; - - switch (this.context) { - case Context.CHROME: - let wargs = evaluate.fromJSON(args, this.curBrowser.seenEls, win); - let harness = new simpletest.Harness( - win, - Context.CHROME, - this.marionetteLog, - scriptTimeout, - function() {}, - this.testName); - - let sb = sandbox.createSimpleTest(win, harness); - // TODO(ato): Not sure this is needed: - sb = sandbox.augment(sb, new logging.Adapter(this.marionetteLog)); - - let res = yield evaluate.sandbox(sb, script, wargs, opts); - resp.body.value = evaluate.toJSON(res, this.curBrowser.seenEls); - break; - - case Context.CONTENT: - resp.body.value = yield this.listener.executeSimpleTest(script, args, scriptTimeout, opts); - break; - } -}; - -/** * Navigate to given URL. * * Navigates the current browsing context to the given URL and waits for diff --git a/testing/marionette/harness/marionette_harness/tests/unit/test_execute_script.py b/testing/marionette/harness/marionette_harness/tests/unit/test_execute_script.py index 1a7c208c5566..74674a798fbb 100644 --- a/testing/marionette/harness/marionette_harness/tests/unit/test_execute_script.py +++ b/testing/marionette/harness/marionette_harness/tests/unit/test_execute_script.py @@ -29,19 +29,6 @@ globals = set([ ]) -class TestExecuteSimpleTestContent(MarionetteTestCase): - def test_stack_trace(self): - try: - self.marionette.execute_js_script(""" - let a = 1; - throwHere(); - """, filename="file.js") - self.assertFalse(True) - except errors.JavascriptException as e: - self.assertIn("throwHere is not defined", e.message) - self.assertIn("@file.js:2", e.stacktrace) - - class TestExecuteContent(MarionetteTestCase): def assert_is_defined(self, property, sandbox="default"): diff --git a/testing/marionette/harness/marionette_harness/tests/unit/test_simpletest_chrome.js b/testing/marionette/harness/marionette_harness/tests/unit/test_simpletest_chrome.js deleted file mode 100644 index d5edffa67a00..000000000000 --- a/testing/marionette/harness/marionette_harness/tests/unit/test_simpletest_chrome.js +++ /dev/null @@ -1,12 +0,0 @@ -/* 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/. */ - -MARIONETTE_TIMEOUT = 1000; -MARIONETTE_CONTEXT = 'chrome'; - -is(2, 2, "test for is()"); -isnot(2, 3, "test for isnot()"); -ok(2 == 2, "test for ok()"); -finish(); - diff --git a/testing/marionette/harness/marionette_harness/tests/unit/test_simpletest_fail.js b/testing/marionette/harness/marionette_harness/tests/unit/test_simpletest_fail.js deleted file mode 100644 index 16d9aea592b0..000000000000 --- a/testing/marionette/harness/marionette_harness/tests/unit/test_simpletest_fail.js +++ /dev/null @@ -1,16 +0,0 @@ -/* 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/. */ - -MARIONETTE_TIMEOUT = 1000; - -/* this test will fail */ - -setTimeout(function() { - is(1, 2, "is(1,2) should fail", TEST_UNEXPECTED_FAIL, TEST_PASS); - finish(); -}, 100); -isnot(1, 1, "isnot(1,1) should fail", TEST_UNEXPECTED_FAIL, TEST_PASS); -ok(1 == 2, "ok(1==2) should fail", TEST_UNEXPECTED_FAIL, TEST_PASS); - - diff --git a/testing/marionette/harness/marionette_harness/tests/unit/test_simpletest_pass.js b/testing/marionette/harness/marionette_harness/tests/unit/test_simpletest_pass.js deleted file mode 100644 index 93ee676191c8..000000000000 --- a/testing/marionette/harness/marionette_harness/tests/unit/test_simpletest_pass.js +++ /dev/null @@ -1,12 +0,0 @@ -/* 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/. */ - -MARIONETTE_TIMEOUT = 1000; - -is(2, 2, "test for is()"); -isnot(2, 3, "test for isnot()"); -ok(2 == 2, "test for ok()"); - -setTimeout(finish, 100); - diff --git a/testing/marionette/harness/marionette_harness/tests/unit/test_simpletest_sanity.py b/testing/marionette/harness/marionette_harness/tests/unit/test_simpletest_sanity.py deleted file mode 100644 index 8f9728561451..000000000000 --- a/testing/marionette/harness/marionette_harness/tests/unit/test_simpletest_sanity.py +++ /dev/null @@ -1,107 +0,0 @@ -# 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/. - -from marionette_harness import MarionetteTestCase - - -class SimpletestSanityTest(MarionetteTestCase): - callFinish = "return finish();" - - def run_sync(self, test): - return self.marionette.execute_js_script(test, async=False) - - def run_async(self, test): - return self.marionette.execute_js_script(test) - - def test_is(self): - def runtests(): - sentFail1 = "is(true, false, 'isTest1', TEST_UNEXPECTED_FAIL, TEST_PASS);" + self.callFinish - sentFail2 = "is(true, false, 'isTest2', TEST_UNEXPECTED_FAIL, TEST_PASS);" + self.callFinish - sentPass1 = "is(true, true, 'isTest3');" + self.callFinish - sentPass2 = "is(true, true, 'isTest4');" + self.callFinish - - self.assertEqual(1, len(self.run_sync(sentFail1)["failures"])) - self.assertEqual(0, self.run_sync(sentFail2)["passed"]) - self.assertEqual(1, self.run_sync(sentPass1)["passed"]) - self.assertEqual(0, len(self.run_sync(sentPass2)["failures"])) - - self.marionette.timeout.script = 1 - self.assertEqual(1, len(self.run_async(sentFail1)["failures"])) - self.assertEqual(0, self.run_async(sentFail2)["passed"]) - self.assertEqual(1, self.run_async(sentPass1)["passed"]) - self.assertEqual(0, len(self.run_async(sentPass2)["failures"])) - - self.marionette.set_context("content") - runtests() - self.marionette.set_context("chrome") - runtests() - - def test_isnot(self): - def runtests(): - sentFail1 = "isnot(true, true, 'isnotTest3', TEST_UNEXPECTED_FAIL, TEST_PASS);" + self.callFinish - sentFail2 = "isnot(true, true, 'isnotTest4', TEST_UNEXPECTED_FAIL, TEST_PASS);" + self.callFinish - sentPass1 = "isnot(true, false, 'isnotTest1');" + self.callFinish - sentPass2 = "isnot(true, false, 'isnotTest2');" + self.callFinish - - self.assertEqual(1, len(self.run_sync(sentFail1)["failures"])); - self.assertEqual(0, self.run_sync(sentFail2)["passed"]); - self.assertEqual(0, len(self.run_sync(sentPass1)["failures"])); - self.assertEqual(1, self.run_sync(sentPass2)["passed"]); - - self.marionette.timeout.script = 1 - self.assertEqual(1, len(self.run_async(sentFail1)["failures"])); - self.assertEqual(0, self.run_async(sentFail2)["passed"]); - self.assertEqual(0, len(self.run_async(sentPass1)["failures"])); - self.assertEqual(1, self.run_async(sentPass2)["passed"]); - - self.marionette.set_context("content") - runtests() - self.marionette.set_context("chrome") - runtests() - - def test_ok(self): - def runtests(): - sentFail1 = "ok(1==2, 'testOk1', TEST_UNEXPECTED_FAIL, TEST_PASS);" + self.callFinish - sentFail2 = "ok(1==2, 'testOk2', TEST_UNEXPECTED_FAIL, TEST_PASS);" + self.callFinish - sentPass1 = "ok(1==1, 'testOk3');" + self.callFinish - sentPass2 = "ok(1==1, 'testOk4');" + self.callFinish - - self.assertEqual(1, len(self.run_sync(sentFail1)["failures"])); - self.assertEqual(0, self.run_sync(sentFail2)["passed"]); - self.assertEqual(0, len(self.run_sync(sentPass1)["failures"])); - self.assertEqual(1, self.run_sync(sentPass2)["passed"]); - - self.marionette.timeout.script = 1 - self.assertEqual(1, len(self.run_async(sentFail1)["failures"])); - self.assertEqual(0, self.run_async(sentFail2)["passed"]); - self.assertEqual(0, len(self.run_async(sentPass1)["failures"])); - self.assertEqual(1, self.run_async(sentPass2)["passed"]); - - self.marionette.set_context("content") - runtests() - self.marionette.set_context("chrome") - runtests() - - def test_todo(self): - def runtests(): - sentFail1 = "todo(1==1, 'testTodo1', TEST_UNEXPECTED_PASS, TEST_KNOWN_FAIL);" + self.callFinish - sentFail2 = "todo(1==1, 'testTodo2', TEST_UNEXPECTED_PASS, TEST_KNOWN_FAIL);" + self.callFinish - sentPass1 = "todo(1==2, 'testTodo3');" + self.callFinish - sentPass2 = "todo(1==2, 'testTodo4');" + self.callFinish - - self.assertEqual(1, len(self.run_sync(sentFail1)["unexpectedSuccesses"])); - self.assertEqual(0, len(self.run_sync(sentFail2)["expectedFailures"])); - self.assertEqual(0, len(self.run_sync(sentPass1)["unexpectedSuccesses"])); - self.assertEqual(1, len(self.run_sync(sentPass2)["expectedFailures"])); - - self.marionette.timeout.script = 1 - self.assertEqual(1, len(self.run_async(sentFail1)["unexpectedSuccesses"])); - self.assertEqual(0, len(self.run_async(sentFail2)["expectedFailures"])); - self.assertEqual(0, len(self.run_async(sentPass1)["unexpectedSuccesses"])); - self.assertEqual(1, len(self.run_async(sentPass2)["expectedFailures"])); - - self.marionette.set_context("content") - runtests() - self.marionette.set_context("chrome") - runtests() diff --git a/testing/marionette/harness/marionette_harness/tests/unit/test_simpletest_timeout.js b/testing/marionette/harness/marionette_harness/tests/unit/test_simpletest_timeout.js deleted file mode 100644 index 9792a936a316..000000000000 --- a/testing/marionette/harness/marionette_harness/tests/unit/test_simpletest_timeout.js +++ /dev/null @@ -1,16 +0,0 @@ -/* 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/. */ - -MARIONETTE_TIMEOUT = 100; - -/* this test will timeout */ - -function do_test() { - is(1, 1); - isnot(1, 2); - ok(1 == 1); - finish(); -} - -setTimeout(do_test, 1000); diff --git a/testing/marionette/harness/marionette_harness/tests/unit/unit-tests.ini b/testing/marionette/harness/marionette_harness/tests/unit/unit-tests.ini index 3aa10486b108..ba5fd496873a 100644 --- a/testing/marionette/harness/marionette_harness/tests/unit/unit-tests.ini +++ b/testing/marionette/harness/marionette_harness/tests/unit/unit-tests.ini @@ -33,7 +33,6 @@ skip-if = true # "Bug 896046" [test_execute_async_script.py] [test_execute_script.py] -[test_simpletest_fail.js] [test_element_retrieval.py] [test_findelement_chrome.py] skip-if = appname == 'fennec' @@ -46,10 +45,6 @@ skip-if = appname == 'fennec' [test_single_finger_desktop.py] skip-if = appname == 'fennec' || os == "win" # Bug 1025040 -[test_simpletest_pass.js] -[test_simpletest_sanity.py] -[test_simpletest_chrome.js] -[test_simpletest_timeout.js] [test_anonymous_content.py] skip-if = appname == 'fennec' [test_switch_frame.py] diff --git a/testing/marionette/listener.js b/testing/marionette/listener.js index 5d5887509872..a6ac0e964cbb 100644 --- a/testing/marionette/listener.js +++ b/testing/marionette/listener.js @@ -27,7 +27,6 @@ Cu.import("chrome://marionette/content/logging.js"); Cu.import("chrome://marionette/content/navigate.js"); Cu.import("chrome://marionette/content/proxy.js"); Cu.import("chrome://marionette/content/session.js"); -Cu.import("chrome://marionette/content/simpletest.js"); Cu.import("resource://gre/modules/FileUtils.jsm"); Cu.import("resource://gre/modules/Preferences.jsm"); @@ -490,7 +489,6 @@ var deleteCookieFn = dispatch(deleteCookie); var deleteAllCookiesFn = dispatch(deleteAllCookies); var executeFn = dispatch(execute); var executeInSandboxFn = dispatch(executeInSandbox); -var executeSimpleTestFn = dispatch(executeSimpleTest); var sendKeysToElementFn = dispatch(sendKeysToElement); /** @@ -500,7 +498,6 @@ function startListeners() { addMessageListenerId("Marionette:newSession", newSession); addMessageListenerId("Marionette:execute", executeFn); addMessageListenerId("Marionette:executeInSandbox", executeInSandboxFn); - addMessageListenerId("Marionette:executeSimpleTest", executeSimpleTestFn); addMessageListenerId("Marionette:singleTap", singleTapFn); addMessageListenerId("Marionette:performActions", performActionsFn); addMessageListenerId("Marionette:releaseActions", releaseActionsFn); @@ -576,7 +573,6 @@ function deleteSession(msg) { removeMessageListenerId("Marionette:newSession", newSession); removeMessageListenerId("Marionette:execute", executeFn); removeMessageListenerId("Marionette:executeInSandbox", executeInSandboxFn); - removeMessageListenerId("Marionette:executeSimpleTest", executeSimpleTestFn); removeMessageListenerId("Marionette:singleTap", singleTapFn); removeMessageListenerId("Marionette:performActions", performActionsFn); removeMessageListenerId("Marionette:releaseActions", releaseActionsFn); @@ -763,31 +759,6 @@ function* executeInSandbox(script, args, timeout, opts) { return evaluate.toJSON(res, seenEls); } -function* executeSimpleTest(script, args, timeout, opts) { - opts.timeout = timeout; - let win = curContainer.frame; - - let harness = new simpletest.Harness( - win, - "content", - contentLog, - timeout, - marionetteTestName); - let sb = sandbox.createSimpleTest(curContainer.frame, harness); - // TODO(ato): Not sure this is needed: - sb = sandbox.augment(sb, new logging.Adapter(contentLog)); - - let wargs = evaluate.fromJSON( - args, seenEls, curContainer.frame, curContainer.shadowRoot); - let evaluatePromise = evaluate.sandbox(sb, script, wargs, opts); - - let res = yield evaluatePromise; - sendSyncMessage( - "Marionette:shareData", - {log: evaluate.toJSON(contentLog.get(), seenEls)}); - return evaluate.toJSON(res, seenEls); -} - /** * Sets the test name, used in logging messages. */ diff --git a/testing/marionette/simpletest.js b/testing/marionette/simpletest.js deleted file mode 100644 index b179d2a8c28e..000000000000 --- a/testing/marionette/simpletest.js +++ /dev/null @@ -1,208 +0,0 @@ -/* 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/. */ - -"use strict"; - -const {utils: Cu} = Components; - -Cu.import("chrome://marionette/content/error.js"); - -this.EXPORTED_SYMBOLS = ["simpletest"]; - -this.simpletest = {}; - -/** - * The simpletest harness, exposed in the script evaluation sandbox. - */ -simpletest.Harness = class { - constructor(window, context, contentLogger, timeout, testName) { - this.window = window; - this.tests = []; - this.logger = contentLogger; - this.context = context; - this.timeout = timeout; - this.testName = testName; - this.TEST_UNEXPECTED_FAIL = "TEST-UNEXPECTED-FAIL"; - this.TEST_UNEXPECTED_PASS = "TEST-UNEXPECTED-PASS"; - this.TEST_PASS = "TEST-PASS"; - this.TEST_KNOWN_FAIL = "TEST-KNOWN-FAIL"; - } - - get exports() { - return new Map([ - ["ok", this.ok.bind(this)], - ["is", this.is.bind(this)], - ["isnot", this.isnot.bind(this)], - ["todo", this.todo.bind(this)], - ["log", this.log.bind(this)], - ["getLogs", this.getLogs.bind(this)], - ["generate_results", this.generate_results.bind(this)], - ["waitFor", this.waitFor.bind(this)], - ["TEST_PASS", this.TEST_PASS], - ["TEST_KNOWN_FAIL", this.TEST_KNOWN_FAIL], - ["TEST_UNEXPECTED_FAIL", this.TEST_UNEXPECTED_FAIL], - ["TEST_UNEXPECTED_PASS", this.TEST_UNEXPECTED_PASS], - ]); - } - - addTest(condition, name, passString, failString, diag, state) { - let test = { - result: !!condition, - name: name, - diag: diag, - state: state - }; - this.logResult( - test, - typeof passString == "undefined" ? this.TEST_PASS : passString, - typeof failString == "undefined" ? this.TEST_UNEXPECTED_FAIL : failString); - this.tests.push(test); - } - - ok(condition, name, passString, failString) { - let diag = `${this.repr(condition)} was ${!!condition}, expected true`; - this.addTest(condition, name, passString, failString, diag); - } - - is(a, b, name, passString, failString) { - let pass = (a == b); - let diag = pass ? this.repr(a) + " should equal " + this.repr(b) - : "got " + this.repr(a) + ", expected " + this.repr(b); - this.addTest(pass, name, passString, failString, diag); - } - - isnot(a, b, name, passString, failString) { - let pass = (a != b); - let diag = pass ? this.repr(a) + " should not equal " + this.repr(b) - : "didn't expect " + this.repr(a) + ", but got it"; - this.addTest(pass, name, passString, failString, diag); - } - - todo(condition, name, passString, failString) { - let diag = this.repr(condition) + " was expected false"; - this.addTest(!condition, - name, - typeof(passString) == "undefined" ? this.TEST_KNOWN_FAIL : passString, - typeof(failString) == "undefined" ? this.TEST_UNEXPECTED_FAIL : failString, - diag, - "todo"); - } - - log(msg, level) { - dump("MARIONETTE LOG: " + (level ? level : "INFO") + ": " + msg + "\n"); - if (this.logger) { - this.logger.log(msg, level); - } - } - - // TODO(ato): Suspect this isn't used anywhere - getLogs() { - if (this.logger) { - return this.logger.get(); - } - } - - generate_results() { - let passed = 0; - let failures = []; - let expectedFailures = []; - let unexpectedSuccesses = []; - for (let i in this.tests) { - let isTodo = (this.tests[i].state == "todo"); - if(this.tests[i].result) { - if (isTodo) { - expectedFailures.push({'name': this.tests[i].name, 'diag': this.tests[i].diag}); - } - else { - passed++; - } - } - else { - if (isTodo) { - unexpectedSuccesses.push({'name': this.tests[i].name, 'diag': this.tests[i].diag}); - } - else { - failures.push({'name': this.tests[i].name, 'diag': this.tests[i].diag}); - } - } - } - // Reset state in case this object is reused for more tests. - this.tests = []; - return { - passed: passed, - failures: failures, - expectedFailures: expectedFailures, - unexpectedSuccesses: unexpectedSuccesses, - }; - } - - logToFile(file) { - //TODO - } - - logResult(test, passString, failString) { - //TODO: dump to file - let resultString = test.result ? passString : failString; - let diagnostic = test.name + (test.diag ? " - " + test.diag : ""); - let msg = resultString + " | " + this.testName + " | " + diagnostic; - dump("MARIONETTE TEST RESULT:" + msg + "\n"); - } - - repr(o) { - if (typeof o == "undefined") { - return "undefined"; - } else if (o === null) { - return "null"; - } - - try { - if (typeof o.__repr__ == "function") { - return o.__repr__(); - } else if (typeof o.repr == "function" && o.repr !== arguments.callee) { - return o.repr(); - } - } catch (e) {} - - try { - if (typeof o.NAME === "string" && - (o.toString === Function.prototype.toString || o.toString === Object.prototype.toString)) { - return o.NAME; - } - } catch (e) {} - - let ostring; - try { - ostring = (o + ""); - } catch (e) { - return "[" + typeof(o) + "]"; - } - - if (typeof o == "function") { - o = ostring.replace(/^\s+/, ""); - let idx = o.indexOf("{"); - if (idx != -1) { - o = o.substr(0, idx) + "{...}"; - } - } - return ostring; - } - - waitFor(callback, test, timeout) { - if (test()) { - callback(); - return; - } - - let now = new Date(); - let deadline = (timeout instanceof Date) ? timeout : - new Date(now.valueOf() + (typeof timeout == "undefined" ? this.timeout : timeout)); - if (deadline <= now) { - dump("waitFor timeout: " + test.toString() + "\n"); - // the script will timeout here, so no need to raise a separate - // timeout exception - return; - } - this.window.setTimeout(this.waitFor.bind(this), 100, callback, test, deadline); - } -}; -- 2.11.4.GIT