diff --git a/java/test/org/openqa/selenium/javascript/ClosureTestStatement.java b/java/test/org/openqa/selenium/javascript/ClosureTestStatement.java index 444a2213f4784..921826005986b 100644 --- a/java/test/org/openqa/selenium/javascript/ClosureTestStatement.java +++ b/java/test/org/openqa/selenium/javascript/ClosureTestStatement.java @@ -18,7 +18,6 @@ package org.openqa.selenium.javascript; import static java.lang.System.nanoTime; -import static java.util.Objects.requireNonNull; import static java.util.concurrent.TimeUnit.NANOSECONDS; import java.net.URL; @@ -67,12 +66,17 @@ public void evaluate() throws Throwable { } JavascriptExecutor executor = (JavascriptExecutor) driver; - // Avoid Safari JS leak between tests. - executor.executeScript("if (window && window.top) window.top.G_testRunner = null"); + // Avoid Safari JS leak between tests - clear both Closure and QUnit runners + executor.executeScript( + "if (window && window.top) { window.top.G_testRunner = null; window.top.QUnitTestRunner =" + + " null; }"); driver.get(testUrl.toString()); - while (!getBoolean(executor, Query.IS_FINISHED)) { + // Detect which test runner is being used and poll accordingly + TestRunner runner = detectTestRunner(executor); + + while (!runner.isFinished(executor)) { long elapsedTime = NANOSECONDS.toSeconds(nanoTime() - start); if (timeoutSeconds > 0 && elapsedTime > timeoutSeconds) { throw new JavaScriptAssertionError( @@ -88,32 +92,84 @@ public void evaluate() throws Throwable { TimeUnit.MILLISECONDS.sleep(100); } - if (!getBoolean(executor, Query.IS_SUCCESS)) { - String report = getString(executor, Query.GET_REPORT); + if (!runner.isSuccess(executor)) { + String report = runner.getReport(executor); throw new JavaScriptAssertionError(report); } } - private boolean getBoolean(JavascriptExecutor executor, Query query) { - return (Boolean) - requireNonNull( - executor.executeScript(query.script), - () -> "JS returned null instead of boolean: " + query.script); - } + private TestRunner detectTestRunner(JavascriptExecutor executor) throws InterruptedException { + // It may take a while for the test runner to initialise + for (int i = 0; i < 50; i++) { + boolean hasQUnit = + (boolean) + executor.executeScript("return !!(window.top.QUnitTestRunner || window.QUnit);"); + if (hasQUnit) { + LOG.fine("Detected QUnit test runner"); + return TestRunner.QUNIT; + } + + boolean hasClosure = (boolean) executor.executeScript("return !!window.top.G_testRunner;"); + if (Boolean.TRUE.equals(hasClosure)) { + LOG.fine("Detected Closure test runner"); + return TestRunner.CLOSURE; + } + + TimeUnit.MILLISECONDS.sleep(100); + } - private String getString(JavascriptExecutor executor, Query query) { - return (String) executor.executeScript(query.script); + // Default to Closure for backward compatibility + LOG.warning("Could not detect test runner, defaulting to Closure"); + return TestRunner.CLOSURE; } - private enum Query { - IS_FINISHED("return !!tr && tr.isFinished();"), - IS_SUCCESS("return !!tr && tr.isSuccess();"), - GET_REPORT("return tr.getReport(true);"); + private enum TestRunner { + CLOSURE { + private static final String PREFIX = "var tr = window.top.G_testRunner;"; + + @Override + boolean isFinished(JavascriptExecutor executor) { + return Boolean.TRUE.equals( + executor.executeScript(PREFIX + "return !!tr && tr.isFinished();")); + } - private final String script; + @Override + boolean isSuccess(JavascriptExecutor executor) { + return Boolean.TRUE.equals( + executor.executeScript(PREFIX + "return !!tr && tr.isSuccess();")); + } - Query(String script) { - this.script = "var tr = window.top.G_testRunner;" + script; - } + @Override + String getReport(JavascriptExecutor executor) { + return (String) executor.executeScript(PREFIX + "return tr.getReport(true);"); + } + }, + + QUNIT { + private static final String PREFIX = "var tr = window.top.QUnitTestRunner;"; + + @Override + boolean isFinished(JavascriptExecutor executor) { + return Boolean.TRUE.equals( + executor.executeScript(PREFIX + "return !!tr && tr.isFinished();")); + } + + @Override + boolean isSuccess(JavascriptExecutor executor) { + return Boolean.TRUE.equals( + executor.executeScript(PREFIX + "return !!tr && tr.isSuccess();")); + } + + @Override + String getReport(JavascriptExecutor executor) { + return (String) executor.executeScript(PREFIX + "return tr.getReport();"); + } + }; + + abstract boolean isFinished(JavascriptExecutor executor); + + abstract boolean isSuccess(JavascriptExecutor executor); + + abstract String getReport(JavascriptExecutor executor); } } diff --git a/javascript/atoms/test/action_test.html b/javascript/atoms/test/action_test.html index 22d1f0934c939..55e2beba5c0cc 100644 --- a/javascript/atoms/test/action_test.html +++ b/javascript/atoms/test/action_test.html @@ -1,7 +1,11 @@ + action_test.html + + + +
+
diff --git a/javascript/atoms/test/attribute_test.html b/javascript/atoms/test/attribute_test.html index 9b6c3a53f378d..03e4e6facd5e9 100644 --- a/javascript/atoms/test/attribute_test.html +++ b/javascript/atoms/test/attribute_test.html @@ -18,46 +18,53 @@ + attribute_test.html + + + - +
+
Cheddar
diff --git a/javascript/atoms/test/child_locator_test.html b/javascript/atoms/test/child_locator_test.html index 0b3cde336c7e8..d64fc915b165a 100644 --- a/javascript/atoms/test/child_locator_test.html +++ b/javascript/atoms/test/child_locator_test.html @@ -1,192 +1,197 @@ + child_locator_test.html + + + +
+

Not really!

