Commit 8de2f239 authored by aocampo@chromium.org's avatar aocampo@chromium.org

Added 3 more functions in popups.py

testUnblockedPopupShowsInHistory
testBlockedPopupNotShowInHistory
testUnblockedPopupAddedToOmnibox

removed GetOmniboxMatchesFor from omnibox.py and added to test_utils.py

Review URL: http://codereview.chromium.org/7043026

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86198 0039d316-1c4b-4281-b951-d872f2087c98
parent e8aa5839
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
'-find_in_page.FindMatchTests.testLocalizationAndCaseOrder', '-find_in_page.FindMatchTests.testLocalizationAndCaseOrder',
'execute_javascript', 'execute_javascript',
'history', 'history',
'https', 'https',
'imports', 'imports',
'infobars', 'infobars',
'instant', 'instant',
...@@ -67,6 +67,8 @@ ...@@ -67,6 +67,8 @@
'popups', 'popups',
# crbug.com/82629 - real bug. # crbug.com/82629 - real bug.
'-popups.PopupsTest.testPopupsLaunchUponBrowserBackButton', '-popups.PopupsTest.testPopupsLaunchUponBrowserBackButton',
# crbug.com/47935
'-popups.PopupsTest.testBlockedPopupNotShowInHistory',
'prefs', 'prefs',
'search_engines', 'search_engines',
'shortcuts', 'shortcuts',
......
#!/usr/bin/python #!/usr/bin/python
# Copyright (c) 2010 The Chromium Authors. All rights reserved. # Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
...@@ -12,6 +12,7 @@ import urlparse ...@@ -12,6 +12,7 @@ import urlparse
import pyauto_functional # Must be imported before pyauto import pyauto_functional # Must be imported before pyauto
import pyauto import pyauto
import test_utils
class OmniboxTest(pyauto.PyUITest): class OmniboxTest(pyauto.PyUITest):
...@@ -34,26 +35,6 @@ class OmniboxTest(pyauto.PyUITest): ...@@ -34,26 +35,6 @@ class OmniboxTest(pyauto.PyUITest):
self.WaitUntilOmniboxReadyHack() self.WaitUntilOmniboxReadyHack()
self.assertTrue(self.GetOmniboxInfo().Properties('has_focus')) self.assertTrue(self.GetOmniboxInfo().Properties('has_focus'))
def _GetOmniboxMatchesFor(self, text, windex=0, attr_dict=None):
"""Fetch omnibox matches with the given attributes for the given query.
Args:
text: the query text to use
windex: the window index to work on. Defaults to 0 (first window)
attr_dict: the dictionary of properties to be satisfied
Returns:
a list of match items
"""
self.SetOmniboxText(text, windex=windex)
self.WaitUntilOmniboxQueryDone(windex=windex)
if not attr_dict:
matches = self.GetOmniboxInfo(windex=windex).Matches()
else:
matches = self.GetOmniboxInfo(windex=windex).MatchesWithAttributes(
attr_dict=attr_dict)
return matches
def testHistoryResult(self): def testHistoryResult(self):
"""Verify that omnibox can fetch items from history.""" """Verify that omnibox can fetch items from history."""
url = self.GetFileURLForDataPath('title2.html') url = self.GetFileURLForDataPath('title2.html')
...@@ -62,7 +43,7 @@ class OmniboxTest(pyauto.PyUITest): ...@@ -62,7 +43,7 @@ class OmniboxTest(pyauto.PyUITest):
def _VerifyHistoryResult(query_list, description, windex=0): def _VerifyHistoryResult(query_list, description, windex=0):
"""Verify result matching given description for given list of queries.""" """Verify result matching given description for given list of queries."""
for query_text in query_list: for query_text in query_list:
matches = self._GetOmniboxMatchesFor( matches = test_utils.GetOmniboxMatchesFor(self,
query_text, windex=windex, attr_dict={'description': description}) query_text, windex=windex, attr_dict={'description': description})
self.assertTrue(matches) self.assertTrue(matches)
self.assertEqual(1, len(matches)) self.assertEqual(1, len(matches))
...@@ -91,7 +72,7 @@ class OmniboxTest(pyauto.PyUITest): ...@@ -91,7 +72,7 @@ class OmniboxTest(pyauto.PyUITest):
to match against to match against
windex: the window index to work on. Defaults to 0 (first window) windex: the window index to work on. Defaults to 0 (first window)
""" """
matches_description = self._GetOmniboxMatchesFor( matches_description = test_utils.GetOmniboxMatchesFor(self,
url, windex=windex, attr_dict={'description': description}) url, windex=windex, attr_dict={'description': description})
self.assertEqual(1, len(matches_description)) self.assertEqual(1, len(matches_description))
if description == 'Google Search': if description == 'Google Search':
...@@ -124,7 +105,7 @@ class OmniboxTest(pyauto.PyUITest): ...@@ -124,7 +105,7 @@ class OmniboxTest(pyauto.PyUITest):
title1 = 'Title Of Awesomeness' title1 = 'Title Of Awesomeness'
self.NavigateToURL(url1) self.NavigateToURL(url1)
self.NavigateToURL(url2) self.NavigateToURL(url2)
matches = self._GetOmniboxMatchesFor('file://') matches = test_utils.GetOmniboxMatchesFor(self, 'file://')
self.assertTrue(matches) self.assertTrue(matches)
# Find the index of match for url1 # Find the index of match for url1
index = None index = None
...@@ -142,7 +123,7 @@ class OmniboxTest(pyauto.PyUITest): ...@@ -142,7 +123,7 @@ class OmniboxTest(pyauto.PyUITest):
search_text = 'hello world' search_text = 'hello world'
verify_str = 'Google Search' verify_str = 'Google Search'
url_re = 'http://www.google.com/search\?.*q=hello\+world.*' url_re = 'http://www.google.com/search\?.*q=hello\+world.*'
matches_description = self._GetOmniboxMatchesFor( matches_description = test_utils.GetOmniboxMatchesFor(self,
search_text, attr_dict={'description': verify_str}) search_text, attr_dict={'description': verify_str})
self.assertTrue(matches_description) self.assertTrue(matches_description)
self.assertEqual(1, len(matches_description)) self.assertEqual(1, len(matches_description))
...@@ -153,7 +134,7 @@ class OmniboxTest(pyauto.PyUITest): ...@@ -153,7 +134,7 @@ class OmniboxTest(pyauto.PyUITest):
def testInlinAutoComplete(self): def testInlinAutoComplete(self):
"""Verify inline autocomplete for a pre-visited url.""" """Verify inline autocomplete for a pre-visited url."""
self.NavigateToURL('http://www.google.com') self.NavigateToURL('http://www.google.com')
matches = self._GetOmniboxMatchesFor('goog') matches = test_utils.GetOmniboxMatchesFor(self, 'goog')
self.assertTrue(matches) self.assertTrue(matches)
# Omnibox should suggest auto completed url as the first item # Omnibox should suggest auto completed url as the first item
matches_description = matches[0] matches_description = matches[0]
...@@ -201,7 +182,7 @@ class OmniboxTest(pyauto.PyUITest): ...@@ -201,7 +182,7 @@ class OmniboxTest(pyauto.PyUITest):
# Verify omnibox queries. # Verify omnibox queries.
for file_url in crazy_fileurls: for file_url in crazy_fileurls:
matches = self._GetOmniboxMatchesFor( matches = test_utils.GetOmniboxMatchesFor(self,
file_url, attr_dict={'type': 'url-what-you-typed', file_url, attr_dict={'type': 'url-what-you-typed',
'description': title}) 'description': title})
self.assertTrue(matches) self.assertTrue(matches)
...@@ -213,7 +194,7 @@ class OmniboxTest(pyauto.PyUITest): ...@@ -213,7 +194,7 @@ class OmniboxTest(pyauto.PyUITest):
def testSuggest(self): def testSuggest(self):
"""Verify suggested results in omnibox.""" """Verify suggested results in omnibox."""
matches = self._GetOmniboxMatchesFor('apple') matches = test_utils.GetOmniboxMatchesFor(self, 'apple')
self.assertTrue(matches) self.assertTrue(matches)
self.assertTrue([x for x in matches if x['type'] == 'search-suggest']) self.assertTrue([x for x in matches if x['type'] == 'search-suggest'])
...@@ -228,7 +209,7 @@ class OmniboxTest(pyauto.PyUITest): ...@@ -228,7 +209,7 @@ class OmniboxTest(pyauto.PyUITest):
self.AddBookmarkURL( # Add a bookmark self.AddBookmarkURL( # Add a bookmark
self.GetBookmarkModel().BookmarkBar()['id'], 0, title, url) self.GetBookmarkModel().BookmarkBar()['id'], 0, title, url)
self.NavigateToURL(url) # Build up history self.NavigateToURL(url) # Build up history
matches = self._GetOmniboxMatchesFor(search_string) matches = test_utils.GetOmniboxMatchesFor(self, search_string)
self.assertTrue(matches) self.assertTrue(matches)
# Verify starred result (indicating bookmarked url) # Verify starred result (indicating bookmarked url)
self.assertTrue([x for x in matches if x['starred'] == True]) self.assertTrue([x for x in matches if x['starred'] == True])
...@@ -240,13 +221,13 @@ class OmniboxTest(pyauto.PyUITest): ...@@ -240,13 +221,13 @@ class OmniboxTest(pyauto.PyUITest):
"""Verify no suggests for omnibox when suggested-services disabled.""" """Verify no suggests for omnibox when suggested-services disabled."""
search_string = 'apple' search_string = 'apple'
self.assertTrue(self.GetPrefsInfo().Prefs(pyauto.kSearchSuggestEnabled)) self.assertTrue(self.GetPrefsInfo().Prefs(pyauto.kSearchSuggestEnabled))
matches = self._GetOmniboxMatchesFor(search_string) matches = test_utils.GetOmniboxMatchesFor(self, search_string)
self.assertTrue(matches) self.assertTrue(matches)
self.assertTrue([x for x in matches if x['type'] == 'search-suggest']) self.assertTrue([x for x in matches if x['type'] == 'search-suggest'])
# Disable suggest-service # Disable suggest-service
self.SetPrefs(pyauto.kSearchSuggestEnabled, False) self.SetPrefs(pyauto.kSearchSuggestEnabled, False)
self.assertFalse(self.GetPrefsInfo().Prefs(pyauto.kSearchSuggestEnabled)) self.assertFalse(self.GetPrefsInfo().Prefs(pyauto.kSearchSuggestEnabled))
matches = self._GetOmniboxMatchesFor(search_string) matches = test_utils.GetOmniboxMatchesFor(self, search_string)
self.assertTrue(matches) self.assertTrue(matches)
# Verify there are no suggest results # Verify there are no suggest results
self.assertFalse([x for x in matches if x['type'] == 'search-suggest']) self.assertFalse([x for x in matches if x['type'] == 'search-suggest'])
...@@ -255,7 +236,7 @@ class OmniboxTest(pyauto.PyUITest): ...@@ -255,7 +236,7 @@ class OmniboxTest(pyauto.PyUITest):
"""Verify omnibox autocomplete for search.""" """Verify omnibox autocomplete for search."""
search_string = 'youtu' search_string = 'youtu'
verify_string = 'youtube' verify_string = 'youtube'
matches = self._GetOmniboxMatchesFor(search_string) matches = test_utils.GetOmniboxMatchesFor(self, search_string)
# retrieve last contents element. # retrieve last contents element.
matches_description = matches[-1]['contents'].split() matches_description = matches[-1]['contents'].split()
self.assertEqual(verify_string, matches_description[0]) self.assertEqual(verify_string, matches_description[0])
...@@ -263,19 +244,21 @@ class OmniboxTest(pyauto.PyUITest): ...@@ -263,19 +244,21 @@ class OmniboxTest(pyauto.PyUITest):
def _CheckBookmarkResultForVariousInputs(self, url, title, windex=0): def _CheckBookmarkResultForVariousInputs(self, url, title, windex=0):
"""Check if we get the Bookmark for complete and partial inputs.""" """Check if we get the Bookmark for complete and partial inputs."""
# Check if the complete URL would get the bookmark. # Check if the complete URL would get the bookmark.
url_matches = self._GetOmniboxMatchesFor(url, windex=windex) url_matches = test_utils.GetOmniboxMatchesFor(self, url, windex=windex)
self._VerifyHasBookmarkResult(url_matches) self._VerifyHasBookmarkResult(url_matches)
# Check if the complete title would get the bookmark. # Check if the complete title would get the bookmark.
title_matches = self._GetOmniboxMatchesFor(title, windex=windex) title_matches = test_utils.GetOmniboxMatchesFor(self, title, windex=windex)
self._VerifyHasBookmarkResult(title_matches) self._VerifyHasBookmarkResult(title_matches)
# Check if the partial URL would get the bookmark. # Check if the partial URL would get the bookmark.
split_url = urlparse.urlsplit(url) split_url = urlparse.urlsplit(url)
partial_url = self._GetOmniboxMatchesFor(split_url.scheme, windex=windex) partial_url = test_utils.GetOmniboxMatchesFor(self,
split_url.scheme, windex=windex)
self._VerifyHasBookmarkResult(partial_url) self._VerifyHasBookmarkResult(partial_url)
# Check if the partial title would get the bookmark. # Check if the partial title would get the bookmark.
split_title = title.split() split_title = title.split()
search_term = split_title[len(split_title) - 1] search_term = split_title[len(split_title) - 1]
partial_title = self._GetOmniboxMatchesFor(search_term, windex=windex) partial_title = test_utils.GetOmniboxMatchesFor(self,
search_term, windex=windex)
self._VerifyHasBookmarkResult(partial_title) self._VerifyHasBookmarkResult(partial_title)
def _GotContentHistory(self, search_text, url): def _GotContentHistory(self, search_text, url):
...@@ -285,7 +268,7 @@ class OmniboxTest(pyauto.PyUITest): ...@@ -285,7 +268,7 @@ class OmniboxTest(pyauto.PyUITest):
# Omnibox doesn't change results if searching the same text repeatedly. # Omnibox doesn't change results if searching the same text repeatedly.
# So setting '' in omnibox before the next repeated search. # So setting '' in omnibox before the next repeated search.
self.SetOmniboxText('') self.SetOmniboxText('')
matches = self._GetOmniboxMatchesFor(search_text) matches = test_utils.GetOmniboxMatchesFor(self, search_text)
matches_description = [x for x in matches if x['destination_url'] == url] matches_description = [x for x in matches if x['destination_url'] == url]
return 1 == len(matches_description) return 1 == len(matches_description)
......
#!/usr/bin/python #!/usr/bin/python
# Copyright (c) 2010 The Chromium Authors. All rights reserved. # Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
...@@ -8,7 +8,7 @@ import logging ...@@ -8,7 +8,7 @@ import logging
import pyauto_functional # Must be imported before pyauto import pyauto_functional # Must be imported before pyauto
import pyauto import pyauto
import test_utils
class PopupsTest(pyauto.PyUITest): class PopupsTest(pyauto.PyUITest):
"""TestCase for Popup blocking.""" """TestCase for Popup blocking."""
...@@ -141,6 +141,38 @@ class PopupsTest(pyauto.PyUITest): ...@@ -141,6 +141,38 @@ class PopupsTest(pyauto.PyUITest):
self.assertEqual(5, self.GetBrowserWindowCount(), self.assertEqual(5, self.GetBrowserWindowCount(),
msg='Last popup did not launch when the tab is closed.') msg='Last popup did not launch when the tab is closed.')
def testUnblockedPopupShowsInHistory(self):
"""Verify that when you unblock popup, the popup shows in history."""
file_url = self.GetFileURLForDataPath('popup_blocker',
'popup-window-open.html')
self.NavigateToURL(file_url)
self.assertEqual(1, len(self.GetBlockedPopupsInfo()))
self.UnblockAndLaunchBlockedPopup(0)
history = self.GetHistoryInfo().History()
self.assertEqual(2, len(history))
self.assertEqual('Popup Success!', history[0]['title'])
def testBlockedPopupNotShowInHistory(self):
"""Verify that a blocked popup does not show up in history."""
file_url = self.GetFileURLForDataPath('popup_blocker',
'popup-window-open.html')
self.NavigateToURL(file_url)
self.assertEqual(1, len(self.GetBlockedPopupsInfo()))
self.assertEqual(1, len(self.GetHistoryInfo().History()))
def testUnblockedPopupAddedToOmnibox(self):
"""Verify that an unblocked popup shows up in omnibox suggestions."""
file_url = self.GetFileURLForDataPath('popup_blocker',
'popup-window-open.html')
self.NavigateToURL(file_url)
self.assertEqual(1, len(self.GetBlockedPopupsInfo()))
self.UnblockAndLaunchBlockedPopup(0)
search_string = 'data:text/html,<title>Popup Success!</title> \
you should not see this message if popup blocker is enabled'
matches = test_utils.GetOmniboxMatchesFor(self, search_string)
self.assertEqual(search_string, matches[0]['destination_url'])
self.assertEqual(search_string, matches[0]['contents'])
if __name__ == '__main__': if __name__ == '__main__':
pyauto_functional.Main() pyauto_functional.Main()
...@@ -236,6 +236,25 @@ def CallFunctionWithNewTimeout(self, new_timeout, function): ...@@ -236,6 +236,25 @@ def CallFunctionWithNewTimeout(self, new_timeout, function):
function() function()
del timeout_changer del timeout_changer
def GetOmniboxMatchesFor(self, text, windex=0, attr_dict=None):
"""Fetch omnibox matches with the given attributes for the given query.
Args:
text: the query text to use
windex: the window index to work on. Defaults to 0 (first window)
attr_dict: the dictionary of properties to be satisfied
Returns:
a list of match items
"""
self.SetOmniboxText(text, windex=windex)
self.WaitUntilOmniboxQueryDone(windex=windex)
if not attr_dict:
matches = self.GetOmniboxInfo(windex=windex).Matches()
else:
matches = self.GetOmniboxInfo(windex=windex).MatchesWithAttributes(
attr_dict=attr_dict)
return matches
def GetMemoryUsageOfProcess(pid): def GetMemoryUsageOfProcess(pid):
"""Queries the system for the current memory usage of a specified process. """Queries the system for the current memory usage of a specified process.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment