Index: tools/chrome_remote_control/chrome_remote_control/browser_finder_unittest.py |
diff --git a/tools/chrome_remote_control/chrome_remote_control/browser_finder_unittest.py b/tools/chrome_remote_control/chrome_remote_control/browser_finder_unittest.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1925a69c31a8120b58181e4cb57201d87da0b0b9 |
--- /dev/null |
+++ b/tools/chrome_remote_control/chrome_remote_control/browser_finder_unittest.py |
@@ -0,0 +1,102 @@ |
+# 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. |
+ |
+import unittest |
+import browser |
+import browser_finder |
dtu
2012/08/24 08:55:43
import browser_options
|
+import os as real_os |
+ |
+# This file verifies the logic for finding a browser instance on all platforms |
+# at once. It does so by providing stubs for the OS/sys/subprocess primitives |
+# that the underlying finding logic usually uses to locate a suitable browser. |
+# We prefer this approach to having to run the same test on every platform on |
+# which we want this code to work. |
+ |
+class StubOSPath(object): |
+ def __init__(self, stub_os): |
+ self._stub_os = stub_os |
+ |
+ def exists(self, path): |
+ return path in self._stub_os.files |
+ |
+ def join(self, *args): |
+ return real_os.path.join(*args) |
+ |
+ def dirname(self, filename): |
+ return real_os.path.dirname(filename) |
+ |
+class StubOS(object): |
+ def __init__(self): |
+ self.path = StubOSPath(self) |
+ self.files = [] |
+ |
+class StubSys(object): |
+ def __init__(self): |
+ self.platform = "" |
+ |
+class StubSubprocess(object): |
+ def __init__(self): |
+ self.call_hook = None |
+ |
+ def call(self, args): |
+ if not self.call_hook: |
+ raise Exception("Should not be reached.") |
+ return self.call_hook(args) |
+ |
+class FindTestBase(unittest.TestCase): |
+ def setUp(self): |
+ self._options = browser.BrowserOptions() |
dtu
2012/08/24 08:55:43
browser_options.BrowserOptions()
|
+ self._stub_os = StubOS() |
+ self._stub_sys = StubSys() |
+ self._stub_subproces = StubSubprocess() |
+ |
+ @property |
+ def _files(self): |
+ return self._stub_os.files |
+ |
+ def DoFind(self): |
+ return browser_finder.Find(self._options, "../../../", |
+ self._stub_os, self._stub_sys, self._stub_subproces) |
+ |
+class OSXFindTest(FindTestBase): |
+ def setUp(self): |
+ super(OSXFindTest, self).setUp() |
+ self._stub_sys.platform = 'darwin' |
+ self._files.append("/Applications/Google Chrome Canary.app/" + |
+ "Contents/MacOS/Google Chrome Canary") |
+ self._files.append("/Applications/Google Chrome.app/" + |
+ "Contents/MacOS/Google Chrome") |
+ |
+ def testFindStableWithBothPresent(self): |
+ x = self.DoFind() |
+ self.assertEquals(self._files[1], x) |
+ |
+ def testFindCanary(self): |
+ self._options.canary = True |
+ x = self.DoFind() |
+ self.assertEquals(self._files[0], x) |
+ |
+class LinuxFindTest(FindTestBase): |
+ def setUp(self): |
+ super(LinuxFindTest, self).setUp() |
+ |
+ self._stub_sys.platform = 'linux2' |
+ self._stub_os.files.append("/foo/chrome") |
+ self._stub_os.files.append("../../../out/Release/chrome") |
+ self._stub_os.files.append("../../../out/Debug/chrome") |
+ |
+ def testFindWithProvidedExecutable(self): |
+ self._options.browser_executable = "/foo/chrome" |
+ x = self.DoFind() |
+ self.assertEquals(self._files[0], x) |
+ |
+ def testFindUsingDefaults(self): |
+ x = self.DoFind() |
+ self.assertEquals(self._files[1], x) |
+ |
+ def testFindUsingRelease(self): |
+ self._options.debug = True |
+ x = self.DoFind() |
+ self.assertEquals(self._files[2], x) |
+ |