@@ -211,4 +216,3 @@ this is a link - diff --git a/javascript/atoms/test/click_link_test.html b/javascript/atoms/test/click_link_test.html index bed5b033fac37..c96c219c0248f 100644 --- a/javascript/atoms/test/click_link_test.html +++ b/javascript/atoms/test/click_link_test.html @@ -2,7 +2,11 @@ + click_link_test.html + + + @@ -29,7 +32,7 @@ var findElements = bot.locators.findElements; var log = goog.log.getLogger('click_link_test'); - function setUp() { + QUnit.testStart(function() { iframe = bot.locators.findElement({id: 'iframe'}); iframeWindow = goog.dom.getFrameContentWindow(iframe); otherFrame = bot.locators.findElement({id: 'other'}); @@ -43,9 +46,7 @@ link.blur(); link2.blur(); window.focus(); - - return waitForLoad(iframe); - } + }); function checkActionCompatibility(action) { if (action == bot.action.tap) { @@ -60,16 +61,6 @@ }); } - /** - * Creates a promise that will be resolved after a 0-based setTimeout. - * This is used by tests to yield for a DOM reflow. The promise must - * is resolved after the 0-based timeout to trigger the browser's default - * yield (~4ms); resolving the promise immediately could potentially - * run on the very next tick (depending on the browser) and prevent the - * reflow that we are trying to yield to. - * - * @return {!goog.Promise} A new promise. - */ function timeout() { return new goog.Promise(function(done) { setTimeout(done, 0); @@ -87,217 +78,239 @@ return target; } - function executesDefaultHandler(action) { + function executesDefaultHandler(assert, action) { if (!checkActionCompatibility(action)) { + assert.ok(true, 'Action not supported, skipping'); return; } var clickTarget = findElement({id: 'clickTarget'}); - // Make sure no other event listeners are interfering. goog.events.removeAll(clickTarget); - // Use a random value as we don't want to keep an old - // misleading hash in the url. var targetHref = '#' + Math.random(); clickTarget.href = targetHref; action(clickTarget); - return timeout().then(function() { - assertEquals(targetHref, window.location.hash); + var done = assert.async(); + timeout().then(function() { + assert.strictEqual(window.location.hash, targetHref); + done(); }); } - var testClickExecutesDefaultHandler = - goog.partial(executesDefaultHandler, bot.action.click); + QUnit.test('click executes default handler', function(assert) { + executesDefaultHandler(assert, bot.action.click); + }); - var testTapExecutesDefaultHandler = - goog.partial(executesDefaultHandler, bot.action.tap); + QUnit.test('tap executes default handler', function(assert) { + executesDefaultHandler(assert, bot.action.tap); + }); - function nestedElementExecutesDefaultHandler(action) { + function nestedElementExecutesDefaultHandler(assert, action) { if (!checkActionCompatibility(action)) { + assert.ok(true, 'Action not supported, skipping'); return; } var parent = findElement({id: 'clickTargetWithAChild'}); - // Use a random value as we don't want to keep an old - // misleading hash in the url. var targetHref = '#' + Math.random(); parent.href = targetHref; var clickTarget = goog.dom.getFirstElementChild(parent); action(clickTarget); - return timeout().then(function() { - assertEquals(targetHref, window.location.hash); + var done = assert.async(); + timeout().then(function() { + assert.strictEqual(window.location.hash, targetHref); + done(); }); } - var testClickNestedElementExecutesDefaultHandler = - goog.partial(nestedElementExecutesDefaultHandler, bot.action.click); + QUnit.test('click nested element executes default handler', function(assert) { + nestedElementExecutesDefaultHandler(assert, bot.action.click); + }); - var testTapNestedElementExecutesDefaultHandler = - goog.partial(nestedElementExecutesDefaultHandler, bot.action.tap); + QUnit.test('tap nested element executes default handler', function(assert) { + nestedElementExecutesDefaultHandler(assert, bot.action.tap); + }); - function correctlyResolvesEmptyFragment(action) { + function correctlyResolvesEmptyFragment(assert, action) { if (!checkActionCompatibility(action)) { + assert.ok(true, 'Action not supported, skipping'); return; } - // A bug in the closure goog.Uri module once prevented this from working. var clickTarget = findElement({id: 'clickTarget'}); - // Make sure no other event listeners are interfering. goog.events.removeAll(clickTarget); clickTarget.href = '#'; action(clickTarget); - return timeout().then(function() { + var done = assert.async(); + timeout().then(function() { var windowHref = window.location.href; - assertEquals('#', windowHref.charAt(windowHref.length - 1)); + assert.strictEqual(windowHref.charAt(windowHref.length - 1), '#'); + done(); }); } - var testClickCorrectlyResolvesEmptyFragment = - goog.partial(correctlyResolvesEmptyFragment, bot.action.click); + QUnit.test('click correctly resolves empty fragment', function(assert) { + correctlyResolvesEmptyFragment(assert, bot.action.click); + }); - var testTapCorrectlyResolvesEmptyFragment = - goog.partial(correctlyResolvesEmptyFragment, bot.action.tap); + QUnit.test('tap correctly resolves empty fragment', function(assert) { + correctlyResolvesEmptyFragment(assert, bot.action.tap); + }); - function absoluteUrlInAnIframeExecutesDefaultHandler(action) { + function absoluteUrlInAnIframeExecutesDefaultHandler(assert, action) { if (!checkActionCompatibility(action)) { + assert.ok(true, 'Action not supported, skipping'); return; } - var domHelper = goog.dom.getDomHelper(iframeWindow); - var clickTarget = domHelper.getElement('iframeClickTarget'); + var done = assert.async(); + waitForLoad(iframe).then(function() { + var domHelper = goog.dom.getDomHelper(iframeWindow); + var clickTarget = domHelper.getElement('iframeClickTarget'); - // Use a random value as we don't want to keep an old - // misleading hash in the url. - var targetHref = goog.Uri.resolve(iframeWindow.location, - '#' + Math.random()).toString(); + var targetHref = goog.Uri.resolve(iframeWindow.location, + '#' + Math.random()).toString(); - // Let's make sure it is an absolute url. - assertContains('http', targetHref); + assert.ok(targetHref.indexOf('http') !== -1); - clickTarget.href = targetHref; - action(clickTarget); - return timeout().then(function() { - assertEquals(targetHref, iframeWindow.location.href); + clickTarget.href = targetHref; + action(clickTarget); + timeout().then(function() { + assert.strictEqual(iframeWindow.location.href, targetHref); + done(); + }); }); } - var testClickAbsoluteUrlInAnIframeExecutesDefaultHandler = - goog.partial(absoluteUrlInAnIframeExecutesDefaultHandler, - bot.action.click); + QUnit.test('click absolute url in an iframe executes default handler', function(assert) { + absoluteUrlInAnIframeExecutesDefaultHandler(assert, bot.action.click); + }); - var testTapAbsoluteUrlInAnIframeExecutesDefaultHandler = - goog.partial(absoluteUrlInAnIframeExecutesDefaultHandler, - bot.action.tap); + QUnit.test('tap absolute url in an iframe executes default handler', function(assert) { + absoluteUrlInAnIframeExecutesDefaultHandler(assert, bot.action.tap); + }); - function absoluteServerPathAnchorInAnIframeExecutesDefaultHandler(action) { + function absoluteServerPathAnchorInAnIframeExecutesDefaultHandler(assert, action) { if (!checkActionCompatibility(action)) { + assert.ok(true, 'Action not supported, skipping'); return; } - var domHelper = goog.dom.getDomHelper(iframeWindow); - var clickTarget = domHelper.getElement('iframeClickTarget'); - - // Use a random value as we don't want to keep an old - // misleading hash in the url. - var testPath = window.location.pathname; - var targetHref = testPath.substring(0, testPath.lastIndexOf('/')) + - '/testdata/click_iframe.html#' + Math.random(); - clickTarget.href = targetHref; - action(clickTarget); - return timeout().then(function() { - assertContains(targetHref, iframeWindow.location.href); + var done = assert.async(); + waitForLoad(iframe).then(function() { + var domHelper = goog.dom.getDomHelper(iframeWindow); + var clickTarget = domHelper.getElement('iframeClickTarget'); + + var testPath = window.location.pathname; + var targetHref = testPath.substring(0, testPath.lastIndexOf('/')) + + '/testdata/click_iframe.html#' + Math.random(); + clickTarget.href = targetHref; + action(clickTarget); + timeout().then(function() { + assert.ok(iframeWindow.location.href.indexOf(targetHref) !== -1); + done(); + }); }); } - var testClickAbsoluteServerPathAnchorInAnIframeExecutesDefaultHandler = - goog.partial(absoluteServerPathAnchorInAnIframeExecutesDefaultHandler, - bot.action.click); + QUnit.test('click absolute server path anchor in an iframe executes default handler', function(assert) { + absoluteServerPathAnchorInAnIframeExecutesDefaultHandler(assert, bot.action.click); + }); - var testTapAbsoluteServerPathAnchorInAnIframeExecutesDefaultHandler = - goog.partial(absoluteServerPathAnchorInAnIframeExecutesDefaultHandler, - bot.action.tap); + QUnit.test('tap absolute server path anchor in an iframe executes default handler', function(assert) { + absoluteServerPathAnchorInAnIframeExecutesDefaultHandler(assert, bot.action.tap); + }); - function relativeServerPathAnchorInAnIframeExecutesDefaultHandler(action) { + function relativeServerPathAnchorInAnIframeExecutesDefaultHandler(assert, action) { if (!checkActionCompatibility(action)) { + assert.ok(true, 'Action not supported, skipping'); return; } - var domHelper = goog.dom.getDomHelper(iframeWindow); - var clickTarget = domHelper.getElement('iframeClickTarget'); + var done = assert.async(); + waitForLoad(iframe).then(function() { + var domHelper = goog.dom.getDomHelper(iframeWindow); + var clickTarget = domHelper.getElement('iframeClickTarget'); - // Use a random value as we don't want to keep an old - // misleading hash in the url. - var targetHref = 'click_iframe.html#' + Math.random(); - clickTarget.href = targetHref; - action(clickTarget); - return timeout().then(function() { - assertContains(targetHref, iframeWindow.location.href); + var targetHref = 'click_iframe.html#' + Math.random(); + clickTarget.href = targetHref; + action(clickTarget); + timeout().then(function() { + assert.ok(iframeWindow.location.href.indexOf(targetHref) !== -1); + done(); + }); }); } - var testClickRelativeServerPathAnchorInAnIframeExecutesDefaultHandler = - goog.partial(relativeServerPathAnchorInAnIframeExecutesDefaultHandler, - bot.action.click); + QUnit.test('click relative server path anchor in an iframe executes default handler', function(assert) { + relativeServerPathAnchorInAnIframeExecutesDefaultHandler(assert, bot.action.click); + }); - var testTapRelativeServerPathAnchorInAnIframeExecutesDefaultHandler = - goog.partial(relativeServerPathAnchorInAnIframeExecutesDefaultHandler, - bot.action.tap); + QUnit.test('tap relative server path anchor in an iframe executes default handler', function(assert) { + relativeServerPathAnchorInAnIframeExecutesDefaultHandler(assert, bot.action.tap); + }); - function hashOnlyAnchorInAnIframeExecutesDefaultHandler(action) { + function hashOnlyAnchorInAnIframeExecutesDefaultHandler(assert, action) { if (!checkActionCompatibility(action)) { + assert.ok(true, 'Action not supported, skipping'); return; } - var domHelper = goog.dom.getDomHelper(iframeWindow); - var clickTarget = domHelper.getElement('iframeClickTarget'); + var done = assert.async(); + waitForLoad(iframe).then(function() { + var domHelper = goog.dom.getDomHelper(iframeWindow); + var clickTarget = domHelper.getElement('iframeClickTarget'); - // Use a random value as we don't want to keep an old - // misleading hash in the url. - var targetHref = '#' + Math.random(); - clickTarget.href = targetHref; - action(clickTarget); - return timeout().then(function() { - assertEquals(targetHref, iframeWindow.location.hash); + var targetHref = '#' + Math.random(); + clickTarget.href = targetHref; + action(clickTarget); + timeout().then(function() { + assert.strictEqual(iframeWindow.location.hash, targetHref); + done(); + }); }); } - var testClickHashOnlyAnchorInAnIframeExecutesDefaultHandler = - goog.partial(hashOnlyAnchorInAnIframeExecutesDefaultHandler, - bot.action.click); + QUnit.test('click hash only anchor in an iframe executes default handler', function(assert) { + hashOnlyAnchorInAnIframeExecutesDefaultHandler(assert, bot.action.click); + }); - var testTapHashOnlyAnchorInAnIframeExecutesDefaultHandler = - goog.partial(hashOnlyAnchorInAnIframeExecutesDefaultHandler, - bot.action.tap); + QUnit.test('tap hash only anchor in an iframe executes default handler', function(assert) { + hashOnlyAnchorInAnIframeExecutesDefaultHandler(assert, bot.action.tap); + }); - function nestedElementInAnIframeExecutesDefaultHandler(action) { + function nestedElementInAnIframeExecutesDefaultHandler(assert, action) { if (!checkActionCompatibility(action)) { + assert.ok(true, 'Action not supported, skipping'); return; } - var domHelper = goog.dom.getDomHelper(iframeWindow); - var parent = domHelper.getElement('iframeClickTargetWithAChild'); - var clickTarget = goog.dom.getFirstElementChild(parent); - - // Use a random value as we don't want to keep an old - // misleading hash in the url. - var targetHref = '#' + Math.random(); - parent.href = targetHref; - action(clickTarget); - return timeout().then(function() { - assertEquals(targetHref, iframeWindow.location.hash); + var done = assert.async(); + waitForLoad(iframe).then(function() { + var domHelper = goog.dom.getDomHelper(iframeWindow); + var parent = domHelper.getElement('iframeClickTargetWithAChild'); + var clickTarget = goog.dom.getFirstElementChild(parent); + + var targetHref = '#' + Math.random(); + parent.href = targetHref; + action(clickTarget); + timeout().then(function() { + assert.strictEqual(iframeWindow.location.hash, targetHref); + done(); + }); }); } - var testClickNestedElementInAnIframeExecutesDefaultHandler = - goog.partial(nestedElementInAnIframeExecutesDefaultHandler, - bot.action.click); + QUnit.test('click nested element in an iframe executes default handler', function(assert) { + nestedElementInAnIframeExecutesDefaultHandler(assert, bot.action.click); + }); - var testTapHashNestedElementInAnIframeExecutesDefaultHandler = - goog.partial(nestedElementInAnIframeExecutesDefaultHandler, - bot.action.tap); + QUnit.test('tap hash nested element in an iframe executes default handler', function(assert) { + nestedElementInAnIframeExecutesDefaultHandler(assert, bot.action.tap); + }); - function doesNotFollowLinkWhenEventDefaultPrevented(action) { + function doesNotFollowLinkWhenEventDefaultPrevented(assert, action) { if (!checkActionCompatibility(action)) { + assert.ok(true, 'Action not supported, skipping'); return; } var clickTarget = findElement({id: 'clickTarget'}); - // Make sure no other event listeners are interfering. goog.events.removeAll(clickTarget); var previousLocation = window.location.href; @@ -307,21 +320,24 @@ }); action(clickTarget); - return timeout().then(function() { - assertEquals(previousLocation, window.location.href); + var done = assert.async(); + timeout().then(function() { + assert.strictEqual(window.location.href, previousLocation); + done(); }); } - var testClickDoesNotFollowLinkWhenEventDefaultPrevented = - goog.partial(doesNotFollowLinkWhenEventDefaultPrevented, - bot.action.click); + QUnit.test('click does not follow link when event default prevented', function(assert) { + doesNotFollowLinkWhenEventDefaultPrevented(assert, bot.action.click); + }); - var testTapDoesNotFollowLinkWhenEventDefaultPrevented = - goog.partial(doesNotFollowLinkWhenEventDefaultPrevented, - bot.action.tap); + QUnit.test('tap does not follow link when event default prevented', function(assert) { + doesNotFollowLinkWhenEventDefaultPrevented(assert, bot.action.tap); + }); - function doNotFollowLinkWhenEventDefaultPreventedWithInlineHandler(action) { + function doNotFollowLinkWhenEventDefaultPreventedWithInlineHandler(assert, action) { if (!checkActionCompatibility(action)) { + assert.ok(true, 'Action not supported, skipping'); return; } var clickTarget = findElement({id: 'clickTargetWithInlineHandler'}); @@ -330,189 +346,228 @@ clickTarget.href = '#' + Math.random(); action(clickTarget); - return timeout().then(function() { - assertEquals(previousLocation, window.location.href); + var done = assert.async(); + timeout().then(function() { + assert.strictEqual(window.location.href, previousLocation); + done(); }); } - var testClickDoNotFollowLinkWhenEventDefaultPreventedWithInlineHandler = - goog.partial(doNotFollowLinkWhenEventDefaultPreventedWithInlineHandler, - bot.action.click); + QUnit.test('click do not follow link when event default prevented with inline handler', function(assert) { + doNotFollowLinkWhenEventDefaultPreventedWithInlineHandler(assert, bot.action.click); + }); - var testTapDoNotFollowLinkWhenEventDefaultPreventedWithInlineHandler = - goog.partial(doNotFollowLinkWhenEventDefaultPreventedWithInlineHandler, - bot.action.tap); + QUnit.test('tap do not follow link when event default prevented with inline handler', function(assert) { + doNotFollowLinkWhenEventDefaultPreventedWithInlineHandler(assert, bot.action.tap); + }); - function doesNotFollowLinkWhenNoHrefIsGiven(action) { + function doesNotFollowLinkWhenNoHrefIsGiven(assert, action) { if (!checkActionCompatibility(action)) { + assert.ok(true, 'Action not supported, skipping'); return; } var clickTarget = findElement({id: 'clickTargetWithNoHref'}); - // Make sure no other event listeners are interfering. goog.events.removeAll(clickTarget); var previousLocation = window.location.href; action(clickTarget); - return timeout().then(function() { - assertEquals(previousLocation, window.location.href); + var done = assert.async(); + timeout().then(function() { + assert.strictEqual(window.location.href, previousLocation); + done(); }); } - var testClickDoesNotFollowLinkWhenNoHrefIsGiven = goog.partial( - doesNotFollowLinkWhenNoHrefIsGiven, bot.action.click); + QUnit.test('click does not follow link when no href is given', function(assert) { + doesNotFollowLinkWhenNoHrefIsGiven(assert, bot.action.click); + }); - var testTapDoesNotFollowLinkWhenNoHrefIsGiven = goog.partial( - doesNotFollowLinkWhenNoHrefIsGiven, bot.action.tap); + QUnit.test('tap does not follow link when no href is given', function(assert) { + doesNotFollowLinkWhenNoHrefIsGiven(assert, bot.action.tap); + }); - function nestedElelementDoesNotFollowLinkWhenNoHrefIsGiven(action) { + function nestedElelementDoesNotFollowLinkWhenNoHrefIsGiven(assert, action) { if (!checkActionCompatibility(action)) { + assert.ok(true, 'Action not supported, skipping'); return; } var clickTarget = findElement({id: 'clickTargetWithAChildAndNoHref'}); var previousLocation = window.location.href; action(clickTarget); - assertContains(previousLocation, window.location.href); + assert.ok(window.location.href.indexOf(previousLocation) !== -1); } - var testClickNestedElelementDoesNotFollowLinkWhenNoHrefIsGiven = - goog.partial(nestedElelementDoesNotFollowLinkWhenNoHrefIsGiven, - bot.action.click); + QUnit.test('click nested elelment does not follow link when no href is given', function(assert) { + nestedElelementDoesNotFollowLinkWhenNoHrefIsGiven(assert, bot.action.click); + }); - var testTapNestedElelementDoesNotFollowLinkWhenNoHrefIsGiven = - goog.partial(nestedElelementDoesNotFollowLinkWhenNoHrefIsGiven, - bot.action.tap); + QUnit.test('tap nested elelment does not follow link when no href is given', function(assert) { + nestedElelementDoesNotFollowLinkWhenNoHrefIsGiven(assert, bot.action.tap); + }); - function doesNotEncodeReservedButAllowedCharactersInQuery(action) { + function doesNotEncodeReservedButAllowedCharactersInQuery(assert, action) { if (!checkActionCompatibility(action)) { + assert.ok(true, 'Action not supported, skipping'); return; } - // A bug in the closure goog.Uri module once prevented this from working. - var domHelper = goog.dom.getDomHelper(iframeWindow); - var clickTarget = domHelper.getElement('iframeClickTarget'); + var done = assert.async(); + waitForLoad(iframe).then(function() { + var domHelper = goog.dom.getDomHelper(iframeWindow); + var clickTarget = domHelper.getElement('iframeClickTarget'); - var targetHref = '?a=?/+'; - clickTarget.href = targetHref; - action(clickTarget); - return waitForLoad(iframe).then(function() { - assertEquals(targetHref, iframeWindow.location.search); + var targetHref = '?a=?/+'; + clickTarget.href = targetHref; + action(clickTarget); + waitForLoad(iframe).then(function() { + assert.strictEqual(iframeWindow.location.search, targetHref); + done(); + }); }); } - var testClickDoesNoteEncodeReservedButAllowedCharactersInQuery = - goog.partial(doesNotEncodeReservedButAllowedCharactersInQuery, - bot.action.click); + QUnit.test('click does not encode reserved but allowed characters in query', function(assert) { + doesNotEncodeReservedButAllowedCharactersInQuery(assert, bot.action.click); + }); - var testTapDoesNoteEncodeReservedButAllowedCharactersInQuery = - goog.partial(doesNotEncodeReservedButAllowedCharactersInQuery, - bot.action.tap); + QUnit.test('tap does not encode reserved but allowed characters in query', function(assert) { + doesNotEncodeReservedButAllowedCharactersInQuery(assert, bot.action.tap); + }); - function absoluteAnchorInAnIframeExecutesDefaultHandler(action) { + function absoluteAnchorInAnIframeExecutesDefaultHandler(assert, action) { if (!checkActionCompatibility(action)) { + assert.ok(true, 'Action not supported, skipping'); return; } - var clickTarget = getClickTarget('testdata/click_destination.html'); - var targetHref = clickTarget.href; - action(clickTarget); - return waitForLoad(iframe).then(function() { - assertEquals(targetHref, iframeWindow.location.href); + var done = assert.async(); + waitForLoad(iframe).then(function() { + var clickTarget = getClickTarget('testdata/click_destination.html'); + var targetHref = clickTarget.href; + action(clickTarget); + waitForLoad(iframe).then(function() { + assert.strictEqual(iframeWindow.location.href, targetHref); + done(); + }); }); } - var testClickAbsoluteAnchorInAnIframeExecutesDefaultHandler = - goog.partial(absoluteAnchorInAnIframeExecutesDefaultHandler, - bot.action.click); + QUnit.test('click absolute anchor in an iframe executes default handler', function(assert) { + absoluteAnchorInAnIframeExecutesDefaultHandler(assert, bot.action.click); + }); - var testTapAbsoluteAnchorInAnIframeExecutesDefaultHandler = - goog.partial(absoluteAnchorInAnIframeExecutesDefaultHandler, - bot.action.tap); + QUnit.test('tap absolute anchor in an iframe executes default handler', function(assert) { + absoluteAnchorInAnIframeExecutesDefaultHandler(assert, bot.action.tap); + }); - function linkThatCausesContentToLoadInAnotherFrame(action) { + function linkThatCausesContentToLoadInAnotherFrame(assert, action) { if (!checkActionCompatibility(action)) { + assert.ok(true, 'Action not supported, skipping'); return; } - var clickTarget = getClickTarget('testdata/click_destination.html'); - var targetHref = clickTarget.href; - clickTarget.target = 'other'; - action(clickTarget); - return waitForLoad(otherFrame).then(function() { - assertEquals(targetHref, otherFrameWindow.location.href); + var done = assert.async(); + waitForLoad(iframe).then(function() { + var clickTarget = getClickTarget('testdata/click_destination.html'); + var targetHref = clickTarget.href; + clickTarget.target = 'other'; + action(clickTarget); + waitForLoad(otherFrame).then(function() { + assert.strictEqual(otherFrameWindow.location.href, targetHref); + done(); + }); }); } - var testClickLinkThatCausesContentToLoadInAnotherFrame = - goog.partial(linkThatCausesContentToLoadInAnotherFrame, - bot.action.click); + QUnit.test('click link that causes content to load in another frame', function(assert) { + linkThatCausesContentToLoadInAnotherFrame(assert, bot.action.click); + }); - var testTapLinkThatCausesContentToLoadInAnotherFrame = - goog.partial(linkThatCausesContentToLoadInAnotherFrame, - bot.action.tap); + QUnit.test('tap link that causes content to load in another frame', function(assert) { + linkThatCausesContentToLoadInAnotherFrame(assert, bot.action.tap); + }); - function onSelfPageReloadsPage(action) { + function onSelfPageReloadsPage(assert, action) { if (!checkActionCompatibility(action)) { + assert.ok(true, 'Action not supported, skipping'); return; } - var clickTarget = getClickTarget(iframeWindow.location.href); - var targetHref = clickTarget.href; - action(clickTarget); - return waitForLoad(iframe).then(function() { - assertEquals(targetHref, iframeWindow.location.href); + var done = assert.async(); + waitForLoad(iframe).then(function() { + var clickTarget = getClickTarget(iframeWindow.location.href); + var targetHref = clickTarget.href; + action(clickTarget); + waitForLoad(iframe).then(function() { + assert.strictEqual(iframeWindow.location.href, targetHref); + done(); + }); }); } - var testClickOnSelfPageReloadsPage = goog.partial(onSelfPageReloadsPage, - bot.action.click); + QUnit.test('click on self page reloads page', function(assert) { + onSelfPageReloadsPage(assert, bot.action.click); + }); - var testTapOnSelfPageReloadsPage = goog.partial(onSelfPageReloadsPage, - bot.action.tap); + QUnit.test('tap on self page reloads page', function(assert) { + onSelfPageReloadsPage(assert, bot.action.tap); + }); - function actionOnHashDoesNotReloadThePage(action) { + function actionOnHashDoesNotReloadThePage(assert, action) { if (!checkActionCompatibility(action)) { + assert.ok(true, 'Action not supported, skipping'); return; } - var clickTarget = getClickTarget(''); - clickTarget.href = '#'; - // Fail immediately if the iframe is loaded. - return new goog.Promise(function(fulfill, reject) { + var done = assert.async(); + waitForLoad(iframe).then(function() { + var clickTarget = getClickTarget(''); + clickTarget.href = '#'; + var id = goog.events.listenOnce(iframe, 'load', function() { - reject(Error('Did not expect iframe to load a new page')); + assert.ok(false, 'Did not expect iframe to load a new page'); + done(); }); action(clickTarget); - // After a delay, assume page is not going to load and pass the test. window.setTimeout(function() { goog.events.unlistenByKey(id); - fulfill(); + assert.ok(true); + done(); }, 250); }); } - var testClickOnHashDoesNotReloadThePage = goog.partial( - actionOnHashDoesNotReloadThePage, bot.action.click); + QUnit.test('click on hash does not reload the page', function(assert) { + actionOnHashDoesNotReloadThePage(assert, bot.action.click); + }); - var testTapOnHashDoesNotReloadThePage = goog.partial( - onSelfPageReloadsPage, bot.action.tap); + QUnit.test('tap on hash does not reload the page', function(assert) { + onSelfPageReloadsPage(assert, bot.action.tap); + }); - function focusOnAnElementBeforeFinishingClickSequence(action) { + function focusOnAnElementBeforeFinishingClickSequence(assert, action) { if (!checkActionCompatibility(action)) { + assert.ok(true, 'Action not supported, skipping'); return; } - return new goog.Promise(function(done) { - goog.events.listenOnce(link, goog.events.EventType.FOCUS, done); - action(link); + var done = assert.async(); + goog.events.listenOnce(link, goog.events.EventType.FOCUS, function() { + assert.ok(true); + done(); }); + action(link); } - var testClickFocusOnAnElementBeforeFinishingClickSequence = goog.partial( - focusOnAnElementBeforeFinishingClickSequence, bot.action.click); + QUnit.test('click focus on an element before finishing click sequence', function(assert) { + focusOnAnElementBeforeFinishingClickSequence(assert, bot.action.click); + }); - var testTapFocusOnAnElementBeforeFinishingClickSequence = goog.partial( - focusOnAnElementBeforeFinishingClickSequence, bot.action.tap); + QUnit.test('tap focus on an element before finishing click sequence', function(assert) { + focusOnAnElementBeforeFinishingClickSequence(assert, bot.action.tap); + }); - function focusOnAnElementWhenMousedownChangesFocus(action) { + function focusOnAnElementWhenMousedownChangesFocus(assert, action) { if (!checkActionCompatibility(action)) { + assert.ok(true, 'Action not supported, skipping'); return; } var mousedownPreemptsFocus = action == bot.action.tap ? false : @@ -520,37 +575,49 @@ goog.events.listen(link, goog.events.EventType.MOUSEDOWN, function() { link2.focus(); }); - return new goog.Promise(function(fulfill, reject) { - goog.events.listen(link, goog.events.EventType.FOCUS, function() { - if (mousedownPreemptsFocus) { - reject(Error('Did not expect link to be focused')); - } else { - fulfill(); - } - }); - - goog.events.listen(link2, goog.events.EventType.FOCUS, function() { - // If the mousedown will preempt the focus, delay the continue testing - // call for a short delay to make sure the above assert never triggers. - if (mousedownPreemptsFocus) { - window.setTimeout(function() { - fulfill(); // No-op if the above handler above calls reject. - }, 100); - } - }); + var done = assert.async(); + var resolved = false; + + goog.events.listen(link, goog.events.EventType.FOCUS, function() { + if (resolved) return; + if (mousedownPreemptsFocus) { + assert.ok(false, 'Did not expect link to be focused'); + resolved = true; + done(); + } else { + assert.ok(true); + resolved = true; + done(); + } + }); - action(link); + goog.events.listen(link2, goog.events.EventType.FOCUS, function() { + if (resolved) return; + if (mousedownPreemptsFocus) { + window.setTimeout(function() { + if (resolved) return; + assert.ok(true); + resolved = true; + done(); + }, 100); + } }); + + action(link); } - var testClickFocusOnAnElementWhenMousedownChangesFocus = goog.partial( - focusOnAnElementWhenMousedownChangesFocus, bot.action.click); + QUnit.test('click focus on an element when mousedown changes focus', function(assert) { + focusOnAnElementWhenMousedownChangesFocus(assert, bot.action.click); + }); - var testTapFocusOnAnElementWhenMousedownChangesFocus = goog.partial( - focusOnAnElementWhenMousedownChangesFocus, bot.action.tap); + QUnit.test('tap focus on an element when mousedown changes focus', function(assert) { + focusOnAnElementWhenMousedownChangesFocus(assert, bot.action.tap); + }); +
+
+ +
+
diff --git a/javascript/atoms/test/click_test.html b/javascript/atoms/test/click_test.html index aa11aee985136..55a53470337bd 100644 --- a/javascript/atoms/test/click_test.html +++ b/javascript/atoms/test/click_test.html @@ -3,7 +3,11 @@ + click_test.html + + + +
+


diff --git a/javascript/atoms/test/clientrect_test.html b/javascript/atoms/test/clientrect_test.html index 04f10b03a4740..c96e9be493d10 100644 --- a/javascript/atoms/test/clientrect_test.html +++ b/javascript/atoms/test/clientrect_test.html @@ -1,7 +1,11 @@ + clientrect_test.html + + + +
+
relative
diff --git a/javascript/atoms/test/color_test.html b/javascript/atoms/test/color_test.html index 45e2f7551f516..5843341e96c2f 100644 --- a/javascript/atoms/test/color_test.html +++ b/javascript/atoms/test/color_test.html @@ -1,71 +1,66 @@ + color_test.html + + + +
+
diff --git a/javascript/atoms/test/dom_test.html b/javascript/atoms/test/dom_test.html index 23226d56708f1..d28410376a7e4 100644 --- a/javascript/atoms/test/dom_test.html +++ b/javascript/atoms/test/dom_test.html @@ -1,21 +1,26 @@ + dom_test + + + +
+
@@ -98,4 +102,3 @@ - diff --git a/javascript/atoms/test/drag_test.html b/javascript/atoms/test/drag_test.html index 43dbc8d6d7032..8ab432fa746a8 100644 --- a/javascript/atoms/test/drag_test.html +++ b/javascript/atoms/test/drag_test.html @@ -1,7 +1,11 @@ + drag_test.html + + + +
+
Drag
Drop inside me.
Unit tests for bot.dom.isEnabled + + + +
+
diff --git a/javascript/atoms/test/enter_submit_test.html b/javascript/atoms/test/enter_submit_test.html index fea33e129fef1..41e532b46132f 100644 --- a/javascript/atoms/test/enter_submit_test.html +++ b/javascript/atoms/test/enter_submit_test.html @@ -1,7 +1,11 @@ + enter_submit_test + + + +
+

diff --git a/javascript/atoms/test/error_test.html b/javascript/atoms/test/error_test.html index 0a828f3357c9c..0bf8072226b98 100644 --- a/javascript/atoms/test/error_test.html +++ b/javascript/atoms/test/error_test.html @@ -1,16 +1,27 @@ + + + error_test.html + + + + + +
+
+ + diff --git a/javascript/atoms/test/events_test.html b/javascript/atoms/test/events_test.html index eb5d3c370c20b..e140243638027 100644 --- a/javascript/atoms/test/events_test.html +++ b/javascript/atoms/test/events_test.html @@ -17,7 +17,11 @@ --> + events_test.html + + + +
+
diff --git a/javascript/atoms/test/focus_test.html b/javascript/atoms/test/focus_test.html index 7e10b1dae3e9a..9eb4001b9eab2 100644 --- a/javascript/atoms/test/focus_test.html +++ b/javascript/atoms/test/focus_test.html @@ -1,7 +1,11 @@ + focus_test.html + + + @@ -20,25 +23,20 @@ var text1, text2, actualEvents, expectedEvents; - function setUp() { + QUnit.testStart(function() { actualEvents = []; expectedEvents = []; text1 = goog.dom.$('text1'); text2 = goog.dom.$('text2'); - // Make sure neither text1 nor text2 have focus. Since this could - // cause events to dispatch, we need to wait for them to do so - // before continuing. In IE, this means continuing in a timeout. bot.action.focusOnElement(goog.dom.$('dummyFocusHolder')); - return timeout(); - } - + }); - function tearDown() { + QUnit.testDone(function() { events.removeAll(text1); events.removeAll(text2); - } + }); function buildRecord(id, type) { return id + ': ' + type; @@ -54,97 +52,94 @@ expectedEvents.push(buildRecord(onElement.id, eventType)); } - function assertHasExpectedEventOrder() { - assertArrayEquals(expectedEvents, actualEvents); + function assertHasExpectedEventOrder(assert) { + assert.deepEqual(actualEvents, expectedEvents); } - function assertElementIsActiveElement(expected) { + function assertElementIsActiveElement(assert, expected) { var actual = goog.dom.getActiveElement(document); if (actual) { - // NOTE(jleyba): Using assertEquals(expected, document.activeElement) - // causes an error in IE when the assertion fails (from trying to - // convert the DOM elements into strings for the error message): - // "'constructor' is null or not an object". - // The following assertions give us the same check without this error. var msg = 'Expected "' + expected.id + '" to be the activeElement, ' + 'but was "' + actual.id + '".'; - assertTrue(msg, expected == actual); + assert.ok(expected == actual, msg); } } - /** - * Pauses the test momentarily so IE can dispatch the onfocus event, which - * is scheduled for the next event loop after element.focus() is called. - */ function timeout() { return new goog.Promise(function(done) { setTimeout(done, 5); }); } - function testShouldBeAbleToFocusOnAnElement() { - // NOTE(jleyba): Test does not work on IE 8 with the new IE Driver, - // I suspect due to something similar to - // http://support.microsoft.com/kb/973528 + QUnit.test('should be able to focus on an element', function(assert) { if (goog.userAgent.IE && goog.userAgent.isVersionOrHigher('8')) { + assert.ok(true, 'Skipping: IE 8+ issue'); return; } if (!bot.test.isWindowFocused()) { + assert.ok(true, 'Skipping: window not focused'); return; } + var done = assert.async(); recordBlurAndFocus(text1); recordBlurAndFocus(text2); expect(eventType.FOCUS, text1); bot.action.focusOnElement(text1); - return timeout().then(function() { - assertHasExpectedEventOrder(); - assertElementIsActiveElement(text1); + timeout().then(function() { + assertHasExpectedEventOrder(assert); + assertElementIsActiveElement(assert, text1); expect(eventType.BLUR, text1); expect(eventType.FOCUS, text2); bot.action.focusOnElement(text2); return timeout(); }).then(function() { - assertHasExpectedEventOrder(); - assertElementIsActiveElement(text2); + assertHasExpectedEventOrder(assert); + assertElementIsActiveElement(assert, text2); expect(eventType.BLUR, text2); expect(eventType.FOCUS, text1); bot.action.focusOnElement(text1); return timeout(); }).then(function() { - assertHasExpectedEventOrder(); - assertElementIsActiveElement(text1); + assertHasExpectedEventOrder(assert); + assertElementIsActiveElement(assert, text1); + done(); }); - } + }); - function testShouldRetainFocusIfElementIsAlreadyActive() { + QUnit.test('should retain focus if element is already active', function(assert) { if (!bot.test.isWindowFocused()) { + assert.ok(true, 'Skipping: window not focused'); return; } + var done = assert.async(); recordBlurAndFocus(text1); recordBlurAndFocus(text2); expect(eventType.FOCUS, text1); bot.action.focusOnElement(text1); - return timeout().then(function() { - assertHasExpectedEventOrder(); - assertElementIsActiveElement(text1); + timeout().then(function() { + assertHasExpectedEventOrder(assert); + assertElementIsActiveElement(assert, text1); bot.action.focusOnElement(text1); return timeout(); }).then(function() { - assertHasExpectedEventOrder(); - assertElementIsActiveElement(text1); + assertHasExpectedEventOrder(assert); + assertElementIsActiveElement(assert, text1); + done(); }); - } + }); - function testShouldRetainFocusIfFirstFocusableAncestorIsAlreadyActive() { + QUnit.test('should retain focus if first focusable ancestor is already active', function(assert) { if (!bot.test.isWindowFocused()) { + assert.ok(true, 'Skipping: window not focused'); return; } + var done = assert.async(); var parent = document.getElementById('hideOnBlur'); var child = document.getElementById('hideOnBlurChild'); @@ -152,46 +147,46 @@ expect(eventType.FOCUS, parent); bot.action.focusOnElement(parent); - return timeout().then(function() { - assertHasExpectedEventOrder(); - assertElementIsActiveElement(parent); + timeout().then(function() { + assertHasExpectedEventOrder(assert); + assertElementIsActiveElement(assert, parent); bot.action.focusOnElement(child); - // No additional events expected. The parent should retain focus. return timeout(); }).then(function() { - assertHasExpectedEventOrder(); - assertElementIsActiveElement(parent); + assertHasExpectedEventOrder(assert); + assertElementIsActiveElement(assert, parent); bot.action.focusOnElement(text1); expect(eventType.BLUR, parent); return timeout(); }).then(function() { - assertHasExpectedEventOrder(); + assertHasExpectedEventOrder(assert); + done(); }); - } + }); - function testFocusOnHiddenElementThrows() { + QUnit.test('focus on hidden element throws', function(assert) { var element = document.getElementById('invisibleText'); - assertThrows(goog.partial(bot.action.focusOnElement, element)); - } + assert.throws(function() { bot.action.focusOnElement(element); }); + }); - function testFocusOnDisabledElementThrows() { + QUnit.test('focus on disabled element throws', function(assert) { var element = document.getElementById('disabledText'); - assertThrows(goog.partial(bot.action.focusOnElement, element)); - } + assert.throws(function() { bot.action.focusOnElement(element); }); + }); - function testIsFocusable() { + QUnit.test('is focusable', function(assert) { if (goog.userAgent.IE) { - // TODO: Don't skip this. + assert.ok(true, 'Skipping: IE issue'); return; } function assertIsFocusable(element, opt_reason) { - assertTrue(opt_reason || '', bot.dom.isFocusable(element)); + assert.ok(bot.dom.isFocusable(element), opt_reason || ''); } function assertNotFocusable(element, opt_reason) { - assertFalse(opt_reason || '', bot.dom.isFocusable(element)); + assert.notOk(bot.dom.isFocusable(element), opt_reason || ''); } goog.array.forEach(bot.dom.FOCUSABLE_FORM_FIELDS_, function(tagName) { @@ -206,20 +201,22 @@ assertIsFocusable(div, 'has a tab index of 0'); div.tabIndex = -1; - assertEquals('-1', bot.dom.getAttribute(div, 'tabindex')); + assert.strictEqual(bot.dom.getAttribute(div, 'tabindex'), '-1'); assertNotFocusable(div, 'has a negative tab index'); div.tabIndex = 2; - assertEquals('2', bot.dom.getAttribute(div, 'tabindex')); + assert.strictEqual(bot.dom.getAttribute(div, 'tabindex'), '2'); assertIsFocusable(div, 'has a tab index of 2'); div.removeAttribute('tabindex'); - assertNull(bot.dom.getAttribute(div, 'tabindex')); + assert.strictEqual(bot.dom.getAttribute(div, 'tabindex'), null); assertNotFocusable(div, 'tab index was removed'); - } + }); +
+
diff --git a/javascript/atoms/test/frame_scroll_test.html b/javascript/atoms/test/frame_scroll_test.html index b9cfcb0f16139..f2d0aeaae7269 100644 --- a/javascript/atoms/test/frame_scroll_test.html +++ b/javascript/atoms/test/frame_scroll_test.html @@ -1,7 +1,11 @@ + frame_scroll_test + + + +
+
diff --git a/javascript/atoms/test/frame_size_test.html b/javascript/atoms/test/frame_size_test.html index 76cdbd37e350c..ad57fed9b2ac3 100644 --- a/javascript/atoms/test/frame_size_test.html +++ b/javascript/atoms/test/frame_size_test.html @@ -1,7 +1,11 @@ + frame_size_test + + + +
+
diff --git a/javascript/atoms/test/frame_test.html b/javascript/atoms/test/frame_test.html index e10cd9cb7ebcb..43c007d86d0cb 100644 --- a/javascript/atoms/test/frame_test.html +++ b/javascript/atoms/test/frame_test.html @@ -17,167 +17,171 @@ --> + frame_test.html + + + diff --git a/javascript/atoms/test/gestures_test.html b/javascript/atoms/test/gestures_test.html index ebfe722e4eb72..d4f295a596d68 100644 --- a/javascript/atoms/test/gestures_test.html +++ b/javascript/atoms/test/gestures_test.html @@ -1,7 +1,11 @@ + gestures_test.html + + + +
+
+ + history_test.html + + + +
+
diff --git a/javascript/atoms/test/html5/appcache_test.html b/javascript/atoms/test/html5/appcache_test.html index 9f87c5f508b23..300f5ff51dd40 100644 --- a/javascript/atoms/test/html5/appcache_test.html +++ b/javascript/atoms/test/html5/appcache_test.html @@ -1,14 +1,17 @@ + HTML5 application cache test with manifest + + + @@ -25,18 +28,25 @@ }); } - function testGetStatusWithHtmlManifest() { + QUnit.test('getStatusWithHtmlManifest', function(assert) { if (APPCACHE_NOT_WORKING) { + assert.ok(true, 'Skipping: appcache not working'); return; } // On most browsers, the app is cached by now. This check should not be // made asynch because one cannot reliably detect the cached event. if (isCached) { - assertEquals(window.applicationCache.IDLE, - bot.appcache.getStatus(window)); + assert.strictEqual(bot.appcache.getStatus(window), + window.applicationCache.IDLE); + } else { + assert.ok(true, 'App not yet cached'); } - } + }); + +
+
+ diff --git a/javascript/atoms/test/html5/database_test.html b/javascript/atoms/test/html5/database_test.html index f7978bb461638..af25ce5d4df49 100644 --- a/javascript/atoms/test/html5/database_test.html +++ b/javascript/atoms/test/html5/database_test.html @@ -1,14 +1,17 @@ + Web database storage + + + - + +
+
+ diff --git a/javascript/atoms/test/html5/location_test.html b/javascript/atoms/test/html5/location_test.html index d4bcb2b5170c1..5790d3e2273e0 100644 --- a/javascript/atoms/test/html5/location_test.html +++ b/javascript/atoms/test/html5/location_test.html @@ -1,7 +1,11 @@ + HTML5 Geo-location test + + + @@ -37,47 +39,52 @@ goog.userAgent.product.CHROME) || bot.userAgent.IE_DOC_9; - - function setUpPage() { - goog.testing.TestCase.getActiveTestCase().promiseTimeout = 10000; // 10s - } + QUnit.config.testTimeout = 10000; // 10s /** * This method checks if the device location * can be retrieved, i.e. non-null value of Position within the timeout * period. */ - function testLocationWithinDefaultInterval() { + QUnit.test('locationWithinDefaultInterval', function(assert) { if (GEOLOCATION_NOT_WORKING) { + assert.ok(true, 'Skipping: geolocation not working'); return; } - return new goog.Promise(function(success, fail) { - try { - bot.geolocation.getCurrentPosition(success, function(error) { - switch (error.code) { - case error.POSITION_UNAVAILABLE: - // Some test machines run on a private ip address range where - // location is not be available, so do not consider this case - // as an error. - success(); - return; - case error.PERMISSION_DENIED: - fail('User denied the request for Geolocation.'); - return; - case error.TIMEOUT: - fail('When enabled, location should be known within ' + - (bot.geolocation.DEFAULT_OPTIONS.timeout / 1000) + 's'); - return; - default: - fail('An unknown error occurred. ' + error.message); - return; - } - }); - } catch (e) { - assertEquals(e.code, bot.ErrorCode.UNKNOWN_ERROR); - } - }); - } + var done = assert.async(); + try { + bot.geolocation.getCurrentPosition(function() { + assert.ok(true, 'Location retrieved'); + done(); + }, function(error) { + switch (error.code) { + case error.POSITION_UNAVAILABLE: + // Some test machines run on a private ip address range where + // location is not be available, so do not consider this case + // as an error. + assert.ok(true, 'Position unavailable - acceptable'); + done(); + return; + case error.PERMISSION_DENIED: + assert.ok(false, 'User denied the request for Geolocation.'); + done(); + return; + case error.TIMEOUT: + assert.ok(false, 'When enabled, location should be known within ' + + (bot.geolocation.DEFAULT_OPTIONS.timeout / 1000) + 's'); + done(); + return; + default: + assert.ok(false, 'An unknown error occurred. ' + error.message); + done(); + return; + } + }); + } catch (e) { + assert.strictEqual(e.code, bot.ErrorCode.UNKNOWN_ERROR); + done(); + } + }); /** * Tested with Chrome and Firefox. It checks if the device location cannot @@ -88,8 +95,9 @@ * invoke the errorCallback (if present) with a new PositionError object * whose code attribute is set to TIMEOUT. */ - function testLocationNoTimeout() { + QUnit.test('locationNoTimeout', function(assert) { if (GEOLOCATION_NOT_WORKING) { + assert.ok(true, 'Skipping: geolocation not working'); return; } @@ -99,23 +107,29 @@ timeout: 0 }; - return new goog.Promise(function(success, fail) { - try { - bot.geolocation.getCurrentPosition( - goog.partial(fail, - 'Location within 0s timeout interval and 0s max age fails'), - success, - posOptions); - } catch (e) { - assertEquals(e.code, bot.ErrorCode.UNKNOWN_ERROR); - success(); - } - }); - } + var done = assert.async(); + try { + bot.geolocation.getCurrentPosition( + function() { + assert.ok(false, 'Location within 0s timeout interval and 0s max age fails'); + done(); + }, + function() { + assert.ok(true, 'Expected timeout error'); + done(); + }, + posOptions); + } catch (e) { + assert.strictEqual(e.code, bot.ErrorCode.UNKNOWN_ERROR); + done(); + } + }); // TODO: Add more tests to check the returned value. +
+
diff --git a/javascript/atoms/test/html5/nested_window_storage_test.html b/javascript/atoms/test/html5/nested_window_storage_test.html index c9f1e2e46f4e0..8e95f74068ab3 100644 --- a/javascript/atoms/test/html5/nested_window_storage_test.html +++ b/javascript/atoms/test/html5/nested_window_storage_test.html @@ -1,63 +1,70 @@ + HTML5 storage with nested frames + + + - +
+
+ diff --git a/javascript/atoms/test/html5/no_manifest_appcache_test.html b/javascript/atoms/test/html5/no_manifest_appcache_test.html index 8132bd44a6763..615c1419b1b8e 100644 --- a/javascript/atoms/test/html5/no_manifest_appcache_test.html +++ b/javascript/atoms/test/html5/no_manifest_appcache_test.html @@ -1,29 +1,33 @@ + HTML5 application cache without html manifest attribute + + + -Test - +
+
+ Test + - - diff --git a/javascript/atoms/test/html5/shadow_dom_test.html b/javascript/atoms/test/html5/shadow_dom_test.html index e5c39c40c9c73..237d3966ba07e 100644 --- a/javascript/atoms/test/html5/shadow_dom_test.html +++ b/javascript/atoms/test/html5/shadow_dom_test.html @@ -1,13 +1,19 @@ + + + + +
+
+

Page for Shadow DOM tests

Foo
@@ -92,20 +98,22 @@

Page for Shadow DOM tests

'DefaultDefault'; } - function testIsShown() { + QUnit.test('isShown', function(assert) { if (!bot.dom.IS_SHADOW_DOM_ENABLED) { + assert.ok(true, 'Skipping: shadow DOM not enabled'); return; } - assert(bot.dom.isShown(elementIsShown)); + assert.ok(bot.dom.isShown(elementIsShown)); elementIsShown.style.display = 'none'; - assertFalse(bot.dom.isShown(elementIsShown)); - } + assert.notOk(bot.dom.isShown(elementIsShown)); + }); - function testIsShownInShadow() { + QUnit.test('isShownInShadow', function(assert) { if (!bot.dom.IS_SHADOW_DOM_ENABLED) { + assert.ok(true, 'Skipping: shadow DOM not enabled'); return; } @@ -113,15 +121,16 @@

Page for Shadow DOM tests

.shadowRoot .querySelector('.test'); - assert(bot.dom.isShown(el)); + assert.ok(bot.dom.isShown(el)); elementIsShownInShadow.style.display = 'none'; - assertFalse(bot.dom.isShown(el)); - } + assert.notOk(bot.dom.isShown(el)); + }); - function testIsShownDirectlyInShadow() { + QUnit.test('isShownDirectlyInShadow', function(assert) { if (!bot.dom.IS_SHADOW_DOM_ENABLED) { + assert.ok(true, 'Skipping: shadow DOM not enabled'); return; } @@ -129,85 +138,91 @@

Page for Shadow DOM tests

.shadowRoot .querySelector('div'); - assert(bot.dom.isShown(el)); + assert.ok(bot.dom.isShown(el)); elementIsShownDirectlyInShadow.style.display = 'none'; - assertFalse(bot.dom.isShown(el)); - } + assert.notOk(bot.dom.isShown(el)); + }); - function testIsShownInSlot() { + QUnit.test('isShownInSlot', function(assert) { if (!bot.dom.IS_SHADOW_DOM_ENABLED) { + assert.ok(true, 'Skipping: shadow DOM not enabled'); return; } var el = elementIsShownInSlot.children[0]; - assert(bot.dom.isShown(el)); + assert.ok(bot.dom.isShown(el)); elementIsShownInSlot.style.display = 'none'; - assertFalse(bot.dom.isShown(el)); + assert.notOk(bot.dom.isShown(el)); elementIsShownInSlot.style.display = ''; // Remove the slot, so our child is no longer slotted elementIsShownInSlot.shadowRoot.innerHTML = ''; - assertFalse(bot.dom.isShown(el)); - } + assert.notOk(bot.dom.isShown(el)); + }); - function testGetParentNodeInComposedDom() { + QUnit.test('getParentNodeInComposedDom', function(assert) { if (!bot.dom.IS_SHADOW_DOM_ENABLED) { + assert.ok(true, 'Skipping: shadow DOM not enabled'); return; } var el = elementGetParent.children[0]; - assertEquals(elementGetParent, bot.dom.getParentNodeInComposedDom(el)); + assert.strictEqual(bot.dom.getParentNodeInComposedDom(el), elementGetParent); el = elementGetParentSlot.children[0]; - assertEquals( - elementGetParentSlot.shadowRoot.querySelector('div'), - bot.dom.getParentNodeInComposedDom(el) + assert.strictEqual( + bot.dom.getParentNodeInComposedDom(el), + elementGetParentSlot.shadowRoot.querySelector('div') ); elementGetParentSlot.shadowRoot.innerHTML = ''; - assertEquals(null, bot.dom.getParentNodeInComposedDom(el)); - } + assert.strictEqual(bot.dom.getParentNodeInComposedDom(el), null); + }); - function testGetVisibleText() { + QUnit.test('getVisibleText', function(assert) { if (!bot.dom.IS_SHADOW_DOM_ENABLED) { + assert.ok(true, 'Skipping: shadow DOM not enabled'); return; } - assertEquals('Foo', bot.dom.getVisibleText(elementGetText)); - } + assert.strictEqual(bot.dom.getVisibleText(elementGetText), 'Foo'); + }); - function testGetVisibleTextInShadow() { + QUnit.test('getVisibleTextInShadow', function(assert) { if (!bot.dom.IS_SHADOW_DOM_ENABLED) { + assert.ok(true, 'Skipping: shadow DOM not enabled'); return; } - assertEquals('foo', bot.dom.getVisibleText(elementGetTextShadow)); - } + assert.strictEqual(bot.dom.getVisibleText(elementGetTextShadow), 'foo'); + }); - function testGetVisibleTextInSlot() { + QUnit.test('getVisibleTextInSlot', function(assert) { if (!bot.dom.IS_SHADOW_DOM_ENABLED) { + assert.ok(true, 'Skipping: shadow DOM not enabled'); return; } - assertEquals('aFoob', bot.dom.getVisibleText(elementGetTextSlot)); - } + assert.strictEqual(bot.dom.getVisibleText(elementGetTextSlot), 'aFoob'); + }); - function testGetVisibleTextInSlots() { + QUnit.test('getVisibleTextInSlots', function(assert) { if (!bot.dom.IS_SHADOW_DOM_ENABLED) { + assert.ok(true, 'Skipping: shadow DOM not enabled'); return; } - assertEquals('Foo\nBar', bot.dom.getVisibleText(elementGetTextSlots)); - } + assert.strictEqual(bot.dom.getVisibleText(elementGetTextSlots), 'Foo\nBar'); + }); diff --git a/javascript/atoms/test/html5/storage_test.html b/javascript/atoms/test/html5/storage_test.html index 4640d9ee6c1cf..13e6bdc077e85 100644 --- a/javascript/atoms/test/html5/storage_test.html +++ b/javascript/atoms/test/html5/storage_test.html @@ -1,14 +1,17 @@ + HTML5 storage + + + @@ -21,63 +24,69 @@ !bot.html5.isSupported(bot.html5.API.SESSION_STORAGE) || goog.userAgent.product.FIREFOX; - function testGetLocalStorage() { + QUnit.test('getLocalStorage', function(assert) { if (LOCAL_STORAGE_NOT_WORKING) { + assert.ok(true, 'Skipping: local storage not working'); return; } var storage = bot.storage.getLocalStorage(); - assertEquals(storage.getStorageMap(), localStorage); - } + assert.strictEqual(storage.getStorageMap(), localStorage); + }); - function testGetLocalStorageWithWindow() { + QUnit.test('getLocalStorageWithWindow', function(assert) { if (LOCAL_STORAGE_NOT_WORKING) { + assert.ok(true, 'Skipping: local storage not working'); return; } var storage = bot.storage.getLocalStorage(bot.getWindow()); - assertEquals(storage.getStorageMap(), localStorage); - } + assert.strictEqual(storage.getStorageMap(), localStorage); + }); - function testGetSessionStorage() { + QUnit.test('getSessionStorage', function(assert) { if (SESSION_STORAGE_NOT_WORKING) { + assert.ok(true, 'Skipping: session storage not working'); return; } var storage = bot.storage.getSessionStorage(); - assertEquals(storage.getStorageMap(), sessionStorage); - } + assert.strictEqual(storage.getStorageMap(), sessionStorage); + }); - function testGetSessionStorageWithWindow() { + QUnit.test('getSessionStorageWithWindow', function(assert) { if (SESSION_STORAGE_NOT_WORKING) { + assert.ok(true, 'Skipping: session storage not working'); return; } var storage = bot.storage.getSessionStorage(bot.getWindow()); - assertEquals(storage.getStorageMap(), storage.getStorageMap()); - } + assert.strictEqual(storage.getStorageMap(), storage.getStorageMap()); + }); - function testClear() { + QUnit.test('clear', function(assert) { if (LOCAL_STORAGE_NOT_WORKING) { + assert.ok(true, 'Skipping: local storage not working'); return; } var storage = bot.storage.getLocalStorage(); storage.clear(); - assertEquals(0, storage.size()); + assert.strictEqual(storage.size(), 0); storage.setItem('first', 'one'); storage.setItem('second', 'two'); storage.setItem('third', 'two'); storage.clear(); - assertEquals(0, storage.size()); - assertNull(storage.getItem('first')); - assertNull(storage.getItem('second')); - assertNull(storage.getItem('third')); - } + assert.strictEqual(storage.size(), 0); + assert.strictEqual(storage.getItem('first'), null); + assert.strictEqual(storage.getItem('second'), null); + assert.strictEqual(storage.getItem('third'), null); + }); - function testSetAndGetSimpleItem() { + QUnit.test('setAndGetSimpleItem', function(assert) { if (SESSION_STORAGE_NOT_WORKING) { + assert.ok(true, 'Skipping: session storage not working'); return; } @@ -85,20 +94,21 @@ // set-get storage.setItem('first', 'one'); - assertEquals('one', storage.getItem('first')); + assert.strictEqual(storage.getItem('first'), 'one'); storage.setItem('second', 2); - assertEquals('2', storage.getItem('second')); - assertNull(storage.getItem('third')); + assert.strictEqual(storage.getItem('second'), '2'); + assert.strictEqual(storage.getItem('third'), null); // resetItem storage.setItem('first', '1'); - assertEquals('1', storage.getItem('first')); + assert.strictEqual(storage.getItem('first'), '1'); storage.clear(); - } + }); - function testSetArbitraryValue() { + QUnit.test('setArbitraryValue', function(assert) { if (SESSION_STORAGE_NOT_WORKING) { + assert.ok(true, 'Skipping: session storage not working'); return; } @@ -106,22 +116,23 @@ // set different types of value storage.setItem('foo', ''); - assertEquals('', storage.getItem('foo')); + assert.strictEqual(storage.getItem('foo'), ''); var d = new Date(2011, 02, 29, 12, 33, 44, 44); storage.setItem('date', d); - assertEquals(d.toString(), storage.getItem('date')); + assert.strictEqual(storage.getItem('date'), d.toString()); // set null value. storage.setItem('foo1', null); - assertEquals('null', storage.getItem('foo1')); + assert.strictEqual(storage.getItem('foo1'), 'null'); storage.setItem('foo2', 'null'); - assertEquals(storage.getItem('foo1'), storage.getItem('foo2')); + assert.strictEqual(storage.getItem('foo1'), storage.getItem('foo2')); storage.clear(); - } + }); - function testRemoveItem() { + QUnit.test('removeItem', function(assert) { if (SESSION_STORAGE_NOT_WORKING) { + assert.ok(true, 'Skipping: session storage not working'); return; } @@ -131,14 +142,15 @@ storage.setItem('first', 'one'); storage.setItem('second', 'two'); - assertEquals('one', storage.removeItem('first')); - assertEquals('two', storage.removeItem('second')); - assertEquals(null, storage.removeItem('first')); - assertEquals(null, storage.removeItem('foo')); - } + assert.strictEqual(storage.removeItem('first'), 'one'); + assert.strictEqual(storage.removeItem('second'), 'two'); + assert.strictEqual(storage.removeItem('first'), null); + assert.strictEqual(storage.removeItem('foo'), null); + }); - function testSize() { + QUnit.test('size', function(assert) { if (SESSION_STORAGE_NOT_WORKING) { + assert.ok(true, 'Skipping: session storage not working'); return; } @@ -148,11 +160,12 @@ storage.setItem('first', 'one'); storage.setItem('second', 'two'); storage.setItem('third', 'three'); - assertEquals(3, storage.size()); - } + assert.strictEqual(storage.size(), 3); + }); - function testKeySet() { + QUnit.test('keySet', function(assert) { if (SESSION_STORAGE_NOT_WORKING) { + assert.ok(true, 'Skipping: session storage not working'); return; } @@ -162,39 +175,41 @@ storage.setItem('third', 'three'); storage.setItem('first', 'one'); storage.setItem('second', 'two'); - assertEquals(3, storage.size()); + assert.strictEqual(storage.size(), 3); // keySet var keys = storage.keySet(); // Use goog.array.indexOf because IE9 doesn't have Array.indexOf - assertNotEquals(-1, goog.array.indexOf(keys, 'first')); - assertNotEquals(-1, goog.array.indexOf(keys, 'second')); - assertEquals(-1, goog.array.indexOf(keys, 'five')); + assert.notStrictEqual(goog.array.indexOf(keys, 'first'), -1); + assert.notStrictEqual(goog.array.indexOf(keys, 'second'), -1); + assert.strictEqual(goog.array.indexOf(keys, 'five'), -1); var sortedKeys = keys.sort(); - assertArrayEquals(['first', 'second', 'third'], sortedKeys); - } + assert.deepEqual(sortedKeys, ['first', 'second', 'third']); + }); - function testIdenticalLocalStorage() { + QUnit.test('identicalLocalStorage', function(assert) { if (LOCAL_STORAGE_NOT_WORKING) { + assert.ok(true, 'Skipping: local storage not working'); return; } var localStorage1 = bot.storage.getLocalStorage(); var localStorage2 = bot.storage.getLocalStorage(); localStorage1.clear(); - assertEquals(0, localStorage1.size()); - assertEquals(0, localStorage2.size()); + assert.strictEqual(localStorage1.size(), 0); + assert.strictEqual(localStorage2.size(), 0); localStorage1.setItem('foo', 'bar'); - assertEquals('bar', localStorage1.getItem('foo')); - assertEquals('bar', localStorage2.getItem('foo')); + assert.strictEqual(localStorage1.getItem('foo'), 'bar'); + assert.strictEqual(localStorage2.getItem('foo'), 'bar'); localStorage2.removeItem('foo'); - assertNull(localStorage1.getItem('foo')); - assertNull(localStorage2.getItem('foo')); - } + assert.strictEqual(localStorage1.getItem('foo'), null); + assert.strictEqual(localStorage2.getItem('foo'), null); + }); - function testPersistentLocalStorage() { + QUnit.test('persistentLocalStorage', function(assert) { if (LOCAL_STORAGE_NOT_WORKING) { + assert.ok(true, 'Skipping: local storage not working'); return; } @@ -203,13 +218,15 @@ if (localStorage.getItem('foosession') === null) { localStorage.setItem('foosession', 'barsession'); } - assertEquals('barsession', localStorage.getItem('foosession')); + assert.strictEqual(localStorage.getItem('foosession'), 'barsession'); localStorage.removeItem('foosession'); - assertNull(localStorage.getItem('foosession')); - } + assert.strictEqual(localStorage.getItem('foosession'), null); + }); +
+
diff --git a/javascript/atoms/test/inject_test.html b/javascript/atoms/test/inject_test.html index 494ae7acf0122..4382ae7da0825 100644 --- a/javascript/atoms/test/inject_test.html +++ b/javascript/atoms/test/inject_test.html @@ -17,7 +17,11 @@ --> + Unit Tests for bot.inject + + + +
+
@@ -43,415 +48,400 @@ var frame, frameWin, frameDoc; - function setUpPage() { - goog.testing.TestCase.getActiveTestCase().promiseTimeout = 30000; // 30s - } - - function setUp() { + QUnit.testStart(function() { frame = goog.dom.$('test-frame'); frameWin = goog.dom.getFrameContentWindow(frame); frameDoc = goog.dom.getFrameContentDocument(frame); - // Force the cache to be recreated on the next access. We cannot "delete" - // it here because IE complains about it being an unsupported operation. document[bot.inject.cache.CACHE_KEY_] = null; - - // Delete the cache in our test frame, if it was created. frameDoc[bot.inject.cache.CACHE_KEY_] = null; - } + }); - function testAddWindowToCache() { + QUnit.test('AddWindowToCache', function(assert) { var id = bot.inject.cache.addElement(frameWin); - assertEquals(frameWin, bot.inject.cache.getElement(id)); - } + assert.strictEqual(bot.inject.cache.getElement(id), frameWin); + }); - function testAddWindowToCacheMultipleTimesReusesIds() { + QUnit.test('AddWindowToCacheMultipleTimesReusesIds', function(assert) { var id1 = bot.inject.cache.addElement(frameWin); var id2 = bot.inject.cache.addElement(frameWin); - assertEquals(id1, id2); - } + assert.strictEqual(id2, id1); + }); - function testGetElementThrowsIfWindowIsClosed() { + QUnit.test('GetElementThrowsIfWindowIsClosed', function(assert) { var win = {document: 1, closed: 1}; var id = bot.inject.cache.addElement(win); - assertThrows(goog.partial(bot.inject.cache.getElement, id)); - } + assert.throws(function() { bot.inject.cache.getElement(id); }); + }); - function testShouldWrapAndUnwrapWindow() { + QUnit.test('ShouldWrapAndUnwrapWindow', function(assert) { var wrapped = bot.inject.wrapValue(frameWin); - assertNotNull(wrapped); - assertNotUndefined(wrapped); - assertTrue(goog.isObject(wrapped)); - assertTrue(goog.object.containsKey(wrapped, bot.inject.WINDOW_KEY)); + assert.ok(wrapped !== null); + assert.ok(wrapped !== undefined); + assert.ok(goog.isObject(wrapped)); + assert.ok(goog.object.containsKey(wrapped, bot.inject.WINDOW_KEY)); var id = wrapped[bot.inject.WINDOW_KEY]; var res = bot.inject.cache.getElement(id); - assertEquals(frameWin, res); - assertEquals(frameWin, bot.inject.unwrapValue(wrapped)); - } + assert.strictEqual(res, frameWin); + assert.strictEqual(bot.inject.unwrapValue(wrapped), frameWin); + }); - function testShouldBeAbleToCacheElements() { + QUnit.test('ShouldBeAbleToCacheElements', function(assert) { var id = bot.inject.cache.addElement(document.body); var el = bot.inject.cache.getElement(id); - assertEquals(document.body, el); - } + assert.strictEqual(el, document.body); + }); - function testShouldReuseExistingIdIfElementAlreadyExistsInTheCache() { + QUnit.test('ShouldReuseExistingIdIfElementAlreadyExistsInTheCache', function(assert) { var id1 = bot.inject.cache.addElement(document.body); var id2 = bot.inject.cache.addElement(document.body); - assertEquals(id1, id2); - } + assert.strictEqual(id2, id1); + }); - function testShouldThrowIfElementDoesNotExistInTheCache() { - assertThrows(goog.partial(bot.inject.cache.getElement, 'not-there')); - } + QUnit.test('ShouldThrowIfElementDoesNotExistInTheCache', function(assert) { + assert.throws(function() { bot.inject.cache.getElement('not-there'); }); + }); - function testShouldDecodeIdsWhenRetrievingFromTheCache() { + QUnit.test('ShouldDecodeIdsWhenRetrievingFromTheCache', function(assert) { var id = bot.inject.cache.addElement(document.body); id = encodeURIComponent(id); var el = bot.inject.cache.getElement(id); - assertEquals(document.body, el); - } + assert.strictEqual(el, document.body); + }); - function testShouldThrowIfCachedElementIsNoLongerAttachedToTheDom() { + QUnit.test('ShouldThrowIfCachedElementIsNoLongerAttachedToTheDom', function(assert) { if (goog.userAgent.IE) { - // TODO: Don't skip this. + assert.ok(true, 'Skipping: TODO fix for IE'); return; } var div = document.createElement('DIV'); document.body.appendChild(div); var id = bot.inject.cache.addElement(div); - assertEquals(div, bot.inject.cache.getElement(id)); + assert.strictEqual(bot.inject.cache.getElement(id), div); document.body.removeChild(div); - assertThrows(goog.partial(bot.inject.cache.getElement, id)); - } + assert.throws(function() { bot.inject.cache.getElement(id); }); + }); - function testDoesNotWrapStringBooleansNumbersOrNull() { - assertEquals('foo', bot.inject.wrapValue('foo')); - assertEquals(123, bot.inject.wrapValue(123)); - assertTrue(bot.inject.wrapValue(true)); - assertNull(bot.inject.wrapValue(null)); - } + QUnit.test('DoesNotWrapStringBooleansNumbersOrNull', function(assert) { + assert.strictEqual(bot.inject.wrapValue('foo'), 'foo'); + assert.strictEqual(bot.inject.wrapValue(123), 123); + assert.ok(bot.inject.wrapValue(true)); + assert.strictEqual(bot.inject.wrapValue(null), null); + }); - function testConvertsUndefinedValueToNullForWrapping() { - assertNull(bot.inject.wrapValue(undefined)); - } + QUnit.test('ConvertsUndefinedValueToNullForWrapping', function(assert) { + assert.strictEqual(bot.inject.wrapValue(undefined), null); + }); - function testShouldAddElementsToCacheWhenWrapping() { + QUnit.test('ShouldAddElementsToCacheWhenWrapping', function(assert) { var wrapped = bot.inject.wrapValue(document.body); - assertNotNull(wrapped); - assertNotUndefined(wrapped); - assertTrue(goog.isObject(wrapped)); - assertTrue(goog.object.containsKey(wrapped, bot.inject.ELEMENT_KEY)); + assert.ok(wrapped !== null); + assert.ok(wrapped !== undefined); + assert.ok(goog.isObject(wrapped)); + assert.ok(goog.object.containsKey(wrapped, bot.inject.ELEMENT_KEY)); var id = wrapped[bot.inject.ELEMENT_KEY]; var el = bot.inject.cache.getElement(id); - assertEquals(document.body, el); - } + assert.strictEqual(el, document.body); + }); - function testShouldRecursivelyWrapArrays() { + QUnit.test('ShouldRecursivelyWrapArrays', function(assert) { var unwrapped = [123, 'abc', null, document.body]; var wrapped = bot.inject.wrapValue(unwrapped); - assertEquals(unwrapped.length, wrapped.length); - assertEquals(unwrapped[0], wrapped[0]); - assertEquals(unwrapped[1], wrapped[1]); - assertEquals(unwrapped[2], wrapped[2]); + assert.strictEqual(wrapped.length, unwrapped.length); + assert.strictEqual(wrapped[0], unwrapped[0]); + assert.strictEqual(wrapped[1], unwrapped[1]); + assert.strictEqual(wrapped[2], unwrapped[2]); - assertTrue(goog.object.containsKey(wrapped[3], bot.inject.ELEMENT_KEY)); - assertEquals(unwrapped[3], bot.inject.cache.getElement( - wrapped[3][bot.inject.ELEMENT_KEY])); - } + assert.ok(goog.object.containsKey(wrapped[3], bot.inject.ELEMENT_KEY)); + assert.strictEqual(bot.inject.cache.getElement( + wrapped[3][bot.inject.ELEMENT_KEY]), unwrapped[3]); + }); - function testShouldBeAbleToWrapNodeListsAsArrays() { + QUnit.test('ShouldBeAbleToWrapNodeListsAsArrays', function(assert) { var unwrapped = document.getElementsByTagName('body'); var wrapped = bot.inject.wrapValue(unwrapped); - assertTrue('should return an array, but was ' + goog.typeOf(wrapped), - Array.isArray(wrapped)); - assertEquals(unwrapped.length, wrapped.length); - assertTrue(goog.object.containsKey(wrapped[0], bot.inject.ELEMENT_KEY)); - assertEquals(document.body, bot.inject.cache.getElement( - wrapped[0][bot.inject.ELEMENT_KEY])); - } + assert.ok(Array.isArray(wrapped), 'should return an array, but was ' + goog.typeOf(wrapped)); + assert.strictEqual(wrapped.length, unwrapped.length); + assert.ok(goog.object.containsKey(wrapped[0], bot.inject.ELEMENT_KEY)); + assert.strictEqual(bot.inject.cache.getElement( + wrapped[0][bot.inject.ELEMENT_KEY]), document.body); + }); - function testShouldThrowWhenWrappingRecursiveStructure() { + QUnit.test('ShouldThrowWhenWrappingRecursiveStructure', function(assert) { var obj1 = {}; var obj2 = {}; obj1['obj2'] = obj2; obj2['obj1'] = obj1; - assertThrows(goog.partial(bot.inject.wrapValue, obj1)); - } + assert.throws(function() { bot.inject.wrapValue(obj1); }); + }); - function testShouldBeAbleToUnWrapWrappedValues() { + QUnit.test('ShouldBeAbleToUnWrapWrappedValues', function(assert) { var unwrapped = [123, 'abc', null, document.body]; var wrapped = bot.inject.wrapValue(unwrapped); var roundTripped = bot.inject.unwrapValue(wrapped); - assertArrayEquals(unwrapped, roundTripped); - } + assert.deepEqual(roundTripped, unwrapped); + }); - function testShouldBeAbleToUnWrapNestedArrays() { + QUnit.test('ShouldBeAbleToUnWrapNestedArrays', function(assert) { var unwrapped = [123, 'abc', null, [document.body, null, [document.body]]]; var wrapped = bot.inject.wrapValue(unwrapped); var roundTripped = bot.inject.unwrapValue(wrapped); - assertArrayEquals(unwrapped, roundTripped); - } + assert.deepEqual(roundTripped, unwrapped); + }); - function testShouldBeAbleToUnWrapNestedObjects() { + QUnit.test('ShouldBeAbleToUnWrapNestedObjects', function(assert) { var unwrapped = {'foo': {'bar': document.body}}; var wrapped = bot.inject.wrapValue(unwrapped); var roundTripped = bot.inject.unwrapValue(wrapped); - assertTrue(goog.object.containsKey(roundTripped, 'foo')); + assert.ok(goog.object.containsKey(roundTripped, 'foo')); var foo = roundTripped['foo']; - assertTrue(goog.object.containsKey(foo, 'bar')); - assertEquals(document.body, foo['bar']); - } + assert.ok(goog.object.containsKey(foo, 'bar')); + assert.strictEqual(foo['bar'], document.body); + }); - function testShouldUnWrapElementsUsingTheGivenDocumentsCache() { + QUnit.test('ShouldUnWrapElementsUsingTheGivenDocumentsCache', function(assert) { var wrapped = bot.inject.wrapValue(frameDoc.body); - assertNotNull(wrapped); - assertNotUndefined(wrapped); - assertTrue(goog.isObject(wrapped)); - assertTrue(goog.object.containsKey(wrapped, bot.inject.ELEMENT_KEY)); + assert.ok(wrapped !== null); + assert.ok(wrapped !== undefined); + assert.ok(goog.isObject(wrapped)); + assert.ok(goog.object.containsKey(wrapped, bot.inject.ELEMENT_KEY)); - // Should not be able to unwrap using our document since the element - // was cached on its ownerDocument. - assertThrows(goog.partial(bot.inject.unwrapValue, wrapped)); + assert.throws(function() { bot.inject.unwrapValue(wrapped); }); var unwrapped = bot.inject.unwrapValue(wrapped, frameDoc); - assertEquals(frameDoc.body, unwrapped); - } + assert.strictEqual(unwrapped, frameDoc.body); + }); - function testShouldBeAbleToUnwrapArgumentsExecuteScriptAndWrapResult() { + QUnit.test('ShouldBeAbleToUnwrapArgumentsExecuteScriptAndWrapResult', function(assert) { var id = bot.inject.cache.addElement(document.body); var args = [{}]; args[0][bot.inject.ELEMENT_KEY] = id; var result = bot.inject.executeScript( function() { return arguments[0]; }, args); - assertTrue(goog.object.containsKey(result, 'status')); - assertEquals(bot.ErrorCode.SUCCESS, result['status']); + assert.ok(goog.object.containsKey(result, 'status')); + assert.strictEqual(result['status'], bot.ErrorCode.SUCCESS); - assertTrue(goog.object.containsKey(result, 'value')); - assertTrue(goog.object.containsKey(result['value'], + assert.ok(goog.object.containsKey(result, 'value')); + assert.ok(goog.object.containsKey(result['value'], bot.inject.ELEMENT_KEY)); - assertEquals(document.body, bot.inject.cache.getElement( - result['value'][bot.inject.ELEMENT_KEY])); - } + assert.strictEqual(bot.inject.cache.getElement( + result['value'][bot.inject.ELEMENT_KEY]), document.body); + }); - function testShouldTrapAndReturnWrappedErrorsFromInjectedScripts() { + QUnit.test('ShouldTrapAndReturnWrappedErrorsFromInjectedScripts', function(assert) { var result = bot.inject.executeScript( function() { throw Error('ouch'); }, []); - assertTrue(goog.object.containsKey(result, 'status')); - assertTrue(goog.object.containsKey(result, 'value')); + assert.ok(goog.object.containsKey(result, 'status')); + assert.ok(goog.object.containsKey(result, 'value')); - assertEquals(bot.ErrorCode.UNKNOWN_ERROR, result['status']); + assert.strictEqual(result['status'], bot.ErrorCode.UNKNOWN_ERROR); result = result['value']; - assertTrue(goog.object.containsKey(result, 'message')); - assertEquals('ouch', result['message']); - } + assert.ok(goog.object.containsKey(result, 'message')); + assert.strictEqual(result['message'], 'ouch'); + }); - function testShouldResetCacheWhenPageIsRefreshed() { + QUnit.test('ShouldResetCacheWhenPageIsRefreshed', function(assert) { + var done = assert.async(); var id = bot.inject.cache.addElement(frameDoc.body); - assertEquals(frameDoc.body, bot.inject.cache.getElement(id, frameDoc)); + assert.strictEqual(bot.inject.cache.getElement(id, frameDoc), frameDoc.body); - return new goog.Promise(function(loaded) { - goog.events.listenOnce(frame, 'load', loaded); - frameWin.location.reload(); - }).then(function() { + goog.events.listenOnce(frame, 'load', function() { frameDoc = goog.dom.getFrameContentDocument(frame); - assertThrows(goog.partial(bot.inject.cache.getElement, id, frameDoc)); + assert.throws(function() { bot.inject.cache.getElement(id, frameDoc); }); + done(); }); - } + frameWin.location.reload(); + }); - function testShouldStringifyResultsWhenAskedToDoSo() { + QUnit.test('ShouldStringifyResultsWhenAskedToDoSo', function(assert) { var result = bot.inject.executeScript(function() { return arguments[0] + arguments[1]; }, ['abc', 123], true); - assertEquals('string', goog.typeOf(result)); + assert.strictEqual(goog.typeOf(result), 'string'); var json = bot.json.parse(result); - assertTrue('No status: ' + result, 'status' in json); - assertTrue('No value: ' + result, 'value' in json); - assertEquals(0, json['status']); - assertEquals('abc123', json['value']); - } + assert.ok('status' in json, 'No status: ' + result); + assert.ok('value' in json, 'No value: ' + result); + assert.strictEqual(json['status'], 0); + assert.strictEqual(json['value'], 'abc123'); + }); - function testShouldStringifyErrorsWhenAskedForStringResults() { + QUnit.test('ShouldStringifyErrorsWhenAskedForStringResults', function(assert) { var result = bot.inject.executeScript(function() { throw new bot.Error(bot.ErrorCode.NO_SUCH_ELEMENT, 'ouch'); }, [], true); - assertEquals('string', goog.typeOf(result)); + assert.strictEqual(goog.typeOf(result), 'string'); var json = bot.json.parse(result); - assertTrue('No status: ' + result, 'status' in json); - assertTrue('No value: ' + result, 'value' in json); - assertEquals(bot.ErrorCode.NO_SUCH_ELEMENT, json['status']); - assertTrue('No message: ' + result, 'message' in json['value']); - assertEquals('ouch', json['value']['message']); - } - - - function testShouldBeAbleToExecuteAsyncScript() { - return new goog.Promise(function(done) { - bot.inject.executeAsyncScript( - 'window.setTimeout(goog.partial(arguments[0], 1), 10)', - [], 250, done); - }).then(function(result) { - assertTrue(goog.object.containsKey(result, 'status')); - assertEquals(bot.ErrorCode.SUCCESS, result['status']); - assertTrue(goog.object.containsKey(result, 'value')); - assertEquals(1, result['value']); + assert.ok('status' in json, 'No status: ' + result); + assert.ok('value' in json, 'No value: ' + result); + assert.strictEqual(json['status'], bot.ErrorCode.NO_SUCH_ELEMENT); + assert.ok('message' in json['value'], 'No message: ' + result); + assert.strictEqual(json['value']['message'], 'ouch'); + }); + + + QUnit.test('ShouldBeAbleToExecuteAsyncScript', function(assert) { + var done = assert.async(); + bot.inject.executeAsyncScript( + 'window.setTimeout(goog.partial(arguments[0], 1), 10)', + [], 250, function(result) { + assert.ok(goog.object.containsKey(result, 'status')); + assert.strictEqual(result['status'], bot.ErrorCode.SUCCESS); + assert.ok(goog.object.containsKey(result, 'value')); + assert.strictEqual(result['value'], 1); + done(); }); - } + }); - function testShouldBeAbleToExecuteAsyncScriptThatCallsbackSynchronously() { - return new goog.Promise(function(done) { - bot.inject.executeAsyncScript('arguments[0](1)', [], 0, done); - }).then(function(result) { - assertTrue(goog.object.containsKey(result, 'status')); - assertEquals(bot.ErrorCode.SUCCESS, result['status']); - assertTrue(goog.object.containsKey(result, 'value')); - assertEquals(1, result['value']); + QUnit.test('ShouldBeAbleToExecuteAsyncScriptThatCallsbackSynchronously', function(assert) { + var done = assert.async(); + bot.inject.executeAsyncScript('arguments[0](1)', [], 0, function(result) { + assert.ok(goog.object.containsKey(result, 'status')); + assert.strictEqual(result['status'], bot.ErrorCode.SUCCESS); + assert.ok(goog.object.containsKey(result, 'value')); + assert.strictEqual(result['value'], 1); + done(); }); - } - - - function testShouldBeAbleToExecuteAsyncFunc() { - return new goog.Promise(function(done) { - bot.inject.executeAsyncScript( - function(callback) { callback(1) }, [], 0, done); - }).then(function(result) { - assertTrue(goog.object.containsKey(result, 'status')); - assertEquals(bot.ErrorCode.SUCCESS, result['status']); - assertTrue(goog.object.containsKey(result, 'value')); - assertEquals(1, result['value']); + }); + + + QUnit.test('ShouldBeAbleToExecuteAsyncFunc', function(assert) { + var done = assert.async(); + bot.inject.executeAsyncScript( + function(callback) { callback(1) }, [], 0, function(result) { + assert.ok(goog.object.containsKey(result, 'status')); + assert.strictEqual(result['status'], bot.ErrorCode.SUCCESS); + assert.ok(goog.object.containsKey(result, 'value')); + assert.strictEqual(result['value'], 1); + done(); }); - } + }); - function testShouldThrowOnExecuteAsyncException() { - return new goog.Promise(function(done) { - bot.inject.executeAsyncScript('nosuchfunc()', [], 0, done); - }).then(function(result) { - assertTrue(goog.object.containsKey(result, 'status')); - assertEquals(bot.ErrorCode.UNKNOWN_ERROR, result['status']); + QUnit.test('ShouldThrowOnExecuteAsyncException', function(assert) { + var done = assert.async(); + bot.inject.executeAsyncScript('nosuchfunc()', [], 0, function(result) { + assert.ok(goog.object.containsKey(result, 'status')); + assert.strictEqual(result['status'], bot.ErrorCode.UNKNOWN_ERROR); + done(); }); - } + }); - function testShouldTimeoutInExecuteAsync() { - return new goog.Promise(function(done) { - bot.inject.executeAsyncScript('', [], 0, done); - }).then(function(result) { - assertTrue(goog.object.containsKey(result, 'status')); - assertEquals(bot.ErrorCode.SCRIPT_TIMEOUT, result['status']); + QUnit.test('ShouldTimeoutInExecuteAsync', function(assert) { + var done = assert.async(); + bot.inject.executeAsyncScript('', [], 0, function(result) { + assert.ok(goog.object.containsKey(result, 'status')); + assert.strictEqual(result['status'], bot.ErrorCode.SCRIPT_TIMEOUT); + done(); }); - } + }); - function testShouldBeAbleToStringifyResult() { - return new goog.Promise(function(done) { - bot.inject.executeAsyncScript('', [], 0, done, true); - }).then(function(jsonResult) { + QUnit.test('ShouldBeAbleToStringifyResult', function(assert) { + var done = assert.async(); + bot.inject.executeAsyncScript('', [], 0, function(jsonResult) { var result = bot.json.parse(jsonResult); - assertTrue(goog.object.containsKey(result, 'status')); - assertEquals(bot.ErrorCode.SCRIPT_TIMEOUT, result['status']); - }); - } - - - function testShouldBeAbleToWrapAndUnwrapInExecuteAsyncScript() { - return new goog.Promise(function(done) { - var id = bot.inject.cache.addElement(document.body); - var args = [{}]; - args[0][bot.inject.ELEMENT_KEY] = id; - bot.inject.executeAsyncScript( - 'arguments[1](arguments[0])', args, 0, done); - }).then(function(result) { - assertTrue(goog.object.containsKey(result, 'status')); - assertEquals(bot.ErrorCode.SUCCESS, result['status']); - - assertTrue(goog.object.containsKey(result, 'value')); - assertTrue(goog.object.containsKey(result['value'], + assert.ok(goog.object.containsKey(result, 'status')); + assert.strictEqual(result['status'], bot.ErrorCode.SCRIPT_TIMEOUT); + done(); + }, true); + }); + + + QUnit.test('ShouldBeAbleToWrapAndUnwrapInExecuteAsyncScript', function(assert) { + var done = assert.async(); + var id = bot.inject.cache.addElement(document.body); + var args = [{}]; + args[0][bot.inject.ELEMENT_KEY] = id; + bot.inject.executeAsyncScript( + 'arguments[1](arguments[0])', args, 0, function(result) { + assert.ok(goog.object.containsKey(result, 'status')); + assert.strictEqual(result['status'], bot.ErrorCode.SUCCESS); + + assert.ok(goog.object.containsKey(result, 'value')); + assert.ok(goog.object.containsKey(result['value'], bot.inject.ELEMENT_KEY)); - assertEquals(document.body, bot.inject.cache.getElement( - result['value'][bot.inject.ELEMENT_KEY])); + assert.strictEqual(bot.inject.cache.getElement( + result['value'][bot.inject.ELEMENT_KEY]), document.body); + done(); }); - } + }); - function testShouldExecuteAsyncScriptsInTheContextOfTheSpecifiedWindow() { + QUnit.test('ShouldExecuteAsyncScriptsInTheContextOfTheSpecifiedWindow', function(assert) { if (goog.userAgent.IE || goog.userAgent.product.SAFARI || (goog.userAgent.product.ANDROID && !bot.userAgent.isProductVersion(4))) { - // Android prior to Ice Cream Sandwich has a known issue, b/5006213. - // TODO: Don't skip this. + assert.ok(true, 'Skipping: known issue on this browser'); return; } - return new goog.Promise(function(done) { - bot.inject.executeAsyncScript(function(callback) { - callback({ - 'this == window': (this == window), - 'this == top': (this == window.top), - 'typeof window.MY_GLOBAL_CONSTANT': (typeof MY_GLOBAL_CONSTANT), - 'typeof window.top.MY_GLOBAL_CONSTANT': - (typeof window.top.MY_GLOBAL_CONSTANT) - }); - }, [], 0, done, false, frameWin); - }).then(function(result) { + var done = assert.async(); + bot.inject.executeAsyncScript(function(callback) { + callback({ + 'this == window': (this == window), + 'this == top': (this == window.top), + 'typeof window.MY_GLOBAL_CONSTANT': (typeof MY_GLOBAL_CONSTANT), + 'typeof window.top.MY_GLOBAL_CONSTANT': + (typeof window.top.MY_GLOBAL_CONSTANT) + }); + }, [], 0, function(result) { var jsonResult = bot.json.stringify(result); - assertTrue(jsonResult, goog.object.containsKey(result, 'status')); - assertEquals(jsonResult, bot.ErrorCode.SUCCESS, result['status']); + assert.ok(goog.object.containsKey(result, 'status'), jsonResult); + assert.strictEqual(result['status'], bot.ErrorCode.SUCCESS, jsonResult); - assertTrue(jsonResult, goog.object.containsKey(result, 'value')); + assert.ok(goog.object.containsKey(result, 'value'), jsonResult); var value = result['value']; - assertEquals(jsonResult, true, value['this == window']); - assertEquals(jsonResult, false, value['this == top']); - assertEquals(jsonResult, 'undefined', - value['typeof window.MY_GLOBAL_CONSTANT']); - assertEquals(jsonResult, 'number', - value['typeof window.top.MY_GLOBAL_CONSTANT']); - }); - } + assert.strictEqual(value['this == window'], true, jsonResult); + assert.strictEqual(value['this == top'], false, jsonResult); + assert.strictEqual(value['typeof window.MY_GLOBAL_CONSTANT'], 'undefined', jsonResult); + assert.strictEqual(value['typeof window.top.MY_GLOBAL_CONSTANT'], 'number', jsonResult); + done(); + }, false, frameWin); + }); - function testShouldExecuteScriptsInTheContextOfTheSpecifiedWindow() { + QUnit.test('ShouldExecuteScriptsInTheContextOfTheSpecifiedWindow', function(assert) { if (goog.userAgent.IE || goog.userAgent.product.SAFARI || (goog.userAgent.product.ANDROID && !bot.userAgent.isProductVersion(4))) { - // Android prior to Ice Cream Sandwich has a known issue, b/5006213. - // TODO: Don't skip this. + assert.ok(true, 'Skipping: known issue on this browser'); return; } @@ -467,43 +457,41 @@ var jsonResult = bot.json.stringify(result); - assertTrue(jsonResult, goog.object.containsKey(result, 'status')); - assertEquals(jsonResult, bot.ErrorCode.SUCCESS, result['status']); + assert.ok(goog.object.containsKey(result, 'status'), jsonResult); + assert.strictEqual(result['status'], bot.ErrorCode.SUCCESS, jsonResult); - assertTrue(jsonResult, goog.object.containsKey(result, 'value')); + assert.ok(goog.object.containsKey(result, 'value'), jsonResult); var value = result['value']; - assertEquals(jsonResult, true, value['this == window']); - assertEquals(jsonResult, false, value['this == top']); - assertEquals(jsonResult, 'undefined', - value['typeof window.MY_GLOBAL_CONSTANT']); - assertEquals(jsonResult, 'number', - value['typeof window.top.MY_GLOBAL_CONSTANT']); - } + assert.strictEqual(value['this == window'], true, jsonResult); + assert.strictEqual(value['this == top'], false, jsonResult); + assert.strictEqual(value['typeof window.MY_GLOBAL_CONSTANT'], 'undefined', jsonResult); + assert.strictEqual(value['typeof window.top.MY_GLOBAL_CONSTANT'], 'number', jsonResult); + }); - function testCorrectlyUnwrapsFunctionArgsForInjectedScripts() { + QUnit.test('CorrectlyUnwrapsFunctionArgsForInjectedScripts', function(assert) { var result = bot.inject.executeScript(function() { return arguments[0](); }, [function() {return 1;}]); - assertEquals(bot.ErrorCode.SUCCESS, result['status']); - assertEquals(1, result['value']); - } - - function testCorrectlyUnwrapsFunctionArgsForInjectedAsyncScripts() { - return new goog.Promise(function(done) { - bot.inject.executeAsyncScript(function() { - var callback = arguments[arguments.length - 1]; - callback(arguments[0]()); - }, [function() {return 1;}], 0, done, false); - }).then(function(result) { - assertEquals(bot.ErrorCode.SUCCESS, result['status']); - assertEquals(1, result['value']); - }); - } - - function testCorrectlyUnwrapsArgsForInjectedScripts() { + assert.strictEqual(result['status'], bot.ErrorCode.SUCCESS); + assert.strictEqual(result['value'], 1); + }); + + QUnit.test('CorrectlyUnwrapsFunctionArgsForInjectedAsyncScripts', function(assert) { + var done = assert.async(); + bot.inject.executeAsyncScript(function() { + var callback = arguments[arguments.length - 1]; + callback(arguments[0]()); + }, [function() {return 1;}], 0, function(result) { + assert.strictEqual(result['status'], bot.ErrorCode.SUCCESS); + assert.strictEqual(result['value'], 1); + done(); + }, false); + }); + + QUnit.test('CorrectlyUnwrapsArgsForInjectedScripts', function(assert) { if (goog.userAgent.IE) { - // TODO: Don't skip this. + assert.ok(true, 'Skipping: TODO fix for IE'); return; } var wrapped = bot.inject.wrapValue(frameDoc.body); @@ -512,67 +500,67 @@ return [arguments[0], arguments[0].tagName.toUpperCase()]; }, [wrapped], false, frameWin); - assertEquals(bot.ErrorCode.SUCCESS, result['status']); + assert.strictEqual(result['status'], bot.ErrorCode.SUCCESS); var value = result['value']; - assertTrue(Array.isArray(value)); - assertEquals(2, value.length); + assert.ok(Array.isArray(value)); + assert.strictEqual(value.length, 2); - assertTrue(goog.isObject(value[0])); - assertTrue(goog.object.containsKey(value[0], bot.inject.ELEMENT_KEY)); - assertEquals(wrapped[bot.inject.ELEMENT_KEY], - value[0][bot.inject.ELEMENT_KEY]); + assert.ok(goog.isObject(value[0])); + assert.ok(goog.object.containsKey(value[0], bot.inject.ELEMENT_KEY)); + assert.strictEqual(value[0][bot.inject.ELEMENT_KEY], + wrapped[bot.inject.ELEMENT_KEY]); - assertEquals('BODY', value[1]); - } + assert.strictEqual(value[1], 'BODY'); + }); - function testCorrectlyUnwrapsArgsForInjectedAsyncScripts() { + QUnit.test('CorrectlyUnwrapsArgsForInjectedAsyncScripts', function(assert) { if (goog.userAgent.IE) { - // TODO: Don't skip this. + assert.ok(true, 'Skipping: TODO fix for IE'); return; } var wrapped = bot.inject.wrapValue(frameDoc.body); - return new goog.Promise(function(done) { - bot.inject.executeAsyncScript(function(element, callback) { - callback([element, element.tagName.toUpperCase()]); - }, [wrapped], 0, done, false, frameWin); - }).then(function(result) { - assertEquals(bot.ErrorCode.SUCCESS, result['status']); + var done = assert.async(); + bot.inject.executeAsyncScript(function(element, callback) { + callback([element, element.tagName.toUpperCase()]); + }, [wrapped], 0, function(result) { + assert.strictEqual(result['status'], bot.ErrorCode.SUCCESS); var value = result['value']; - assertTrue(Array.isArray(value)); - assertEquals(2, value.length); + assert.ok(Array.isArray(value)); + assert.strictEqual(value.length, 2); - assertTrue(goog.isObject(value[0])); - assertTrue(goog.object.containsKey(value[0], bot.inject.ELEMENT_KEY)); - assertEquals(wrapped[bot.inject.ELEMENT_KEY], - value[0][bot.inject.ELEMENT_KEY]); + assert.ok(goog.isObject(value[0])); + assert.ok(goog.object.containsKey(value[0], bot.inject.ELEMENT_KEY)); + assert.strictEqual(value[0][bot.inject.ELEMENT_KEY], + wrapped[bot.inject.ELEMENT_KEY]); - assertEquals('BODY', value[1]); - }); - } + assert.strictEqual(value[1], 'BODY'); + done(); + }, false, frameWin); + }); - function testExecuteScriptShouldBeAbleToRecurseOnItself() { + QUnit.test('ExecuteScriptShouldBeAbleToRecurseOnItself', function(assert) { if (goog.userAgent.IE) { - // TODO: Don't skip this. + assert.ok(true, 'Skipping: TODO fix for IE'); return; } var json = bot.inject.executeScript(bot.inject.executeScript, ['return 1 +2;'], true); var result = bot.json.parse(json); - assertTrue(json, goog.object.containsKey(result, 'status')); - assertEquals(json, bot.ErrorCode.SUCCESS, result['status']); - assertTrue(json, goog.object.containsKey(result, 'value')); + assert.ok(goog.object.containsKey(result, 'status'), json); + assert.strictEqual(result['status'], bot.ErrorCode.SUCCESS, json); + assert.ok(goog.object.containsKey(result, 'value'), json); var innerResult = result['value']; - assertTrue(json, goog.isObject(innerResult)); - assertTrue(json, goog.object.containsKey(innerResult, 'status')); - assertEquals(json, bot.ErrorCode.SUCCESS, innerResult['status']); - assertTrue(json, goog.object.containsKey(innerResult, 'value')); - assertEquals(json, 3, innerResult['value']); - } + assert.ok(goog.isObject(innerResult), json); + assert.ok(goog.object.containsKey(innerResult, 'status'), json); + assert.strictEqual(innerResult['status'], bot.ErrorCode.SUCCESS, json); + assert.ok(goog.object.containsKey(innerResult, 'value'), json); + assert.strictEqual(innerResult['value'], 3, json); + }); diff --git a/javascript/atoms/test/interactable_size_test.html b/javascript/atoms/test/interactable_size_test.html index 8231f518d9f36..b3609cc6603c8 100644 --- a/javascript/atoms/test/interactable_size_test.html +++ b/javascript/atoms/test/interactable_size_test.html @@ -1,15 +1,17 @@ + interactable_size_test - + + + @@ -22,44 +24,41 @@ return bot.window.getInteractableSize(win); } - function testShouldReturnViewportSizeIfThatIsLargest() { + QUnit.test('should return viewport size if that is largest', function(assert) { var size = getSizeOfFrameWithId('set_size'); - assertEquals(110, size.width); - assertEquals(100, size.height); - } + assert.strictEqual(size.width, 110); + assert.strictEqual(size.height, 100); + }); - function testShouldReturnDocumentSizeIfThatIsGreatestAndInStandardsMode() { + QUnit.test('should return document size if that is greatest and in standards mode', function(assert) { var size = getSizeOfFrameWithId('doc_size'); - assertEquals(700, size.width); - assertEquals(500, size.height); - } + assert.strictEqual(size.width, 700); + assert.strictEqual(size.height, 500); + }); - function testShouldReturnDocumentSizeIfThatIsGreatestAndInQuirksMode() { + QUnit.test('should return document size if that is greatest and in quirks mode', function(assert) { var size = getSizeOfFrameWithId('quirks_size'); - // In quirks mode IE limits the size of the frame to the content var width = bot.userAgent.IE_DOC_PRE9 ? 110 : 700; var height = bot.userAgent.IE_DOC_PRE9 ? 100 : 500; - assertEquals(width, size.width); - assertEquals(height, size.height); - } + assert.strictEqual(size.width, width); + assert.strictEqual(size.height, height); + }); - function testSizeShouldBeBasedOnLargestElementInThePage() { + QUnit.test('size should be based on largest element in the page', function(assert) { var size = getSizeOfFrameWithId('table_size'); - // We can't be sure of the size of the window, but it's at least these - // values, which are based on the table size in the doc. - assertTrue('Width needs to be at least 349px. It is: ' + size.width, - size.width > 349); - assertTrue('Height needs to be at least 199px. It is: ' + size.height, - size.height > 199); - } + assert.ok(size.width > 349, 'Width needs to be at least 349px. It is: ' + size.width); + assert.ok(size.height > 199, 'Height needs to be at least 199px. It is: ' + size.height); + }); +
+
diff --git a/javascript/atoms/test/keyboard_test.html b/javascript/atoms/test/keyboard_test.html index f096658ebedb6..87cbe3af2cc47 100644 --- a/javascript/atoms/test/keyboard_test.html +++ b/javascript/atoms/test/keyboard_test.html @@ -1,47 +1,52 @@ -keyboard_test - - + + keyboard_test + + + + + +
+
diff --git a/javascript/atoms/test/locator_test.html b/javascript/atoms/test/locator_test.html index 97026cd88a869..4b21a5e13f298 100644 --- a/javascript/atoms/test/locator_test.html +++ b/javascript/atoms/test/locator_test.html @@ -17,443 +17,528 @@ --> - locator_test.html - - - - + + + - var second = bot.locators.findElement(locator); - assertEquals('tiger', second.getAttribute('name')); - } finally { - delete Object.prototype.cheese; - delete Object.prototype.Inherits; - } - } + -

Para

- -
nope
-
yup
-
simba
-
shere khan
-
dotted class
-
another dotted class
- - -
- - - - - - Furrfu - -
    -
  • item -
  • item -
  • item -
  • item -
-
apóstrofo
-
comilla
-
barra invertida
-
space
-
queso!
- - this is a link - this is a link - this is a link - this is a link - this is a link - - unrelated - - has, a comma - - +
+
diff --git a/javascript/atoms/test/mouse_test.html b/javascript/atoms/test/mouse_test.html index cfc8469451b2c..cdaa813cf1583 100644 --- a/javascript/atoms/test/mouse_test.html +++ b/javascript/atoms/test/mouse_test.html @@ -1,36 +1,40 @@ -mouse_test - - + + mouse_test + + + + + + -
-
Red
-
-
-
+
+
+
+
Red
+
+
+
+
-
diff --git a/javascript/atoms/test/opacity_test.html b/javascript/atoms/test/opacity_test.html index 17777710e337d..71836081bcc0d 100644 --- a/javascript/atoms/test/opacity_test.html +++ b/javascript/atoms/test/opacity_test.html @@ -1,6 +1,7 @@ + opacity_test.html - + + + @@ -33,20 +35,6 @@ var findElement = bot.locators.findElement; var helper = new goog.dom.DomHelper(); - function testOpacity() { - var suite = buildTestSuites(); - - if(!bot.userAgent.IE_DOC_PRE9) { - runTestSuite(suite, 'others'); - } else if(bot.userAgent.isEngineVersion(8)) { - runTestSuite(suite, 'ie8'); - } else if(bot.userAgent.isEngineVersion(7)) { - runTestSuite(suite, 'ie7'); - } else if(bot.userAgent.isEngineVersion(6)) { - runTestSuite(suite, 'ie6'); - } - } - function buildMap(headers, row) { var map = {}; var values = helper.getElementsByTagNameAndClass(goog.dom.TagName.TD, undefined, row); @@ -74,22 +62,36 @@ return suites; } - function runTestSuite(testSpecs, browser) { + function runTestSuite(assert, testSpecs, browser) { goog.iter.forEach(testSpecs, function(testSpec) { var node = testSpec['example']; var comment = "Test no." + testSpec['id'] + " for browser " + browser + ": " + testSpec['style']; try { - assertEquals(comment, Number(testSpec[browser]), bot.dom.getOpacity(node)); - //alert(comment + " expected: " + Number(testSpec[browser]) + " value: " + bot.dom.getOpacity(node)); + assert.strictEqual(bot.dom.getOpacity(node), Number(testSpec[browser]), comment); } catch(e) { - fail("Test no." + testSpec['id'] + " failed with exception: " + e.message); + assert.ok(false, "Test no." + testSpec['id'] + " failed with exception: " + e.message); } }); - //alert("run " + testSpecs.length); } + + QUnit.test('opacity', function(assert) { + var suite = buildTestSuites(); + + if(!bot.userAgent.IE_DOC_PRE9) { + runTestSuite(assert, suite, 'others'); + } else if(bot.userAgent.isEngineVersion(8)) { + runTestSuite(assert, suite, 'ie8'); + } else if(bot.userAgent.isEngineVersion(7)) { + runTestSuite(assert, suite, 'ie7'); + } else if(bot.userAgent.isEngineVersion(6)) { + runTestSuite(assert, suite, 'ie6'); + } + }); +
+

To determine opacity, it is not enough to simply read a property diff --git a/javascript/atoms/test/orientation_test.html b/javascript/atoms/test/orientation_test.html index 960847fe92fa0..345dcb7aecd75 100644 --- a/javascript/atoms/test/orientation_test.html +++ b/javascript/atoms/test/orientation_test.html @@ -1,26 +1,31 @@ + orientation_test + + + +

+
diff --git a/javascript/atoms/test/overflow_test.html b/javascript/atoms/test/overflow_test.html index 6c98b4cd04d9a..8c4e3b2a84473 100644 --- a/javascript/atoms/test/overflow_test.html +++ b/javascript/atoms/test/overflow_test.html @@ -1,14 +1,17 @@ + overflow_test.html + + + @@ -17,14 +20,11 @@ var HIDDEN = bot.dom.OverflowState.HIDDEN; var SCROLL = bot.dom.OverflowState.SCROLL; - function tearDown() { + QUnit.testDone(function() { document.documentElement.style.position = ''; - } + }); - function testElemHiddenByParent() { - // Column 1: position style of the element - // Column 2: position style of the element's parent - // Column 3: expected overflow state of the element + QUnit.test('elemHiddenByParent', function(assert) { var positionStylesToOverflowStateTable = [ ['absolute', 'absolute', HIDDEN], ['absolute', 'fixed', HIDDEN], @@ -61,16 +61,12 @@ parent.appendChild(elem); document.body.appendChild(parent); - assertEquals('position: ' + position + '; parent position: ' + - parentPosition, expectedState, bot.dom.getOverflowState(elem)); + assert.strictEqual(bot.dom.getOverflowState(elem), expectedState, + 'position: ' + position + '; parent position: ' + parentPosition); }); - } + }); - function testElemHiddenByGrandparent() { - // Column 1: position style of the element - // Column 2: position style of the element's parent - // Column 3: position style of the element's grandparent - // Column 4: expected overflow state of the element + QUnit.test('elemHiddenByGrandparent', function(assert) { var positionStylesToOverflowStateTable = [ ['absolute', 'absolute', 'absolute', HIDDEN], ['absolute', 'absolute', 'fixed' , HIDDEN], @@ -161,41 +157,38 @@ grandparent.appendChild(parent); document.body.appendChild(grandparent); - assertEquals('position: ' + position + '; parent position: ' + - parentPosition + '; grandparent position: ' + grandparentPosition, - expectedState, bot.dom.getOverflowState(elem)); + assert.strictEqual(bot.dom.getOverflowState(elem), expectedState, + 'position: ' + position + '; parent position: ' + + parentPosition + '; grandparent position: ' + grandparentPosition); }); - } + }); - function testChildOfScrollStyleHasScrollStatus() { + QUnit.test('childOfScrollStyleHasScrollStatus', function(assert) { var e = document.getElementById('overflowScroll'); - assertEquals(SCROLL, bot.dom.getOverflowState(e)); - } + assert.strictEqual(bot.dom.getOverflowState(e), SCROLL); + }); - function testChildOfAutoStyleHasScrollStatus() { + QUnit.test('childOfAutoStyleHasScrollStatus', function(assert) { var e = document.getElementById('overflowAuto'); - assertEquals(SCROLL, bot.dom.getOverflowState(e)); - } + assert.strictEqual(bot.dom.getOverflowState(e), SCROLL); + }); - function testChildOfScrollStyleInHiddenHasScrollStatusWhenParentNotInOverflow() { + QUnit.test('childOfScrollStyleInHiddenHasScrollStatusWhenParentNotInOverflow', function(assert) { var e = document.getElementById('overflowScrollInHiddenIsScroll'); - assertEquals(SCROLL, bot.dom.getOverflowState(e)); - } + assert.strictEqual(bot.dom.getOverflowState(e), SCROLL); + }); - function testChildOfScrollStyleInHiddenHasHiddenStatusWhenParentInOverflow() { + QUnit.test('childOfScrollStyleInHiddenHasHiddenStatusWhenParentInOverflow', function(assert) { var e = document.getElementById('overflowScrollInHiddenIsHidden'); - assertEquals(HIDDEN, bot.dom.getOverflowState(e)); - } + assert.strictEqual(bot.dom.getOverflowState(e), HIDDEN); + }); - function testOverflowOfHtmlAndBodyElements() { + QUnit.test('overflowOfHtmlAndBodyElements', function(assert) { if (bot.userAgent.ANDROID_PRE_GINGERBREAD) { + assert.ok(true, 'Skipping: Android pre-Gingerbread'); return; } - // Column 1: overflow style of the element - // Column 2: overflow style of the element - // Column 3: expected overflow state of the overflowsBodyNotDoc element - // Column 4: expected overflow state of the overflowsBodyAndDoc element var overflowStylesToOverflowStateTable = [ ['auto' , 'auto' , SCROLL, SCROLL], ['auto' , 'hidden' , HIDDEN, HIDDEN], @@ -232,53 +225,49 @@ var msg = 'html overflow style: ' + htmlOverflowStyle + '; ' + 'body overflow style: ' + bodyOverflowStyle; overflowsNothing.innerHTML = msg; - assertEquals(msg, NONE, - bot.dom.getOverflowState(overflowsNothing)); - assertEquals(msg, expectedOverflowsBodyNotDocState, - bot.dom.getOverflowState(overflowsBodyNotDoc)); - assertEquals(msg, expectedOverflowsBodyAndDocState, - bot.dom.getOverflowState(overflowsBodyAndDoc)); + assert.strictEqual(bot.dom.getOverflowState(overflowsNothing), NONE, msg); + assert.strictEqual(bot.dom.getOverflowState(overflowsBodyNotDoc), + expectedOverflowsBodyNotDocState, msg); + assert.strictEqual(bot.dom.getOverflowState(overflowsBodyAndDoc), + expectedOverflowsBodyAndDocState, msg); }); - } + }); - function testChildOfAnElementWithZeroHeightAndWidthAndOverflowHiddenIsNotVisible() { + QUnit.test('childOfAnElementWithZeroHeightAndWidthAndOverflowHiddenIsNotVisible', function(assert) { var child = document.getElementById('bug5140-1-child'); - assertEquals(HIDDEN, bot.dom.getOverflowState(child)); - } + assert.strictEqual(bot.dom.getOverflowState(child), HIDDEN); + }); - function testFarShiftedChildOfAnElementWitOverflowHiddenIsNotVisible() { + QUnit.test('farShiftedChildOfAnElementWitOverflowHiddenIsNotVisible', function(assert) { var child = document.getElementById('bug5140-2-child'); - assertEquals(HIDDEN, bot.dom.getOverflowState(child)); - } + assert.strictEqual(bot.dom.getOverflowState(child), HIDDEN); + }); - function testNotFarShiftedChildOfAnElementWithOverflowHiddenIsVisible() { + QUnit.test('notFarShiftedChildOfAnElementWithOverflowHiddenIsVisible', function(assert) { var child = document.getElementById('bug5140-3-child'); - assertEquals(NONE, bot.dom.getOverflowState(child)); - } + assert.strictEqual(bot.dom.getOverflowState(child), NONE); + }); - function testFarShiftedGrandchildOfAnElementWitOverflowHiddenIsNotVisible() { + QUnit.test('farShiftedGrandchildOfAnElementWitOverflowHiddenIsNotVisible', function(assert) { var child = document.getElementById('bug5140-4-grandchild'); - assertEquals(HIDDEN, bot.dom.getOverflowState(child)); - } + assert.strictEqual(bot.dom.getOverflowState(child), HIDDEN); + }); - function testFloatingElemHiddenByBlockParent() { + QUnit.test('floatingElemHiddenByBlockParent', function(assert) { var elem = document.getElementById('floatingInsideBlockParent'); - assertEquals(HIDDEN, bot.dom.getOverflowState(elem)); - } + assert.strictEqual(bot.dom.getOverflowState(elem), HIDDEN); + }); - function testFloatingElemNotHiddenByInlineParent() { + QUnit.test('floatingElemNotHiddenByInlineParent', function(assert) { var elem = document.getElementById('floatingInsideInlineParent'); - assertEquals(NONE, bot.dom.getOverflowState(elem)); - } + assert.strictEqual(bot.dom.getOverflowState(elem), NONE); + }); - function testNegativePositionInOverflowVisibleParent() { - // IE 6 does not support fixed-position elements properly. + QUnit.test('negativePositionInOverflowVisibleParent', function(assert) { if (goog.userAgent.IE && !bot.userAgent.isProductVersion(7)) { + assert.ok(true, 'Skipping: IE 6 does not support fixed-position elements properly'); return; } - // Column 1: position style of the element - // Column 2: position style of the element's parent - // Column 3: expected overflow state of element var positionStylesToOverflowStateTable = [ ['absolute', 'absolute', NONE ], ['absolute', 'fixed', NONE ], @@ -322,19 +311,16 @@ parent.appendChild(elem); parentContainer.appendChild(parent); - assertEquals('position: ' + position + '; parent position: ' + - parentPosition, expectedState, bot.dom.getOverflowState(elem)); + assert.strictEqual(bot.dom.getOverflowState(elem), expectedState, + 'position: ' + position + '; parent position: ' + parentPosition); }); - } + }); - function testNegativePositionNotInOverflowVisibleParent() { - // IE 6 does not support fixed-position elements properly. + QUnit.test('negativePositionNotInOverflowVisibleParent', function(assert) { if (goog.userAgent.IE && !bot.userAgent.isProductVersion(7)) { + assert.ok(true, 'Skipping: IE 6 does not support fixed-position elements properly'); return; } - // Column 1: position style of the element - // Column 2: position style of the element's parent - // Column 3: expected overflow state var positionStylesToOverflowStateTable = [ ['absolute', 'absolute', HIDDEN], ['absolute', 'fixed', HIDDEN], @@ -381,93 +367,93 @@ goog.array.forEach(nonVisibleOverflowStyles, function(parentOverflowStyle) { parent.style['overflow'] = parentOverflowStyle; - assertEquals('position: ' + position + '; parent position: ' + - parentPosition, expectedState, bot.dom.getOverflowState(elem)); + assert.strictEqual(bot.dom.getOverflowState(elem), expectedState, + 'position: ' + position + '; parent position: ' + parentPosition); }); }); - } + }); - function testScrollingInAndOutOfView() { + QUnit.test('scrollingInAndOutOfView', function(assert) { var line1 = document.getElementById('line1'); var line5 = document.getElementById('line5'); - assertEquals(NONE, bot.dom.getOverflowState(line1)); - assertEquals(SCROLL, bot.dom.getOverflowState(line5)); + assert.strictEqual(bot.dom.getOverflowState(line1), NONE); + assert.strictEqual(bot.dom.getOverflowState(line5), SCROLL); line5.scrollIntoView(); - assertEquals(SCROLL, bot.dom.getOverflowState(line1)); - assertEquals(NONE, bot.dom.getOverflowState(line5)); + assert.strictEqual(bot.dom.getOverflowState(line1), SCROLL); + assert.strictEqual(bot.dom.getOverflowState(line5), NONE); line1.scrollIntoView(); - assertEquals(NONE, bot.dom.getOverflowState(line1)); - assertEquals(SCROLL, bot.dom.getOverflowState(line5)); - } + assert.strictEqual(bot.dom.getOverflowState(line1), NONE); + assert.strictEqual(bot.dom.getOverflowState(line5), SCROLL); + }); - function testInOverflowHiddenByTransform() { - // IE versions < 9 do not support CSS transform styles. + QUnit.test('inOverflowHiddenByTransform', function(assert) { if (goog.userAgent.IE && !bot.userAgent.isProductVersion(9)) { + assert.ok(true, 'Skipping: IE versions < 9 do not support CSS transform styles'); return; } var hiddenTransformX = document.getElementById('hidden-transformX'); - assertEquals(HIDDEN, bot.dom.getOverflowState(hiddenTransformX)); + assert.strictEqual(bot.dom.getOverflowState(hiddenTransformX), HIDDEN); var hiddenTransformY = document.getElementById('hidden-transformY'); - assertEquals(HIDDEN, bot.dom.getOverflowState(hiddenTransformY)); - } + assert.strictEqual(bot.dom.getOverflowState(hiddenTransformY), HIDDEN); + }); - function testOverflowStateOfRelativeCoordinate() { - // IE 6 does not support overflow state properly. + QUnit.test('overflowStateOfRelativeCoordinate', function(assert) { if (goog.userAgent.IE && !bot.userAgent.isProductVersion(7)) { + assert.ok(true, 'Skipping: IE 6 does not support overflow state properly'); return; } var elem = document.getElementById('halfHidden'); - assertEquals(NONE, bot.dom.getOverflowState(elem, - new goog.math.Coordinate(1, 1))); - assertEquals(HIDDEN, bot.dom.getOverflowState(elem, - new goog.math.Coordinate(60, 60))); - } + assert.strictEqual(bot.dom.getOverflowState(elem, + new goog.math.Coordinate(1, 1)), NONE); + assert.strictEqual(bot.dom.getOverflowState(elem, + new goog.math.Coordinate(60, 60)), HIDDEN); + }); - function testOverflowStateOfRelativeRectangle() { - // IE 6 does not support overflow state properly. + QUnit.test('overflowStateOfRelativeRectangle', function(assert) { if (goog.userAgent.IE && !bot.userAgent.isProductVersion(7)) { + assert.ok(true, 'Skipping: IE 6 does not support overflow state properly'); return; } var elem = document.getElementById('halfHidden'); - assertEquals(NONE, bot.dom.getOverflowState(elem, - new goog.math.Rect(25, 25, 50, 50))); - assertEquals(HIDDEN, bot.dom.getOverflowState(elem, - new goog.math.Coordinate(60, 60, 50, 50))); - } + assert.strictEqual(bot.dom.getOverflowState(elem, + new goog.math.Rect(25, 25, 50, 50)), NONE); + assert.strictEqual(bot.dom.getOverflowState(elem, + new goog.math.Coordinate(60, 60, 50, 50)), HIDDEN); + }); - function testFixedPositionOffscreenIsHidden() { - // IE 6 does not support fixed-position elements properly. + QUnit.test('fixedPositionOffscreenIsHidden', function(assert) { if (goog.userAgent.IE && !bot.userAgent.isProductVersion(7)) { + assert.ok(true, 'Skipping: IE 6 does not support fixed-position elements properly'); return; } var fixedOffscreen = document.getElementById('fixed-offscreen'); - assertEquals(HIDDEN, bot.dom.getOverflowState(fixedOffscreen)); - } + assert.strictEqual(bot.dom.getOverflowState(fixedOffscreen), HIDDEN); + }); - function testChildOfFixedTreatedAsFixed() { - // IE 6 does not support fixed-position elements properly. + QUnit.test('childOfFixedTreatedAsFixed', function(assert) { if (goog.userAgent.IE && !bot.userAgent.isProductVersion(7)) { + assert.ok(true, 'Skipping: IE 6 does not support fixed-position elements properly'); return; } var fixedParent = document.getElementById('fixed-parent'); - assertEquals(NONE, bot.dom.getOverflowState(fixedParent)); + assert.strictEqual(bot.dom.getOverflowState(fixedParent), NONE); var childOfFixed = document.getElementById('child-of-fixed'); - assertEquals(HIDDEN, bot.dom.getOverflowState(childOfFixed)); - } + assert.strictEqual(bot.dom.getOverflowState(childOfFixed), HIDDEN); + }); - function testElementHiddenByZeroSizedContainer() { + QUnit.test('elementHiddenByZeroSizedContainer', function(assert) { var elem = document.getElementById('hasZeroSizedContainer'); - assertEquals(HIDDEN, bot.dom.getOverflowState(elem)); - } + assert.strictEqual(bot.dom.getOverflowState(elem), HIDDEN); + }); - function testElementWithHtmlElementFixed() { + QUnit.test('elementWithHtmlElementFixed', function(assert) { document.documentElement.style.position = 'fixed'; var elem = document.getElementById('line1'); - assertEquals(NONE, bot.dom.getOverflowState(elem)); - } + assert.strictEqual(bot.dom.getOverflowState(elem), NONE); + }); +
+
scroll down to see element









diff --git a/javascript/atoms/test/property_test.html b/javascript/atoms/test/property_test.html index c32d015ecf2da..fca6a1b78996e 100644 --- a/javascript/atoms/test/property_test.html +++ b/javascript/atoms/test/property_test.html @@ -17,69 +17,74 @@ --> + property_test.html + + + +
+
Cheddar
Brie
Gouda
diff --git a/javascript/atoms/test/relative_locator_test.html b/javascript/atoms/test/relative_locator_test.html index bd35c18bcbc39..03896e9b2a6b2 100644 --- a/javascript/atoms/test/relative_locator_test.html +++ b/javascript/atoms/test/relative_locator_test.html @@ -1,252 +1,222 @@ + relative_locator_test.html - - + + + + - -

Relative Locator Tests

-
-

This text is above.

-

This is a paragraph of text in the middle.

-

This text is below.

-
- - - - - - - - - - - - - - - - - -
123
45
789
- -
-
El-A
-
El-B
-
El-C
-
El-D
-
El-E
-
El-F
-
- -
+
+
diff --git a/javascript/atoms/test/response_test.html b/javascript/atoms/test/response_test.html index ed237c1ca4b3d..ab21fec248986 100644 --- a/javascript/atoms/test/response_test.html +++ b/javascript/atoms/test/response_test.html @@ -16,23 +16,28 @@ --> + response_test + + + +
+
diff --git a/javascript/atoms/test/scrolling_test.html b/javascript/atoms/test/scrolling_test.html index 91a3c788d539e..81efaacab0b25 100644 --- a/javascript/atoms/test/scrolling_test.html +++ b/javascript/atoms/test/scrolling_test.html @@ -1,7 +1,11 @@ - + + scrolling_test.html + + + +
+
diff --git a/javascript/atoms/test/select_test.html b/javascript/atoms/test/select_test.html index de5a6e698df0f..ef28d54e69473 100644 --- a/javascript/atoms/test/select_test.html +++ b/javascript/atoms/test/select_test.html @@ -3,7 +3,11 @@ + select_test.html + + + +
+
" + escapeText(val.label) + ''; + } else { + urlConfigHtml += "'; + } + } + return urlConfigHtml; + } + + // Handle "click" events on toolbar checkboxes and "change" for select menus. + // Updates the URL with the new state of `config.urlConfig` values. + function toolbarChanged() { + var field = this; + var params = {}; + + // Detect if field is a select menu or a checkbox + var value; + if ('selectedIndex' in field) { + value = field.options[field.selectedIndex].value || undefined; + } else { + value = field.checked ? field.defaultValue || true : undefined; + } + params[field.name] = value; + var updatedUrl = setUrl(params); + + // Check if we can apply the change without a page refresh + if (field.name === 'hidepassed' && 'replaceState' in window$1.history) { + QUnit.urlParams[field.name] = value; + config[field.name] = value || false; + var tests = id('qunit-tests'); + if (tests) { + var length = tests.children.length; + var children = tests.children; + if (field.checked) { + for (var i = 0; i < length; i++) { + var test = children[i]; + var className = test ? test.className : ''; + var classNameHasPass = className.indexOf('pass') > -1; + var classNameHasSkipped = className.indexOf('skipped') > -1; + if (classNameHasPass || classNameHasSkipped) { + hiddenTests.push(test); + } + } + var _iterator = _createForOfIteratorHelper(hiddenTests), + _step; + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var hiddenTest = _step.value; + tests.removeChild(hiddenTest); + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + } else { + while (hiddenTests.length) { + tests.appendChild(hiddenTests.shift()); + } + } + } + window$1.history.replaceState(null, '', updatedUrl); + } else { + window$1.location = updatedUrl; + } + } + function setUrl(params) { + var querystring = '?'; + var location = window$1.location; + params = extend(extend({}, QUnit.urlParams), params); + for (var key in params) { + // Skip inherited or undefined properties + if (hasOwn.call(params, key) && params[key] !== undefined) { + // Output a parameter for each value of this key + // (but usually just one) + var arrValue = [].concat(params[key]); + for (var i = 0; i < arrValue.length; i++) { + querystring += encodeURIComponent(key); + if (arrValue[i] !== true) { + querystring += '=' + encodeURIComponent(arrValue[i]); + } + querystring += '&'; + } + } + } + return location.protocol + '//' + location.host + location.pathname + querystring.slice(0, -1); + } + function applyUrlParams() { + var filter = id('qunit-filter-input').value; + window$1.location = setUrl({ + filter: filter === '' ? undefined : filter, + moduleId: _toConsumableArray(dropdownData.selectedMap.keys()), + // Remove module and testId filter + module: undefined, + testId: undefined + }); + } + function toolbarUrlConfigContainer() { + var urlConfigContainer = document.createElement('span'); + urlConfigContainer.innerHTML = getUrlConfigHtml(); + addClass(urlConfigContainer, 'qunit-url-config'); + addEvents(urlConfigContainer.getElementsByTagName('input'), 'change', toolbarChanged); + addEvents(urlConfigContainer.getElementsByTagName('select'), 'change', toolbarChanged); + return urlConfigContainer; + } + function abortTestsButton() { + var button = document.createElement('button'); + button.id = 'qunit-abort-tests-button'; + button.innerHTML = 'Abort'; + addEvent(button, 'click', abortTests); + return button; + } + function toolbarLooseFilter() { + var filter = document.createElement('form'); + var label = document.createElement('label'); + var input = document.createElement('input'); + var button = document.createElement('button'); + addClass(filter, 'qunit-filter'); + label.innerHTML = 'Filter: '; + input.type = 'text'; + input.value = config.filter || ''; + input.name = 'filter'; + input.id = 'qunit-filter-input'; + button.innerHTML = 'Go'; + label.appendChild(input); + filter.appendChild(label); + filter.appendChild(document.createTextNode(' ')); + filter.appendChild(button); + addEvent(filter, 'submit', interceptNavigation); + return filter; + } + function createModuleListItem(moduleId, name, checked) { + return '
  • '; + } + + /** + * @param {Array} Results from fuzzysort + * @return {string} HTML + */ + function moduleListHtml(results) { + var html = ''; + + // Hoist the already selected items, and show them always + // even if not matched by the current search. + dropdownData.selectedMap.forEach(function (name, moduleId) { + html += createModuleListItem(moduleId, name, true); + }); + for (var i = 0; i < results.length; i++) { + var mod = results[i].obj; + if (!dropdownData.selectedMap.has(mod.moduleId)) { + html += createModuleListItem(mod.moduleId, mod.name, false); + } + } + return html; + } + function toolbarModuleFilter(beginDetails) { + var initialSelected = null; + dropdownData = { + options: beginDetails.modules.slice(), + selectedMap: new StringMap(), + isDirty: function isDirty() { + return _toConsumableArray(dropdownData.selectedMap.keys()).sort().join(',') !== _toConsumableArray(initialSelected.keys()).sort().join(','); + } + }; + if (config.moduleId.length) { + // The module dropdown is seeded with the runtime configuration of the last run. + // + // We don't reference `config.moduleId` directly after this and keep our own + // copy because: + // 1. This naturally filters out unknown moduleIds. + // 2. Gives us a place to manage and remember unsubmitted checkbox changes. + // 3. Gives us an efficient way to map a selected moduleId to module name + // during rendering. + for (var i = 0; i < beginDetails.modules.length; i++) { + var mod = beginDetails.modules[i]; + if (config.moduleId.indexOf(mod.moduleId) !== -1) { + dropdownData.selectedMap.set(mod.moduleId, mod.name); + } + } + } + initialSelected = new StringMap(dropdownData.selectedMap); + var moduleSearch = document.createElement('input'); + moduleSearch.id = 'qunit-modulefilter-search'; + moduleSearch.autocomplete = 'off'; + addEvent(moduleSearch, 'input', searchInput); + addEvent(moduleSearch, 'input', searchFocus); + addEvent(moduleSearch, 'focus', searchFocus); + addEvent(moduleSearch, 'click', searchFocus); + var label = document.createElement('label'); + label.htmlFor = 'qunit-modulefilter-search'; + label.textContent = 'Module:'; + var searchContainer = document.createElement('span'); + searchContainer.id = 'qunit-modulefilter-search-container'; + searchContainer.appendChild(moduleSearch); + var applyButton = document.createElement('button'); + applyButton.textContent = 'Apply'; + applyButton.title = 'Re-run the selected test modules'; + addEvent(applyButton, 'click', applyUrlParams); + var resetButton = document.createElement('button'); + resetButton.textContent = 'Reset'; + resetButton.type = 'reset'; + resetButton.title = 'Restore the previous module selection'; + var clearButton = document.createElement('button'); + clearButton.textContent = 'Select none'; + clearButton.type = 'button'; + clearButton.title = 'Clear the current module selection'; + addEvent(clearButton, 'click', function () { + dropdownData.selectedMap.clear(); + selectionChange(); + searchInput(); + }); + var actions = document.createElement('span'); + actions.id = 'qunit-modulefilter-actions'; + actions.appendChild(applyButton); + actions.appendChild(resetButton); + if (initialSelected.size) { + // Only show clear button if functionally different from reset + actions.appendChild(clearButton); + } + var dropDownList = document.createElement('ul'); + dropDownList.id = 'qunit-modulefilter-dropdown-list'; + var dropDown = document.createElement('div'); + dropDown.id = 'qunit-modulefilter-dropdown'; + dropDown.style.display = 'none'; + dropDown.appendChild(actions); + dropDown.appendChild(dropDownList); + addEvent(dropDown, 'change', selectionChange); + searchContainer.appendChild(dropDown); + // Set initial moduleSearch.placeholder and clearButton/resetButton. + selectionChange(); + var moduleFilter = document.createElement('form'); + moduleFilter.id = 'qunit-modulefilter'; + moduleFilter.appendChild(label); + moduleFilter.appendChild(document.createTextNode(' ')); + moduleFilter.appendChild(searchContainer); + addEvent(moduleFilter, 'submit', interceptNavigation); + addEvent(moduleFilter, 'reset', function () { + dropdownData.selectedMap = new StringMap(initialSelected); + // Set moduleSearch.placeholder and reflect non-dirty state + selectionChange(); + searchInput(); + }); + + // Enables show/hide for the dropdown + function searchFocus() { + if (dropDown.style.display !== 'none') { + return; + } + + // Optimization: Defer rendering options until focussed. + // https://github.com/qunitjs/qunit/issues/1664 + searchInput(); + dropDown.style.display = 'block'; + + // Hide on Escape keydown or on click outside the container + addEvent(document, 'click', hideHandler); + addEvent(document, 'keydown', hideHandler); + function hideHandler(e) { + var inContainer = moduleFilter.contains(e.target); + if (e.keyCode === 27 || !inContainer) { + if (e.keyCode === 27 && inContainer) { + moduleSearch.focus(); + } + dropDown.style.display = 'none'; + removeEvent(document, 'click', hideHandler); + removeEvent(document, 'keydown', hideHandler); + moduleSearch.value = ''; + searchInput(); + } + } + } + + /** + * @param {string} searchText + * @return {string} HTML + */ + function filterModules(searchText) { + var results; + if (searchText === '') { + // Improve on-boarding experience by having an immediate display of + // module names, indicating how the interface works. This also makes + // for a quicker interaction in the common case of small projects. + // Don't mandate typing just to get the menu. + results = dropdownData.options.slice(0, 20).map(function (obj) { + // Fake empty results. https://github.com/farzher/fuzzysort/issues/41 + return { + obj: obj + }; + }); + } else { + results = fuzzysort.go(searchText, dropdownData.options, { + limit: 20, + key: 'name', + allowTypo: true + }); + } + return moduleListHtml(results); + } + + // Processes module search box input + var searchInputTimeout; + function searchInput() { + // Use a debounce with a ~0ms timeout. This is effectively instantaneous, + // but is better than undebounced because it avoids an ever-growing + // backlog of unprocessed now-outdated input events if fuzzysearch or + // drodown DOM is slow (e.g. very large test suite). + window$1.clearTimeout(searchInputTimeout); + searchInputTimeout = window$1.setTimeout(function () { + dropDownList.innerHTML = filterModules(moduleSearch.value); + }); + } + + // Processes checkbox change, or a generic render (initial render, or after reset event) + // Avoid any dropdown rendering here as this is used by toolbarModuleFilter() + // during the initial render, which should not delay test execution. + function selectionChange(evt) { + var checkbox = evt && evt.target || null; + if (checkbox) { + // Update internal state + if (checkbox.checked) { + dropdownData.selectedMap.set(checkbox.value, checkbox.parentNode.textContent); + } else { + dropdownData.selectedMap.delete(checkbox.value); + } + + // Update UI state + toggleClass(checkbox.parentNode, 'checked', checkbox.checked); + } + var textForm = dropdownData.selectedMap.size ? dropdownData.selectedMap.size + ' ' + (dropdownData.selectedMap.size === 1 ? 'module' : 'modules') : 'All modules'; + moduleSearch.placeholder = textForm; + moduleSearch.title = 'Type to search through and reduce the list.'; + resetButton.disabled = !dropdownData.isDirty(); + clearButton.style.display = dropdownData.selectedMap.size ? '' : 'none'; + } + return moduleFilter; + } + function appendToolbar(beginDetails) { + var toolbar = id('qunit-testrunner-toolbar'); + if (toolbar) { + toolbar.appendChild(toolbarUrlConfigContainer()); + var toolbarFilters = document.createElement('span'); + toolbarFilters.id = 'qunit-toolbar-filters'; + toolbarFilters.appendChild(toolbarLooseFilter()); + toolbarFilters.appendChild(toolbarModuleFilter(beginDetails)); + var clearfix = document.createElement('div'); + clearfix.className = 'clearfix'; + toolbar.appendChild(toolbarFilters); + toolbar.appendChild(clearfix); + } + } + function appendHeader() { + var header = id('qunit-header'); + if (header) { + header.innerHTML = "" + header.innerHTML + ' '; + } + } + function appendBanner() { + var banner = id('qunit-banner'); + if (banner) { + banner.className = ''; + } + } + function appendTestResults() { + var tests = id('qunit-tests'); + var result = id('qunit-testresult'); + var controls; + if (result) { + result.parentNode.removeChild(result); + } + if (tests) { + tests.innerHTML = ''; + result = document.createElement('p'); + result.id = 'qunit-testresult'; + result.className = 'result'; + tests.parentNode.insertBefore(result, tests); + result.innerHTML = '
    Running...
     
    ' + '
    ' + '
    '; + controls = id('qunit-testresult-controls'); + } + if (controls) { + controls.appendChild(abortTestsButton()); + } + } + function appendFilteredTest() { + var testId = QUnit.config.testId; + if (!testId || testId.length <= 0) { + return ''; + } + return "
    Rerunning selected tests: " + escapeText(testId.join(', ')) + " Run all tests
    "; + } + function appendUserAgent() { + var userAgent = id('qunit-userAgent'); + if (userAgent) { + userAgent.innerHTML = ''; + userAgent.appendChild(document.createTextNode('QUnit ' + QUnit.version + '; ' + navigator.userAgent)); + } + } + function appendInterface(beginDetails) { + var qunit = id('qunit'); + + // For compat with QUnit 1.2, and to support fully custom theme HTML, + // we will use any existing elements if no id="qunit" element exists. + // + // Note that we don't fail or fallback to creating it ourselves, + // because not having id="qunit" (and not having the below elements) + // simply means QUnit acts headless, allowing users to use their own + // reporters, or for a test runner to listen for events directly without + // having the HTML reporter actively render anything. + if (qunit) { + qunit.setAttribute('role', 'main'); + + // Since QUnit 1.3, these are created automatically if the page + // contains id="qunit". + qunit.innerHTML = "

    " + escapeText(document.title) + '

    ' + "

    " + "" + appendFilteredTest() + "

    " + "
      "; + } + appendHeader(); + appendBanner(); + appendTestResults(); + appendUserAgent(); + appendToolbar(beginDetails); + } + function appendTest(name, testId, moduleName) { + var tests = id('qunit-tests'); + if (!tests) { + return; + } + var title = document.createElement('strong'); + title.innerHTML = getNameHtml(name, moduleName); + var testBlock = document.createElement('li'); + testBlock.appendChild(title); + + // No ID or rerun link for "global failure" blocks + if (testId !== undefined) { + var rerunTrigger = document.createElement('a'); + rerunTrigger.innerHTML = 'Rerun'; + rerunTrigger.href = setUrl({ + testId: testId + }); + testBlock.id = 'qunit-test-output-' + testId; + testBlock.appendChild(rerunTrigger); + } + var assertList = document.createElement('ol'); + assertList.className = 'qunit-assert-list'; + testBlock.appendChild(assertList); + tests.appendChild(testBlock); + return testBlock; + } + + // HTML Reporter initialization and load + QUnit.on('runStart', function (runStart) { + stats.defined = runStart.testCounts.total; + }); + QUnit.begin(function (beginDetails) { + // Initialize QUnit elements + // This is done from begin() instead of runStart, because + // urlparams.js uses begin(), which we need to wait for. + // urlparams.js in turn uses begin() to allow plugins to + // add entries to QUnit.config.urlConfig, which may be done + // asynchronously. + // + appendInterface(beginDetails); + }); + function getRerunFailedHtml(failedTests) { + if (failedTests.length === 0) { + return ''; + } + var href = setUrl({ + testId: failedTests + }); + return ["
      ", failedTests.length === 1 ? 'Rerun 1 failed test' : 'Rerun ' + failedTests.length + ' failed tests', ''].join(''); + } + QUnit.on('runEnd', function (runEnd) { + var banner = id('qunit-banner'); + var tests = id('qunit-tests'); + var abortButton = id('qunit-abort-tests-button'); + var assertPassed = config.stats.all - config.stats.bad; + var html = [runEnd.testCounts.total, ' tests completed in ', runEnd.runtime, ' milliseconds, with ', runEnd.testCounts.failed, ' failed, ', runEnd.testCounts.skipped, ' skipped, and ', runEnd.testCounts.todo, ' todo.
      ', "", assertPassed, " assertions of ", config.stats.all, " passed, ", config.stats.bad, ' failed.', getRerunFailedHtml(stats.failedTests)].join(''); + var test; + var assertLi; + var assertList; + + // Update remaining tests to aborted + if (abortButton && abortButton.disabled) { + html = 'Tests aborted after ' + runEnd.runtime + ' milliseconds.'; + for (var i = 0; i < tests.children.length; i++) { + test = tests.children[i]; + if (test.className === '' || test.className === 'running') { + test.className = 'aborted'; + assertList = test.getElementsByTagName('ol')[0]; + assertLi = document.createElement('li'); + assertLi.className = 'fail'; + assertLi.innerHTML = 'Test aborted.'; + assertList.appendChild(assertLi); + } + } + } + if (banner && (!abortButton || abortButton.disabled === false)) { + banner.className = runEnd.status === 'failed' ? 'qunit-fail' : 'qunit-pass'; + } + if (abortButton) { + abortButton.parentNode.removeChild(abortButton); + } + if (tests) { + id('qunit-testresult-display').innerHTML = html; + } + if (config.altertitle && document.title) { + // Show ✖ for good, ✔ for bad suite result in title + // use escape sequences in case file gets loaded with non-utf-8 + // charset + document.title = [runEnd.status === 'failed' ? "\u2716" : "\u2714", document.title.replace(/^[\u2714\u2716] /i, '')].join(' '); + } + + // Scroll back to top to show results + if (config.scrolltop && window$1.scrollTo) { + window$1.scrollTo(0, 0); + } + }); + function getNameHtml(name, module) { + var nameHtml = ''; + if (module) { + nameHtml = "" + escapeText(module) + ': '; + } + nameHtml += "" + escapeText(name) + ''; + return nameHtml; + } + function getProgressHtml(stats) { + return [stats.completed, ' / ', stats.defined, ' tests completed.
      '].join(''); + } + QUnit.testStart(function (details) { + var running, bad; + appendTest(details.name, details.testId, details.module); + running = id('qunit-testresult-display'); + if (running) { + addClass(running, 'running'); + bad = QUnit.config.reorder && details.previousFailure; + running.innerHTML = [getProgressHtml(stats), bad ? 'Rerunning previously failed test:
      ' : 'Running: ', getNameHtml(details.name, details.module), getRerunFailedHtml(stats.failedTests)].join(''); + } + }); + function stripHtml(string) { + // Strip tags, html entity and whitespaces + return string.replace(/<\/?[^>]+(>|$)/g, '').replace(/"/g, '').replace(/\s+/g, ''); + } + QUnit.log(function (details) { + var testItem = id('qunit-test-output-' + details.testId); + if (!testItem) { + return; + } + var message = escapeText(details.message) || (details.result ? 'okay' : 'failed'); + message = "" + message + ''; + message += "@ " + details.runtime + ' ms'; + var expected; + var actual; + var diff; + var showDiff = false; + + // When pushFailure() is called, it is implied that no expected value + // or diff should be shown, because both expected and actual as undefined. + // + // This must check details.expected existence. If it exists as undefined, + // that's a regular assertion for which to render actual/expected and a diff. + var showAnyValues = !details.result && (details.expected !== undefined || details.actual !== undefined); + if (showAnyValues) { + if (details.negative) { + expected = 'NOT ' + QUnit.dump.parse(details.expected); + } else { + expected = QUnit.dump.parse(details.expected); + } + actual = QUnit.dump.parse(details.actual); + message += "'; + if (actual !== expected) { + message += "'; + if (typeof details.actual === 'number' && typeof details.expected === 'number') { + if (!isNaN(details.actual) && !isNaN(details.expected)) { + showDiff = true; + diff = details.actual - details.expected; + diff = (diff > 0 ? '+' : '') + diff; + } + } else if (typeof details.actual !== 'boolean' && typeof details.expected !== 'boolean') { + diff = QUnit.diff(expected, actual); + + // don't show diff if there is zero overlap + showDiff = stripHtml(diff).length !== stripHtml(expected).length + stripHtml(actual).length; + } + if (showDiff) { + message += "'; + } + } else if (expected.indexOf('[object Array]') !== -1 || expected.indexOf('[object Object]') !== -1) { + message += "'; + } else { + message += "'; + } + if (details.source) { + message += "'; + } + message += '
      Expected:
      " + escapeText(expected) + '
      Result:
      " + escapeText(actual) + '
      Diff:
      " + diff + '
      Message: " + 'Diff suppressed as the depth of object is more than current max depth (' + QUnit.dump.maxDepth + ').

      Hint: Use QUnit.dump.maxDepth to ' + " run with a higher max depth or " + 'Rerun without max depth.

      Message: " + 'Diff suppressed as the expected and actual results have an equivalent' + ' serialization
      Source:
      " + escapeText(details.source) + '
      '; + + // This occurs when pushFailure is set and we have an extracted stack trace + } else if (!details.result && details.source) { + message += '' + "' + '
      Source:
      " + escapeText(details.source) + '
      '; + } + var assertList = testItem.getElementsByTagName('ol')[0]; + var assertLi = document.createElement('li'); + assertLi.className = details.result ? 'pass' : 'fail'; + assertLi.innerHTML = message; + assertList.appendChild(assertLi); + }); + QUnit.testDone(function (details) { + var tests = id('qunit-tests'); + var testItem = id('qunit-test-output-' + details.testId); + if (!tests || !testItem) { + return; + } + removeClass(testItem, 'running'); + var status; + if (details.failed > 0) { + status = 'failed'; + } else if (details.todo) { + status = 'todo'; + } else { + status = details.skipped ? 'skipped' : 'passed'; + } + var assertList = testItem.getElementsByTagName('ol')[0]; + var good = details.passed; + var bad = details.failed; + + // This test passed if it has no unexpected failed assertions + var testPassed = details.failed > 0 ? details.todo : !details.todo; + if (testPassed) { + // Collapse the passing tests + addClass(assertList, 'qunit-collapsed'); + } else { + stats.failedTests.push(details.testId); + if (config.collapse) { + if (!collapseNext) { + // Skip collapsing the first failing test + collapseNext = true; + } else { + // Collapse remaining tests + addClass(assertList, 'qunit-collapsed'); + } + } + } + + // The testItem.firstChild is the test name + var testTitle = testItem.firstChild; + var testCounts = bad ? "" + bad + ', ' + "" + good + ', ' : ''; + testTitle.innerHTML += " (" + testCounts + details.assertions.length + ')'; + stats.completed++; + if (details.skipped) { + testItem.className = 'skipped'; + var skipped = document.createElement('em'); + skipped.className = 'qunit-skipped-label'; + skipped.innerHTML = 'skipped'; + testItem.insertBefore(skipped, testTitle); + } else { + addEvent(testTitle, 'click', function () { + toggleClass(assertList, 'qunit-collapsed'); + }); + testItem.className = testPassed ? 'pass' : 'fail'; + if (details.todo) { + var todoLabel = document.createElement('em'); + todoLabel.className = 'qunit-todo-label'; + todoLabel.innerHTML = 'todo'; + testItem.className += ' todo'; + testItem.insertBefore(todoLabel, testTitle); + } + var time = document.createElement('span'); + time.className = 'runtime'; + time.innerHTML = details.runtime + ' ms'; + testItem.insertBefore(time, assertList); + } + + // Show the source of the test when showing assertions + if (details.source) { + var sourceName = document.createElement('p'); + sourceName.innerHTML = 'Source: ' + escapeText(details.source); + addClass(sourceName, 'qunit-source'); + if (testPassed) { + addClass(sourceName, 'qunit-collapsed'); + } + addEvent(testTitle, 'click', function () { + toggleClass(sourceName, 'qunit-collapsed'); + }); + testItem.appendChild(sourceName); + } + if (config.hidepassed && (status === 'passed' || details.skipped)) { + // use removeChild instead of remove because of support + hiddenTests.push(testItem); + tests.removeChild(testItem); + } + }); + QUnit.on('error', function (error) { + var testItem = appendTest('global failure'); + if (!testItem) { + // HTML Reporter is probably disabled or not yet initialized. + return; + } + + // Render similar to a failed assertion (see above QUnit.log callback) + var message = escapeText(errorString(error)); + message = "" + message + ''; + if (error && error.stack) { + message += '' + "' + '
      Source:
      " + escapeText(error.stack) + '
      '; + } + var assertList = testItem.getElementsByTagName('ol')[0]; + var assertLi = document.createElement('li'); + assertLi.className = 'fail'; + assertLi.innerHTML = message; + assertList.appendChild(assertLi); + + // Make it visible + testItem.className = 'fail'; + }); + + // Avoid readyState issue with phantomjs + // Ref: #818 + var usingPhantom = function (p) { + return p && p.version && p.version.major > 0; + }(window$1.phantom); + if (usingPhantom) { + console$1.warn('Support for PhantomJS is deprecated and will be removed in QUnit 3.0.'); + } + if (!usingPhantom && document.readyState === 'complete') { + QUnit.autostart(); + } else { + addEvent(window$1, 'load', QUnit.autostart); + } + + // Wrap window.onerror. We will call the original window.onerror to see if + // the existing handler fully handles the error; if not, we will call the + // QUnit.onError function. + var originalWindowOnError = window$1.onerror; + + // Cover uncaught exceptions + // Returning true will suppress the default browser handler, + // returning false will let it run. + window$1.onerror = function (message, fileName, lineNumber, columnNumber, errorObj) { + var ret = false; + if (originalWindowOnError) { + for (var _len = arguments.length, args = new Array(_len > 5 ? _len - 5 : 0), _key = 5; _key < _len; _key++) { + args[_key - 5] = arguments[_key]; + } + ret = originalWindowOnError.call.apply(originalWindowOnError, [this, message, fileName, lineNumber, columnNumber, errorObj].concat(args)); + } + + // Treat return value as window.onerror itself does, + // Only do our handling if not suppressed. + if (ret !== true) { + // If there is a current test that sets the internal `ignoreGlobalErrors` field + // (such as during `assert.throws()`), then the error is ignored and native + // error reporting is suppressed as well. This is because in browsers, an error + // can sometimes end up in `window.onerror` instead of in the local try/catch. + // This ignoring of errors does not apply to our general onUncaughtException + // method, nor to our `unhandledRejection` handlers, as those are not meant + // to receive an "expected" error during `assert.throws()`. + if (config.current && config.current.ignoreGlobalErrors) { + return true; + } + + // According to + // https://blog.sentry.io/2016/01/04/client-javascript-reporting-window-onerror, + // most modern browsers support an errorObj argument; use that to + // get a full stack trace if it's available. + var error = errorObj || new Error(message); + if (!error.stack && fileName && lineNumber) { + error.stack = "".concat(fileName, ":").concat(lineNumber); + } + QUnit.onUncaughtException(error); + } + return ret; + }; + window$1.addEventListener('unhandledrejection', function (event) { + QUnit.onUncaughtException(event.reason); + }); + })(); + +})(); diff --git a/third_party/js/qunit/qunit_test_runner.js b/third_party/js/qunit/qunit_test_runner.js new file mode 100644 index 0000000000000..9e6245f08db1c --- /dev/null +++ b/third_party/js/qunit/qunit_test_runner.js @@ -0,0 +1,99 @@ +// Licensed to the Software Freedom Conservancy (SFC) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The SFC licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +/** + * @fileoverview QUnit test runner adapter for Selenium's Java test harness. + * + * This script registers QUnit callbacks to track test execution and exposes + * a simple API on window.top that the Java ClosureTestStatement can poll + * to determine when tests are finished and whether they passed. + */ +(function() { + 'use strict'; + + var results = { + finished: false, + passed: false, + report: '', + failures: [] + }; + + // Expose the test runner interface on window.top for the Java harness to poll + window.top.QUnitTestRunner = { + isFinished: function() { + return results.finished; + }, + isSuccess: function() { + return results.passed; + }, + getReport: function() { + return results.report; + } + }; + + QUnit.on('testEnd', function(testEnd) { + if (testEnd.status === 'failed') { + var fullName = testEnd.fullName.join(' > '); + var errors = testEnd.errors.map(function(err) { + var msg = err.message || ''; + if (err.actual !== undefined && err.expected !== undefined) { + msg += '\n Expected: ' + JSON.stringify(err.expected); + msg += '\n Actual: ' + JSON.stringify(err.actual); + } + if (err.stack) { + msg += '\n Stack: ' + err.stack; + } + return msg; + }); + results.failures.push({ + name: fullName, + errors: errors + }); + } + }); + + QUnit.on('runEnd', function(runEnd) { + results.finished = true; + results.passed = runEnd.status === 'passed'; + + var lines = []; + lines.push('QUnit Test Results'); + lines.push('=================='); + lines.push('Status: ' + runEnd.status); + lines.push('Total: ' + runEnd.testCounts.total); + lines.push('Passed: ' + runEnd.testCounts.passed); + lines.push('Failed: ' + runEnd.testCounts.failed); + lines.push('Skipped: ' + runEnd.testCounts.skipped); + lines.push('Todo: ' + runEnd.testCounts.todo); + lines.push('Runtime: ' + runEnd.runtime + 'ms'); + + if (results.failures.length > 0) { + lines.push(''); + lines.push('Failures:'); + lines.push('---------'); + results.failures.forEach(function(failure) { + lines.push(''); + lines.push('Test: ' + failure.name); + failure.errors.forEach(function(err) { + lines.push(' ' + err); + }); + }); + } + + results.report = lines.join('\n'); + }); +})();