Bug 1461463 - [marionette] Add validation for known contexts. r=ato

MozReview-Commit-ID: 1t0hk5rdY1a

--HG--
rename : testing/marionette/harness/marionette_harness/tests/unit/test_with_using_context.py => testing/marionette/harness/marionette_harness/tests/unit/test_context.py
extra : rebase_source : 02e5e3ef11183e6ed8898934190f3d15840ef0b2
This commit is contained in:
Henrik Skupin 2018-05-24 16:47:30 +02:00
Родитель 01fa4d3a5c
Коммит 1986106785
3 изменённых файлов: 42 добавлений и 9 удалений

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

@ -138,8 +138,7 @@ this.GeckoDriver = function(appId, server) {
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());
@ -162,6 +161,20 @@ Object.defineProperty(GeckoDriver.prototype, "a11yChecks", {
},
});
/**
* 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.
@ -800,7 +813,8 @@ GeckoDriver.prototype.getSessionCapabilities = function(cmd, resp) {
*/
GeckoDriver.prototype.setContext = function(cmd) {
let value = assert.string(cmd.parameters.value);
this.context = Context.fromString(value);
this.context = value;
};
/**

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

@ -6,26 +6,43 @@ 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)
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")
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 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)
@ -61,8 +78,10 @@ class TestSetContext(MarionetteTestCase):
@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)

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

@ -95,7 +95,7 @@ skip-if = true # Bug 925688
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