コード例 #1
0
    def __init__(self, marionette_getter, element):
        assert isinstance(element, HTMLElement)

        BaseLib.__init__(self, marionette_getter)
        self._element = element

        self.app_info = AppInfo(marionette_getter)
        self.utils = Utils(marionette_getter)
コード例 #2
0
class SubscriptionsSettings(BaseLib):

    def __init__(self, marionette_getter):
        BaseLib.__init__(self, marionette_getter)

        self.app_info = AppInfo(marionette_getter)
        self.utils = Utils(marionette_getter)

    #################################
    # Public Properties and Methods #
    #################################

    def open(self):
        self.marionette.navigate("about:requestpolicy?subscriptions")

    def enable(self, subscription_name):
        if not self.is_enabled(subscription_name):
            self.toggle(subscription_name)

    def disable(self, subscription_name):
        if self.is_enabled(subscription_name):
            self.toggle(subscription_name)

    def is_enabled(self, subscription_name):
        if self.utils.compare_version(self.app_info.version, "49") < 0:
            # up to Firefox 48 (Bug 1272653)
            return self._get(subscription_name).get_attribute("checked")
        return self._get(subscription_name).get_property("checked")

    def toggle(self, subscription_name):
        self._get(subscription_name).click()
        # Wait for the subscriptions to be ready.
        # FIXME: Use API for detection, as soon as there is such an API.
        time.sleep(1)

    def enable_all(self):
        for name in self.AVAILABLE_SUBSCRIPTIONS:
            self.enable(name)

    def disable_all(self):
        for name in self.AVAILABLE_SUBSCRIPTIONS:
            self.disable(name)

    ##################################
    # Private Properties and Methods #
    ##################################

    AVAILABLE_SUBSCRIPTIONS = [
        "allow_embedded", "allow_extensions", "allow_functionality",
        "allow_mozilla", "allow_sameorg", "deny_trackers"
    ]

    def _get(self, subscription_name):
        return (self.marionette
                .find_element("css selector",
                              "input[name={}]".format(subscription_name)))
コード例 #3
0
class SubscriptionsSettings(BaseLib):
    def __init__(self, marionette_getter):
        BaseLib.__init__(self, marionette_getter)

        self.app_info = AppInfo(marionette_getter)
        self.utils = Utils(marionette_getter)

    #################################
    # Public Properties and Methods #
    #################################

    def open(self):
        self.marionette.navigate("about:requestpolicy?subscriptions")

    def enable(self, subscription_name):
        if not self.is_enabled(subscription_name):
            self.toggle(subscription_name)

    def disable(self, subscription_name):
        if self.is_enabled(subscription_name):
            self.toggle(subscription_name)

    def is_enabled(self, subscription_name):
        if self.utils.compare_version(self.app_info.version, "49") < 0:
            # up to Firefox 48 (Bug 1272653)
            return self._get(subscription_name).get_attribute("checked")
        return self._get(subscription_name).get_property("checked")

    def toggle(self, subscription_name):
        self._get(subscription_name).click()
        # Wait for the subscriptions to be ready.
        # FIXME: Use API for detection, as soon as there is such an API.
        time.sleep(1)

    def enable_all(self):
        for name in self.AVAILABLE_SUBSCRIPTIONS:
            self.enable(name)

    def disable_all(self):
        for name in self.AVAILABLE_SUBSCRIPTIONS:
            self.disable(name)

    ##################################
    # Private Properties and Methods #
    ##################################

    AVAILABLE_SUBSCRIPTIONS = [
        "allow_embedded", "allow_extensions", "allow_functionality",
        "allow_mozilla", "allow_sameorg", "deny_trackers"
    ]

    def _get(self, subscription_name):
        return (self.marionette.find_element(
            "css selector", "input[name={}]".format(subscription_name)))
コード例 #4
0
    def setUp(self):
        super(TestImagePlaceholder, self).setUp()

        app_version = AppInfo(lambda: self.marionette).version
        utils = Utils(lambda: self.marionette)
        self.fx_older_than_v49 = utils.compare_version(app_version, "49") < 0
コード例 #5
0
    def __init__(self, marionette_getter):
        BaseLib.__init__(self, marionette_getter)

        self.app_info = AppInfo(marionette_getter)
        self.utils = Utils(marionette_getter)
