timeoutSettings.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.TimeoutSettings = exports.DEFAULT_TIMEOUT = exports.DEFAULT_LAUNCH_TIMEOUT = void 0;
  6. var _utils = require("../utils");
  7. /**
  8. * Copyright 2019 Google Inc. All rights reserved.
  9. * Modifications copyright (c) Microsoft Corporation.
  10. *
  11. * Licensed under the Apache License, Version 2.0 (the "License");
  12. * you may not use this file except in compliance with the License.
  13. * You may obtain a copy of the License at
  14. *
  15. * http://www.apache.org/licenses/LICENSE-2.0
  16. *
  17. * Unless required by applicable law or agreed to in writing, software
  18. * distributed under the License is distributed on an "AS IS" BASIS,
  19. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  20. * See the License for the specific language governing permissions and
  21. * limitations under the License.
  22. */
  23. const DEFAULT_TIMEOUT = exports.DEFAULT_TIMEOUT = 30000;
  24. const DEFAULT_LAUNCH_TIMEOUT = exports.DEFAULT_LAUNCH_TIMEOUT = 3 * 60 * 1000; // 3 minutes
  25. class TimeoutSettings {
  26. constructor(parent) {
  27. this._parent = void 0;
  28. this._defaultTimeout = void 0;
  29. this._defaultNavigationTimeout = void 0;
  30. this._parent = parent;
  31. }
  32. setDefaultTimeout(timeout) {
  33. this._defaultTimeout = timeout;
  34. }
  35. setDefaultNavigationTimeout(timeout) {
  36. this._defaultNavigationTimeout = timeout;
  37. }
  38. defaultNavigationTimeout() {
  39. return this._defaultNavigationTimeout;
  40. }
  41. defaultTimeout() {
  42. return this._defaultTimeout;
  43. }
  44. navigationTimeout(options) {
  45. if (typeof options.timeout === 'number') return options.timeout;
  46. if (this._defaultNavigationTimeout !== undefined) return this._defaultNavigationTimeout;
  47. if ((0, _utils.debugMode)()) return 0;
  48. if (this._defaultTimeout !== undefined) return this._defaultTimeout;
  49. if (this._parent) return this._parent.navigationTimeout(options);
  50. return DEFAULT_TIMEOUT;
  51. }
  52. timeout(options) {
  53. if (typeof options.timeout === 'number') return options.timeout;
  54. if ((0, _utils.debugMode)()) return 0;
  55. if (this._defaultTimeout !== undefined) return this._defaultTimeout;
  56. if (this._parent) return this._parent.timeout(options);
  57. return DEFAULT_TIMEOUT;
  58. }
  59. static timeout(options) {
  60. if (typeof options.timeout === 'number') return options.timeout;
  61. if ((0, _utils.debugMode)()) return 0;
  62. return DEFAULT_TIMEOUT;
  63. }
  64. static launchTimeout(options) {
  65. if (typeof options.timeout === 'number') return options.timeout;
  66. if ((0, _utils.debugMode)()) return 0;
  67. return DEFAULT_LAUNCH_TIMEOUT;
  68. }
  69. }
  70. exports.TimeoutSettings = TimeoutSettings;