Listen for ownership-taken signal on DBus

Many tests that touch on device Ownership were using a
function that simply watched for the presence of policy
and owner key files to indicate that the session_manager
had completed the ownership-taking process on the sign-in
of the first user. This could be tricked, though, in the
case of the UI being restarted between the test clearing
these files and then checking for them again. Stop using
this and switch to watching for signals announcing that
ownership has been taken, which the session_manager has
sent all along anyhow.

BUG=chromium:355664
TEST=login_*Ownership*

Change-Id: I54000c426cfb1aef8fd1518f9cdadec2b42c6500
Reviewed-on: https://chromium-review.googlesource.com/194142
Reviewed-by: Chris Masone <cmasone@chromium.org>
Commit-Queue: Chris Masone <cmasone@chromium.org>
Tested-by: Chris Masone <cmasone@chromium.org>
diff --git a/client/common_lib/cros/policy.py b/client/common_lib/cros/policy.py
index 09a4e23..b039a7a 100644
--- a/client/common_lib/cros/policy.py
+++ b/client/common_lib/cros/policy.py
@@ -2,11 +2,12 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
-import dbus, sys
+import dbus, gobject, sys
 
 import common
 from autotest_lib.client.common_lib import error
-from autotest_lib.client.cros import login, ownership
+from autotest_lib.client.common_lib.cros import session_manager
+from autotest_lib.client.cros import ownership
 
 
 """Utility class for tests that generate, push and fetch policies.
@@ -165,8 +166,10 @@
 
     @raises error.TestFail if policy push failed.
     """
+    listener = session_manager.OwnershipSignalListener(gobject.MainLoop())
+    listener.listen_for_new_policy()
     sm.StorePolicy(dbus.ByteArray(policy_string), byte_arrays=True)
-    login.wait_for_ownership()
+    listener.wait_for_signals(desc='Policy push.')
 
     retrieved_policy = sm.RetrievePolicy(byte_arrays=True)
     if retrieved_policy != policy_string: