From 111fa63e08ee1dc70aafd7289f4d81cdf36ef959 Mon Sep 17 00:00:00 2001
From: "jianli@chromium.org"
 <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>
Date: Wed, 5 Aug 2009 20:41:59 +0000
Subject: Fix layout test controller simulation script to make it work for
 worker UI test.

BUG=none
TEST=none

Review URL: http://codereview.chromium.org/160670

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22527 0039d316-1c4b-4281-b951-d872f2087c98
---
 .../test/data/layout_tests/layout_test_controller.html | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/chrome/test/data/layout_tests/layout_test_controller.html b/chrome/test/data/layout_tests/layout_test_controller.html
index 5e14a39..ff9f776 100644
--- a/chrome/test/data/layout_tests/layout_test_controller.html
+++ b/chrome/test/data/layout_tests/layout_test_controller.html
@@ -1,7 +1,10 @@
 <script>
 function LayoutTestController() {
+  this.dump_as_text_ = false;
   this.wait_until_done_ = false;
-  this.dumpAsText = function () { };
+  this.dumpAsText = function () {
+    this.dump_as_text_ = true;
+  };
   this.waitUntilDone = function () {
     this.wait_until_done_ = true;
   };
@@ -9,12 +12,21 @@ function LayoutTestController() {
     var cookie = "%COOKIE%=" + encodeURIComponent(document.firstChild.innerText);
     document.cookie = cookie;
   };
-  this.OnTimerEvent = function () {
+  this.OnCheckFinishEvent = function () {
     // Some layout tests do not call waitUntilDone.  If this is true, we should
     // assume the test is done when it's finished loading.
-    if (!this.wait_until_done_)
+    if (!layoutTestController.wait_until_done_)
       layoutTestController.notifyDone();
   };
+  this.OnTimerEvent = function () {
+    // Some layout tests put the script in the body part which causes it to be
+    // executed after onload being triggered. To handle this, we check first if
+    // dumpAsText() is called.
+    if (layoutTestController.dump_as_text_)
+      layoutTestController.OnCheckFinishEvent();
+    else
+      setTimeout(layoutTestController.OnTimerEvent, 200);
+  };
   this.OnLoadEvent = function (event) {
     // Do a timeout to ensure that we run after all other onload handlers have
     // finished.
-- 
cgit v1.1