summaryrefslogtreecommitdiffstats
path: root/testing/marionette/puppeteer/firefox/firefox_puppeteer/ui/pageinfo/deck.py
blob: 0f2a2167a8b390a04e35f93124818a5da98c91e5 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# 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, Wait

from firefox_puppeteer.ui.base import UIBaseLib
from firefox_puppeteer.ui.deck import Panel


class Deck(UIBaseLib):

    def _create_panel_for_id(self, panel_id):
        """Creates an instance of :class:`Panel` for the specified panel id.

        :param panel_id: The ID of the panel to create an instance of.

        :returns: :class:`Panel` instance
        """
        mapping = {'feedPanel': FeedPanel,
                   'generalPanel': GeneralPanel,
                   'mediaPanel': MediaPanel,
                   'permPanel': PermissionsPanel,
                   'securityPanel': SecurityPanel
                   }

        panel = self.element.find_element(By.ID, panel_id)
        return mapping.get(panel_id, Panel)(self.marionette, self.window, panel)

    # Properties for visual elements of the deck #

    @property
    def feed(self):
        """The :class:`FeedPanel` instance for the feed panel.

        :returns: :class:`FeedPanel` instance.
        """
        return self._create_panel_for_id('feedPanel')

    @property
    def general(self):
        """The :class:`GeneralPanel` instance for the general panel.

        :returns: :class:`GeneralPanel` instance.
        """
        return self._create_panel_for_id('generalPanel')

    @property
    def media(self):
        """The :class:`MediaPanel` instance for the media panel.

        :returns: :class:`MediaPanel` instance.
        """
        return self._create_panel_for_id('mediaPanel')

    @property
    def panels(self):
        """List of all the :class:`Panel` instances of the current deck.

        :returns: List of :class:`Panel` instances.
        """
        panels = self.marionette.execute_script("""
          let deck = arguments[0];
          let panels = [];

          for (let index = 0; index < deck.children.length; index++) {
            if (deck.children[index].id) {
              panels.push(deck.children[index].id);
            }
          }

          return panels;
        """, script_args=[self.element])

        return [self._create_panel_for_id(panel) for panel in panels]

    @property
    def permissions(self):
        """The :class:`PermissionsPanel` instance for the permissions panel.

        :returns: :class:`PermissionsPanel` instance.
        """
        return self._create_panel_for_id('permPanel')

    @property
    def security(self):
        """The :class:`SecurityPanel` instance for the security panel.

        :returns: :class:`SecurityPanel` instance.
        """
        return self._create_panel_for_id('securityPanel')

    # Properties for helpers when working with the deck #

    @property
    def selected_index(self):
        """The index of the currently selected panel.

        :return: Index of the selected panel.
        """
        return int(self.element.get_property('selectedIndex'))

    @property
    def selected_panel(self):
        """A :class:`Panel` instance of the currently selected panel.

        :returns: :class:`Panel` instance.
        """
        return self.panels[self.selected_index]

    # Methods for helpers when working with the deck #

    def select(self, panel):
        """Selects the specified panel via the tab element.

        :param panel: The panel to select.

        :returns: :class:`Panel` instance of the selected panel.
        """
        panel.tab.click()
        Wait(self.marionette).until(
            lambda _: self.selected_panel == panel,
            message='Panel with ID "%s" could not be selected.' % panel)

        return panel


class PageInfoPanel(Panel):

    @property
    def tab(self):
        """The DOM element which represents the corresponding tab element at the top.

        :returns: Reference to the tab element.
        """
        name = self.element.get_property('id').split('Panel')[0]
        return self.window.window_element.find_element(By.ID, name + 'Tab')


class FeedPanel(PageInfoPanel):
    pass


class GeneralPanel(PageInfoPanel):
    pass


class MediaPanel(PageInfoPanel):
    pass


class PermissionsPanel(PageInfoPanel):
    pass


class SecurityPanel(PageInfoPanel):

    @property
    def domain(self):
        """The DOM element which represents the domain textbox.

        :returns: Reference to the textbox element.
        """
        return self.element.find_element(By.ID, 'security-identity-domain-value')

    @property
    def owner(self):
        """The DOM element which represents the owner textbox.

        :returns: Reference to the textbox element.
        """
        return self.element.find_element(By.ID, 'security-identity-owner-value')

    @property
    def verifier(self):
        """The DOM element which represents the verifier textbox.

        :returns: Reference to the textbox element.
        """
        return self.element.find_element(By.ID, 'security-identity-verifier-value')

    @property
    def view_certificate(self):
        """The DOM element which represents the view certificate button.

        :returns: Reference to the button element.
        """
        return self.element.find_element(By.ID, 'security-view-cert')

    @property
    def view_cookies(self):
        """The DOM element which represents the view cookies button.

        :returns: Reference to the button element.
        """
        return self.element.find_element(By.ID, 'security-view-cookies')

    @property
    def view_passwords(self):
        """The DOM element which represents the view passwords button.

        :returns: Reference to the button element.
        """
        return self.element.find_element(By.ID, 'security-view-password')