summaryrefslogtreecommitdiffstats
path: root/testing/marionette/puppeteer/firefox/firefox_puppeteer/ui/about_window/deck.py
blob: 9d8d90603c1349459244fabe93361e2d45ac1329 (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
# 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.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 = {'apply': ApplyPanel,
                   'checkForUpdates': CheckForUpdatesPanel,
                   'checkingForUpdates': CheckingForUpdatesPanel,
                   'downloadAndInstall': DownloadAndInstallPanel,
                   'downloadFailed': DownloadFailedPanel,
                   'downloading': DownloadingPanel,
                   'noUpdatesFound': NoUpdatesFoundPanel,
                   }

        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 apply(self):
        """The :class:`ApplyPanel` instance for the apply panel.

        :returns: :class:`ApplyPanel` instance.
        """
        return self._create_panel_for_id('apply')

    @property
    def check_for_updates(self):
        """The :class:`CheckForUpdatesPanel` instance for the check for updates panel.

        :returns: :class:`CheckForUpdatesPanel` instance.
        """
        return self._create_panel_for_id('checkForUpdates')

    @property
    def checking_for_updates(self):
        """The :class:`CheckingForUpdatesPanel` instance for the checking for updates panel.

        :returns: :class:`CheckingForUpdatesPanel` instance.
        """
        return self._create_panel_for_id('checkingForUpdates')

    @property
    def download_and_install(self):
        """The :class:`DownloadAndInstallPanel` instance for the download and install panel.

        :returns: :class:`DownloadAndInstallPanel` instance.
        """
        return self._create_panel_for_id('downloadAndInstall')

    @property
    def download_failed(self):
        """The :class:`DownloadFailedPanel` instance for the download failed panel.

        :returns: :class:`DownloadFailedPanel` instance.
        """
        return self._create_panel_for_id('downloadFailed')

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

        :returns: :class:`DownloadingPanel` instance.
        """
        return self._create_panel_for_id('downloading')

    @property
    def no_updates_found(self):
        """The :class:`NoUpdatesFoundPanel` instance for the no updates found panel.

        :returns: :class:`NoUpdatesFoundPanel` instance.
        """
        return self._create_panel_for_id('noUpdatesFound')

    @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 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]


class ApplyPanel(Panel):

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

        :returns: Reference to the button element.
        """
        return self.element.find_element(By.ID, 'updateButton')


class CheckForUpdatesPanel(Panel):

    @property
    def button(self):
        """The DOM element which represents the Check for Updates button.

        :returns: Reference to the button element.
        """
        return self.element.find_element(By.ID, 'checkForUpdatesButton')


class CheckingForUpdatesPanel(Panel):
    pass


class DownloadAndInstallPanel(Panel):

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

        :returns: Reference to the button element.
        """
        return self.element.find_element(By.ID, 'downloadAndInstallButton')


class DownloadFailedPanel(Panel):
    pass


class DownloadingPanel(Panel):
    pass


class NoUpdatesFoundPanel(Panel):
    pass