OLD | NEW |
| (Empty) |
1 #!/usr/bin/env python | |
2 # Copyright (c) 2012 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 | |
8 import pyauto_functional # must be imported before pyauto | |
9 | |
10 import chromeos.file_browser | |
11 import pyauto | |
12 import test_utils | |
13 | |
14 | |
15 class DocViewingTest(pyauto.PyUITest): | |
16 """Basic tests for ChromeOS document viewing. | |
17 | |
18 Requires ChromeOS to be logged in. | |
19 """ | |
20 | |
21 def setUp(self): | |
22 pyauto.PyUITest.setUp(self) | |
23 extension_path = '/opt/google/chrome/extensions'\ | |
24 '/gbkeegbaiigmenfmjfclcdgdpimamgkj.crx' | |
25 # If crx file with doesn't exist, component extensions should be used. | |
26 if os.path.exists(extension_path): | |
27 ext_id = self.InstallExtension(extension_path, from_webstore=True) | |
28 self.assertTrue(ext_id, msg='Failed to install extension %s' % | |
29 extension_path) | |
30 | |
31 def _GetFullPageFileBrowser(self): | |
32 """Display the full page file browser. | |
33 | |
34 Returns: | |
35 ChromeosFileBrowser object. | |
36 """ | |
37 self.NavigateToURL('chrome://files/#/Downloads') | |
38 executor = pyauto.PyUITest.JavascriptExecutorInTab(self) | |
39 file_browser = chromeos.file_browser.FileBrowser(self, executor) | |
40 if file_browser.WaitUntilInitialized(): | |
41 return file_browser | |
42 else: | |
43 return None | |
44 | |
45 def testOpenOfficeFiles(self): | |
46 """Test we can open office files from the file manager.""" | |
47 path = os.path.abspath(os.path.join(self.DataDir(), | |
48 'pyauto_private', 'office')) | |
49 # Copy sample files to Downloads directory. | |
50 for (path, dirs, private_office_files) in os.walk(path): | |
51 # Open sample files: .ppt, .pptx, .doc, .docx, xls, xlsx. | |
52 for fname in private_office_files: | |
53 test_utils.CopyFileFromDataDirToDownloadDir(self, os.path.join(path, | |
54 fname)) | |
55 file_browser = self._GetFullPageFileBrowser() | |
56 self.assertTrue(file_browser, msg='File browser failed to initialize.') | |
57 | |
58 def _SelectFile(): | |
59 try: | |
60 file_browser.Select(fname) | |
61 return True | |
62 except AssertionError: | |
63 return False | |
64 | |
65 self.assertTrue(self.WaitUntil(_SelectFile), | |
66 msg='"%s" does not exist.' % fname) | |
67 file_browser.ExecuteDefaultTask() | |
68 self.assertTrue(self.WaitUntil(self.GetActiveTabTitle, | |
69 expect_retval=fname), | |
70 msg='"%s" does not open.' % fname) | |
71 # Close the document viewing tab after use. | |
72 self.CloseTab(tab_index=1) | |
73 | |
74 | |
75 if __name__ == '__main__': | |
76 pyauto_functional.Main() | |
OLD | NEW |