コード例 #6
0
class ContextMenu(BaseLib):

    def __init__(self, marionette_getter):
        BaseLib.__init__(self, marionette_getter)

        self.app_info = AppInfo(marionette_getter)
        self.utils = Utils(marionette_getter)

    #################################
    # Public Properties and Methods #
    #################################

    @property
    def element(self):
        return self.marionette.find_element("id", "contentAreaContextMenu")

    @property
    def state(self):
        if self.utils.compare_version(self.app_info.version, "49") < 0:
            # up to Firefox 48 (Bug 1272653)
            return self.element.get_attribute("state")
        return self.element.get_property("state")

    def select_entry(self, entry_id, context_element):
        """Select a specific entry in the context menu of an HTMLElement."""

        self._open(context_element)
        try:
            self._click(entry_id)
        finally:
            # The context menu should always be closed.
            self._close()

    ##################################
    # Private Properties and Methods #
    ##################################

    def _open(self, context_element):
        """Open the context menu."""

        with self.marionette.using_context("content"):
            # right click on the HTML element
            Actions(self.marionette).click(context_element, 2).perform()

        self._wait_for_state("open")

        # FIXME: Sub-menus aren't currently supported. To support those,
        #        implement the Mozmill Controller's `_buildMenu()` function.
        #        It populates all submenus of the context menu recursively.
        #        Right now only top-level menu entries can be selected.

    def _click(self, entry_id):
        """Click on an entry in the menu."""

        def is_displayed(entry):
            rect = entry.rect
            return rect["width"] > 0 and rect["height"] > 0

        entry = self.element.find_element("id", entry_id)
        if is_displayed(entry):
            entry.click()
        else:
            raise ElementNotDisplayedException

    def _close(self):
        """Close the context menu."""

        # Only close if the menu is open. The menu for example closes itself
        # in case the URL in the current tab changes. Sending ESC to a menu
        # which is _not_ open anymore will cause the page load to stop.
        if self.state == "open":
            self.element.send_keys(Keys.ESCAPE)
        self._wait_for_state("closed")

    def _wait_for_state(self, state):
        Wait(self.marionette).until(
            lambda _: self.state == state,
            message="The menu's state is now '{}'.".format(state))
コード例 #7
0
class Menu(BaseLib):
    is_working = False  # menu.open() fails due to a TimeoutException

    def __init__(self, marionette_getter):
        BaseLib.__init__(self, marionette_getter)

        self.app_info = AppInfo(marionette_getter)
        self.utils = Utils(marionette_getter)

    #################################
    # Public Properties and Methods #
    #################################

    @property
    def total_num_requests(self):
        label_element = self.marionette.find_element(
            "id", "rpc-origin-num-requests")
        if self.utils.compare_version(self.app_info.version, "49") < 0:
            # up to Firefox 48 (Bug 1272653)
            text = label_element.get_attribute("value")
        else:
            text = label_element.get_property("value")
        match = re.match(r"^(\d+) \((\d+)\+(\d+)\)$", text)
        return int(match.group(1))

    def open(self, trigger="api"):
        if self.is_open():
            return
        self._toggle(trigger=trigger)

    def is_open(self):
        return self._popup_state == "open"

    def close(self, trigger="api"):
        if not self.is_open():
            return
        self._toggle(trigger=trigger)

    @property
    def preferences_button(self):
        return self.marionette.find_element("id", "rpc-link-prefs")

    @property
    def manage_policies_button(self):
        return self.marionette.find_element("id", "rpc-link-policies")

    def switch_to_iframe(self):
        self.marionette.switch_to_frame(self._iframe)

    @contextmanager
    def in_iframe(self):
        frame = self.marionette.get_active_frame()
        self.switch_to_iframe()
        yield
        self.marionette.switch_to_frame(frame)

    ##################################
    # Private Properties and Methods #
    ##################################

    @property
    def _toolbar_button(self):
        return self.marionette.find_element(
            "id", "rpcontinuedOffAmoToolbarButton"
        )

    @property
    def _popup(self):
        return self.marionette.find_element("id", "rpc-popup")

    @property
    def _iframe(self):
        return self.marionette.find_element("id", "rpc-popup-frame")

    @property
    def _popup_state(self):
        if self.utils.compare_version(self.app_info.version, "49") < 0:
            # up to Firefox 48 (Bug 1272653)
            return self._popup.get_attribute("state")
        return self._popup.get_property("state")

    def _toggle(self, trigger="api"):
        is_open = self.is_open()
        target_popup_state = "closed" if is_open else "open"

        if callable(trigger):
            trigger()
        elif trigger == "button":
            self._toolbar_button.click()
        elif trigger == "shortcut":
            window = Windows(lambda: self.marionette).current
            window.send_shortcut("r", alt=True, shift=True)
        elif trigger == "api":
            self._ensure_popup_state(target_popup_state)
        else:
            raise ValueError("Unknown trigger method: \"{}\"".format(trigger))

        if target_popup_state == "open":
            # Briefly enter the iframe to make sure the it's loaded.
            with self.in_iframe():
                pass

        (
            Wait(self.marionette, timeout=1)
            .until(lambda _: self.is_open() is not is_open)
        )

    def _ensure_popup_state(self, state):
        assert state in ["open", "closed"]

        if self._popup_state == state:
            return

        fn_name = "openPopup" if state == "open" else "hidePopup"

        self.marionette.execute_script("""
          let popup = arguments[0];
          let fnName = arguments[1];
          popup[fnName]();
        """, script_args=[self._popup, fn_name])

        Wait(self.marionette).until(lambda _: self._popup_state == state)
コード例 #8
0
    def __init__(self, marionette_getter):
        BaseLib.__init__(self, marionette_getter)

        self.app_info = AppInfo(marionette_getter)
        self.utils = Utils(marionette_getter)
