HtmlUnit: Taming jQuery

Nearly three weeks ago my wife went on a trip with her sister’s family to visit her grandfather, who was celebrating his ninetieth birthday in Indiana. She was gone for four days, including an entire weekend. Now some guys might take an opportunity like that, call up whatever single friends they have left, and have some fun out on the town. I, on the other hand, realized that it had been a really, really long time since I’d last been able to indulge in an all-night hackathon ;-)

I’ve got a couple of side projects going, but I finally settled on trying to get HtmlUnit to run through the jQuery unit tests. As web applications have gotten more and more complex, they’ve begun to rely on really complex libraries like jQuery, Dojo, Prototype and YUI to abstract away lower-level details like browser incompatibility and tedious APIs like getElementsByTagNameButOnlyOnMonday()… or something like that. I forget. The point is that HtmlUnit has not kept up with this trend (though we’re fairly compatible with Prototype).

Knowing that HtmlUnit has fairly advanced JavaScript support, I figured that full jQuery support couldn’t be more than two days work away. Well, three weeks later, I’m proud to announce that HtmlUnit 1.12 will fully support jQuery, and we can prove it because we run jQuery’s own unit tests as part of HtmlUnit’s unit tests. That’s a lot of units!

So now for the details. The following HtmlUnit bugs had to be fixed in order to reach this point:

  • Bug in string.replace() implementation when using string parameters.
  • Bug in string.replace() implementation when using function parameters.
  • Bug in the scope of eval() invocations in event handlers.
  • Bug in document.getElementsByTagName(‘*’), which was always returning an empty collection.
  • Bug in default option selection in select elements without an explicit selection.
  • Add missing IE-only element.style.filter attribute.
  • Bug in element.innerHTML and element.outerHTML: uppercase tag names when emulating IE.
  • Bug in element.innerHTML and element.outerHTML: don’t quote attributes that don’t contain whitespace when emulating IE.
  • Bug in element.innerHTML and element.outerHTML: always use separate open and close tags (even if the tag is empty).
  • Bug in element.innerHTML, element.innerText and element.outerHTML: escape XML characters inside text nodes.
  • Allow background tasks initiated with setTimeout() to finish if clearTimeout() is called after they have started execution.
  • The method element.style.getPropertyValue(‘foo’) was expecting camel cased property names, rather than delimiter-separated names.

The first three bugs never even made it into a production release, because they were introduced in changes made since the last release (1.11). Only one of the fixes involved adding support for an entirely new feature — the rest were all refinements of existing implementations.

I think this is fairly indicative of how far along HtmlUnit’s DOM and JavaScript support has come, and I expect similar efforts with other JavaScript libraries to become less and less onerous as these refinements get to be smaller and fewer.

Indeed, support for the Prototype library is pretty far along (we also run its unit tests as part of HtmlUnit’s unit tests) and is blocked in many places by small incompatibilities between the Rhino JavaScript engine and the browser JavaScript engines — not by HtmlUnit bugs.

So enjoy the upcoming HtmlUnit release, and let us know if you run into any problems. And if you have the time and inclination, send a couple of patches our way ;-)

About these ads

5 Comments

  1. Marc Guillemot said,

    August 9, 2007 at 1:30 am

    Cool, congratulation!

    Perhaps should you precise that the problems in String.replace have been introduced while fixing a Rhino bug. The one in eval() probably too.

  2. Daniel Gredler said,

    August 9, 2007 at 8:46 am

    Hey Marc,

    I think you just pointed it out :-) Seriously though, the point I was trying to make is that there weren’t all that many bugs that had to be fixed, and most of them were bugs, not missing features.

    There’s a ton of improvements going into 1.12!

  3. Kenny MacLeod said,

    September 2, 2008 at 5:55 am

    Things seem to have taken a step backwards in recent months. HtmlUnit 1.14 will not run jQuery 1.2.6, it fails in jQuery’s isFunction(), which is known to be too clever for its own good.

  4. Daniel Gredler said,

    September 2, 2008 at 9:11 am

    Hi Kenny,

    Give HtmlUnit 2.2 a try, and if it still fails, please try to narrow the issue down and post a bug report to the HtmlUnit bug tracker (http://sourceforge.net/tracker/?atid=448266&group_id=47038&func=browse).

    Thanks!

  5. Hrish said,

    October 18, 2008 at 4:52 am

    Hmm…After trying and failing to get JWebUnit and HttpUnit to work with Jquery (1.2.6), I tried this, but the same problems :( …have reported the issue in detail in the bug tracker.


Follow

Get every new post delivered to your Inbox.

%d bloggers like this: