Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import codecs | 6 import codecs |
| 7 import os | 7 import os |
| 8 import unittest | 8 import unittest |
| 9 | 9 |
| 10 import pyauto_functional | 10 import pyauto_functional |
| 11 import pyauto | 11 import pyauto |
| 12 import pyauto_errors | |
| 12 import test_utils | 13 import test_utils |
| 13 | 14 |
| 14 | 15 |
| 15 class FindMatchTests(pyauto.PyUITest): | 16 class FindMatchTests(pyauto.PyUITest): |
| 16 | 17 |
| 17 # Data dir where all find test data files are kept | 18 # Data dir where all find test data files are kept |
| 18 find_test_data_dir = 'find_in_page' | 19 find_test_data_dir = 'find_in_page' |
| 19 | 20 |
| 20 def testCanFindMatchCount(self): | 21 def testCanFindMatchCount(self): |
| 21 """Verify Find match count for valid search""" | 22 """Verify Find match count for valid search""" |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 # Finding previous occurrence | 208 # Finding previous occurrence |
| 208 back_occurence_dict = self.FindInPage('2010 Pro Bowl', | 209 back_occurence_dict = self.FindInPage('2010 Pro Bowl', |
| 209 find_next = True, forward = False) | 210 find_next = True, forward = False) |
| 210 self.assertEqual(first_occurence_dict, back_occurence_dict, | 211 self.assertEqual(first_occurence_dict, back_occurence_dict, |
| 211 'We have only one occurrence in this page so ' | 212 'We have only one occurrence in this page so ' |
| 212 'first and back search coordinates must be same') | 213 'first and back search coordinates must be same') |
| 213 | 214 |
| 214 def _VerifySearchInPDFURL(self, url, word, expected_count): | 215 def _VerifySearchInPDFURL(self, url, word, expected_count): |
| 215 """Verify that we can find in a pdf file.""" | 216 """Verify that we can find in a pdf file.""" |
| 216 self.NavigateToURL(url) | 217 self.NavigateToURL(url) |
| 217 search_count = self.FindInPage(word)['match_count'] | 218 # Check for JSONInterfaceError thrown when FindInPage called before page |
| 219 # loaded. | |
|
kkania
2011/12/15 00:41:36
Add an explanation about the bug and a reference t
vclarke1
2011/12/15 00:52:09
Done.
| |
| 220 num_loops = 10 | |
| 221 for loop in range(num_loops): | |
| 222 try: | |
| 223 search_count = self.FindInPage(word, timeout=1000)['match_count'] | |
| 224 break | |
| 225 except pyauto_errors.JSONInterfaceError: | |
| 226 if loop == num_loops - 1: | |
| 227 raise | |
| 218 self.assertEqual(expected_count, search_count, | 228 self.assertEqual(expected_count, search_count, |
| 219 'Failed to find in the %s pdf file' % url) | 229 'Failed to find in the %s pdf file' % url) |
| 220 | 230 |
| 221 def testSearchInPDF(self): | 231 def testSearchInPDF(self): |
| 222 """Verify that we can find in a pdf file. | 232 """Verify that we can find in a pdf file. |
| 223 | 233 |
| 224 Only for Google Chrome builds (Chromium builds do not have internal pdf). | 234 Only for Google Chrome builds (Chromium builds do not have internal pdf). |
| 225 """ | 235 """ |
| 226 # bail out if not a branded build | 236 # bail out if not a branded build |
| 227 properties = self.GetBrowserInfo()['properties'] | 237 properties = self.GetBrowserInfo()['properties'] |
| 228 if properties['branding'] != 'Google Chrome': | 238 if properties['branding'] != 'Google Chrome': |
| 229 return | 239 return |
| 230 # Search in pdf file over file://. | 240 # Search in pdf file over file://. |
| 231 file_url = self.GetFileURLForDataPath('plugin', 'Embed.pdf') | 241 file_url = self.GetFileURLForDataPath('plugin', 'Embed.pdf') |
| 232 self._VerifySearchInPDFURL(file_url, 'adobe', 8) | 242 self._VerifySearchInPDFURL(file_url, 'adobe', 8) |
| 233 | 243 |
| 234 # Disabling this test crbug.com/70927 | |
| 235 # Search in pdf file over http://. | 244 # Search in pdf file over http://. |
| 236 # http_url = 'http://www.irs.gov/pub/irs-pdf/fw4.pdf' | 245 http_url = 'http://www.irs.gov/pub/irs-pdf/fw4.pdf' |
| 237 # self._VerifySearchInPDFURL(http_url, 'Allowances', 16) | 246 self._VerifySearchInPDFURL(http_url, 'Allowances', 16) |
| 238 | 247 |
| 239 if __name__ == '__main__': | 248 if __name__ == '__main__': |
| 240 pyauto_functional.Main() | 249 pyauto_functional.Main() |
| OLD | NEW |