@@ -40,154 +40,3 @@ def with_lightdm_mock(mock_type):
40 return fn(*args, **kwargs)
40 return fn(*args, **kwargs)
41 return wrapper
41 return wrapper
42 return with_lightdm_mock_internal
42 return with_lightdm_mock_internal
45−# TODO: Mixing classes like these are ikky. Remove them, and replace with
47−class TestShellHelpers(object):
48− """Helpers for testing the Shell"""
50− def select_greeter_user(self, username):
51− greeter = self.main_window.get_greeter()
52− self.assertThat(greeter.created, Eventually(Equals(True)))
53− self.assertThat(greeter.multiUser, Eventually(Equals(True)))
55− login_loader = self.main_window.get_login_loader()
56− self.assertThat(login_loader.progress, Eventually(Equals(1)))
58− login_list = self.main_window.get_login_list()
59− list_view = login_list.get_children_by_type("QQuickListView")[0]
62− max_tries = 50 # just in case we go off rails
63− while try_count < max_tries:
64− users = list_view.get_children_by_type("QQuickItem")[0].get_children_by_type("QQuickItem")
68− user_label = user.get_children_by_type("Label")[0]
69− if user.opacity < 0.1:
70− continue # off-screen item
71− if user_label.text == username:
74− elif target_user is None or user.y > target_user.y:
78− if target_user is None:
80− user_label = target_user.get_children_by_type("Label")[0]
81− self.touch.tap_object(user_label)
82− self.assertThat(list_view.movingInternally, Eventually(Equals(False)))
83− if user_label.text == username:
84− return login_list.get_children_by_type("TextField")[0]
85− try_count = try_count + 1
86− self.fail() # We didn't find it
88− def unlock_greeter(self, retries=2):
89− greeter = self.main_window.get_greeter()
90− self.assertThat(greeter.created, Eventually(Equals(True)))
92− if greeter.multiUser:
93− password_field = self.select_greeter_user("No Password")
94− self.assertThat(password_field.opacity, Eventually(Equals(1)))
95− self.touch.tap_object(password_field)
98− rect = greeter.globalRect
99− start_x = rect[0] + rect[2] - 3
100− start_y = int(rect[1] + rect[3] / 2)
101− stop_x = int(rect[0] + rect[2] * 0.2)
103− self.touch.drag(start_x, start_y, stop_x, stop_y)
105− # Because the shell loads up lots of stuff, unlocking the greeter can
106− # be a bit stuttery while scopes are still consuming all resources.
107− # Give it another (max retries) chance
109− self.assertThat(greeter.created, Eventually(Equals(False)))
112− logger.warning("Failed to unlock greeter. Retrying...")
113− self.unlock_greeter(retries-1)
115− logger.warning("Failed to unlock greeter. Giving up. Tests may fail...")
118− def open_first_dash_home_app(self, retries=2):
119− self.assertThat(lambda: self.main_window.get_dash_home_applications_grid(), Eventually(NotEquals(None)))
120− app_grid = self.main_window.get_dash_home_applications_grid()
121− # Wait for the grids to be expanded
122− self.assertThat(app_grid.get_children()[0].totalContentHeight, Eventually(NotEquals(0)))
123− self.assertThat(app_grid.get_children()[0].height, Eventually(Equals(app_grid.get_children()[0].totalContentHeight)))
124− first_app = app_grid.get_children()[0].get_children()[0].get_children()[0].get_children()[0]
125− self.touch.tap_object(first_app)
126− bottombar = self.main_window.get_bottombar()
128− # if we have huge amounts of pixels (e.g. Nexus10), but slow video (e.g. VM) it might take a little
129− # until the dash is fully rendered after sliding away the greeter/lockscreen and the click might
130− # go to the void for the first time because there's no real way to know what the display has
131− # painted already. Give it another (max retries) chance.
133− self.assertThat(lambda: getattr(bottombar, "applicationIsOnForeground"),
134− Eventually(Equals(True)))
137− logger.warning("Failed to launch app. Retrying...")
138− self.open_first_dash_home_app(retries-1)
140− logger.warning("Failed to launch app. Giving up. Tests may fail...")
143− def show_hud(self, retries=2):
144− self.open_first_dash_home_app()
146− hud_show_button = self.main_window.get_hud_show_button()
147− hud = self.main_window.get_hud()
148− window = self.main_window.get_qml_view()
149− start_x = int(window.x + window.width / 2)
150− start_y = window.y + window.height - 3
151− self.assertThat(hud_show_button.opacity, Eventually(Equals(0)))
152− self.touch.press(start_x, start_y)
153− self.touch._finger_move(start_x, start_y - self.grid_size)
154− self.assertThat(hud_show_button.opacity, Eventually(Equals(0)))
155− self.touch._finger_move(start_x, start_y - self.grid_size * 2)
156− self.touch._finger_move(start_x, start_y - self.grid_size * 3)
157− self.touch._finger_move(start_x, start_y - self.grid_size * 4)
159− self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
162− logger.warning("Failed to get hud button to show. Retrying...")
163− self.touch.release()
164− self.show_hud(retries-1)
167− logger.warning("Failed to get hud button to show. Giving up. Tests may fail...")
168− self.assertThat(hud_show_button.mouseOver, Eventually(Equals(False)))
169− self.touch._finger_move(start_x, start_y - self.grid_size * 34)
170− self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
171− self.assertThat(hud_show_button.mouseOver, Eventually(Equals(True)))
172− self.touch.release()
173− self.assertThat(hud_show_button.opacity, Eventually(Equals(0)))
174− self.assertThat(hud.shown, Eventually(Equals(True)))
176− def close_hud_click(self):
177− hud = self.main_window.get_hud()
178− self.assertThat(hud.shown, Eventually(Equals(True)))
179− rect = hud.globalRect
180− x = int(rect[0] + rect[2] / 2)
181− y = rect[1] + self.grid_size
182− self.touch.tap(x, y)
183− self.assertThat(hud.shown, Eventually(Equals(False)))
185− def show_launcher(self):
186− launcher = self.main_window.get_launcher()
187− view = self.main_window.get_qml_view()
188− start_x = view.x + 1
189− start_y = view.y + view.height / 2
190− stop_x = start_x + launcher.panelWidth + 1
192− self.touch.drag(start_x, start_y, stop_x, stop_y)
193− self.assertThat(launcher.shown, Eventually(Equals(True)))