permission_broker: Fixes to run with gtest-1.6

* Programatically calculate gmock/gtest library dependencies.
* Mock out WaitForEmptyUdevQueue() while running test. The unit test
  hangs at this call with gtest 1.6. We shouldn't be using the real
  implementation while running tests anyway.
* Make PermissionBroker destructor virtual.

BUG=chromium:211445
TEST=built and ran permission_broker unit tests against gmock/gtest-1.6

Change-Id: I9eef56acbe7956b07f77b1a1e98b1cdf72af0460
diff --git a/Makefile b/Makefile
index b37d90b..c56fbc1 100644
--- a/Makefile
+++ b/Makefile
@@ -38,7 +38,9 @@
 clean: CLEAN(permission_broker)
 
 PERMISSION_BROKER_UNITTEST_FLAGS = $(PERMISSION_BROKER_FLAGS)
-PERMISSION_BROKER_UNITTEST_LIBS = $(PERMISSION_BROKER_LIBS) -lgmock -lgtest
+TEST_LIBS := $(shell gmock-config --libs) $(shell gtest-config --libs)
+PERMISSION_BROKER_UNITTEST_LIBS = $(PERMISSION_BROKER_LIBS) $(TEST_LIBS)
+
 CXX_BINARY(permission_broker_unittest): \
   CXXFLAGS += $(PERMISSION_BROKER_UNITTEST_FLAGS)
 CXX_BINARY(permission_broker_unittest): \
diff --git a/permission_broker.h b/permission_broker.h
index f469631..9296e87 100644
--- a/permission_broker.h
+++ b/permission_broker.h
@@ -26,7 +26,7 @@
 class PermissionBroker {
  public:
   PermissionBroker();
-  ~PermissionBroker();
+  virtual ~PermissionBroker();
 
   // Initializes the broker and loops waiting for requests on the DBus
   // interface. Never returns.
@@ -57,7 +57,7 @@
   // Waits for all queued udev events to complete before returning. Is
   // equivalent to invoking 'udevadm settle', but without the external
   // dependency and overhead.
-  void WaitForEmptyUdevQueue();
+  virtual void WaitForEmptyUdevQueue();
 
   // Invokes each of the rules in order on |path| until either a rule explicitly
   // denies access to the path or until there are no more rules left. If, after
diff --git a/permission_broker_unittest.cc b/permission_broker_unittest.cc
index 75312fd..15018d7 100644
--- a/permission_broker_unittest.cc
+++ b/permission_broker_unittest.cc
@@ -34,6 +34,7 @@
   virtual ~MockPermissionBroker() {}
 
   MOCK_METHOD1(MockGrantAccess, bool(const string &path));
+  MOCK_METHOD0(WaitForEmptyUdevQueue, void(void));
 
  private:
   virtual bool GrantAccess(const string &path) {