[Webkit-unassigned] [Bug 8843] New: new tool for building objective-c test cases in html (using embedded python)

bugzilla-daemon at opendarwin.org bugzilla-daemon at opendarwin.org
Wed May 10 23:52:43 PDT 2006


           Summary: new tool for building objective-c test cases in html
                    (using embedded python)
           Product: WebKit
           Version: 420+ (nightly)
          Platform: Macintosh
        OS/Version: Mac OS X 10.0
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Tools
        AssignedTo: webkit-unassigned at opendarwin.org
        ReportedBy: speth at end.com

I've been working on a way to write test cases for areas of the Objective-C API
that would be easier and more flexible than patching DumpRenderTree.  What I've
come up with is a WebKit plugin that allows you to embed python (and PyObjC)
scripts into the HTML of the tests, so it gets executed when the test page is
loaded.  This provides an extremely flexible way to build tests which run in
the browser, but can access the resources necessary to test the obj-c API.

The plugin itself is written in Python using PyObjC.  To build, run "python
setup.py py2app" in the source directory.  You have to have Python (2.3.5 is
ok) and an up-to-date install of PyObjC.  It will create a "dist" directory and
put the plugin (pythonscript.plugin) there.  To install, copy the plugin to
~/Library/Internet Plug-Ins

Use: the plugin should be embedded in the test html file using a line like:

  <embed name="pythonscript" width="1" height="1"

where the dimensions can be larger for testing things like embedded views. 
Elsewhere in the file, you put your python code inside a script tag, like this:

  <script type="application/x-pythonscript">
      class MyWindowDelegate (NSObject):
          def windowWillClose_(self, window):
              NSLog('%s is closing' % `window`)
      delegate = MyWindowDelegate.alloc().init()

Indentation of the entire block is relative to the first line of code in the
block, so the above example would be valid.  Code inside a script tag like this
will be executed in the global namespace (the document namespace), like you
were typing it at the interpreter prompt.  So it's a good place for imports and
class definitions.

You can also attach python scripts to the event triggers on an element, like

  <div __init__="x = 0" __mouseover__="self.setValue_forKey_('test%d' % x,
'innerHTML')" __mouseout__="x += 1">test</div>

The script stored in the __init__ attribute will be executed once, just after
the page loads.  The other ones are executed when their events occur.  (The
plugin translates "__mouseover__" to "onmouseover" and wraps the value in a
javascript call to itself.)  You can use "\n" in the scripts for multiple
lines.  Code attached to an element like this executes in its own local
namespace associated with the element.  Its globals are set to the document's
namespace.  (So, this div's scripts could use the "delegate" variable from the
first example, but the delegate wouldn't be able to use the div's "x"

Requirements: Python 2.3.5 or higher, PyObjC (latest from svn)

Security: this is a huge security problem!  don't use this plugin when browsing
or viewing anything other than known and trusted test files.  it can execute
arbitrary code with your user's priveledges.

Examples: there are a few examples, which I'll try to document well.

This is very alpha, so be warned, though I don't think it will destroy anything
(unless your test file tells it to).  I'd really like to hear feedback about
this.  Is it potentially useful?, what needs improving, etc.

Configure bugmail: http://bugzilla.opendarwin.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

More information about the webkit-unassigned mailing list