diff --git a/core/misc/debounce.js b/core/misc/debounce.js index 995e3d7..32d9ea7 100644 --- a/core/misc/debounce.js +++ b/core/misc/debounce.js @@ -40,8 +40,14 @@ Drupal.debounce = function (func, wait, immediate) { if (!immediate) { result = func.apply(context, args); } + Drupal.debounceCount--; }; var callNow = immediate && !timeout; + + if (!timeout) { + Drupal.debounceCount++; + } + clearTimeout(timeout); timeout = setTimeout(later, wait); if (callNow) { @@ -50,3 +56,10 @@ Drupal.debounce = function (func, wait, immediate) { return result; }; }; + +/** + * The number of running debounces. + * + * @type {number} + */ +Drupal.debounceCount = 0; diff --git a/core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php b/core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php index 94a9108..16302ad 100644 --- a/core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php @@ -24,6 +24,9 @@ class JSWebAssert extends WebAssert { * @throws \RuntimeException * When the request is not completed. If left blank, a default message will * be displayed. + * + * @deprecated + * This method is deprecated in favor or waitForJavascriptActivity(). */ public function assertWaitOnAjaxRequest($timeout = 10000, $message = 'Unable to complete AJAX request.') { $result = $this->session->wait($timeout, '(typeof(jQuery)=="undefined" || (0 === jQuery.active && 0 === jQuery(\':animated\').length))'); @@ -36,6 +39,9 @@ public function assertWaitOnAjaxRequest($timeout = 10000, $message = 'Unable to * Waits for the jQuery autocomplete delay duration. * * @see https://api.jqueryui.com/autocomplete/#option-delay + * + * @deprecated + * This method is deprecated in favor or waitForJavascriptActivity(). */ public function waitOnAutocomplete() { // Drupal is using the default delay value of 300 milliseconds. @@ -44,6 +50,38 @@ public function waitOnAutocomplete() { } /** + * Waits for Javascript activity to completed. + * + * @param int $timeout + * (Optional) Timeout in milliseconds, defaults to 10000. + * @param string $message + * (optional) A message for exception. + * + * @throws \RuntimeException + * When the activity is not completed. If left blank, a default message will + * be displayed. + */ + public function waitForJavascriptActivity($timeout = 10000, $message = 'Unable to complete javascript activity.') { + $condition = <<session->wait($timeout, $condition); + + if (!$result) { + throw new \RuntimeException($message); + } + } + + /** * Test that a node, or it's specific corner, is visible in the viewport. * * Note: Always set the viewport size. This can be done with a PhantomJS