| 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 time | |
| 7 import unittest | |
| 8 | |
| 9 import pyauto_functional # Must be imported before pyauto | |
| 10 import pyauto | |
| 11 import pyauto_errors | |
| 12 | |
| 13 | |
| 14 class PyAutoTest(pyauto.PyUITest): | |
| 15 """Test functionality of the PyAuto framework.""" | |
| 16 | |
| 17 _EXTRA_CHROME_FLAGS = [ | |
| 18 '--scooby-doo=123', | |
| 19 '--donald-duck=cool', | |
| 20 '--super-mario', | |
| 21 '--marvin-the-martian', | |
| 22 ] | |
| 23 | |
| 24 def ExtraChromeFlags(self): | |
| 25 """Ensures Chrome is launched with some custom flags. | |
| 26 | |
| 27 Overrides the default list of extra flags passed to Chrome. See | |
| 28 ExtraChromeFlags() in pyauto.py. | |
| 29 """ | |
| 30 return pyauto.PyUITest.ExtraChromeFlags(self) + self._EXTRA_CHROME_FLAGS | |
| 31 | |
| 32 def testSetCustomChromeFlags(self): | |
| 33 """Ensures that Chrome can be launched with custom flags.""" | |
| 34 self.NavigateToURL('about://version') | |
| 35 for flag in self._EXTRA_CHROME_FLAGS: | |
| 36 self.assertEqual(self.FindInPage(flag)['match_count'], 1, | |
| 37 msg='Missing expected Chrome flag "%s"' % flag) | |
| 38 | |
| 39 def testCallOnInvalidWindow(self): | |
| 40 """Verify that exception is raised when a browser is missing/invalid.""" | |
| 41 self.assertEqual(1, self.GetBrowserWindowCount()) | |
| 42 self.assertRaises( | |
| 43 pyauto_errors.JSONInterfaceError, | |
| 44 lambda: self.FindInPage('some text', windex=1)) # invalid window | |
| 45 | |
| 46 def testJSONInterfaceTimeout(self): | |
| 47 """Verify that an exception is raised when the JSON interface times out.""" | |
| 48 self.ClearEventQueue() | |
| 49 self.AddDomEventObserver('foo') | |
| 50 self.assertRaises( | |
| 51 pyauto_errors.AutomationCommandTimeout, | |
| 52 lambda: self.GetNextEvent(timeout=2000)) # event queue is empty | |
| 53 | |
| 54 def testActionTimeoutChanger(self): | |
| 55 """Verify that ActionTimeoutChanger works.""" | |
| 56 new_timeout = 1000 # 1 sec | |
| 57 changer = pyauto.PyUITest.ActionTimeoutChanger(self, new_timeout) | |
| 58 self.assertEqual(self._automation_timeout, new_timeout) | |
| 59 | |
| 60 # Verify the amount of time taken for automation timeout | |
| 61 then = time.time() | |
| 62 self.assertRaises( | |
| 63 pyauto_errors.AutomationCommandTimeout, | |
| 64 lambda: self.ExecuteJavascript('invalid js should timeout')) | |
| 65 elapsed = time.time() - then | |
| 66 self.assertTrue(elapsed < new_timeout / 1000.0 + 2, # margin of 2 secs | |
| 67 msg='ActionTimeoutChanger did not work. ' | |
| 68 'Automation timeout took %f secs' % elapsed) | |
| 69 | |
| 70 | |
| 71 if __name__ == '__main__': | |
| 72 pyauto_functional.Main() | |
| OLD | NEW |