Chromium Code Reviews| Index: chrome/test/functional/chromoting/mock_pref_pane_enable |
| =================================================================== |
| --- chrome/test/functional/chromoting/mock_pref_pane_enable (revision 0) |
| +++ chrome/test/functional/chromoting/mock_pref_pane_enable (revision 0) |
| @@ -0,0 +1,66 @@ |
| +#!/bin/bash |
| + |
| +suid-python <<END |
| + |
| +import Foundation |
| +import os |
| +import subprocess |
| +import tempfile |
| +import time |
| + |
| +SERVICE_NAME = "org.chromium.chromoting" |
|
garykac
2012/07/31 00:25:11
This is pretty much exactly the same as mock_pref_
yihongg1
2012/08/03 00:40:06
Done.
|
| + |
| +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') |
| + print "*** field 2=%s, field 0=%s ***" % (fields[2], fields[0]) |
| + 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, "--enable"], 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", "start", 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 = False |
| +for i in range(1, 10): |
| + if is_job_running(): |
| + is_running = True |
| + 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 |