summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authoryihongg@chromium.org <yihongg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-12 20:19:00 +0000
committeryihongg@chromium.org <yihongg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-12 20:19:00 +0000
commit2a00b0f7cc9f0b449d81458c50dd19d7c8b8791a (patch)
tree91a9c88e13b9e738311ff64a5ad9557a35a33935 /chrome
parentdc0e7dfff737abc1d90f82d4f73ab49b0402e033 (diff)
downloadchromium_src-2a00b0f7cc9f0b449d81458c50dd19d7c8b8791a.zip
chromium_src-2a00b0f7cc9f0b449d81458c50dd19d7c8b8791a.tar.gz
chromium_src-2a00b0f7cc9f0b449d81458c50dd19d7c8b8791a.tar.bz2
Made two changes to fix the failures on mac.
- "svn move" moved mock_pref_pane.py over to the new directory but the file is empty. Add the file content. - Use abspath to get key files and mock_pref_pane.py. NOTRY=true Review URL: https://chromiumcodereview.appspot.com/10928153 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@156364 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/test/pyautolib/chromoting_helper.py11
-rw-r--r--chrome/test/pyautolib/mock_pref_pane.py124
2 files changed, 131 insertions, 4 deletions
diff --git a/chrome/test/pyautolib/chromoting_helper.py b/chrome/test/pyautolib/chromoting_helper.py
index 7d017c2..39088a2 100644
--- a/chrome/test/pyautolib/chromoting_helper.py
+++ b/chrome/test/pyautolib/chromoting_helper.py
@@ -57,8 +57,10 @@ class ChromotingHelperMac(ChromotingHelper):
os.seteuid(0)
key_chain = '/Library/Keychains/ChromotingTest'
password = '1111'
- key = os.path.join(os.path.dirname(__file__), 'chromoting_key.p12')
- cert = os.path.join(os.path.dirname(__file__), 'chromoting_cert.p12')
+ key = os.path.join(os.path.dirname(os.path.abspath(__file__)),
+ 'chromoting_key.p12')
+ cert = os.path.join(os.path.dirname(os.path.abspath(__file__)),
+ 'chromoting_cert.p12')
subprocess.call(['security', 'delete-keychain', key_chain])
subprocess.call(['security', 'create-keychain', '-p',
password, key_chain])
@@ -124,8 +126,9 @@ class ChromotingHelperMac(ChromotingHelper):
mock_pref_pane = os.path.join(pref_pane_dir, 'mock_pref_pane')
pref_pane = os.path.join(pref_pane_dir,
'org.chromium.chromoting.prefPane')
- mock_pref_pane_python = os.path.join(os.path.dirname(__file__),
- 'mock_pref_pane.py')
+ mock_pref_pane_python = os.path.join(
+ os.path.dirname(os.path.abspath(__file__)),
+ 'mock_pref_pane.py')
# When the symlink from real pref pane to mock pref pane exists,
# mock pref pane will be modified to be a dir when the host is installed.
diff --git a/chrome/test/pyautolib/mock_pref_pane.py b/chrome/test/pyautolib/mock_pref_pane.py
index e69de29..cbb3a48 100644
--- a/chrome/test/pyautolib/mock_pref_pane.py
+++ b/chrome/test/pyautolib/mock_pref_pane.py
@@ -0,0 +1,124 @@
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Mock pref pane for testing purpose on Mac."""
+
+import Foundation
+import os
+import signal
+import subprocess
+import sys
+import tempfile
+import time
+
+
+class MockPrefPane(object):
+ """Mock Pref Pane to enable/disable/changepin without system prompt.
+
+ This only applies to Mac.
+ """
+
+ def __init__(self):
+ self._service_name = 'org.chromium.chromoting'
+ self._real_user_id = os.getuid()
+ self._config_file = os.path.join(tempfile.gettempdir(),
+ '%s.json' % self._service_name)
+ self._tool_script = '/Library/PrivilegedHelperTools/%s.me2me.sh' % \
+ self._service_name
+
+ def _GetJobPid(self):
+ """Gets the org.chromium.chromoting job id."""
+ process = subprocess.Popen(['launchctl', 'list'], stdout=subprocess.PIPE)
+ pid = None
+ 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)
+ fields = line.strip().split('\t')
+ if fields[2] == self._service_name and fields[0] != "-":
+ pid = fields[0]
+ break
+ process.wait()
+ return pid
+
+ def Enable(self):
+ """Handles what pref pane does for enabling connection."""
+ # Elevate privileges, otherwise tool_script executes with EUID != 0.
+ os.setuid(0)
+ subprocess.call([self._tool_script, '--enable'],
+ stdin=open(self._config_file))
+
+ # Drop privileges, start the launchd job as the logged-in user.
+ os.setuid(self._real_user_id)
+ subprocess.call(['launchctl', 'start', self._service_name])
+
+ # Starting a launchd job is an asynchronous operation that typically takes
+ # a couple of seconds, so poll until the job has started.
+ for _ in range(1, 10):
+ if self._GetJobPid():
+ print '*** org.chromium.chromoting is running ***'
+ break
+ time.sleep(2)
+
+ def Disable(self):
+ """Handles what pref pane does for disabling connection."""
+ # Elevate privileges, otherwise tool_script executes with EUID != 0.
+ os.setuid(0)
+ subprocess.call([self._tool_script, '--disable'],
+ stdin=open(self._config_file))
+
+ # Drop privileges, stop the launchd job as the logged-in user.
+ os.setuid(self._real_user_id)
+ subprocess.call(['launchctl', 'stop', self._service_name])
+
+ # Stopping a launchd job is an asynchronous operation that typically takes
+ # a couple of seconds, so poll until the job has stopped.
+ for _ in range(1, 10):
+ if not self._GetJobPid():
+ print '*** org.chromium.chromoting is not running ***'
+ break
+ time.sleep(2)
+
+ def ChangePin(self):
+ """Handles what pref pane does for changing pin."""
+ # Elevate privileges, otherwise tool_script executes with EUID != 0.
+ os.setuid(0)
+ subprocess.call([self._tool_script, '--save-config'],
+ stdin=open(self._config_file))
+
+ # Drop privileges and send SIGHUP to org.chromium.chromoting
+ os.setuid(self._real_user_id)
+ os.kill(int(self._GetJobPid()), signal.SIGHUP)
+
+ def NotifyWebapp(self):
+ """Notifies the web app that pref pane operation is done."""
+ notif_center = Foundation.NSDistributedNotificationCenter.defaultCenter()
+ notif_center.postNotificationName_object_userInfo_(
+ self._service_name + '.update_succeeded', None, None)
+
+
+def Main():
+ """Handles the mock pref pane actions."""
+ assert sys.platform.startswith('darwin')
+
+ print '*** Started mock pref pane ***'
+ print '*** EUID=%d, UID=%d ***' % (os.geteuid(), os.getuid())
+
+ pref_pane = MockPrefPane()
+
+ if sys.argv[1] == 'enable':
+ pref_pane.Enable()
+ elif sys.argv[1] == 'disable':
+ pref_pane.Disable()
+ elif sys.argv[1] == 'changepin':
+ pref_pane.ChangePin()
+ else:
+ print >>sys.stderr, 'Invalid syntax'
+ return
+
+ pref_pane.NotifyWebapp()
+
+
+if __name__ == '__main__':
+ Main() \ No newline at end of file