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 os | 6 import os |
7 import glob | 7 import glob |
8 | 8 |
9 import pyauto_functional # Must be imported before pyauto | 9 import pyauto_functional # Must be imported before pyauto |
10 import pyauto | 10 import pyauto |
| 11 from pyauto_errors import JSONInterfaceError |
11 | 12 |
12 | 13 |
13 class PDFTest(pyauto.PyUITest): | 14 class PDFTest(pyauto.PyUITest): |
14 """PDF related tests | 15 """PDF related tests |
15 | 16 |
16 This test runs only on Google Chrome build, not on Chromium. | 17 This test runs only on Google Chrome build, not on Chromium. |
17 """ | 18 """ |
18 | 19 |
| 20 unloadable_pdfs = [] |
| 21 |
19 def _PerformPDFAction(self, action, tab_index=0, windex=0): | 22 def _PerformPDFAction(self, action, tab_index=0, windex=0): |
20 """Perform an action on a PDF tab. | 23 """Perform an action on a PDF tab. |
21 | 24 |
22 Args: | 25 Args: |
23 action: one of "fitToHeight", "fitToWidth", "ZoomIn", "ZoomOut" | 26 action: one of "fitToHeight", "fitToWidth", "ZoomIn", "ZoomOut" |
24 tab_index: tab index Defaults to 0 | 27 tab_index: tab index Defaults to 0 |
25 windex: window index. Defaults to 0 | 28 windex: window index. Defaults to 0 |
26 """ | 29 """ |
27 # Sometimes the zoom/fit bar is not fully loaded. We need to wait for it to | 30 # Sometimes the zoom/fit bar is not fully loaded. We need to wait for it to |
28 # load before we can perform actions. | 31 # load before we can perform actions. |
29 js = """if (document.getElementsByName("plugin") && | 32 js = """if (document.getElementsByName("plugin") && |
30 document.getElementsByName("plugin")[0]) | 33 document.getElementsByName("plugin")[0]) |
31 { window.domAutomationController.send("true"); } | 34 { window.domAutomationController.send("true"); } |
32 else {window.domAutomationController.send("false"); }""" | 35 else {window.domAutomationController.send("false"); }""" |
33 self.assertTrue(self.WaitUntil(lambda: self.ExecuteJavascript(js, | 36 try: |
34 tab_index=tab_index, windex=windex), expect_retval="true"), | 37 self.assertTrue(self.WaitUntil(lambda: self.ExecuteJavascript(js, |
35 msg='Could not find zoom/fit to page/width bar so we will not be able ' | 38 tab_index=tab_index, windex=windex), expect_retval="true"), |
36 'to peform the requested action') | 39 msg='Could not find zoom/fit to page/width bar so we will not be able ' |
| 40 'to peform the requested action') |
| 41 except JSONInterfaceError as e: |
| 42 # The PDF did not load, add it to the list and move on, we don't want the |
| 43 # test to abort so we can check all of the PDFs. |
| 44 PDFTest.unloadable_pdfs.append(self.GetActiveTabTitle()) |
| 45 return |
37 assert action in ('fitToHeight', 'fitToWidth', 'ZoomIn', 'ZoomOut') | 46 assert action in ('fitToHeight', 'fitToWidth', 'ZoomIn', 'ZoomOut') |
38 js = 'document.getElementsByName("plugin")[0].%s()' % action | 47 js = 'document.getElementsByName("plugin")[0].%s()' % action |
39 # Add an empty string so that there's something to return back | 48 # Add an empty string so that there's something to return back |
40 # (or else it hangs) | 49 # (or else it hangs) |
41 return self.GetDOMValue('%s + ""' % js, tab_index) | 50 return self.GetDOMValue('%s + ""' % js, tab_index) |
42 | 51 |
43 | 52 |
44 def testPDFRunner(self): | 53 def testPDFRunner(self): |
45 """Navigate to pdf files and verify that browser doesn't crash""" | 54 """Navigate to pdf files and verify that browser doesn't crash""" |
46 # bail out if not a branded build | 55 # bail out if not a branded build |
47 properties = self.GetBrowserInfo()['properties'] | 56 properties = self.GetBrowserInfo()['properties'] |
48 if properties['branding'] != 'Google Chrome': | 57 if properties['branding'] != 'Google Chrome': |
49 return | 58 return |
50 breakpad_folder = properties['DIR_CRASH_DUMPS'] | 59 breakpad_folder = properties['DIR_CRASH_DUMPS'] |
51 old_dmp_files = glob.glob(os.path.join(breakpad_folder, '*.dmp')) | 60 old_dmp_files = glob.glob(os.path.join(breakpad_folder, '*.dmp')) |
52 pdf_files_path = os.path.join(self.DataDir(), 'pyauto_private', 'pdf') | 61 pdf_files_path = os.path.join(self.DataDir(), 'pyauto_private', 'pdf') |
53 pdf_files = map(self.GetFileURLForPath, | 62 pdf_files = map(self.GetFileURLForPath, |
54 glob.glob(os.path.join(pdf_files_path, '*.pdf'))) | 63 glob.glob(os.path.join(pdf_files_path, '*.pdf'))) |
55 # Add a pdf file over http:// to the list of pdf files. | 64 # Add a pdf file over http:// to the list of pdf files. |
56 # crbug.com/70454 | 65 # crbug.com/70454 |
57 pdf_files += ['http://www.irs.gov/pub/irs-pdf/fw4.pdf'] | 66 pdf_files += ['http://www.irs.gov/pub/irs-pdf/fw4.pdf'] |
58 | 67 |
59 # Some pdfs cause known crashes. Exclude them. crbug.com/63549 | 68 # Some pdfs cause known crashes. Exclude them. crbug.com/63549 |
60 exclude_list = ('nullip.pdf', 'sample.pdf') | 69 exclude_list = ('nullip.pdf', 'sample.pdf') |
61 pdf_files = [x for x in pdf_files if | 70 pdf_files = [x for x in pdf_files if |
62 os.path.basename(x) not in exclude_list] | 71 os.path.basename(x) not in exclude_list] |
63 | 72 |
| 73 PDFTest.unloadable_pdfs = [] |
64 for url in pdf_files: | 74 for url in pdf_files: |
65 self.AppendTab(pyauto.GURL(url)) | 75 self.AppendTab(pyauto.GURL(url)) |
66 for tab_index in range(1, len(pdf_files) + 1): | 76 for tab_index in range(1, len(pdf_files) + 1): |
67 self.ActivateTab(tab_index) | 77 self.ActivateTab(tab_index) |
68 self._PerformPDFAction('fitToHeight', tab_index=tab_index) | 78 self._PerformPDFAction('fitToHeight', tab_index=tab_index) |
69 self._PerformPDFAction('fitToWidth', tab_index=tab_index) | 79 self._PerformPDFAction('fitToWidth', tab_index=tab_index) |
70 # Assert that there is at least 1 browser window. | 80 # Assert that there is at least 1 browser window. |
71 self.assertTrue(self.GetBrowserWindowCount(), | 81 self.assertTrue(self.GetBrowserWindowCount(), |
72 'Browser crashed, no window is open') | 82 'Browser crashed, no window is open') |
73 # Verify there're no crash dump files | 83 # Verify there're no crash dump files |
74 for dmp_file in glob.glob(os.path.join(breakpad_folder, '*.dmp')): | 84 for dmp_file in glob.glob(os.path.join(breakpad_folder, '*.dmp')): |
75 self.assertTrue(dmp_file in old_dmp_files, | 85 self.assertTrue(dmp_file in old_dmp_files, |
76 msg='Crash dump %s found' % dmp_file) | 86 msg='Crash dump %s found' % dmp_file) |
| 87 self.assertEqual(len(PDFTest.unloadable_pdfs), 0, msg='The following PDFs ' |
| 88 'did not load: %s' % PDFTest.unloadable_pdfs) |
77 | 89 |
78 | 90 |
79 if __name__ == '__main__': | 91 if __name__ == '__main__': |
80 pyauto_functional.Main() | 92 pyauto_functional.Main() |
OLD | NEW |