<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[242653] trunk/Tools</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/242653">242653</a></dd>
<dt>Author</dt> <dd>slewis@apple.com</dd>
<dt>Date</dt> <dd>2019-03-08 12:52:56 -0800 (Fri, 08 Mar 2019)</dd>
</dl>

<h3>Log Message</h3>
<pre>Ensure old tab state is cleared between iterations of run-benchmark
https://bugs.webkit.org/show_bug.cgi?id=195393
<rdar://problem/46885583>

Reviewed by Dewei Zhu.

a) ensure the default to restore state is not set
b) terminate Safari correctly
c) Set the system default to ignore Persistent State in Safari

* Scripts/webkitpy/benchmark_runner/browser_driver/osx_browser_driver.py:
(OSXBrowserDriver): fix terminate processes to call terminate before killing.
(OSXBrowserDriver.prepare_env):
(OSXBrowserDriver.restore_env):
(OSXBrowserDriver.close_browsers):
(OSXBrowserDriver._terminate_processes):
* Scripts/webkitpy/benchmark_runner/browser_driver/osx_chrome_driver.py: add bundle id
(OSXChromeDriver):
(OSXChromeCanaryDriver):
* Scripts/webkitpy/benchmark_runner/browser_driver/osx_firefox_driver.py: ditto
(OSXFirefoxDriver):
(OSXFirefoxNightlyDriver):
* Scripts/webkitpy/benchmark_runner/browser_driver/osx_safari_driver.py: add preferences to not restore state, bundle id
(OSXSafariDriver):
(OSXSafariDriver.prepare_env):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsScriptswebkitpybenchmark_runnerbrowser_driverosx_browser_driverpy">trunk/Tools/Scripts/webkitpy/benchmark_runner/browser_driver/osx_browser_driver.py</a></li>
<li><a href="#trunkToolsScriptswebkitpybenchmark_runnerbrowser_driverosx_chrome_driverpy">trunk/Tools/Scripts/webkitpy/benchmark_runner/browser_driver/osx_chrome_driver.py</a></li>
<li><a href="#trunkToolsScriptswebkitpybenchmark_runnerbrowser_driverosx_firefox_driverpy">trunk/Tools/Scripts/webkitpy/benchmark_runner/browser_driver/osx_firefox_driver.py</a></li>
<li><a href="#trunkToolsScriptswebkitpybenchmark_runnerbrowser_driverosx_safari_driverpy">trunk/Tools/Scripts/webkitpy/benchmark_runner/browser_driver/osx_safari_driver.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (242652 => 242653)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog    2019-03-08 19:54:02 UTC (rev 242652)
+++ trunk/Tools/ChangeLog       2019-03-08 20:52:56 UTC (rev 242653)
</span><span class="lines">@@ -1,3 +1,31 @@
</span><ins>+2019-03-08  Stephanie Lewis  <slewis@apple.com>
+
+        Ensure old tab state is cleared between iterations of run-benchmark
+        https://bugs.webkit.org/show_bug.cgi?id=195393
+        <rdar://problem/46885583>
+
+        Reviewed by Dewei Zhu.
+
+        a) ensure the default to restore state is not set
+        b) terminate Safari correctly
+        c) Set the system default to ignore Persistent State in Safari
+
+        * Scripts/webkitpy/benchmark_runner/browser_driver/osx_browser_driver.py:
+        (OSXBrowserDriver): fix terminate processes to call terminate before killing.
+        (OSXBrowserDriver.prepare_env): 
+        (OSXBrowserDriver.restore_env):
+        (OSXBrowserDriver.close_browsers):
+        (OSXBrowserDriver._terminate_processes):
+        * Scripts/webkitpy/benchmark_runner/browser_driver/osx_chrome_driver.py: add bundle id
+        (OSXChromeDriver):
+        (OSXChromeCanaryDriver):
+        * Scripts/webkitpy/benchmark_runner/browser_driver/osx_firefox_driver.py: ditto
+        (OSXFirefoxDriver):
+        (OSXFirefoxNightlyDriver):
+        * Scripts/webkitpy/benchmark_runner/browser_driver/osx_safari_driver.py: add preferences to not restore state, bundle id
+        (OSXSafariDriver):
+        (OSXSafariDriver.prepare_env):
+
</ins><span class="cx"> 2019-03-08  Diego Pino Garcia  <dpino@igalia.com>
</span><span class="cx"> 
</span><span class="cx">         [GTK] Several InputMethodFilter tests are failing
</span></span></pre></div>
<a id="trunkToolsScriptswebkitpybenchmark_runnerbrowser_driverosx_browser_driverpy"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/webkitpy/benchmark_runner/browser_driver/osx_browser_driver.py (242652 => 242653)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/webkitpy/benchmark_runner/browser_driver/osx_browser_driver.py       2019-03-08 19:54:02 UTC (rev 242652)
+++ trunk/Tools/Scripts/webkitpy/benchmark_runner/browser_driver/osx_browser_driver.py  2019-03-08 20:52:56 UTC (rev 242653)
</span><span class="lines">@@ -2,6 +2,7 @@
</span><span class="cx"> import logging
</span><span class="cx"> import os
</span><span class="cx"> import subprocess
</span><ins>+import time
</ins><span class="cx"> 
</span><span class="cx"> from browser_driver import BrowserDriver
</span><span class="cx"> from webkitpy.benchmark_runner.utils import write_defaults
</span><span class="lines">@@ -13,6 +14,7 @@
</span><span class="cx"> class OSXBrowserDriver(BrowserDriver):
</span><span class="cx">     process_name = None
</span><span class="cx">     platform = 'osx'
</span><ins>+    bundle_id = None
</ins><span class="cx"> 
</span><span class="cx">     def prepare_env(self, config):
</span><span class="cx">         self.close_browsers()
</span><span class="lines">@@ -20,15 +22,15 @@
</span><span class="cx">         CGWarpMouseCursorPosition((10, 0))
</span><span class="cx">         self.updated_dock_animation_defaults = write_defaults('com.apple.dock', 'launchanim', False)
</span><span class="cx">         if self.updated_dock_animation_defaults:
</span><del>-            self._terminate_processes('Dock')
</del><ins>+            self._terminate_processes('Dock', 'com.apple.dock')
</ins><span class="cx"> 
</span><span class="cx">     def restore_env(self):
</span><span class="cx">         if self.updated_dock_animation_defaults:
</span><span class="cx">             write_defaults('com.apple.dock', 'launchanim', True)
</span><del>-            self._terminate_processes('Dock')
</del><ins>+            self._terminate_processes('Dock', 'com.apple.dock')
</ins><span class="cx"> 
</span><span class="cx">     def close_browsers(self):
</span><del>-        self._terminate_processes(self.process_name)
</del><ins>+        self._terminate_processes(self.process_name, self.bundle_id)
</ins><span class="cx"> 
</span><span class="cx">     @classmethod
</span><span class="cx">     def _launch_process(cls, build_dir, app_name, url, args):
</span><span class="lines">@@ -52,9 +54,16 @@
</span><span class="cx">         driver.get(url)
</span><span class="cx"> 
</span><span class="cx">     @classmethod
</span><del>-    def _terminate_processes(cls, process_name):
</del><ins>+    def _terminate_processes(cls, process_name, bundle_id):
+        from AppKit import NSRunningApplication
</ins><span class="cx">         _log.info('Closing all processes with name %s' % process_name)
</span><del>-        subprocess.call(['/usr/bin/killall', process_name])
</del><ins>+        for app in NSRunningApplication.runningApplicationsWithBundleIdentifier_(bundle_id):
+            app.terminate()
+            # Give the app time to close
+            time.sleep(2)
+            if not app.isTerminated():
+                _log.error("Terminate failed.  Killing.")
+                subprocess.call(['/usr/bin/killall', process_name])
</ins><span class="cx"> 
</span><span class="cx">     @classmethod
</span><span class="cx">     def _launch_process_with_caffeinate(cls, args, env=None):
</span></span></pre></div>
<a id="trunkToolsScriptswebkitpybenchmark_runnerbrowser_driverosx_chrome_driverpy"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/webkitpy/benchmark_runner/browser_driver/osx_chrome_driver.py (242652 => 242653)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/webkitpy/benchmark_runner/browser_driver/osx_chrome_driver.py        2019-03-08 19:54:02 UTC (rev 242652)
+++ trunk/Tools/Scripts/webkitpy/benchmark_runner/browser_driver/osx_chrome_driver.py   2019-03-08 20:52:56 UTC (rev 242653)
</span><span class="lines">@@ -13,6 +13,7 @@
</span><span class="cx">     process_name = 'Google Chrome'
</span><span class="cx">     browser_name = 'chrome'
</span><span class="cx">     app_name = 'Google Chrome.app'
</span><ins>+    bundle_id = 'com.google.Chrome'
</ins><span class="cx"> 
</span><span class="cx">     def launch_url(self, url, options, browser_build_path, browser_path):
</span><span class="cx">         # FIXME: handle self._browser_path.
</span><span class="lines">@@ -37,6 +38,7 @@
</span><span class="cx">     process_name = 'Google Chrome Canary'
</span><span class="cx">     browser_name = 'chrome-canary'
</span><span class="cx">     app_name = 'Google Chrome Canary.app'
</span><ins>+    bundle_id = 'com.google.Chrome.canary'
</ins><span class="cx"> 
</span><span class="cx">     def launch_url(self, url, options, browser_build_path, browser_path):
</span><span class="cx">         # FIXME: handle self._browser_path.
</span></span></pre></div>
<a id="trunkToolsScriptswebkitpybenchmark_runnerbrowser_driverosx_firefox_driverpy"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/webkitpy/benchmark_runner/browser_driver/osx_firefox_driver.py (242652 => 242653)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/webkitpy/benchmark_runner/browser_driver/osx_firefox_driver.py       2019-03-08 19:54:02 UTC (rev 242652)
+++ trunk/Tools/Scripts/webkitpy/benchmark_runner/browser_driver/osx_firefox_driver.py  2019-03-08 20:52:56 UTC (rev 242653)
</span><span class="lines">@@ -13,6 +13,7 @@
</span><span class="cx">     process_name = 'firefox'
</span><span class="cx">     browser_name = 'firefox'
</span><span class="cx">     app_name = 'Firefox.app'
</span><ins>+    bundle_id = 'org.mozilla.firefox'
</ins><span class="cx"> 
</span><span class="cx">     def launch_url(self, url, options, browser_build_path, browser_path):
</span><span class="cx">         # FIXME: handle self._browser_path.
</span><span class="lines">@@ -38,7 +39,9 @@
</span><span class="cx">     process_name = 'firefox'
</span><span class="cx">     browser_name = 'firefox-nightly'
</span><span class="cx">     app_name = 'FirefoxNightly.app'
</span><ins>+    bundle_id = 'org.mozilla.firefox'
</ins><span class="cx"> 
</span><ins>+
</ins><span class="cx">     def launch_url(self, url, options, browser_build_path, browser_path):
</span><span class="cx">         # FIXME: handle self._browser_path.
</span><span class="cx">         args_with_url = self._insert_url(create_args(), 0, url)
</span></span></pre></div>
<a id="trunkToolsScriptswebkitpybenchmark_runnerbrowser_driverosx_safari_driverpy"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/webkitpy/benchmark_runner/browser_driver/osx_safari_driver.py (242652 => 242653)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/webkitpy/benchmark_runner/browser_driver/osx_safari_driver.py        2019-03-08 19:54:02 UTC (rev 242652)
+++ trunk/Tools/Scripts/webkitpy/benchmark_runner/browser_driver/osx_safari_driver.py   2019-03-08 20:52:56 UTC (rev 242653)
</span><span class="lines">@@ -15,14 +15,13 @@
</span><span class="cx"> class OSXSafariDriver(OSXBrowserDriver):
</span><span class="cx">     process_name = 'Safari'
</span><span class="cx">     browser_name = 'safari'
</span><ins>+    bundle_id = 'com.apple.Safari'
</ins><span class="cx"> 
</span><span class="cx">     def prepare_env(self, config):
</span><span class="cx">         self._safari_process = None
</span><ins>+        self._safari_preferences = ["-HomePage", "about:blank", "-WarnAboutFraudulentWebsites", "0", "-ExtensionsEnabled", "0", "-ShowStatusBar", "0", "-NewWindowBehavior", "1", "-NewTabBehavior", "1", "-AlwaysRestoreSessionAtLaunch", "0", "-ApplePersistenceIgnoreStateQuietly", "1"]
</ins><span class="cx">         super(OSXSafariDriver, self).prepare_env(config)
</span><del>-        force_remove(os.path.join(os.path.expanduser('~'), 'Library/Saved Application State/com.apple.Safari.savedState'))
-        force_remove(os.path.join(os.path.expanduser('~'), 'Library/Safari/LastSession.plist'))
</del><span class="cx">         self._maximize_window()
</span><del>-        self._safari_preferences = ["-HomePage", "about:blank", "-WarnAboutFraudulentWebsites", "0", "-ExtensionsEnabled", "0", "-ShowStatusBar", "0", "-NewWindowBehavior", "1", "-NewTabBehavior", "1"]
</del><span class="cx"> 
</span><span class="cx">     def launch_url(self, url, options, browser_build_path, browser_path):
</span><span class="cx">         args = ['/Applications/Safari.app/Contents/MacOS/Safari']
</span></span></pre>
</div>
</div>

</body>
</html>