1 #!/usr/bin/perl 2 3 # Copyright (C) 2006 Alexey Proskuryakov (ap (at] nypop.com) 4 # 5 # Redistribution and use in source and binary forms, with or without 6 # modification, are permitted provided that the following conditions 7 # are met: 8 # 9 # 1. Redistributions of source code must retain the above copyright 10 # notice, this list of conditions and the following disclaimer. 11 # 2. Redistributions in binary form must reproduce the above copyright 12 # notice, this list of conditions and the following disclaimer in the 13 # documentation and/or other materials provided with the distribution. 14 # 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 15 # its contributors may be used to endorse or promote products derived 16 # from this software without specific prior written permission. 17 # 18 # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 19 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 22 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 29 # A script to semi-automatically run iExploder tests. 30 31 use strict; 32 use warnings; 33 34 use Cwd; 35 use File::Spec; 36 use FindBin; 37 use Getopt::Long; 38 use IPC::Open2; 39 40 use lib $FindBin::Bin; 41 use webkitperl::httpd; 42 use webkitdirs; 43 44 sub configureAndOpenHTTPDIfNeeded(); 45 sub runSafariWithIExploder(); 46 47 # Argument handling 48 my $guardMalloc = ''; 49 my $httpdPort = 8000; 50 my $downloadTest; 51 my $iExploderTestDirectory = "/tmp/iExploderTest"; 52 53 GetOptions( 54 'guard-malloc|g' => \$guardMalloc, 55 'get=s' => \$downloadTest, 56 'port=i' => \$httpdPort 57 ); 58 59 60 setConfiguration(); 61 my $productDir = productDir(); 62 63 chdirWebKit(); 64 65 checkFrameworks(); 66 67 my $isHttpdOpen = 0; 68 configureAndOpenHTTPDIfNeeded(); 69 70 if ($downloadTest) { 71 system "/usr/bin/curl -o ~/Desktop/iexploder$downloadTest.html \"http://127.0.0.1:$httpdPort/iexploder.cgi?lookup=1&test=$downloadTest\""; 72 print "Saved the test as iexploder$downloadTest.html on the desktop\n"; 73 } else { 74 runSafariWithIExploder(); 75 print "Last generated tests:\n"; 76 system "grep 'iexploder.cgi' $iExploderTestDirectory/access_log.txt | tail -n -5 | awk -F'[ =&\\?]' '{if (\$8 == \"lookup\") print \$11; else print \$9}'"; 77 } 78 79 rmtree $iExploderTestDirectory; 80 $isHttpdOpen = !closeHTTPD(); 81 82 sub runSafariWithIExploder() 83 { 84 my $redirectTo; 85 if (@ARGV) { 86 $redirectTo = "http://127.0.0.1:$httpdPort/iexploder.cgi?lookup=1&test=$ARGV[0]"; 87 } else { 88 $redirectTo = "http://127.0.0.1:$httpdPort/index.html"; 89 } 90 91 open REDIRECT_HTML, ">", "$iExploderTestDirectory/redirect.html" or die; 92 print REDIRECT_HTML "<html>\n"; 93 print REDIRECT_HTML " <head>\n"; 94 print REDIRECT_HTML " <meta http-equiv=\"refresh\" content=\"1;URL=$redirectTo\" />\n"; 95 print REDIRECT_HTML " <script type=\"text/javascript\">\n"; 96 print REDIRECT_HTML " document.location = \"$redirectTo\";\n"; 97 print REDIRECT_HTML " </script>\n"; 98 print REDIRECT_HTML " </head>\n"; 99 print REDIRECT_HTML " <body>\n"; 100 print REDIRECT_HTML " </body>\n"; 101 print REDIRECT_HTML "</html>\n"; 102 close REDIRECT_HTML; 103 104 if (!isAppleWebKit()) { 105 system "Tools/Scripts/run-launcher", "$iExploderTestDirectory/redirect.html"; 106 } else { 107 local %ENV; 108 $ENV{DYLD_INSERT_LIBRARIES} = "/usr/lib/libgmalloc.dylib" if $guardMalloc; 109 system "Tools/Scripts/run-safari", "-NSOpen", "$iExploderTestDirectory/redirect.html"; 110 } 111 } 112 113 sub configureAndOpenHTTPDIfNeeded() 114 { 115 return if $isHttpdOpen; 116 mkdir $iExploderTestDirectory; 117 my $webkitDirectory = getcwd(); 118 my $testDirectory = $webkitDirectory . "/LayoutTests"; 119 my $iExploderDirectory = $webkitDirectory . "/Tools/iExploder/iExploder-1.3.2"; 120 121 my $httpdConfig = getHTTPDConfigPathForTestDirectory($testDirectory); 122 123 my $documentRoot = "$iExploderDirectory/htdocs"; 124 my $typesConfig = "$testDirectory/http/conf/mime.types"; 125 my $sslCertificate = "$testDirectory/http/conf/webkit-httpd.pem"; 126 my $listen = "127.0.0.1:$httpdPort"; 127 128 129 my @args = ( 130 "-f", "$httpdConfig", 131 "-C", "DocumentRoot \"$documentRoot\"", 132 "-C", "Listen $listen", 133 "-c", "TypesConfig \"$typesConfig\"", 134 "-c", "CustomLog \"$iExploderTestDirectory/access_log.txt\" common", 135 "-c", "ErrorLog \"$iExploderTestDirectory/error_log.txt\"", 136 "-c", "SSLCertificateFile \"$sslCertificate\"", 137 # Apache wouldn't run CGIs with permissions==700 otherwise 138 "-c", "User \"#$<\"" 139 ); 140 141 $isHttpdOpen = openHTTPD(@args); 142 } 143