01-driver-pac.t 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #! /usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use JSON;
  5. use Selenium::Remote::Driver;
  6. use Test::More;
  7. use Test::Fatal;
  8. use Test::LWP::UserAgent;
  9. my $croaking_tests = [
  10. {
  11. name => 'no PAC url',
  12. proxy => {
  13. proxyType => 'pac',
  14. },
  15. pattern => qr/not provided/,
  16. },
  17. {
  18. name => 'PAC url is not http or file',
  19. proxy => {
  20. proxyType => 'pac',
  21. proxyAutoconfigUrl => ''
  22. },
  23. pattern => qr{of format http:// or file://}
  24. }
  25. ];
  26. foreach my $test (@$croaking_tests) {
  27. like(
  28. exception {
  29. Selenium::Remote::Driver->new(proxy => $test->{proxy});
  30. },
  31. $test->{pattern},
  32. 'Coercion croaks for case: ' . $test->{name}
  33. );
  34. }
  35. my $passing_tests = [
  36. {
  37. name => 'PAC url is http',
  38. proxy => {
  39. proxyType => 'pac',
  40. proxyAutoconfigUrl => 'http://pac.file'
  41. }
  42. },
  43. {
  44. name => 'PAC url is file',
  45. proxy => {
  46. proxyType => 'pac',
  47. proxyAutoconfigUrl => 'file://' . __FILE__
  48. }
  49. }
  50. ];
  51. my $tua = mock_simple_webdriver_server();
  52. foreach my $test (@$passing_tests) {
  53. is(
  54. exception {
  55. Selenium::Remote::Driver->new(
  56. proxy => $test->{proxy},
  57. ua => $tua
  58. );
  59. },
  60. undef,
  61. 'Coercion passes for case: ' . $test->{name}
  62. );
  63. }
  64. sub mock_simple_webdriver_server {
  65. my $tua = Test::LWP::UserAgent->new;
  66. $tua->map_response(qr/status/, HTTP::Response->new(200, 'OK'));
  67. $tua->map_response(
  68. qr/session/,
  69. HTTP::Response->new(
  70. 204,
  71. 'OK',
  72. ['Content-Type' => 'application/json'],
  73. to_json({
  74. cmd_return => {},
  75. cmd_status => 'OK',
  76. sessionId => '123123123'
  77. })
  78. )
  79. );
  80. return $tua;
  81. }
  82. done_testing;