Chromium Code Reviews| 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 glob | 6 import glob |
| 7 import logging | 7 import logging |
| 8 import os | 8 import os |
| 9 import shutil | |
| 10 import tempfile | |
| 9 | 11 |
| 10 import pyauto_functional # Must be imported before pyauto | 12 import pyauto_functional # Must be imported before pyauto |
| 11 import pyauto | 13 import pyauto |
| 12 | 14 |
| 13 | 15 |
| 14 class TranslateTest(pyauto.PyUITest): | 16 class TranslateTest(pyauto.PyUITest): |
| 15 """Tests that translate works correctly""" | 17 """Tests that translate works correctly""" |
| 16 | 18 |
| 17 spanish = 'es' | 19 spanish = 'es' |
| 18 after_translate = 'AFTER_TRANSLATE' | 20 after_translate = 'AFTER_TRANSLATE' |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 373 for language in corp_dir: | 375 for language in corp_dir: |
| 374 files = glob.glob(os.path.join(language, '*.html*')) | 376 files = glob.glob(os.path.join(language, '*.html*')) |
| 375 lang_code = os.path.basename(language) | 377 lang_code = os.path.basename(language) |
| 376 logging.debug('Starting language %s' % lang_code) | 378 logging.debug('Starting language %s' % lang_code) |
| 377 # Translate each html file in the language directory. | 379 # Translate each html file in the language directory. |
| 378 for lang_file in files: | 380 for lang_file in files: |
| 379 logging.debug('Starting file %s' % lang_file) | 381 logging.debug('Starting file %s' % lang_file) |
| 380 lang_file = self.GetFileURLForPath(lang_file) | 382 lang_file = self.GetFileURLForPath(lang_file) |
| 381 self._AssertTranslateWorks(lang_file, lang_code) | 383 self._AssertTranslateWorks(lang_file, lang_code) |
| 382 | 384 |
| 385 def _CreateCrazyDownloads(self): | |
| 386 """Doownload files with filenames containing special chars. | |
| 387 The files are created on the fly and cleaned after use. | |
| 388 """ | |
|
Alyssa
2010/08/13 21:05:27
This is now done in 3 files. Is it worth refactori
Nirnimesh
2010/08/13 22:18:16
I won't mind putting this function in pyauto.py, b
| |
| 389 download_dir = self.GetDownloadDirectory().value() | |
| 390 filename = os.path.join(self.DataDir(), 'downloads', 'crazy_filenames.txt') | |
| 391 crazy_filenames = self.EvalDataFrom(filename) | |
| 392 logging.info('Testing with %d crazy filenames' % len(crazy_filenames)) | |
| 393 | |
| 394 def _CreateFile(name): | |
| 395 """Create and fill the given file with some junk.""" | |
| 396 fp = open(name, 'w') # name could be unicode | |
| 397 print >>fp, 'This is a junk file named %s. ' % repr(name) * 100 | |
| 398 fp.close() | |
| 399 | |
| 400 # Temp dir for hosting crazy filenames. | |
| 401 temp_dir = tempfile.mkdtemp(prefix='download') | |
| 402 # Filesystem-interfacing functions like os.listdir() need to | |
| 403 # be given unicode strings to "do the right thing" on win. | |
| 404 # Ref: http://boodebr.org/main/python/all-about-python-and-unicode | |
| 405 try: | |
| 406 for filename in crazy_filenames: # filename is unicode. | |
| 407 utf8_filename = filename.encode('utf-8') | |
| 408 file_path = os.path.join(temp_dir, utf8_filename) | |
| 409 _CreateFile(os.path.join(temp_dir, filename)) # unicode file. | |
| 410 file_url = self.GetFileURLForPath(file_path) | |
| 411 downloaded_file = os.path.join(download_dir, filename) | |
| 412 os.path.exists(downloaded_file) and os.remove(downloaded_file) | |
| 413 self.DownloadAndWaitForStart(file_url) | |
| 414 self.WaitForAllDownloadsToComplete() | |
| 415 | |
| 416 finally: | |
| 417 shutil.rmtree(unicode(temp_dir)) # unicode so that win treats nicely. | |
| 418 | |
| 419 def testHistoryNotTranslated(self): | |
| 420 """Tests navigating to History page with other languages.""" | |
| 421 # Build the history with non-English content. | |
| 422 history_file = os.path.join( | |
| 423 self.DataDir(), 'translate', 'crazy_history.txt') | |
| 424 history_items = self.EvalDataFrom(history_file) | |
| 425 for history_item in history_items: | |
| 426 self.AddHistoryItem(history_item) | |
| 427 # Navigate to a page that triggers the translate bar so we can verify that | |
| 428 # it disappears on the history page. | |
| 429 self._NavigateAndWaitForBar(self._GetDefaultSpanishURL()) | |
| 430 self.NavigateToURL('chrome://history/') | |
| 431 self.WaitForInfobarCount(0) | |
| 432 self.assertFalse('translate_bar' in self.GetTranslateInfo()) | |
| 433 | |
| 434 def testDownloadsNotTranslated(self): | |
| 435 """Tests navigating to the Downloads page with other languages.""" | |
| 436 # Build the download history with non-English content. | |
| 437 self._CreateCrazyDownloads() | |
| 438 # Navigate to a page that triggers the translate bar so we can verify that | |
| 439 # it disappears on the downloads page. | |
| 440 self._NavigateAndWaitForBar(self._GetDefaultSpanishURL()) | |
| 441 self.NavigateToURL('chrome://downloads/') | |
| 442 self.WaitForInfobarCount(0) | |
| 443 self.assertFalse('translate_bar' in self.GetTranslateInfo()) | |
| 444 | |
| 383 | 445 |
| 384 if __name__ == '__main__': | 446 if __name__ == '__main__': |
| 385 pyauto_functional.Main() | 447 pyauto_functional.Main() |
| OLD | NEW |