Bug 1368674 - Remove B2G Permissionis handling from Marionette. r?ato draft
authorDavid Burns <dburns@mozilla.com>
Tue, 06 Jun 2017 13:55:23 +0100
changeset 589610 87d266282bff20a7d6f19007ed911c2072acb171
parent 589593 4acd9e92ac47df86e5d98244365a40e9a8f612dc
child 631955 b9c8a82c5c38ac8421aa732295a262fa515a397d
push id62451
push userbmo:dburns@mozilla.com
push dateTue, 06 Jun 2017 14:16:22 +0000
reviewersato
bugs1368674
milestone55.0a1
Bug 1368674 - Remove B2G Permissionis handling from Marionette. r?ato The Permissions API was used extensively during B2G to make sure the state of the browser and permissions for APIs were in the relevant state. This code is no longer used and can be removed. MozReview-Commit-ID: HgcQe3GEd09
testing/marionette/client/marionette_driver/marionette.py
testing/marionette/harness/marionette_harness/tests/unit/test_switch_remote_frame.py
testing/marionette/harness/marionette_harness/tests/unit/test_using_permissions.py
testing/marionette/harness/marionette_harness/tests/unit/unit-tests.ini
--- a/testing/marionette/client/marionette_driver/marionette.py
+++ b/testing/marionette/client/marionette_driver/marionette.py
@@ -837,144 +837,16 @@ class Marionette(object):
                 val = str(val)
                 for i in range(len(val)):
                     typing.append(val[i])
             else:
                 for i in range(len(val)):
                     typing.append(val[i])
         return "".join(typing)
 
