1# Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""The extensions option page."""
6
7from extension_pages import ExtensionPages
8from selenium.webdriver.common.action_chains import ActionChains
9
10
11CHECK_BOX_LIST = {'send_usage': 'sendUsage'}
12TEXT_BOX_LIST = {'min_video_bitrate': 'minVideoBitrate',
13                 'max_video_bitrate': 'maxVideoBitrate',
14                 'max_tab_frame_rate': 'maxFrameRate',
15                 'add_debug_dongle_ip': 'newReceiverIp'}
16RADIO_BUTTON_LIST = {'tab_casting_quality':
17                         {'extreme': 'ql-highest',
18                          'high': 'ql-high',
19                          'standard': 'ql-low',
20                          'auto': 'ql-auto'},
21                     'resolution':
22                         {'854x480': '854x480',
23                          '1280x720': '1280x720',
24                          '1920x1080': '1920x1080'}
25                    }
26BUTTON_LIST = {'reload': 'reload'}
27
28
29class OptionsPage(ExtensionPages):
30    """Contains all the controls on the options page of the extension."""
31
32    def __init__(self, driver, extension_id):
33        """Constructor."""
34        self._options_url = 'chrome-extension://%s/options.html' % extension_id
35        ExtensionPages.__init__(self, driver, self._options_url)
36
37
38    def set_value(self, field, value):
39        """Set the value of a specific field on the options page.
40        @param field: The name of the control
41        @param value: The value to set
42        """
43        self.go_to_page()
44        if field in CHECK_BOX_LIST.keys():
45            check_box = self._get_check_box(CHECK_BOX_LIST[field], field)
46            check_box.set_value(value)
47        elif field in TEXT_BOX_LIST.keys():
48            text_box = self._get_text_box(TEXT_BOX_LIST[field], field)
49            text_box.set_value(value)
50        elif field in RADIO_BUTTON_LIST.keys():
51            radio_button = self._get_radio_button(
52                RADIO_BUTTON_LIST[field][value], field)
53            radio_button.click()
54
55
56    def min_video_bitrate_text_box(self):
57        """The minimum video bit rate text box."""
58        return self._get_text_box(TEXT_BOX_LIST['min_video_bitrate'],
59                                  'min_video_bitrate')
60
61
62    def max_tab_frame_rate_text_box(self):
63        """The maximum tab frame rate text box."""
64        return self._get_text_box(TEXT_BOX_LIST['max_tab_frame_rate'],
65                                  'max_tab_frame_rate')
66
67
68    def reload_button(self):
69        """The reload button."""
70        return self._get_button(BUTTON_LIST['reload'], 'reload')
71
72
73    def highest_projection_radio_button(self):
74        """The Extreme tab projection quality radio button."""
75        return self._get_radio_button(
76                RADIO_BUTTON_LIST['highest_tab_projection_quality'],
77                'highest_tab_projection_quality')
78
79
80    def high_projection_radio_button(self):
81        """The High tab projection quality radio button."""
82        return self._get_radio_button(
83                RADIO_BUTTON_LIST['high_tab_projection_quality'],
84                'high_tab_projection_quality')
85
86
87    def low_projection_radio_button(self):
88        """The Low tab projection quality radio button."""
89        return self._get_radio_button(
90                RADIO_BUTTON_LIST['low_tab_projection_quality'],
91                'low_tab_projection_quality')
92
93
94    def resolution_640x360_radio_button(self):
95        """The 640x360 resolution radio button."""
96        return self._get_radio_button(RADIO_BUTTON_LIST['resolution_640_360'],
97                                      'resolution_640_360')
98
99
100    def resolution_854x480_radio_button(self):
101        """The 854x640 resolution radio button."""
102        return self._get_radio_button(RADIO_BUTTON_LIST['resolution_854_480'],
103                                      'resolution_854_480')
104
105
106    def resolution_1280x720_radio_button(self):
107        """The 1280x720 resolution radio button."""
108        return self._get_radio_button(RADIO_BUTTON_LIST['resolution_1280_720'],
109                                      'resolution_1280_720')
110
111
112    def resolution_1980x1080_radio_button(self):
113        """The 1980x1080 resolution radio button."""
114        return self._get_radio_button(
115                RADIO_BUTTON_LIST['resolution_1920_1080'],
116                'resolution_1920_1080')
117
118
119    def tab_casting_standard_radio_button(self):
120        """The tab casting mode standard radio button."""
121        return self._get_radio_button(RADIO_BUTTON_LIST['cast_streaming_off'],
122                                      'cast_streaming_off')
123
124
125    def tab_casting_enchanced_radio_button(self):
126        """The tab casting mode enhanced radio button."""
127        return self._GetRadioButton(RADIO_BUTTON_LIST['cast_streaming_on'],
128                                    'cast_streaming_on')
129
130
131    def send_usage_check_box(self):
132      """The send usage check box."""
133      return self._get_check_box(CHECK_BOX_LIST['send_usage'], 'send_usage')
134
135
136    def open_hidden_options_menu(self):
137        """Open the hidden options page."""
138        self.go_to_page()
139        element = self._driver.find_element_by_id('cast-icon')
140        double_click_action = ActionChains(self._driver).double_click(element)
141        double_click_action.perform()
142        double_click_action.perform()
143