summaryrefslogtreecommitdiffstats
path: root/testing/marionette/puppeteer/firefox/firefox_puppeteer/ui/pageinfo/window.py
blob: 070f39f790cb3f500beb12b762181435b397972b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# 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 import By

from firefox_puppeteer.ui.pageinfo.deck import Deck
from firefox_puppeteer.ui.windows import BaseWindow, Windows


class PageInfoWindow(BaseWindow):
    """Representation of a page info window."""

    window_type = 'Browser:page-info'

    dtds = [
        'chrome://browser/locale/pageInfo.dtd',
    ]

    properties = [
        'chrome://browser/locale/browser.properties',
        'chrome://browser/locale/pageInfo.properties',
        'chrome://pippki/locale/pippki.properties',
    ]

    @property
    def deck(self):
        """The :class:`Deck` instance which represents the deck.

        :returns: Reference to the deck.
        """
        deck = self.window_element.find_element(By.ID, 'mainDeck')
        return Deck(self.marionette, self, deck)

    def close(self, trigger='shortcut', force=False):
        """Closes the current page info window by using the specified trigger.

        :param trigger: Optional, method to close the current window. This can
         be a string with one of `menu` (OS X only) or `shortcut`, or a callback
         which gets triggered with the current :class:`PageInfoWindow` as parameter.
         Defaults to `shortcut`.

        :param force: Optional, forces the closing of the window by using the Gecko API.
         Defaults to `False`.
        """
        def callback(win):
            # Prepare action which triggers the opening of the browser window
            if callable(trigger):
                trigger(win)
            elif trigger == 'menu':
                self.menubar.select_by_id('file-menu', 'menu_close')
            elif trigger == 'shortcut':
                win.send_shortcut(win.localize_entity('closeWindow.key'),
                                  accel=True)
            else:
                raise ValueError('Unknown closing method: "%s"' % trigger)

        super(PageInfoWindow, self).close(callback, force)


Windows.register_window(PageInfoWindow.window_type, PageInfoWindow)