Don't use Element.prototype.classList in TestFailures
authoraroben@apple.com <aroben@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Jul 2011 21:49:53 +0000 (21:49 +0000)
committeraroben@apple.com <aroben@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Jul 2011 21:49:53 +0000 (21:49 +0000)
Safari 5 doesn't support it.

Fixes <http://webkit.org/b/64550> Can't expand flaky tests on TestFailures page in Safari 5

Reviewed by Daniel Bates.

* BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/Utilities.js:
(Element.prototype.hasStyleClass):
(Element.prototype.addStyleClass):
(Element.prototype.removeStyleClass):
(Element.prototype.toggleStyleClass):
Added these helper functions which simulate classList functionality.

* BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/Utilities_unittests.js:
Added. Tests for the above.

* BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/ViewController.js:
(ViewController.prototype._domForPossiblyFlakyTests): Changed to use
toggleStyleClass/hasStyleClass instead of classList.

* BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/run-unittests.html:
Added Utilities_unittests.js, and reordered the tested files to be in
roughly dependency order (i.e., the lowest-level files are imported
and tested first).

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@91029 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/Utilities.js
Tools/BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/Utilities_unittests.js [new file with mode: 0644]
Tools/BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/ViewController.js
Tools/BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/run-unittests.html
Tools/ChangeLog

index 2c960e6e2683ff22f25cbd9719cba88390345cf4..36dc7b992d837f2a177a3fbac0dfb5e7a5fc7b64 100644 (file)
@@ -140,6 +140,29 @@ Array.prototype.last = function() {
     return this[this.length - 1];
 }
 
