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

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

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

Powered by Google App Engine
This is Rietveld 408576698