Back to index

unity  6.0.0
test_command_lens.py
Go to the documentation of this file.
00001 # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
00002 # Copyright 2012 Canonical
00003 # Author: Thomi Richards
00004 #
00005 # This program is free software: you can redistribute it and/or modify it
00006 # under the terms of the GNU General Public License version 3, as published
00007 # by the Free Software Foundation.
00008 
00009 from __future__ import absolute_import
00010 
00011 from autopilot.matchers import Eventually
00012 from testtools.matchers import Equals
00013 from time import sleep
00014 
00015 from unity.tests import UnityTestCase
00016 
00017 
00018 class CommandLensSearchTests(UnityTestCase):
00019     """Test the command lense search bahavior."""
00020 
00021     def setUp(self):
00022         super(CommandLensSearchTests, self).setUp()
00023 
00024     def tearDown(self):
00025         self.dash.ensure_hidden()
00026         super(CommandLensSearchTests, self).tearDown()
00027 
00028     def test_no_results(self):
00029         """An empty string should get no results."""
00030         self.dash.reveal_command_lens()
00031         command_lens = self.dash.get_current_lens()
00032 
00033         if self.dash.search_string != "":
00034             self.keyboard.press_and_release("Delete")
00035 
00036         self.assertThat(self.dash.search_string, Eventually(Equals("")))
00037         results_category = command_lens.get_category_by_name("Results")
00038         self.assertThat(results_category.is_visible, Eventually(Equals(False)))
00039 
00040     def test_results_category_appears(self):
00041         """Results category must appear when there are some results."""
00042         self.dash.reveal_command_lens()
00043         command_lens = self.dash.get_current_lens()
00044         # lots of apps start with 'a'...
00045         self.keyboard.type("a")
00046         self.assertThat(self.dash.search_string, Eventually(Equals("a")))
00047         results_category = command_lens.get_category_by_name("Results")
00048         self.assertThat(results_category.is_visible, Eventually(Equals(True)))
00049 
00050     def test_result_category_actually_contains_results(self):
00051         """With a search string of 'a', the results category must contain some results."""
00052         self.dash.reveal_command_lens()
00053         command_lens = self.dash.get_current_lens()
00054         # lots of apps start with 'a'...
00055         self.keyboard.type("a")
00056         self.assertThat(self.dash.search_string, Eventually(Equals("a")))
00057         results_category = command_lens.get_category_by_name("Results")
00058         results = results_category.get_results()
00059         self.assertTrue(results)
00060 
00061     def test_run_before_refresh(self):
00062         """Hitting enter before view has updated results must run the correct command."""
00063         if self.app_is_running("Text Editor"):
00064             self.close_all_app("Text Editor")
00065             sleep(1)
00066 
00067         self.dash.reveal_command_lens()
00068         self.keyboard.type("g")
00069         sleep(1)
00070         self.keyboard.type("edit", 0.1)
00071         self.keyboard.press_and_release("Enter", 0.1)
00072         self.addCleanup(self.close_all_app,  "Text Editor")
00073         app_found = self.bamf.wait_until_application_is_running("gedit.desktop", 5)
00074         self.assertTrue(app_found)
00075 
00076     def test_ctrl_tab_switching(self):
00077         """Pressing Ctrl+Tab after launching command lens must switch to Home lens."""
00078         self.dash.reveal_command_lens()
00079         self.keybinding("dash/lens/next")
00080         self.assertThat(self.dash.active_lens, Eventually(Equals("home.lens")))
00081 
00082     def test_ctrl_shift_tab_switching(self):
00083         """Pressing Ctrl+Shift+Tab after launching command lens must switch to Video lens."""
00084         self.dash.reveal_command_lens()
00085         self.keybinding("dash/lens/prev")
00086         self.assertThat(self.dash.active_lens, Eventually(Equals("video.lens")))