| Index: chrome/test/functional/chromoting/mock_pref_pane_disable
|
| ===================================================================
|
| --- chrome/test/functional/chromoting/mock_pref_pane_disable (revision 0)
|
| +++ chrome/test/functional/chromoting/mock_pref_pane_disable (revision 0)
|
| @@ -0,0 +1,65 @@
|
| +#!/bin/bash
|
| +
|
| +suid-python <<END
|
| +
|
| +import Foundation
|
| +import os
|
| +import subprocess
|
| +import tempfile
|
| +import time
|
| +
|
| +SERVICE_NAME = "org.chromium.chromoting"
|
| +
|
| +def is_job_running():
|
| + process = subprocess.Popen(["launchctl", "list"], stdout=subprocess.PIPE)
|
| + is_running = False
|
| + for line in process.stdout:
|
| + # Format is:
|
| + # 12345 - my.job (if my.job is running, number is job's PID)
|
| + # - 0 my.other.job (if my.other.job is not running)
|
| + print "*** %s ***" % line
|
| + fields = line.strip().split('\t')
|
| + if fields[2] == SERVICE_NAME and fields[0] != "-":
|
| + is_running = True
|
| + break
|
| + process.wait()
|
| + return is_running
|
| +
|
| +print "*** Started mock pref pane ***"
|
| +print "*** EUID=%d, UID=%d ***" % (os.geteuid(), os.getuid())
|
| +
|
| +config_file = os.path.join(tempfile.gettempdir(),
|
| + "%s.json" % SERVICE_NAME)
|
| +
|
| +print "*** config_file=%s" % config_file
|
| +
|
| +tool_script = "/Library/PrivilegedHelperTools/%s.me2me.sh" % SERVICE_NAME
|
| +
|
| +real_user_id = os.getuid()
|
| +
|
| +# Elevate privileges, otherwise tool_script executes with EUID != 0.
|
| +os.setuid(0)
|
| +subprocess.call([tool_script, "--disable"], stdin=open(config_file))
|
| +
|
| +# Drop privileges, in order to start the launchd job as the logged-in user.
|
| +os.setuid(real_user_id)
|
| +subprocess.call(["launchctl", "stop", SERVICE_NAME])
|
| +
|
| +# Starting a launchd job is an asynchronous operation that typically takes
|
| +# a couple of seconds, so poll until the job has started.
|
| +is_running = True
|
| +for i in range(1, 10):
|
| + if not is_job_running():
|
| + is_running = False
|
| + break
|
| + time.sleep(2)
|
| +
|
| +print "*** is_runnning = %d" % is_running
|
| +
|
| +notification_center = Foundation.NSDistributedNotificationCenter.defaultCenter()
|
| +notification_center.postNotificationName_object_userInfo_(
|
| + SERVICE_NAME + ".update_succeeded", None, None)
|
| +
|
| +time.sleep(10)
|
| +
|
| +END
|
|
|