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..327b37a 100644 --- a/core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php @@ -24,23 +24,73 @@ 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))'); - if (!$result) { - throw new \RuntimeException($message); - } + $this->waitForJavascriptActivity($timeout, $message); } /** * 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. - $this->session->wait(300); - $this->assertWaitOnAjaxRequest(); + $this->waitForJavascriptActivity(); + } + + /** + * 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. + */ + public function waitForJavascriptActivity($timeout = 10000, $message = 'Unable to complete javascript activity.') { + $condition = <<session->wait($timeout, $condition); + if (!$result) { + throw new \RuntimeException($message); + } } /**