| Index: tools/telemetry_auto/telemetry_auto/webui_page.py | 
| diff --git a/tools/telemetry_auto/telemetry_auto/webui_page.py b/tools/telemetry_auto/telemetry_auto/webui_page.py | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..9e9e7d1b45de8cefd8b536925eda4d9e14efe5be | 
| --- /dev/null | 
| +++ b/tools/telemetry_auto/telemetry_auto/webui_page.py | 
| @@ -0,0 +1,77 @@ | 
| +# Copyright (c) 2012 The Chromium Authors. All rights reserved. | 
| +# Use of this source code is governed by a BSD-style license that can be | 
| +# found in the LICENSE file. | 
| +import os | 
| +import sys | 
| + | 
| +import telemetry | 
| +from telemetry import util | 
| + | 
| +class TestException(Exception): | 
| +  def __init__(self, message): | 
| +    self.message = message | 
| +    super(TestException, self).__init__() | 
| + | 
| +  def __str__(self): | 
| +    return repr(self.message) | 
| + | 
| +class WebUIPage(object): | 
| +  def __init__(self, browser): | 
| +    self.browser = browser | 
| +    self.page = None | 
| + | 
| +  def __enter__(self): | 
| +    return self | 
| + | 
| +  def __exit__(self, *args): | 
| +    self.Close() | 
| + | 
| +  def AddTestHelperMethods(self): | 
| +    next_command = """ | 
| +      var _raiseMouseEvent = function(target, var_args) { | 
| +        var event = document.createEvent('MouseEvents'); | 
| +        event.initEvent.apply(event, Array.prototype.slice.call(arguments, 1)); | 
| +        target.dispatchEvent(event); | 
| +      }; | 
| +    """ | 
| +    self.page.runtime.Execute(next_command) | 
| + | 
| +  def ConnectToFirstPage(self, pages): | 
| +    try: | 
| +      self.Close() | 
| +    except Exception: | 
| +      # Ignore exceptions here since the page might be gone by now. | 
| +      pass | 
| + | 
| +    for page in pages: | 
| +      self.page = self.browser.tabs.FindByUrl(page) | 
| +      if not self.page is None: | 
| +        print 'Connected to %s' % page | 
| +        return True | 
| + | 
| +    return False | 
| + | 
| +  def WaitForPageToLoad(self, pages): | 
| +    util.WaitFor( | 
| +        lambda: self.ConnectToFirstPage(pages), | 
| +                timeout=10) | 
| +    if self.page is None: | 
| +      raise TestException('Cannot connect to page(s)') | 
| + | 
| +  def WaitUnitGone(self): | 
| +    util.WaitFor( | 
| +        lambda: not self.ConnectToFirstPage(self.page_urls), | 
| +                timeout=30) | 
| +    if not self.page is None: | 
| +      raise TestException('Cannot disconnect from the current page') | 
| + | 
| +  def ClickOnButton(self, button_id): | 
| +    self.page.runtime.Execute(""" | 
| +      _raiseMouseEvent($('%s'), 'click', true, true); | 
| +    """ % button_id) | 
| + | 
| +  def Close(self): | 
| +    if not self.page is None: | 
| +      self.page.Close() | 
| +      self.page = None | 
| + | 
|  |