<commit_before>/**
 * @license
 * Copyright 2016 Google Inc.
 *
 * Licensed 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.
 */

goog.provide('shaka.test.Util');


/**
 * Processes some number of "instantaneous" operations.
 *
 * Instantaneous operations include Promise resolution (e.g.,
 * Promise.resolve()) and 0 second timeouts. This recursively processes
 * these operations, so if for example, one wrote
 *
 * Promise.resolve().then(function() {
 *   var callback = function() {
 *     Promise.resolve().then(function() {
 *       console.log('Hello world!');
 *     });
 *   }
 *   window.setTimeout(callback, 0);
 * });
 *
 * var p = processInstantaneousOperations(10);
 *
 * After |p| resolves, "Hello world!" will be written to the console.
 *
 * The parameter |n| controls the number of rounds to perform. This is
 * necessary since we cannot determine when there are no timeouts remaining
 * at the current time; to determine this we would require access to hidden
 * variables in Jasmine's Clock implementation.
 *
 * @param {number} n The number of rounds to perform.
 * @param {function(function(), number)} setTimeout
 * @return {!Promise}
 * TODO: Cleanup with patch to jasmine-core.
 */
shaka.test.Util.processInstantaneousOperations = function(n, setTimeout) {
  var p = new shaka.util.PublicPromise();
  var inner = function() {
    jasmine.clock().tick(0);
    n -= 1;
    if (n <= 0) {
      p.resolve();
    } else {
      setTimeout(inner, 100);
    }
  };
  inner();
  return p;
};

<commit_msg>Speed up StreamingEngine unit tests<commit_after>/**
 * @license
 * Copyright 2016 Google Inc.
 *
 * Licensed 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.
 */

goog.provide('shaka.test.Util');


/**
 * Processes some number of "instantaneous" operations.
 *
 * Instantaneous operations include Promise resolution (e.g.,
 * Promise.resolve()) and 0 second timeouts. This recursively processes
 * these operations, so if for example, one wrote
 *
 * Promise.resolve().then(function() {
 *   var callback = function() {
 *     Promise.resolve().then(function() {
 *       console.log('Hello world!');
 *     });
 *   }
 *   window.setTimeout(callback, 0);
 * });
 *
 * var p = processInstantaneousOperations(10);
 *
 * After |p| resolves, "Hello world!" will be written to the console.
 *
 * The parameter |n| controls the number of rounds to perform. This is
 * necessary since we cannot determine when there are no timeouts remaining
 * at the current time; to determine this we would require access to hidden
 * variables in Jasmine's Clock implementation.
 *
 * @param {number} n The number of rounds to perform.
 * @param {function(function(), number)} setTimeout
 * @return {!Promise}
 * TODO: Cleanup with patch to jasmine-core.
 */
shaka.test.Util.processInstantaneousOperations = function(n, setTimeout) {
  // This is not something we would do in the library, but this tiny hack is
  // needed here for testing.  On Edge, the delay needed here for Promises to
  // resolve is ~100ms.  On Safari, such a large delay is not only not needed,
  // it causes tests to timeout.  So we choose the delay based on the browser.
  var isEdge = navigator.userAgent.indexOf(' Edge/') >= 0;
  var delay = isEdge ? 100 : 5;
  var p = new shaka.util.PublicPromise();
  var inner = function() {
    jasmine.clock().tick(0);
    n -= 1;
    if (n <= 0) {
      p.resolve();
    } else {
      setTimeout(inner, delay);
    }
  };
  inner();
  return p;
};


{'fraction_non_alphanumeric': 0.11031390134529148, 'fraction_numerical': 0.009192825112107623, 'mean_word_length': 3.443227091633466, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '720238', 'n_tokens_mistral': 1270, 'n_tokens_neox': 1227, 'n_words': 514}