on xenial help sign in
More AP testing
commit2ecb97bb441ab0f10cb4dcc4d0ac2d4f08468bcc authorNick Dedekind <nicholas.dedekind@gmail.com> dateFri 7 Jun 2013, 14:48 (13 years ago) parent8c60ce9
2 files changed+60−5
tests/autopilot/indicators_client/emulators/common.py+2−2 tests/autopilot/indicators_client/tests/test_power.py+58−3
tests/autopilot/indicators_client/emulators/common.py+2−2
@@ -10,5 +10,5 @@ from indicators_client.emulators import IndicatorsIntrospectionObject
1010class SwitchMenu(IndicatorsIntrospectionObject):
1111 """A switch menu control."""
1212
13− def get_checked(self):
14− return self.checked
13+class Switch(IndicatorsIntrospectionObject):
14+ """A switch control."""
tests/autopilot/indicators_client/tests/test_power.py+58−3
@@ -11,8 +11,9 @@ from testtools.matchers import Equals, NotEquals
1111from autopilot.matchers import Eventually
1212
1313from indicators_client.tests import IndicatorsTestCase
14−from indicators_client.emulators.common import SwitchMenu
1514from time import sleep
15+import random
16+import math
1617
1718class TestDisplayMenus(IndicatorsTestCase):
1819 def setUp(self):
@@ -32,15 +33,69 @@ class TestDisplayMenus(IndicatorsTestCase):
3233 # self.main_window.get_indicators_client().reset()
3334 super(TestDisplayMenus, self).tearDown()
3435
36+
37+ # START SECTION
38+ # We need to move these to emulators once autopilot supports emulators for
39+ # applications started with AutopilotTestCase.launch_test_application
40+
41+ def switch_auto_brightness(self, auto_brightness):
42+ ab_switch = auto_brightness.select_single("CheckBox");
43+ self.assertThat(ab_switch, NotEquals(None))
44+
45+ self.pointing_device.move_to_object(ab_switch)
46+ self.pointing_device.click()
47+
48+ def set_brightness_to_value(self, brightness_menu, new_value):
49+ brightness_slider = brightness_menu.select_single("Slider");
50+ self.assertThat(brightness_slider, NotEquals(None))
51+
52+ self.pointing_device.move_to_object(brightness_slider)
53+
54+ old_ab_value = brightness_slider.value
55+ pixel_ratio = brightness_slider.width / (brightness_slider.maximumValue - brightness_slider.minimumValue)
56+ print pixel_ratio
57+
58+ while True:
59+
60+ pixels_to_move = int(pixel_ratio * (new_value - old_ab_value) / 15)
61+ if pixels_to_move == 0:
62+ break;
63+ print pixels_to_move
64+
65+ self.pointing_device.drag(self.pointing_device.x, self.pointing_device.y, self.pointing_device.x + pixels_to_move, self.pointing_device.y)
66+
67+ old_ab_value = brightness_slider.value
68+
3569 def test_auto_bright_switch(self):
3670 """Test the auto-bright switch"""
3771
3872 auto_brightness = self.app.select_single("SwitchMenu", objectName="auto-brightness")
3973 self.assertThat(auto_brightness, NotEquals(None))
4074
41− old_value = auto_brightness.checked
75+ old_ab_value = auto_brightness.checked
76+
77+ self.switch_auto_brightness(auto_brightness)
78+
79+ # TODO - should check backend when it's introspectable.
80+ self.assertThat(auto_brightness.checked, Eventually(NotEquals(old_ab_value)))
81+
82+ def test_brightness_slider(self):
83+ """Test the auto-bright switch"""
84+
85+ brightness_menu = self.app.select_single("SliderMenu", objectName="brightness")
86+ self.assertThat(brightness_menu, NotEquals(None))
87+
88+ old_ab_value = brightness_menu.value
89+ # find a new value to do to. At least 1/4 distance away from current value
90+ while True:
91+ desired_value = random.uniform(brightness_menu.minimumValue, brightness_menu.maximumValue)
92+ if (abs(desired_value - old_ab_value) >= (brightness_menu.maximumValue - brightness_menu.minimumValue)/4):
93+ break;
94+
95+ self.set_brightness_to_value(brightness_menu, desired_value)
4296
43− print auto_brightness.get_checked()
97+ # TODO - should check backend when it's introspectable.
98+ self.assertThat(auto_brightness.value, Eventually(NotEquals(old_ab_value)))
4499
45100
46101