Bug 1461463 - [marionette] Add validation for known contexts.
MozReview-Commit-ID: 1t0hk5rdY1a
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -133,18 +133,17 @@ this.GeckoDriver = function(appId, serve
// topmost chrome frame
this.mainFrame = null;
// chrome iframe that currently has focus
this.curFrame = null;
this.currentFrameElement = null;
this.observing = null;
this._browserIds = new WeakMap();
- // The curent context decides if commands should affect chrome- or
- // content space.
+ // Use content context by default
this.context = Context.Content;
this.sandboxes = new Sandboxes(() => this.getCurrentWindow());
this.legacyactions = new legacyaction.Chain();
this.capabilities = new session.Capabilities();
this.mm = globalMessageManager;
@@ -158,16 +157,30 @@ this.GeckoDriver = function(appId, serve
Object.defineProperty(GeckoDriver.prototype, "a11yChecks", {
get() {
return this.capabilities.get("moz:accessibilityChecks");
},
});
/**
+ * The current context decides if commands are executed in chrome- or
+ * content space.
+ */
+Object.defineProperty(GeckoDriver.prototype, "context", {
+ get() {
+ return this._context;
+ },
+
+ set(context) {
+ this._context = Context.fromString(context);
+ },
+});
+
+/**
* Returns the current URL of the ChromeWindow or content browser,
* depending on context.
*
* @return {URL}
* Read-only property containing the currently loaded URL.
*/
Object.defineProperty(GeckoDriver.prototype, "currentURL", {
get() {
@@ -795,17 +808,18 @@ GeckoDriver.prototype.getSessionCapabili
*
* @throws {InvalidArgumentError}
* If <var>value</var> is not a string.
* @throws {WebDriverError}
* If <var>value</var> is not a valid browsing context.
*/
GeckoDriver.prototype.setContext = function(cmd) {
let value = assert.string(cmd.parameters.value);
- this.context = Context.fromString(value);
+
+ this.context = value;
};
/**
* Gets the context type that is Marionette's current target for
* browsing context scoped commands.
*
* You may choose a context through the {@link #setContext} command.
*
rename from testing/marionette/harness/marionette_harness/tests/unit/test_with_using_context.py
rename to testing/marionette/harness/marionette_harness/tests/unit/test_context.py
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_with_using_context.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_context.py
@@ -1,35 +1,52 @@
# 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 __future__ import absolute_import
from marionette_driver.decorators import using_context
from marionette_driver.errors import MarionetteException
-
from marionette_harness import MarionetteTestCase
-class TestSetContext(MarionetteTestCase):
+class ContextTestCase(MarionetteTestCase):
+
def setUp(self):
- MarionetteTestCase.setUp(self)
+ super(ContextTestCase, self).setUp()
# shortcuts to improve readability of these tests
self.chrome = self.marionette.CONTEXT_CHROME
self.content = self.marionette.CONTEXT_CONTENT
+ self.assertEquals(self.get_context(), self.content)
+
test_url = self.marionette.absolute_url("empty.html")
self.marionette.navigate(test_url)
+
+ def get_context(self):
+ return self.marionette._send_message("getContext", key="value")
+
+
+class TestSetContext(ContextTestCase):
+
+ def test_switch_context(self):
+ self.marionette.set_context(self.chrome)
+ self.assertEquals(self.get_context(), self.chrome)
+
self.marionette.set_context(self.content)
self.assertEquals(self.get_context(), self.content)
- def get_context(self):
- return self.marionette._send_message("getContext", key="value")
+ def test_invalid_context(self):
+ with self.assertRaises(ValueError):
+ self.marionette.set_context("foobar")
+
+
+class TestUsingContext(ContextTestCase):
def test_set_different_context_using_with_block(self):
with self.marionette.using_context(self.chrome):
self.assertEquals(self.get_context(), self.chrome)
self.assertEquals(self.get_context(), self.content)
def test_set_same_context_using_with_block(self):
with self.marionette.using_context(self.content):
@@ -56,13 +73,15 @@ class TestSetContext(MarionetteTestCase)
with self.marionette.using_context(self.chrome):
raise MarionetteException
self.assertEquals(self.get_context(), self.content)
def test_with_using_context_decorator(self):
@using_context('content')
def inner_content(m):
self.assertEquals(self.get_context(), 'content')
+
@using_context('chrome')
def inner_chrome(m):
self.assertEquals(self.get_context(), 'chrome')
+
inner_content(self.marionette)
inner_chrome(self.marionette)
--- a/testing/marionette/harness/marionette_harness/tests/unit/unit-tests.ini
+++ b/testing/marionette/harness/marionette_harness/tests/unit/unit-tests.ini
@@ -90,17 +90,17 @@ skip-if = true # Bug 925688
[test_errors.py]
[test_execute_isolate.py]
[test_click_scrolling.py]
[test_profile_management.py]
skip-if = manage_instance == false || appname == 'fennec' # Bug 1298921
[test_quit_restart.py]
skip-if = manage_instance == false || appname == 'fennec' # Bug 1298921
-[test_with_using_context.py]
+[test_context.py]
[test_modal_dialogs.py]
skip-if = appname == 'fennec' # Bug 1325738
[test_key_actions.py]
[test_legacy_mouse_action.py]
skip-if = appname == 'fennec'
[test_mouse_action.py]
skip-if = appname == 'fennec'