Skip to content

Commit

Permalink
ui:tests: make doh runner work inside ghost
Browse files Browse the repository at this point in the history
It looks a few lines of code, but it is a bit tricky.

1/ original runner.html runs in synchronous mode.
The implementation of xhr sync mode in webkit make processEvents block,
which prevent twisted to actually serve the xhr :-(
2/ firebug.js does not know about webkit, and thus will override console.log (hence the useCustomLogger:true)
This is the reason why we have to copy the whole runner.htm inside our code.
  • Loading branch information
Pierre Tardy committed Nov 20, 2012
1 parent 9ca8b1b commit 0f951a0
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 1 deletion.
3 changes: 3 additions & 0 deletions master/buildbot/test/unit/test_www_ui.py
Expand Up @@ -32,3 +32,6 @@ class TestGhostPy(www.WwwTestMixin,www.WwwGhostTestMixin, unittest.TestCase):
def test_home(self):
return self.doPageLoadTest("/",
( "tests.assertEqual(bb_router.base_url, '%(url)s')"%self.__dict__,))
def test_doh_dojo_tests_colors(self):
"""simple test to make sure our doh tester work. tests an already working dojo unit test"""
return self.doDohPageLoadRunnerTests()
11 changes: 10 additions & 1 deletion master/buildbot/test/util/txghost.py
Expand Up @@ -329,7 +329,16 @@ def evaluate(self, script):
"""
return (self.main_frame.evaluateJavaScript("%s" % script),
self._release_last_resources())

def inject_script(self, script):
self.evaluate(
"""(function(){e = document.createElement("script");
e.type = "text/javascript";
e.textContent = JSON.parse("%s")
e.charset = "utf-8";
document.getElementsByTagName("head")[0].appendChild(e);
})()
"""%(json.dumps(script).replace('"','\\"'))
)
def evaluate_js_file(self, path, encoding='utf-8'):
"""Evaluates javascript file at given path in current frame.
Raises native IOException in case of invalid file.
Expand Down
13 changes: 13 additions & 0 deletions master/buildbot/test/util/www.py
Expand Up @@ -199,3 +199,16 @@ def doPageLoadTest(self, ui_path, js_assertions, selector_to_wait = "#content di
for js in js_assertions:
result, _ = self.ghost.evaluate(doh_boilerplate%dict(js=js))
self.assertEqual(result, "OK")

@defer.inlineCallbacks
def doDohPageLoadRunnerTests(self, doh_tests="dojo/tests/colors"):
self.ghost.wait_timeout = 200
yield self.ghost.open(urljoin(self.url,"static/js.built/lib/tests/runner.html"))
result_selector = "#testListContainer table tfoot tr.inProgress"
self.ghost.inject_script("require(['dojo', 'doh', 'dojo/window'], function(dojo,doh){ require(['"+doh_tests+"'], function(){doh.run()})});")
result_selector = "#testListContainer table tfoot tr.inProgress"
yield self.ghost.wait_for_selector(result_selector)
result, _ = self.ghost.evaluate("dojo.map(dojo.query('"+result_selector+" .failure'),function(a){return a.textContent;});")
self.assertEqual(result, ['0','0'])
result, _ = self.ghost.evaluate("dojo.map(dojo.query('"+result_selector+" td'),function(a){return a.textContent;});")
print "\n",str(result[1]).strip(),
62 changes: 62 additions & 0 deletions master/buildbot/www/static/js/lib/tests/runner.html
@@ -0,0 +1,62 @@
<!DOCTYPE html>
<!-- html Code derived from doh's runner.html, included in buildbot has a way to circuvent integration issues with ghost
The original code is under 3 clauses BSD which is compatible with GPLv2 of buildbot.
-->
<html style="height:100%;">
<head>
<title>The buildbot Unit Test Harness</title>

<script type="text/javascript" src="../../dojo/dojo.js" data-dojo-config="async: true,useCustomLogger:true"></script>
</head>
<table id="testLayout" cellpadding="0" cellspacing="0" style="margin: 0;">
<tr valign="top" height="10">
<td colspan="2"><div id="progressOuter"></div></td>
</tr>
<tr valign="top" style="border: 0; padding: 0; margin: 0;">
<td style="border: 0; padding: 0; margin: 0; height:100%;">
<div id="testListContainer">
<table cellpadding="0" cellspacing="0" border="0"
width="100%" id="testList" style="margin: 0;">
<thead>
<tr id="testListHeader" style="border: 0; padding: 0; margin: 0;" >
<th> </th>
<th width="20">
<input type="checkbox" checked="1"
onclick="doh.toggleRunAll();"/>
</th>
<th width="*" style="text-align: left;">test</th>
<th width="50">time</th>
</tr>
</thead>
<tbody valign="top">
<tr id="groupTemplate" style="display: none;">
<td style="font-family: Arial; width: 15px;">&#9658;</td>
<td>
<input type="checkbox" checked="1"/>
</td>
<td>group name</td>
<td>10ms</td>
</tr>
<tr id="testTemplate" style="display: none;">
<td> </td>
<td> </td>
<td style="padding-left: 20px;">test name</td>
<td>10ms</td>
</tr>
</tbody>
</table>
</div>
</td>
<td style="height: 100%;">
<div class="tabBody"
style="z-index: 1;">
<pre id="logBody"></pre>
<div id="perfTestsBody" style="background-color: white;"></div>
</div>
</td>
</tr>
</table>
<body style="height: 100%;">
</body>
</html>

0 comments on commit 0f951a0

Please sign in to comment.