on xenial help sign in
Grid size is scaled too with display geo, still needs work.
commit5436ae31166d1c6ff7257af733e19df142bb7296 authorChristopher Lee <chris.lee@canonical.com> dateTue 16 Jul 2013, 22:30 (13 years ago) parent8f87949
1 file changed+39−12
tests/autopilot/unity8/shell/tests/__init__.py+39−12
tests/autopilot/unity8/shell/tests/__init__.py+39−12
@@ -12,6 +12,7 @@ from autopilot.testcase import AutopilotTestCase
1212from autopilot.matchers import Eventually
1313from testtools.matchers import Equals, NotEquals
1414from autopilot.input import Touch
15+from autopilot.display import Display
1516import logging
1617import os.path
1718import sysconfig
@@ -29,8 +30,8 @@ class FormFactors(object):
2930
3031def _get_device_emulation_scenarios():
3132 if model() == 'Desktop':
32− return [ ('Desktop Nexus 4', dict(app_width=384, app_height=640, grid_unit_px=18)) ]
33− # return [ ('Desktop Nexus 4', dict(app_width=768, app_height=1280, grid_unit_px=18)) ]
33+ # return [ ('Desktop Nexus 4', dict(app_width=384, app_height=640, grid_unit_px=18)) ]
34+ return [ ('Desktop Nexus 4', dict(app_width=768, app_height=1280, grid_unit_px=18)) ]
3435 else:
3536 return [ ('Native Device', dict(app_width=0, app_height=0, grid_unit_px=0)) ]
3637
@@ -42,27 +43,53 @@ class Unity8TestCase(AutopilotTestCase):
4243 super(Unity8TestCase, self).setUp()
4344 self._proxy = None
4445 self.touch = Touch.create()
45− self._setup_grid_size()
46− self._determine_geometry()
46+ self._setup_display_details()
4747
48− def _setup_grid_size(self):
49− """Use the grid size that may be supplied or use the default."""
50− if getattr(self, 'grid_unit_px', 0) == 0:
51− self.grid_size = int(os.getenv['GRID_UNIT_PX'])
52− else:
53− self.grid_size = self.grid_unit_px
54− self.patch_environment("GRID_UNIT_PX", str(self.grid_size))
48+ def _setup_display_details(self):
49+ # This needs a bit of a cleanup, make it clearer
50+ scale_divisor = self._determine_geometry()
51+ self._setup_grid_size(scale_divisor)
5552
5653 def _determine_geometry(self):
5754 """Use the geometry that may be supplied or use the default."""
5855 width = getattr(self, 'app_width', 0)
5956 height = getattr(self, 'app_height', 0)
57+ scale_divisor = 1
6058 if width == 0 and width == 0:
6159 self.unity_geometry_args = ['-fullscreen']
6260 else:
63− # Work it out until it fits to screen i.e. divisor
61+ if self._geo_larger_than_display(width, height):
62+ scale_divisor = self._get_scaled_down_geo(width, height)
63+ width = width / scale_divisor
64+ height = height / scale_divisor
65+ logger.info("Provided geometry larger than Display, scaled down to: %sx%s",
66+ width,
67+ height
68+ )
6469 geo_string = "%sx%s" % (width, height)
6570 self.unity_geometry_args = ['-geometry', geo_string, '-frameless', '-mousetouch']
71+ return scale_divisor
72+
73+ def _setup_grid_size(self, scale_divisor):
74+ """Use the grid size that may be supplied or use the default."""
75+ if getattr(self, 'grid_unit_px', 0) == 0:
76+ self.grid_size = int(os.getenv['GRID_UNIT_PX'])
77+ else:
78+ self.grid_size = int(self.grid_unit_px / scale_divisor)
79+ self.patch_environment("GRID_UNIT_PX", str(self.grid_size))
80+ logger.info(">>> Seting grid size: %s", self.grid_size)
81+
82+ def _geo_larger_than_display(self, width, height):
83+ screen = Display.create()
84+ screen_width = screen.get_screen_width()
85+ screen_height = screen.get_screen_height()
86+ return (width > screen_width) or (height > screen_height)
87+
88+ def _get_scaled_down_geo(self, width, height):
89+ divisor = 1
90+ while self._geo_larger_than_display(width / divisor, height / divisor):
91+ divisor = divisor * 2
92+ return divisor
6693
6794 def launch_unity(self):
6895 """Launch the unity8 shell, return a proxy object for it."""