Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / test / functional / webpagereplay.py
index da5f860..8d115ef 100755 (executable)
@@ -85,7 +85,7 @@ class ReplayServer(object):
     WPR_REPLAY_DIR: path to alternate Web Page Replay source.
   """
 
-  def __init__(self, archive_path, replay_host, http_port, https_port,
+  def __init__(self, archive_path, replay_host, dns_port, http_port, https_port,
                replay_options=None, replay_dir=None,
                log_path=None):
     """Initialize ReplayServer.
@@ -93,6 +93,9 @@ class ReplayServer(object):
     Args:
       archive_path: a path to a specific WPR archive (required).
       replay_host: the hostname to serve traffic.
+      dns_port: an integer port on which to serve DNS traffic. May be zero
+          to let the OS choose an available port. If None DNS forwarding is
+          disabled.
       http_port: an integer port on which to serve HTTP traffic. May be zero
           to let the OS choose an available port.
       https_port: an integer port on which to serve HTTPS traffic. May be zero
@@ -105,6 +108,7 @@ class ReplayServer(object):
     self.replay_options = list(replay_options or ())
     self.replay_dir = os.environ.get('WPR_REPLAY_DIR', replay_dir or REPLAY_DIR)
     self.log_path = log_path or LOG_PATH
+    self.dns_port = dns_port
     self.http_port = http_port
     self.https_port = https_port
     self._replay_host = replay_host
@@ -135,6 +139,8 @@ class ReplayServer(object):
         '--no-dns_forwarding',
         '--log_level', 'warning'
         ] + self.replay_options
+    if self.dns_port is not None:
+      self.replay_options.extend(['--dns_port', str(self.dns_port)])
 
   def _CheckPath(self, label, path):
     if not os.path.exists(path):
@@ -149,7 +155,7 @@ class ReplayServer(object):
   def WaitForStart(self, timeout):
     """Checks to see if the server is up and running."""
     port_re = re.compile(
-        '.*(?P<protocol>HTTPS?) server started on (?P<host>.*):(?P<port>\d+)')
+        '.*?(?P<protocol>[A-Z]+) server started on (?P<host>.*):(?P<port>\d+)')
 
     start_time = time.time()
     elapsed_time = 0
@@ -158,7 +164,7 @@ class ReplayServer(object):
         break  # The process has exited.
 
       # Read the ports from the WPR log.
-      if not self.http_port or not self.https_port:
+      if not self.http_port or not self.https_port or not self.dns_port:
         for line in open(self.log_path).readlines():
           m = port_re.match(line.strip())
           if m:
@@ -166,6 +172,8 @@ class ReplayServer(object):
               self.http_port = int(m.group('port'))
             elif not self.https_port and m.group('protocol') == 'HTTPS':
               self.https_port = int(m.group('port'))
+            elif not self.dns_port and m.group('protocol') == 'DNS':
+              self.dns_port = int(m.group('port'))
 
       # Try to connect to the WPR ports.
       if self.http_port and self.https_port: