@@ -1,114 +0,0 @@
1−# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2−# Copyright 2013 Canonical
4−# This program is free software: you can redistribute it and/or modify it
5−# under the terms of the GNU General Public License version 3, as published
6−# by the Free Software Foundation.
8−"""Add tests here if you want to ensure the behaviour of the power indicator menus are correct"""
10−from testtools.matchers import Equals, NotEquals
11−from autopilot.input import Touch
12−from autopilot.matchers import Eventually
14−from unity8.indicators_client.tests import IndicatorsTestCase
15−from time import sleep
20−class TestDisplayMenus(IndicatorsTestCase):
22− super(TestDisplayMenus, self).setUp(self.geometry, self.grid_unit)
25− # self.main_window.get_indicators_client().reset()
26− super(TestDisplayMenus, self).tearDown()
29− # We need to move these to emulators once autopilot supports emulators for
30− # applications started with AutopilotTestCase.launch_test_application
32− def open_battery_menu(self):
33− # This opens the messaging menu so you don't have to do that in
35− self.assertThat(lambda: self.main_window.get_battery_menu(), Eventually(NotEquals(None)));
36− self.pointing_device.move_to_object(self.main_window.get_battery_menu())
37− self.pointing_device.click()
39− fn_loader = lambda: self.app.select_single("IndicatorsPage/QQuickLoader", objectName="pageLoader");
40− self.assertThat(fn_loader, Eventually(NotEquals(None)));
41− page_loader = fn_loader();
42− self.assertThat(page_loader.progress, Eventually(Equals(1.0)))
44− def switch_auto_brightness(self, auto_brightness):
45− ab_switch = auto_brightness.select_single("CheckBox");
46− self.assertThat(ab_switch, NotEquals(None))
48− self.pointing_device.move_to_object(ab_switch)
49− self.pointing_device.click()
51− def set_brightness_to_value(self, brightness_menu, new_value):
52− brightness_slider = brightness_menu.select_single("Slider");
53− self.assertThat(brightness_slider, NotEquals(None))
55− self.pointing_device.move_to_object(brightness_slider)
57− old_ab_value = brightness_slider.value
58− pixel_ratio = brightness_slider.width / (brightness_slider.maximumValue - brightness_slider.minimumValue)
62− pixels_to_move = int(pixel_ratio * (new_value - old_ab_value) / 15)
63− if pixels_to_move == 0:
66− self.pointing_device.drag(self.pointing_device.x, self.pointing_device.y, self.pointing_device.x + pixels_to_move, self.pointing_device.y)
68− old_ab_value = brightness_slider.value
70− @unittest.skip("Battery indicator has been removed.")
71− def test_auto_bright_switch(self):
72− """Test the auto-bright switch"""
73− self.open_battery_menu()
75− # wait for the switch menu item
76− fn_auto_brightness = lambda: self.app.select_single("SwitchMenuItem", objectName="auto-brightness");
77− # FIXME: this should go away when we switch to indicator-power
79− self.assertThat(fn_auto_brightness, Eventually(NotEquals(None)));
80− except AssertionError:
81− self.skipTest("WARNING: test skipped due to missing indicator-battery")
82− auto_brightness = fn_auto_brightness();
84− old_ab_value = auto_brightness.checked
86− self.switch_auto_brightness(auto_brightness)
88− # TODO - should check backend when it's introspectable.
89− self.assertThat(auto_brightness.checked, Eventually(NotEquals(old_ab_value)))
91− @unittest.skip("Battery indicator has been removed.")
92− def test_brightness_slider(self):
93− """Test the auto-bright switch"""
94− self.open_battery_menu()
96− fn_brightness_menu = lambda: self.app.select_single("SliderMenuItem", objectName="brightness");
97− # FIXME: this should go away when we switch to indicator-power
99− self.assertThat(fn_brightness_menu, Eventually(NotEquals(None)));
100− except AssertionError:
101− self.skipTest("WARNING: test skipped due to missing indicator-battery")
102− brightness_menu = fn_brightness_menu();
104− old_ab_value = brightness_menu.value
105− # find a new value to do to. At least 1/4 distance away from current value
107− desired_value = random.uniform(brightness_menu.minimumValue, brightness_menu.maximumValue)
108− if (abs(desired_value - old_ab_value) >= (brightness_menu.maximumValue - brightness_menu.minimumValue)/4):
111− self.set_brightness_to_value(brightness_menu, desired_value)
113− # TODO - should check backend when it's introspectable.
114− self.assertThat(brightness_menu.value, Eventually(NotEquals(old_ab_value)))