TimeoutSettings.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * Copyright 2019 Google Inc. All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. const DEFAULT_TIMEOUT = 30000;
  17. class TimeoutSettings {
  18. constructor() {
  19. this._defaultTimeout = null;
  20. this._defaultNavigationTimeout = null;
  21. }
  22. /**
  23. * @param {number} timeout
  24. */
  25. setDefaultTimeout(timeout) {
  26. this._defaultTimeout = timeout;
  27. }
  28. /**
  29. * @param {number} timeout
  30. */
  31. setDefaultNavigationTimeout(timeout) {
  32. this._defaultNavigationTimeout = timeout;
  33. }
  34. /**
  35. * @return {number}
  36. */
  37. navigationTimeout() {
  38. if (this._defaultNavigationTimeout !== null)
  39. return this._defaultNavigationTimeout;
  40. if (this._defaultTimeout !== null)
  41. return this._defaultTimeout;
  42. return DEFAULT_TIMEOUT;
  43. }
  44. timeout() {
  45. if (this._defaultTimeout !== null)
  46. return this._defaultTimeout;
  47. return DEFAULT_TIMEOUT;
  48. }
  49. }
  50. module.exports = {TimeoutSettings};