More and more of the UI in Chrome and ChromeOS is built using DOMUI. DOMUI is the name of Chrome UI built using HTML, JS and CSS with the ability to comunicate to with the browser process using chrome.send calls. Example of UIs implemented using DOMUI consists of the New Tab Page, History, Downloads, Extensions, about:versions and many others. ChromeOS is also in the process of using DOMUI for menus.

Testing these UIs is possible today using UITest with DOM automation enabled. However, writing these test require generating strings of JavaScript code that is (using the automation provider) asynchronously evaluated in the browser tab and the result of that is asynchronously returned.

There are 3 problems with this approach:

Setting up the browser tab requires some C++ and a lot of waiting for the document to be ready.

A string representing the JavaScript needs to be generated.

The evaluation is async making test harder to write and more flaky.

Requirements

Make it easier to write tests by

Allowing writing the test in JavaScript. After all, we need to use JavaScript to interact with the UI so it is only natural to do the test with it. Also dynamic languages are very good for writing unit tests.

Provide a new test class that is specialized for writing tests for DOMUI. It would wrap up all of the boiler plate code and it should...

Allow any DOM UI to be tested by simply providing the URL of the page and...

Provide the URL or path to the test file and...

allow other utility js files to be injected

It might also be interesting to allow a blank page to be used and just inject all the js and css we care about. This could be useful for testing widgets in isolation.

Solution

Create a new test class similar to ExtensionBrowserTest but optimized for DOMUI. This class would have a RunDOMUITest (similar to RunExtensionTest) which would:

Open a tab and navigate to a URL.

Inject one or more javascript files.

Run tests provided by the JavaScript files (ExtensionBrowerTest uses a global array of functions to run called test)

This is better than what we have now for a few reasons:

We do not have to open a new browser for every single test. We can run multiple tests in the same web page.

We can write the test in JS, reducing the work needed to write tests.

We do not have to generate js code and evaluate it using the automation provider for every single test (these are async)