Пример #1
0
    def create_window_instance(self, handle, expected_class=None):
        """Creates a :class:`BaseWindow` instance for the given chrome window

        :param handle: The handle of the chrome window
        :param expected_class: Optional, check for the correct window class
        """
        current_handle = self.marionette.current_chrome_window_handle
        window = None

        try:
            # Retrieve window type to determine the type of chrome window
            if handle != self.marionette.current_chrome_window_handle:
                self.switch_to(handle)
            window_type = self.marionette.get_window_type()
        finally:
            # Ensure to switch back to the original window
            if handle != current_handle:
                self.marionette.switch_to_window(current_handle)

        if window_type == 'navigator:browser':
            window = BrowserWindow(lambda: self.marionette, handle)
        else:
            raise errors.UnknownWindowError(
                'Unknown window type "%s" for handle: "%s"' %
                (window_type, handle))

        if expected_class is not None and type(window) is not expected_class:
            raise errors.UnexpectedWindowTypeError(
                'Expected window "%s" but got "%s"' %
                (expected_class, type(window)))

        return window
Пример #2
0
    def __init__(self, marionette_getter, window_handle):
        BaseLib.__init__(self, marionette_getter)
        self._l10n = L10n(self.get_marionette)
        self._windows = Windows(self.get_marionette)

        if window_handle not in self.marionette.chrome_window_handles:
            raise errors.UnknownWindowError(
                'Window with handle "%s" does not exist' % window_handle)
        self._handle = window_handle
Пример #3
0
    def __init__(self, marionette, window_handle):
        super(BaseWindow, self).__init__(marionette)

        self._windows = Windows(self.marionette)

        if window_handle not in self.marionette.chrome_window_handles:
            raise errors.UnknownWindowError(
                'Window with handle "%s" does not exist' % window_handle)
        self._handle = window_handle
Пример #4
0
    def create_window_instance(self, handle, expected_class=None):
        """Creates a :class:`BaseWindow` instance for the given chrome window.

        :param handle: The handle of the chrome window.
        :param expected_class: Optional, check for the correct window class.
        """
        current_handle = self.marionette.current_chrome_window_handle
        window = None

        with self.marionette.using_context('chrome'):
            try:
                # Retrieve window type to determine the type of chrome window
                if handle != self.marionette.current_chrome_window_handle:
                    self.switch_to(handle)

                window_type = Wait(self.marionette).until(
                    lambda mn: mn.get_window_type(),
                    message=
                    'Cannot get window type for chrome window handle "%s"' %
                    handle)

            finally:
                # Ensure to switch back to the original window
                if handle != current_handle:
                    self.switch_to(current_handle)

            if window_type in self.windows_map:
                window = self.windows_map[window_type](lambda: self.marionette,
                                                       handle)
            else:
                raise errors.UnknownWindowError(
                    'Unknown window type "%s" for handle: "%s"' %
                    (window_type, handle))

            if expected_class is not None and type(
                    window) is not expected_class:
                raise errors.UnexpectedWindowTypeError(
                    'Expected window "%s" but got "%s"' %
                    (expected_class, type(window)))

            # Before continuing ensure the chrome window has been completed loading
            Wait(self.marionette).until(
                lambda _: self.loaded(handle),
                message='Chrome window with handle "%s" did not finish loading.'
                % handle)

        return window
Пример #5
0
    def create_window_instance(self, handle, expected_class=None):
        """Creates a :class:`BaseWindow` instance for the given chrome window.

        :param handle: The handle of the chrome window.
        :param expected_class: Optional, check for the correct window class.
        """
        current_handle = self.marionette.current_chrome_window_handle
        window = None

        try:
            # Bug 1169180 - Workaround for handling newly opened chrome windows
            # Once fixed revert back to make use of self.loaded
            Wait(self.marionette).until(lambda mn: self.marionette.
                                        execute_script("""
              Components.utils.import("resource://gre/modules/Services.jsm");
              let win = Services.wm.getOuterWindowWithId(Number(arguments[0]));
              return win.document.readyState == 'complete';
            """,
                                                       script_args=[handle]))

            # Retrieve window type to determine the type of chrome window
            if handle != self.marionette.current_chrome_window_handle:
                self.switch_to(handle)

            Wait(self.marionette).until(
                lambda mn: mn.get_window_type() is not None)
            window_type = self.marionette.get_window_type()
        finally:
            # Ensure to switch back to the original window
            if handle != current_handle:
                self.marionette.switch_to_window(current_handle)

        if window_type in self.windows_map:
            window = self.windows_map[window_type](lambda: self.marionette,
                                                   handle)
        else:
            raise errors.UnknownWindowError(
                'Unknown window type "%s" for handle: "%s"' %
                (window_type, handle))

        if expected_class is not None and type(window) is not expected_class:
            raise errors.UnexpectedWindowTypeError(
                'Expected window "%s" but got "%s"' %
                (expected_class, type(window)))

        return window
Пример #6
0
    def create_window_instance(self, handle, expected_class=None):
        """Creates a :class:`BaseWindow` instance for the given chrome window.

        :param handle: The handle of the chrome window.
        :param expected_class: Optional, check for the correct window class.
        """
        current_handle = self.marionette.current_chrome_window_handle
        window = None

        try:
            # Retrieve window type to determine the type of chrome window
            if handle != self.marionette.current_chrome_window_handle:
                self.switch_to(handle)

            Wait(self.marionette).until(
                lambda mn: mn.get_window_type() is not None)
            window_type = self.marionette.get_window_type()
        finally:
            # Ensure to switch back to the original window
            if handle != current_handle:
                self.marionette.switch_to_window(current_handle)

        if window_type == 'Browser:About':
            from .about_window.window import AboutWindow
            window = AboutWindow(lambda: self.marionette, handle)
        elif window_type == 'navigator:browser':
            window = BrowserWindow(lambda: self.marionette, handle)
        elif window_type == 'Browser:page-info':
            from .pageinfo.window import PageInfoWindow
            window = PageInfoWindow(lambda: self.marionette, handle)
        elif window_type == 'Update:Wizard':
            from update_wizard import UpdateWizardDialog
            window = UpdateWizardDialog(lambda: self.marionette, handle)
        else:
            raise errors.UnknownWindowError(
                'Unknown window type "%s" for handle: "%s"' %
                (window_type, handle))

        if expected_class is not None and type(window) is not expected_class:
            raise errors.UnexpectedWindowTypeError(
                'Expected window "%s" but got "%s"' %
                (expected_class, type(window)))

        return window