def test_can_access_custom_emulator_properties(self): """Must be able to access properties of a custom emulator.""" class MouseTestWidget(EmulatorBase): pass app = self.start_mock_app(EmulatorBase) test_widget = app.select_single(MouseTestWidget) self.assertThat(test_widget.visible, Eventually(Equals(True)))
def test_switcher_all_mode_shows_all_apps(self): """Test switcher 'show_all' mode shows apps from all workspaces.""" initial_workspace = self.workspace.current_workspace self.addCleanup(self.workspace.switch_to, initial_workspace) calc = self.process_manager.start_app("Calculator") self.workspace.switch_to( (initial_workspace + 1) % self.workspace.num_workspaces) char_map = self.process_manager.start_app("Character Map") self.unity.switcher.initiate(SwitcherMode.ALL) self.addCleanup(self.unity.switcher.terminate) get_icon_names = lambda: [ i.tooltip_text for i in self.unity.switcher.icons ] self.assertThat(get_icon_names, Eventually(Contains(calc.name))) self.assertThat(get_icon_names, Eventually(Contains(char_map.name)))
def test_switcher_shows_current_workspace_only(self): """Switcher must show apps from the current workspace only.""" initial_workspace = self.workspace.current_workspace self.addCleanup(self.workspace.switch_to, initial_workspace) calc = self.process_manager.start_app("Calculator") self.workspace.switch_to( (initial_workspace + 1) % self.workspace.num_workspaces) char_map = self.process_manager.start_app("Character Map") self.unity.switcher.initiate() self.addCleanup(self.unity.switcher.terminate) get_icon_names = lambda: [ i.tooltip_text for i in self.unity.switcher.icons ] self.assertThat(get_icon_names, Eventually(Contains(char_map.name))) self.assertThat(get_icon_names, Eventually(Not(Contains(calc.name))))
def test_email_label_save(self): contact_editor = self.app.main_window.go_to_add_contact() my_emails = [] my_emails.append(data.Email(type_="Home", address="*****@*****.**")) my_emails.append(data.Email(type_="Work", address="*****@*****.**")) my_emails.append(data.Email(type_="Other", address="*****@*****.**")) test_contact = data.Contact(first_name="Sherlock", last_name="Holmes", emails=my_emails) contact_editor.fill_form(test_contact) # Save contact self.app.main_window.save() list_page = self.app.main_window.get_contact_list_page() view_page = list_page.open_contact(0) self.assertThat(view_page.visible, Eventually(Equals(True))) # check if we have 3 emails""" email_group = view_page.select_single("ContactDetailGroupWithTypeView", objectName="emails") self.assertThat(email_group.detailsCount, Eventually(Equals(3))) emails = { "*****@*****.**": "Home", "*****@*****.**": "Work", "*****@*****.**": "Other" } # Check if they have the correct label for idx in range(3): email_type = view_page.select_single("UCLabel", objectName="type_email_" + str(idx)) email_label = view_page.select_single( "UCLabel", objectName="label_emailAddress_" + str(idx) + ".0") self.assertThat(emails[email_label.text], Equals(email_type.text)) del emails[email_label.text] self.assertThat(len(emails), Equals(0))
def test_greeting_keyboard(self): """Greeting with keyboard navigation""" entry_name = self.app.select_single(BuilderName='entry_name') entry_color = self.app.select_single(BuilderName='entry_color') # FIXME: This isn't necessary for real X, but under Xvfb there is no # default focus sometimes if not entry_name.has_focus: self.mouse.click_object(entry_name) # type in name and color self.keyboard.type('Joe') self.keyboard.press_and_release('Tab') self.keyboard.type('red') # entries should now have the typed text self.assertThat(entry_name.text, Eventually(Equals('Joe'))) self.assertThat(entry_color.text, Eventually(Equals('red'))) # should not have any dialogs self.assertThat( lambda: self.app.select_single('GtkMessageDialog'), raises(StateNotFoundError) ) # focus and activate the "Greet" button self.keyboard.press_and_release('Tab') self.keyboard.press_and_release('Enter') # should get the greeting dialog md = self.app.wait_select_single('GtkMessageDialog', visible=True) # we expect the message dialog to show the corresponding greeting self.assertNotEqual(md.select_single('GtkLabel', label=u'Hello Joe, you like red.'), None) # close the dialog self.keyboard.press_and_release('Enter') self.assertThat( lambda: self.app.select_single('GtkMessageDialog', visible=True), raises(StateNotFoundError) )
def test_mouse_does_not_steal_button_focus(self): """When typing in the hud the mouse must not steal button focus.""" self.start_menu_app() self.unity.hud.ensure_visible() (x,y,w,h) = self.unity.hud.view.geometry self.mouse.move(w/4, h/4) self.keyboard.type("e") self.assertThat(self.unity.hud.view.selected_button, Eventually(Equals(1)))
def test_open_directory(self): dir_path = self.make_directory_in_home() first_dir = self._get_file_by_name(os.path.basename(dir_path)) self._open_directory(first_dir) folder_list_page = self.app.main_view.get_folder_list_page() self.assertThat( folder_list_page.get_current_path, Eventually(Equals(dir_path))) self._assert_number_of_files(0, home=False)
def test_hud_input(self): """Entering an input string through gcin will result in a Korean string result in the hud.""" self.unity.hud.ensure_visible() self.addCleanup(self.unity.hud.ensure_hidden) self.enter_hangul_mode() self.keyboard.type(self.input) self.assertThat(self.unity.hud.search_string, Eventually(Equals(self.result)))
def test_launcher_keynav_changes_panel(self): """The panel title must change when in key nav mode and LIM is not enabled. """ self.start_keynav_with_cleanup_cancel() panel = self.unity.panels.get_active_panel() expected_panel_title = ("" if panel.menus.integrated_menus else "Search your computer and online sources") self.assertThat(panel.title, Eventually(Equals(expected_panel_title)))
def launch_application(self): app_qml_source_location = self._get_app_qml_source_path() if os.path.exists(app_qml_source_location): app = self._launch_application_from_source( app_qml_source_location) else: app = self._launch_installed_application() self.assertThat(app.main_view.visible, Eventually(Equals(True))) return app
def test_moving_mouse_during_grab_select_correct_menuitem(self): """Test that moving the mouse during grabbing selects the correct menu item. See bug #1027955. """ self.open_quicklist_with_mouse() mouse_item = self.quicklist.selectable_items[0] mouse_item.mouse_move_to() self.assertThat(mouse_item.selected, Eventually(Equals(True))) # Dragging the mouse horizontally doesn't change the selection self.mouse.press() self.addCleanup(self.mouse.release) self.mouse.move(mouse_item.x + mouse_item.width - 10, mouse_item.y + mouse_item.height / 2) self.assertThat(mouse_item.selected, Eventually(Equals(True))) # Moving the mouse down selects the next item mouse_item = self.quicklist.selectable_items[1] mouse_item.mouse_move_to() self.assertThat(mouse_item.selected, Eventually(Equals(True)))
def test_multi_call_panel(self): """Make sure the multi call panel is visible when two calls are available""" firstNumber = '11111111' secondNumber = '22222222' # place the calls self.place_calls([firstNumber, secondNumber]) # now ensure that the multi-call panel is visible multi_call = self.main_view.live_call_page.get_multi_call_display() self.assertThat(multi_call.visible, Eventually(Equals(True))) # hangup one call self.main_view.live_call_page.click_hangup_button() self.assertThat(multi_call.visible, Eventually(Equals(False))) # and the other one self.main_view.live_call_page.click_hangup_button()
def _setup_overlay_webview_context_menu(self, path): overlay_path = "/with-overlay-link?path={}".format(path) self._launch_application(overlay_path) popup_controller = self.get_popup_controller() animation_watcher = popup_controller.watch_signal( 'windowOverlayOpenAnimationDone()') animation_signal_emission = animation_watcher.num_emissions self._click_window_open() self.assertThat(lambda: len(self.get_popup_overlay_views()), Eventually(Equals(1))) self.assertThat(lambda: animation_watcher.num_emissions, Eventually(GreaterThan(animation_signal_emission))) self.webview = self.get_popup_overlay_views()[0].select_single( objectName="overlayWebview") self.menu = self._open_context_menu(self.webview)
def expect_history_entries(self, ordered_urls, window=None): if window is None: window = self.main_window history = window.get_history_view() if window.wide: self.assertThat(lambda: len(history.get_entries()), Eventually(Equals(len(ordered_urls)))) entries = history.get_entries() else: self.assertThat(lambda: len(history.get_domain_entries()), Eventually(Equals(1))) self.pointing_device.click_object(history.get_domain_entries()[0]) expanded_history = window.get_expanded_history_view() self.assertThat(lambda: len(expanded_history.get_entries()), Eventually(Equals(len(ordered_urls)))) entries = expanded_history.get_entries() self.assertThat([entry.url for entry in entries], Equals(ordered_urls)) return entries
def test_ctrl_shift_tab_switching(self): """Pressing Ctrl+Shift+Tab after launching command scope must switch to Photos or Social scope (Social can be hidden by default).""" self.unity.dash.reveal_command_scope() self.keybinding("dash/lens/prev") self.assertThat( self.unity.dash.active_scope, Eventually( MatchesPredicate( lambda x: x in ["photos.scope", "social.scope"], '%s is not last scope')))
def test_undo_close_tab_incognito(self): start_url = self.main_window.get_current_webview().url self.open_new_tab(open_tabs_view=not self.main_window.wide) url = self.base_url + "/tab/1" self.main_window.go_to_url(url) self.main_window.wait_until_page_loaded(url) self.main_window.press_key('Ctrl+w') self.assert_number_webviews_eventually(1) self.check_current_tab(start_url) incognito_url = self.base_url + "/tab/2" self.main_window.enter_private_mode() self.assertThat(self.main_window.is_in_private_mode, Eventually(Equals(True))) self.main_window.go_to_url(incognito_url) self.main_window.wait_until_page_loaded(incognito_url) self.open_new_tab(open_tabs_view=not self.main_window.wide) self.main_window.go_to_url(incognito_url) self.main_window.wait_until_page_loaded(incognito_url) self.main_window.press_key('Ctrl+w') self.assert_number_incognito_webviews_eventually(1) # Test that no tabs will be restored in incognito mode. # We sleep for a bit after the keypress to give more confidence that # the tab still hasn't appeared within a reasonable amount of time. self.main_window.press_key('Ctrl+Shift+w') time.sleep(1) self.assert_number_incognito_webviews_eventually(1) # Close the last incognito tab to exit the mode. This is done on # purpose instead of using leave_private_mode since we want to # make sure the last tab is also not saved, as it is a corner case self.main_window.press_key('Ctrl+w') self.assertThat(self.main_window.is_in_private_mode, Eventually(Equals(False))) # Tabs that we closed before going incognito will be restored # when going back to default mode self.main_window.press_key('Ctrl+Shift+w') self.assert_number_webviews_eventually(2) self.check_current_tab(url)
def test_quicklist_closes_when_dash_opens(self): """When the quicklist is open you must still be able to open the dash.""" calc = self.process_manager.start_app("Calculator") calc_icon = self.unity.launcher.model.get_icon(desktop_id=calc.desktop_file) self.open_quicklist_for_icon(calc_icon) self.unity.dash.ensure_visible() self.addCleanup(self.unity.dash.ensure_hidden) self.assertThat(self.unity.dash.visible, Eventually(Equals(True)))
def test_override_user_agent(self): args = ['--user-agent-string=MyUserAgent'] self.launch_webcontainer_app_with_local_http_server( args, '/show-user-agent') self.get_webcontainer_window().visible.wait_for(True) # trick until we get e.g. selenium/chromedriver tests result = 'MyUserAgent MyUserAgent' self.assertThat(self.get_oxide_webview().title, Eventually(Equals(result)))
def test_fake_sensor(self): unity_with_sensors = fixture_setup.LaunchUnityWithFakeSensors() self.useFixture(unity_with_sensors) process_helpers.unlock_unity() fake_sensors = unity_with_sensors.fake_sensors o_proxy = unity_with_sensors.main_win.select_single('OrientedShell') fake_sensors.set_orientation(self.action) self.assertThat(o_proxy.physicalOrientation, Eventually(Equals(self.orientation), timeout=15))
def test_changing_default_sim_for_messages(self): # click ask self.system_settings.main_view.scroll_to_and_click( self.get_default_sim_for_messages_selector('ask')) # click second sim self.system_settings.main_view.scroll_to_and_click( self.get_default_sim_for_messages_selector('/ril_1')) self.assertThat(lambda: self.obj_phone.GetDefaultSimForMessages(), Eventually(Equals('/ril_1')))
def test_ignore_key_events_on_dash(self): self.unity.dash.ensure_visible() self.addCleanup(self.unity.dash.ensure_hidden) self.activate_ibus(self.unity.dash.searchbar) self.keyboard.type("cipan") self.keyboard.press_and_release("Tab") self.keyboard.type(" ") self.deactivate_ibus(self.unity.dash.searchbar) self.assertThat(self.unity.dash.search_string, Eventually(NotEquals(" ")))
def setUp(self): super(TestIndicatorBaseTestCase, self).setUp() self.launch_indicator_service() # wait for the indicator to appear in unity self.indicator = indicators.TestIndicator(self.main_window) self.assertThat(self.indicator.is_indicator_icon_visible(), Eventually(Equals(True), timeout=20)) self.indicator_page = self.indicator.open()
def test_collapsed_bookmarks_folders_when_expanded(self): more_button = self.new_tab_view.get_bookmarks_more_button() self.assertThat(more_button.visible, Equals(True)) self.pointing_device.click_object(more_button) folders = self.new_tab_view.get_bookmarks_folder_list_view() self.assertThat(lambda: len(folders.get_delegates()), Eventually(Equals(3))) folder_delegate = folders.get_folder_delegate("") self.assertThat( lambda: len(folders.get_urls_from_folder(folder_delegate)), Eventually(Equals(5))) folder_delegate = folders.get_folder_delegate("Actinide") self.assertThat( lambda: len(folders.get_urls_from_folder(folder_delegate)), Eventually(Equals(0))) folder_delegate = folders.get_folder_delegate("NobleGas") self.assertThat( lambda: len(folders.get_urls_from_folder(folder_delegate)), Eventually(Equals(0)))
def test_focus_invalid(self): """Tests clicking outside of the viewfinder image area, where it should not focus.""" bottom_edge = self.main_window.get_bottom_edge() zoom = self.main_window.get_zoom_control() feed = self.main_window.get_viewfinder_geometry() focus_ring = self.main_window.get_focus_ring() switch_cameras = self.main_window.get_swap_camera_button() exposure_button = self.main_window.get_exposure_button() # The focus ring should be invisible in the beginning self.assertThat(focus_ring.opacity, Eventually(Equals(0.0))) x, y, w, h = bottom_edge.globalRect tx = x + (w // 2) ty = y + h # Click at the bottom of the window. It should never focus there. self.pointing_device.move(tx, ty) self.pointing_device.click() self.assertThat(focus_ring.opacity, Eventually(Equals(0.0))) # Check if there's a gap between the viewfinder feed and the zoom # control. If there is, test that focusing there won't show the focus # ring. if zoom.y > feed.height: # Feed is aligned to the top of the window x, y, h, w = zoom.globalRect click_coords = [x + (h // 2), y - 2] self.pointing_device.move(click_coords[0], click_coords[1]) self.pointing_device.click() self.assertThat(focus_ring.opacity, Eventually(Equals(0.0))) # Switch cameras, wait for camera to settle, and try again self.pointing_device.move_to_object(switch_cameras) self.pointing_device.click() self.assertThat(exposure_button.enabled, Eventually(Equals(True))) # Maybe we will have the gap when we switch the camera, test it again if zoom.y > feed.height: x, y, h, w = zoom.globalRect click_coords = [x + (h // 2), y - 2] self.pointing_device.move(click_coords[0], click_coords[1]) self.pointing_device.click() self.assertThat(focus_ring.opacity, Eventually(Equals(0.0)))
def test_zoom_in_and_out(self): webview = self.main_window.get_current_webview() self.assertThat(webview.zoomFactor, Eventually(AlmostEquals(1.0))) zooms = [1.1, 1.25, 1.5, 1.75, 2.0, 2.5, 3.0, 4.0, 5.0] for zoom in zooms: self.main_window.press_key('Ctrl+plus') self.assertThat(webview.zoomFactor, Eventually(AlmostEquals(zoom))) self.main_window.press_key('Ctrl+0') self.assertThat(webview.zoomFactor, Eventually(AlmostEquals(1.0))) zooms = [0.9, 0.75, 0.666, 0.5, 0.333, 0.25] for zoom in zooms: self.main_window.press_key('Ctrl+minus') self.assertThat(webview.zoomFactor, Eventually(AlmostEquals(zoom))) self.main_window.press_key('Ctrl+0') self.assertThat(webview.zoomFactor, Eventually(AlmostEquals(1.0)))
def test_zoom_not_reset_on_recording_mode_change(self): zoom_control = self.main_window.get_zoom_control() zoom_slider = self.main_window.get_zoom_slider() self.activate_zoom() x, y, w, h = zoom_slider.globalRect tx = x + (w // 2) ty = y + (h // 2) self.pointing_device.drag(tx, ty, (tx + zoom_control.width), ty) self.assertThat(zoom_control.value, Eventually(Equals(zoom_control.maximumValue))) self.main_window.switch_recording_mode() self.assertThat(zoom_control.value, Eventually(Equals(zoom_control.maximumValue))) self.main_window.switch_recording_mode() self.assertThat(zoom_control.value, Eventually(Equals(zoom_control.maximumValue)))
def test_create_directory(self): dir_name = 'Test Directory' self.app.main_view.click_header_action('createFolder') self._confirm_dialog(dir_name) self._assert_number_of_files(1) dir_ = self._get_file_by_name(dir_name) self.assertThat(dir_.fileName, Eventually(Equals(dir_name)))
def test_actions(self): webview = self.main_window.get_current_webview() actions = [ "SelectAll", "Cut", "Undo", "Redo", "Paste", "SelectAll", "Copy", "Erase" ] for action in actions: self.menu.click_action("{}ContextualAction".format(action)) self.assertThat(webview.activeFocus, Eventually(Equals(True))) self.menu = self.main_window.open_context_menu()
def test_switch_hud_dash_does_not_break_the_focused_application_emblem(self): """Switching from HUD to Dash and back must still show the correct HUD icon.""" self.process_manager.close_all_app("Calculator") calc = self.process_manager.start_app("Calculator") self.assertTrue(calc.is_active) self.unity.hud.ensure_visible() self.unity.dash.ensure_visible() self.unity.hud.ensure_visible() self.assertThat(self.unity.hud.icon.icon_name, Eventually(Equals(calc.icon)))
def test_calc(self): """Run a calculation""" display = self.app.select_single(BuilderName='displayitem') self.mouse.click_object(display) self.assertThat(display.buffer, Equals('')) self.keyboard.type('1+1') self.keyboard.press_and_release('Enter') self.assertThat(display.buffer, Eventually(Equals('2')))