+Element.prototype.hasStyleClass = function(klass) {
+    var regex = new RegExp('\\b' + klass + '\\b');
+    return regex.test(this.className);
+}
+
+Element.prototype.addStyleClass = function(klass) {
+    if (this.hasStyleClass(klass))
+        return;
+    this.className += ' ' + klass;
+}
+
+Element.prototype.removeStyleClass = function(klass) {
+    var regex = new RegExp('\\b' + klass + '\\b', 'g');
+    this.className = this.className.replace(regex, '');
+}
+
+Element.prototype.toggleStyleClass = function(klass) {
+    if (this.hasStyleClass(klass))
+        this.removeStyleClass(klass);
+    else
+        this.addStyleClass(klass);
+}
+
 Node.prototype.appendChildren = function(children) {
     for (var i = 0; i < children.length; ++i)
         this.appendChild(children[i]);
diff --git a/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/Utilities_unittests.js b/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/Utilities_unittests.js
new file mode 100644 (file)
index 0000000..4c19a4f
--- /dev/null
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+(function() {
+
+module('Utilities');
+
+test('hasStyleClass', 11, function() {
+    var element = document.createElement('div');
+
+    ok(!element.hasStyleClass('foo'));
+    ok(!element.hasStyleClass('bar'));
+
+    element.className = 'foo';
+    ok(element.hasStyleClass('foo'))
+    ok(!element.hasStyleClass('bar'));
+
+    element.className = 'foo foo';
+    ok(element.hasStyleClass('foo'))
+    ok(!element.hasStyleClass('bar'));
+
+    element.className = 'foo bar';
+    ok(element.hasStyleClass('foo'))
+    ok(element.hasStyleClass('bar'));
+    ok(!element.hasStyleClass('baz'));
+
+    element.className = 'food';
+    ok(!element.hasStyleClass('foo'));
+    ok(element.hasStyleClass('food'));
+});
+
+test('addStyleClass', 4, function() {
+    var element = document.createElement('div');
+
+    element.addStyleClass('foo');
+    equal(element.className, ' foo');
+
+    element.addStyleClass('foo');
+    equal(element.className, ' foo');
+
+    element.addStyleClass('bar');
+    equal(element.className, ' foo bar');
+
+    element.addStyleClass('foo');
+    equal(element.className, ' foo bar');
+});
+
+test('removeStyleClass', 8, function() {
+    var element = document.createElement('div');
+
+    element.removeStyleClass('foo');
+    equal(element.className, '');
+
+    element.className = 'foo';
+    element.removeStyleClass('foo');
+    equal(element.className, '');
+
+    element.className = ' foo';
+    element.removeStyleClass('foo');
+    equal(element.className, ' ');
+
+    element.className = 'foo foo';
+    element.removeStyleClass('foo');
+    equal(element.className, ' ');
+
+    element.className = 'foo bar';
+    element.removeStyleClass('foo');
+    equal(element.className, ' bar');
+
+    element.className = 'foo bar foo bar';
+    element.removeStyleClass('bar');
+    equal(element.className, 'foo  foo ');
+
+    element.className = 'food';
+    element.removeStyleClass('foo');
+    equal(element.className, 'food');
+
+    element.className = 'foo';
+    element.removeStyleClass('food');
+    equal(element.className, 'foo');
+});
+
+test('toggleStyleClass', 5, function() {
+    var element = document.createElement('div');
+
+    element.toggleStyleClass('foo');
+    equal(element.className, ' foo');
+
+    element.toggleStyleClass('foo');
+    equal(element.className, ' ');
+
+    element.className = 'bar';
+    element.toggleStyleClass('foo');
+    equal(element.className, 'bar foo');
+
+    element.className = 'food';
+    element.toggleStyleClass('foo');
+    equal(element.className, 'food foo');
+
+    element.className = 'foo';
+    element.toggleStyleClass('food');
+    equal(element.className, 'foo food');
+});
+
+})();
index f6b1a24ef5be7c8d25c4a77059be15e8607f86d8..d306d2a2ace2c9f666045a07a7414d7e764ca55f 100644 (file)
@@ -436,8 +436,8 @@ ViewController.prototype = {
             failureList.className = 'flakiness-examples-list';
 
             disclosureTriangle.addEventListener('click', function() {
-                item.classList.toggle('expanded');
-                if (!item.classList.contains('expanded')) {
+                item.toggleStyleClass('expanded');
+                if (!item.hasStyleClass('expanded')) {
                     failureList.style.height = '';
                     return;
                 }
index 36c3756160a1d870e0b77d644c631fce77d4dc23..b760b2bd1a39c42f843f1b5e70ca92b5e4aa52bb 100644 (file)
 <ol id="qunit-tests"></ol>
 <!-- FIXME: We should have tests for these files! -->
 <script src="Bugzilla.js"></script>
+
 <script src="Utilities.js"></script>
+<script src="Utilities_unittests.js"></script>
+
+<script src="NewBugForm.js"></script>
+<script src="NewBugForm_unittests.js"></script>
+
+<script src="FlakyLayoutTestDetector.js"></script>
+<script src="FlakyLayoutTestDetector_unittests.js"></script>
 
 <script src="Buildbot.js"></script>
 <script src="Buildbot_unittests.js"></script>
+
 <script src="Builder.js"></script>
 <script src="Builder_unittests.js"></script>
-<script src="FlakyLayoutTestDetector.js"></script>
-<script src="FlakyLayoutTestDetector_unittests.js"></script>
-<script src="NewBugForm.js"></script>
-<script src="NewBugForm_unittests.js"></script>
+
 <script src="TestFailureBugForm.js"></script>
 <script src="TestFailureBugForm_unittests.js"></script>
 </body>
index ede5235265b629a013c0f297c8aeb8ce21ed6aae..283c5346e4412e71e3612c33098b78ba339c02f0 100644 (file)
@@ -1,3 +1,32 @@
+2011-07-14  Adam Roben  <aroben@apple.com>
+
+        Don't use Element.prototype.classList in TestFailures
+
+        Safari 5 doesn't support it.
+
+        Fixes <http://webkit.org/b/64550> Can't expand flaky tests on TestFailures page in Safari 5
+
+        Reviewed by Daniel Bates.
+
+        * BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/Utilities.js:
+        (Element.prototype.hasStyleClass):
+        (Element.prototype.addStyleClass):
+        (Element.prototype.removeStyleClass):
+        (Element.prototype.toggleStyleClass):
+        Added these helper functions which simulate classList functionality.
+
+        * BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/Utilities_unittests.js:
+        Added. Tests for the above.
+
+        * BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/ViewController.js:
+        (ViewController.prototype._domForPossiblyFlakyTests): Changed to use
+        toggleStyleClass/hasStyleClass instead of classList.
+
+        * BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/run-unittests.html:
+        Added Utilities_unittests.js, and reordered the tested files to be in
+        roughly dependency order (i.e., the lowest-level files are imported
+        and tested first).
+
 2011-07-14  Eric Seidel  <eric@webkit.org>
 
         NRWT doesn't store the svn revision in full_results.json on chromium-win