コード例 #9
0
class Menu(BaseLib):
    def __init__(self, marionette_getter):
        BaseLib.__init__(self, marionette_getter)

        self.app_info = AppInfo(marionette_getter)
        self.utils = Utils(marionette_getter)

    #################################
    # Public Properties and Methods #
    #################################

    @property
    def total_num_requests(self):
        label_element = self._popup.find_element("id",
                                                 "rpc-origin-num-requests")
        if self.utils.compare_version(self.app_info.version, "49") < 0:
            # up to Firefox 48 (Bug 1272653)
            text = label_element.get_attribute("value")
        else:
            text = label_element.get_property("value")
        match = re.match(r"^(\d+) \((\d+)\+(\d+)\)$", text)
        return int(match.group(1))

    def open(self, trigger="api"):
        if self.is_open():
            return
        self._toggle(trigger=trigger)

    def is_open(self):
        return self._popup_state == "open"

    def close(self, trigger="api"):
        if not self.is_open():
            return
        self._toggle(trigger=trigger)

    @property
    def preferences_button(self):
        return self._popup.find_element("id", "rpc-link-prefs")

    @property
    def manage_policies_button(self):
        return self._popup.find_element("id", "rpc-link-policies")

    ##################################
    # Private Properties and Methods #
    ##################################

    @property
    def _toolbar_button(self):
        return self.marionette.find_element("id", "rpcontinuedToolbarButton")

    @property
    def _popup(self):
        return self.marionette.find_element("id", "rpc-popup")

    @property
    def _popup_state(self):
        if self.utils.compare_version(self.app_info.version, "49") < 0:
            # up to Firefox 48 (Bug 1272653)
            return self._popup.get_attribute("state")
        return self._popup.get_property("state")

    def _toggle(self, trigger="api"):
        is_open = self.is_open()

        if callable(trigger):
            trigger()
        elif trigger == "button":
            self._toolbar_button.click()
        elif trigger == "shortcut":
            window = Windows(lambda: self.marionette).current
            window.send_shortcut("r", alt=True, shift=True)
        elif trigger == "api":
            self._ensure_popup_state("closed" if is_open else "open")
        else:
            raise ValueError("Unknown trigger method: \"{}\"".format(trigger))

        (Wait(self.marionette,
              timeout=1).until(lambda _: self.is_open() is not is_open))

    def _ensure_popup_state(self, state):
        assert state in ["open", "closed"]

        if self._popup_state == state:
            return

        fn_name = "openPopup" if state == "open" else "hidePopup"

        self.marionette.execute_script("""
          let popup = arguments[0];
          let fnName = arguments[1];
          popup[fnName]();
        """,
                                       script_args=[self._popup, fn_name])

        Wait(self.marionette).until(lambda _: self._popup_state == state)
コード例 #10
0
class ContextMenu(BaseLib):
    def __init__(self, marionette_getter):
        BaseLib.__init__(self, marionette_getter)

        self.app_info = AppInfo(marionette_getter)
        self.utils = Utils(marionette_getter)

    #################################
    # Public Properties and Methods #
    #################################

    @property
    def element(self):
        return self.marionette.find_element("id", "contentAreaContextMenu")

    @property
    def state(self):
        if self.utils.compare_version(self.app_info.version, "49") < 0:
            # up to Firefox 48 (Bug 1272653)
            return self.element.get_attribute("state")
        return self.element.get_property("state")

    def select_entry(self, entry_id, context_element):
        """Select a specific entry in the context menu of an HTMLElement."""

        self._open(context_element)
        try:
            self._click(entry_id)
        finally:
            # The context menu should always be closed.
            self._close()

    ##################################
    # Private Properties and Methods #
    ##################################

    def _open(self, context_element):
        """Open the context menu."""

        with self.marionette.using_context("content"):
            # right click on the HTML element
            Actions(self.marionette).click(context_element, 2).perform()

        self._wait_for_state("open")

        # FIXME: Sub-menus aren't currently supported. To support those,
        #        implement the Mozmill Controller's `_buildMenu()` function.
        #        It populates all submenus of the context menu recursively.
        #        Right now only top-level menu entries can be selected.

    def _click(self, entry_id):
        """Click on an entry in the menu."""
        def is_displayed(entry):
            rect = entry.rect
            return rect["width"] > 0 and rect["height"] > 0

        entry = self.element.find_element("id", entry_id)
        if is_displayed(entry):
            entry.click()
        else:
            raise ElementNotDisplayedException

    def _close(self):
        """Close the context menu."""

        # Only close if the menu is open. The menu for example closes itself
        # in case the URL in the current tab changes. Sending ESC to a menu
        # which is _not_ open anymore will cause the page load to stop.
        if self.state == "open":
            self.element.send_keys(Keys.ESCAPE)
        self._wait_for_state("closed")

    def _wait_for_state(self, state):
        Wait(self.marionette).until(
            lambda _: self.state == state,
            message="The menu's state is now '{}'.".format(state))