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.
9 import pyauto_functional # Must be imported before pyauto
14 class PyAutoTest(pyauto.PyUITest):
15 """Test functionality of the PyAuto framework."""
17 _EXTRA_CHROME_FLAGS = [
21 '--marvin-the-martian',
24 def ExtraChromeFlags(self):
25 """Ensures Chrome is launched with some custom flags.
27 Overrides the default list of extra flags passed to Chrome. See
28 ExtraChromeFlags() in pyauto.py.
30 return pyauto.PyUITest.ExtraChromeFlags(self) + self._EXTRA_CHROME_FLAGS
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)
39 def testCallOnInvalidWindow(self):
40 """Verify that exception is raised when a browser is missing/invalid."""
41 self.assertEqual(1, self.GetBrowserWindowCount())
43 pyauto_errors.JSONInterfaceError,
44 lambda: self.FindInPage('some text', windex=1)) # invalid window
46 def testJSONInterfaceTimeout(self):
47 """Verify that an exception is raised when the JSON interface times out."""
48 self.ClearEventQueue()
49 self.AddDomEventObserver('foo')
51 pyauto_errors.AutomationCommandTimeout,
52 lambda: self.GetNextEvent(timeout=2000)) # event queue is empty
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)
60 # Verify the amount of time taken for automation timeout
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)
71 if __name__ == '__main__':
72 pyauto_functional.Main()