Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(198)

Side by Side Diff: chrome/test/functional/omniboxmodel.py

Issue 10830193: Remove SWIGged use of BrowserProxy and TabProxy from PyAuto tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Used named arguments and deleted unused test files, as suggested by Nirnimesh. Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/test/functional/ntp.py ('k') | chrome/test/functional/passwords.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 import logging
7 import random
8
9 import pyauto_functional
10 from pyauto import PyUITest
11 from pyauto import GURL
12
13 import autotour
14
15
16 class OmniboxModelTest(autotour.Godel, PyUITest):
17 """Omnibox Model which Opens tabs, navigates to specific URL's and keeps track
18 of URL's visited which are then verified agains the Omnibox's info.
19 """
20 def __init__(self, methodName='runTest', **kwargs):
21 PyUITest.__init__(self, methodName=methodName, **kwargs)
22 self._tab_count = 1
23 self._url_map = {}
24 self.InitUrls()
25
26 def InitUrls(self):
27 """Setup Url Map which stores the name of the url and a list of url and
28 visited count.
29 """
30 self._url_map = {
31 'google': ('http://www.google.com', 0),
32 'yahoo': ('http://www.yahoo.com', 0),
33 'msn': ('http://www.msn.com', 0),
34 'facebook': ('http://www.facebook.com', 0),
35 'twitter': ('http://www.twitter.com', 0),
36 }
37
38 def CanOpenTab(self):
39 return self._tab_count < 5
40
41 def CanCloseTab(self):
42 return self._tab_count > 1
43
44 def CanNavigate(self):
45 # FIX: CanNavigate can be called if there is atleast one tab to be closed.
46 # Currently this condition is incorrect because CanCloseTab leaves atleast
47 # one tab because without that, there is some crash which is under
48 # investigation.
49 if self.CanCloseTab():
50 return False
51 for key in self._url_map:
52 if self._url_map[key][1] == 0:
53 return True
54 return False
55
56 def _GetOmniboxMatchesFor(self, text, windex=0, attr_dict=None):
57 """Fetch omnibox matches with the given attributes for the given query.
58
59 Args:
60 text: the query text to use
61 windex: the window index to work on. Defaults to 0 (first window)
62 attr_dict: the dictionary of properties to be satisfied
63
64 Returns:
65 a list of match items
66 """
67 self.SetOmniboxText(text, windex=windex)
68 self.WaitUntilOmniboxQueryDone(windex=windex)
69 if not attr_dict:
70 matches = self.GetOmniboxInfo(windex=windex).Matches()
71 else:
72 matches = self.GetOmniboxInfo(windex=windex).MatchesWithAttributes(
73 attr_dict=attr_dict)
74 return matches
75
76 @autotour.GodelAction(1, CanOpenTab)
77 def OpenTab(self):
78 """Opens a tab in the first window and navigates to a random site from
79 url map.
80 """
81 logging.info('#In Open Tab')
82 self._tab_count = self._tab_count + 1
83 key = random.choice(self._url_map.keys())
84 logging.info('#Navigating to ' + self._url_map[key][0])
85 self.AppendTab(GURL(self._url_map[key][0]))
86 self._url_map[key][1] = self._url_map[key][1] + 1
87 self.VerifyOmniboxInfo()
88
89 @autotour.GodelAction(10, CanCloseTab)
90 def CloseTab(self):
91 """Closes the first tab from the first window"""
92 self._tab_count = self._tab_count - 1
93 self.GetBrowserWindow(0).GetTab(0).Close(True)
94
95 def VerifyOmniboxInfo(self):
96 for key in self._url_map.keys():
97 """Verify inline autocomplete for a pre-visited url."""
98 search_for = key[:3]
99 matches = self._GetOmniboxMatchesFor(search_for, windex=0)
100 self.assertTrue(matches)
101 # Omnibox should suggest auto completed url as the first item
102 matches_description = matches[0]
103 term_to_find = search_for
104 if self._url_map[key][1] > 0:
105 logging.info('#verifying : ' + key)
106 logging.info('#verifying ' + key + ' text ' + search_for)
107 term_to_find = self._url_map[key][0][7:]
108 self.assertEqual('history-url', matches_description['type'])
109 self.assertTrue(self._url_map[key][0][11:] in
110 self.GetOmniboxInfo().Text())
111 self.assertTrue(term_to_find in matches_description['contents'])
112
113 @autotour.GodelAction(10, CanNavigate)
114 def Navigate(self):
115 """Navigates to a URL by picking a random url from list"""
116 logging.info('#In Navigate')
117 index = random.randint(0, len(self._url_map.keys()) - 1)
118 key = self._url_map.keys()[index]
119 logging.info('#navigating to ' + self._url_map[key][0])
120 self.NavigateToURL(self._url_map[key][0])
121 self._url_map[key][1] = self._url_map[key][1] + 1
122 self.VerifyOmniboxInfo()
123
124 def testExplore(self):
125 e = autotour.Explorer()
126 logging.info('#Explorer created')
127 e.Add(self)
128 logging.info('#Object added')
129 e.Explore(self.CanNavigate)
130 logging.info('#Done')
131
132
133 if __name__ == '__main__':
134 pyauto_functional.Main()
OLDNEW
« no previous file with comments | « chrome/test/functional/ntp.py ('k') | chrome/test/functional/passwords.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698