-    def get_permission(self, perm):
-        script = """
-        let value = {
-          'url': document.nodePrincipal.URI.spec,
-          'appId': document.nodePrincipal.appId,
-          'isInIsolatedMozBrowserElement': document.nodePrincipal.isInIsolatedMozBrowserElement,
-          'type': arguments[0]
-        };
-        return value;"""
-        with self.using_context("content"):
-            value = self.execute_script(script, script_args=(perm,), sandbox="system")
-
-        with self.using_context("chrome"):
-            permission = self.execute_script("""
-                Components.utils.import("resource://gre/modules/Services.jsm");
-                let perm = arguments[0];
-                let secMan = Services.scriptSecurityManager;
-                let attrs = {appId: perm.appId,
-                            inIsolatedMozBrowser: perm.isInIsolatedMozBrowserElement};
-                let principal = secMan.createCodebasePrincipal(
-                                Services.io.newURI(perm.url, null, null),
-                                attrs);
-                let testPerm = Services.perms.testPermissionFromPrincipal(
-                               principal, perm.type);
-                return testPerm;
-                """, script_args=(value,))
-        return permission
-
-    def push_permission(self, perm, allow):
-        script = """
-        let allow = arguments[0];
-        if (typeof(allow) == "boolean") {
-            if (allow) {
-              allow = Components.interfaces.nsIPermissionManager.ALLOW_ACTION;
-            }
-            else {
-              allow = Components.interfaces.nsIPermissionManager.DENY_ACTION;
-            }
-        }
-        let perm_type = arguments[1];
-
-        Components.utils.import("resource://gre/modules/Services.jsm");
-        window.wrappedJSObject.permChanged = false;
-        window.wrappedJSObject.permObserver = function(subject, topic, data) {
-          if (topic == "perm-changed") {
-            let permission = subject.QueryInterface(Components.interfaces.nsIPermission);
-            if (perm_type == permission.type) {
-              Services.obs.removeObserver(window.wrappedJSObject.permObserver,
-                                          "perm-changed");
-              window.wrappedJSObject.permChanged = true;
-            }
-          }
-        };
-        Services.obs.addObserver(window.wrappedJSObject.permObserver,
-                                 "perm-changed", false);
-
-        let value = {
-          'url': document.nodePrincipal.URI.spec,
-          'appId': document.nodePrincipal.appId,
-          'isInIsolatedMozBrowserElement': document.nodePrincipal.isInIsolatedMozBrowserElement,
-          'type': perm_type,
-          'action': allow
-        };
-        return value;
-        """
-        with self.using_context("content"):
-            perm = self.execute_script(script, script_args=(allow, perm,), sandbox="system")
-
-        current_perm = self.get_permission(perm["type"])
-        if current_perm == perm["action"]:
-            with self.using_context("content"):
-                self.execute_script("""
-                    Components.utils.import("resource://gre/modules/Services.jsm");
-                    Services.obs.removeObserver(window.wrappedJSObject.permObserver,
-                                                "perm-changed");
-                    """, sandbox="system")
-            return
-
-        with self.using_context("chrome"):
-            self.execute_script("""
-                Components.utils.import("resource://gre/modules/Services.jsm");
-                let perm = arguments[0];
-                let secMan = Services.scriptSecurityManager;
-                let attrs = {appId: perm.appId,
-                             inIsolatedMozBrowser: perm.isInIsolatedMozBrowserElement};
-                let principal = secMan.createCodebasePrincipal(Services.io.newURI(perm.url,
-                                                                                  null, null),
-                                                                                  attrs);
-                Services.perms.addFromPrincipal(principal, perm.type, perm.action);
-                return true;
-                """, script_args=(perm,))
-
-        with self.using_context("content"):
-            self.execute_async_script("""
-                let wait = function() {
-                  if (window.wrappedJSObject.permChanged) {
-                    marionetteScriptFinished();
-                  } else {
-                    window.setTimeout(wait, 100);
-                  }
-                }();
-                """, sandbox="system")
-
-    @contextmanager
-    def using_permissions(self, perms):
-        '''
-        Sets permissions for code being executed in a `with` block,
-        and restores them on exit.
-
-        :param perms: A dict containing one or more perms and their
-        values to be set.
-
-        Usage example::
-
-          with marionette.using_permissions({'systemXHR': True}):
-              ... do stuff ...
-        '''
-        original_perms = {}
-        for perm in perms:
-            original_perms[perm] = self.get_permission(perm)
-            self.push_permission(perm, perms[perm])
-
-        try:
-            yield
-        finally:
-            for perm in original_perms:
-                self.push_permission(perm, original_perms[perm])
-
     def clear_pref(self, pref):
         """Clear the user-defined value from the specified preference.
 
         :param pref: Name of the preference.
         """
         with self.using_context(self.CONTEXT_CHROME):
             self.execute_script("""
                Components.utils.import("resource://gre/modules/Preferences.jsm");
deleted file mode 100644
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_switch_remote_frame.py
+++ /dev/null
@@ -1,118 +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_driver.by import By
-
-from marionette_harness import MarionetteTestCase
-
-
-OOP_BY_DEFAULT = "dom.ipc.browser_frames.oop_by_default"
-BROWSER_FRAMES_ENABLED = "dom.mozBrowserFramesEnabled"
-
-
-class TestSwitchRemoteFrame(MarionetteTestCase):
-    def setUp(self):
-        super(TestSwitchRemoteFrame, self).setUp()
-        with self.marionette.using_context('chrome'):
-            self.oop_by_default = self.marionette.get_pref(OOP_BY_DEFAULT)
-            self.mozBrowserFramesEnabled = self.marionette.get_pref(BROWSER_FRAMES_ENABLED)
-            self.marionette.set_pref(OOP_BY_DEFAULT, True)
-            self.marionette.set_pref(BROWSER_FRAMES_ENABLED, True)
-
-            self.multi_process_browser = self.marionette.execute_script("""
-                try {
-                  return Services.appinfo.browserTabsRemoteAutostart;
-                } catch (e) {
-                  return false;
-                }""")
-
-    def tearDown(self):
-        with self.marionette.using_context("chrome"):
-            if self.oop_by_default is None:
-                self.marionette.clear_pref(OOP_BY_DEFAULT)
-            else:
-                self.marionette.set_pref(OOP_BY_DEFAULT, self.oop_by_default)
-
-            if self.mozBrowserFramesEnabled is None:
-                self.marionette.clear_pref(BROWSER_FRAMES_ENABLED)
-            else:
-                self.marionette.set_pref(BROWSER_FRAMES_ENABLED, self.mozBrowserFramesEnabled)
-
-    @property
-    def is_main_process(self):
-        return self.marionette.execute_script("""
-            return Components.classes["@mozilla.org/xre/app-info;1"].
-                getService(Components.interfaces.nsIXULRuntime).
-                processType == Components.interfaces.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
-        """, sandbox="system")
-
-    def test_remote_frame(self):
-        self.marionette.navigate(self.marionette.absolute_url("test.html"))
-        self.marionette.push_permission('browser', True)
-        self.marionette.execute_script("""
-            let iframe = document.createElement("iframe");
-            iframe.setAttribute('mozbrowser', true);
-            iframe.setAttribute('remote', true);
-            iframe.id = "remote_iframe";
-            iframe.style.height = "100px";
-            iframe.style.width = "100%%";
-            iframe.src = "{}";
-            document.body.appendChild(iframe);
-            """.format(self.marionette.absolute_url("test.html")))
-        remote_iframe = self.marionette.find_element(By.ID, "remote_iframe")
-        self.marionette.switch_to_frame(remote_iframe)
-        main_process = self.is_main_process
-        self.assertFalse(main_process)
-
-    def test_remote_frame_revisit(self):
-        # test if we can revisit a remote frame (this takes a different codepath)
-        self.marionette.navigate(self.marionette.absolute_url("test.html"))
-        self.marionette.push_permission('browser', True)
-        self.marionette.execute_script("""
-            let iframe = document.createElement("iframe");
-            iframe.setAttribute('mozbrowser', true);
-            iframe.setAttribute('remote', true);
-            iframe.id = "remote_iframe";
-            iframe.style.height = "100px";
-            iframe.style.width = "100%%";
-            iframe.src = "{}";
-            document.body.appendChild(iframe);
-            """.format(self.marionette.absolute_url("test.html")))
-        self.marionette.switch_to_frame(self.marionette.find_element(By.ID,
-                                                                     "remote_iframe"))
-        main_process = self.is_main_process
-        self.assertFalse(main_process)
-        self.marionette.switch_to_frame()
-        main_process = self.is_main_process
-        should_be_main_process = not self.multi_process_browser
-        self.assertEqual(main_process, should_be_main_process)
-        self.marionette.switch_to_frame(self.marionette.find_element(By.ID,
-                                                                     "remote_iframe"))
-        main_process = self.is_main_process
-        self.assertFalse(main_process)
-
-    def test_we_can_switch_to_a_remote_frame_by_index(self):
-        # test if we can revisit a remote frame (this takes a different codepath)
-        self.marionette.navigate(self.marionette.absolute_url("test.html"))
-        self.marionette.push_permission('browser', True)
-        self.marionette.execute_script("""
-            let iframe = document.createElement("iframe");
-            iframe.setAttribute('mozbrowser', true);
-            iframe.setAttribute('remote', true);
-            iframe.id = "remote_iframe";
-            iframe.style.height = "100px";
-            iframe.style.width = "100%%";
-            iframe.src = "{}";
-            document.body.appendChild(iframe);
-            """.format(self.marionette.absolute_url("test.html")))
-        self.marionette.switch_to_frame(0)
-        main_process = self.is_main_process
-        self.assertFalse(main_process)
-        self.marionette.switch_to_frame()
-        main_process = self.is_main_process
-        should_be_main_process = not self.multi_process_browser
-        self.assertEqual(main_process, should_be_main_process)
-        self.marionette.switch_to_frame(0)
-        main_process = self.is_main_process
-        self.assertFalse(main_process)
deleted file mode 100644
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_using_permissions.py
+++ /dev/null
@@ -1,46 +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_driver.errors import JavascriptException
-
-from marionette_harness import MarionetteTestCase
-
-
-class TestUsingPermssions(MarionetteTestCase):
-
-    def test_using_permissions(self):
-        # Test that multiple permissions can be set with 'using_permissions',
-        # and that they are set correctly and unset correctly after leaving
-        # the context manager.
-        original_perm = self.marionette.get_permission('systemXHR')
-        original_alarm = self.marionette.get_permission('alarms')
-        new_perm = True if original_perm != 1 else False
-        new_alarm = True if original_alarm != 1 else False
-        with self.marionette.using_permissions({'systemXHR': new_perm,
-                                                'alarms': new_alarm}):
-            now_perm = self.marionette.get_permission('systemXHR')
-            now_alarm = self.marionette.get_permission('alarms')
-            self.assertEquals(new_perm, now_perm)
-            self.assertNotEquals(now_perm, original_perm)
-            self.assertEquals(new_alarm, now_alarm)
-            self.assertNotEquals(now_alarm, original_alarm)
-        self.assertEquals(original_perm,
-                          self.marionette.get_permission('systemXHR'))
-        self.assertEquals(original_alarm,
-                          self.marionette.get_permission('alarms'))
-
-    def test_exception_using_permissions(self):
-        # Test that throwing an exception inside the context manager doesn't
-        # prevent the permissions from being restored at context manager exit.
-        original_perm = self.marionette.get_permission('systemXHR')
-        new_perm = True if original_perm != 1 else False
-        with self.marionette.using_permissions({'systemXHR': new_perm}):
-            now_perm = self.marionette.get_permission('systemXHR')
-            self.assertEquals(new_perm, now_perm)
-            self.assertNotEquals(now_perm, original_perm)
-            self.assertRaises(JavascriptException,
-                              self.marionette.execute_script,
-                              "return foo.bar.baz;")
-        self.assertEquals(original_perm,
-                          self.marionette.get_permission('systemXHR'))
--- a/testing/marionette/harness/marionette_harness/tests/unit/unit-tests.ini
+++ b/testing/marionette/harness/marionette_harness/tests/unit/unit-tests.ini
@@ -45,18 +45,16 @@ skip-if = appname == 'fennec'
 [test_single_finger_desktop.py]
 skip-if = appname == 'fennec' || os == "win" # Bug 1025040
 
 [test_anonymous_content.py]
 skip-if = appname == 'fennec'
 [test_switch_frame.py]
 [test_switch_frame_chrome.py]
 skip-if = appname == 'fennec'
-[test_switch_remote_frame.py]
-skip-if = appname == 'fennec'
 [test_switch_window_chrome.py]
 skip-if = appname == 'fennec'
 [test_switch_window_content.py]
 
 [test_pagesource.py]
 [test_pagesource_chrome.py]
 skip-if = appname == 'fennec'
 
@@ -104,17 +102,16 @@ skip-if = appname == 'fennec' # Bug 1325
 [test_key_actions.py]
 [test_mouse_action.py]
 skip-if = appname == 'fennec'
 [test_teardown_context_preserved.py]
 [test_file_upload.py]
 skip-if = appname == 'fennec' || os == "win" # http://bugs.python.org/issue14574
 
 [test_execute_sandboxes.py]
-[test_using_permissions.py]
 [test_prefs.py]
 
 [test_shadow_dom.py]
 
 [test_chrome.py]
 skip-if = appname == 'fennec'
 
 [test_addons.py]