| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2010 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 | 11 |
| 12 | 12 |
| 13 class PDFTest(pyauto.PyUITest): | 13 class PDFTest(pyauto.PyUITest): |
| 14 """PDF related tests | 14 """PDF related tests |
| 15 | 15 |
| 16 This test runs only on Google Chrome build, not on Chromium. | 16 This test runs only on Google Chrome build, not on Chromium. |
| 17 """ | 17 """ |
| 18 | 18 |
| 19 def _PerformPDFAction(self, action, tab_index=0, windex=0): |
| 20 """Perform an action on a PDF tab. |
| 21 |
| 22 Args: |
| 23 action: one of "fitToHeight", "fitToWidth", "ZoomIn", "ZoomOut" |
| 24 tab_index: tab index Defaults to 0 |
| 25 windex: window index. Defaults to 0 |
| 26 """ |
| 27 assert action in ('fitToHeight', 'fitToWidth', 'ZoomIn', 'ZoomOut') |
| 28 js = 'document.getElementsByName("plugin")[0].%s()' % action |
| 29 # Add an empty string so that there's something to return back |
| 30 # (or else it hangs) |
| 31 return self.GetDOMValue('%s + ""' % js, 0, tab_index) |
| 32 |
| 33 |
| 19 def testPDFRunner(self): | 34 def testPDFRunner(self): |
| 20 """Navigate to pdf files and verify that browser doesn't crash""" | 35 """Navigate to pdf files and verify that browser doesn't crash""" |
| 21 # bail out if not a branded build | 36 # bail out if not a branded build |
| 22 properties = self.GetBrowserInfo()['properties'] | 37 properties = self.GetBrowserInfo()['properties'] |
| 23 if properties['branding'] != 'Google Chrome': | 38 if properties['branding'] != 'Google Chrome': |
| 24 return | 39 return |
| 25 pdf_files_path = os.path.join(self.DataDir(), 'pyauto_private', 'pdf') | 40 pdf_files_path = os.path.join(self.DataDir(), 'pyauto_private', 'pdf') |
| 26 pdf_files = glob.glob(os.path.join(pdf_files_path, '*.pdf')) | 41 pdf_files = glob.glob(os.path.join(pdf_files_path, '*.pdf')) |
| 27 for pdf_file in pdf_files: | 42 for pdf_file in pdf_files: |
| 28 url = self.GetFileURLForPath(os.path.join(pdf_files_path, pdf_file)) | 43 url = self.GetFileURLForPath(os.path.join(pdf_files_path, pdf_file)) |
| 29 self.AppendTab(pyauto.GURL(url)) | 44 self.AppendTab(pyauto.GURL(url)) |
| 45 for tab_index in range(1, len(pdf_files) + 1): |
| 46 self.ActivateTab(tab_index) |
| 47 self._PerformPDFAction('fitToHeight', tab_index=tab_index) |
| 48 self._PerformPDFAction('fitToWidth', tab_index=tab_index) |
| 30 # Assert that there is at least 1 browser window. | 49 # Assert that there is at least 1 browser window. |
| 31 self.assertTrue(self.GetBrowserWindowCount(), | 50 self.assertTrue(self.GetBrowserWindowCount(), |
| 32 'Browser crashed, no window is open') | 51 'Browser crashed, no window is open') |
| 33 | 52 |
| 34 | 53 |
| 35 if __name__ == '__main__': | 54 if __name__ == '__main__': |
| 36 pyauto_functional.Main() | 55 pyauto_functional.Main() |
| OLD | NEW |