Chromium Code Reviews| Index: chrome/test/webdriver/chromedriver_tests.py |
| diff --git a/chrome/test/webdriver/chromedriver_tests.py b/chrome/test/webdriver/chromedriver_tests.py |
| index 55a7bd37ec7dcb538199b9e0a80b18170d727122..8595f133fea5c32a5a1dcfd8a1d9c71e8200b0b8 100755 |
| --- a/chrome/test/webdriver/chromedriver_tests.py |
| +++ b/chrome/test/webdriver/chromedriver_tests.py |
| @@ -10,10 +10,12 @@ If your test is testing a specific part of the WebDriver API, consider adding |
| it to the appropriate place in the WebDriver tree instead. |
| """ |
| -import platform |
| +import hashlib |
| import os |
| +import platform |
| import sys |
| import unittest |
| +import urllib |
| import urllib2 |
| import urlparse |
| @@ -83,6 +85,28 @@ class BasicTest(unittest.TestCase): |
| def tearDown(self): |
| self._launcher.Kill() |
| + @staticmethod |
| + def DataDir(): |
|
kkania
2011/03/17 18:35:11
move this out of BasicTest and put the function up
Joe
2011/03/18 00:33:32
Won't future tests all use reference web files. A
kkania
2011/03/18 19:18:22
Yes, I know this is from pyauto. However, right no
|
| + """Returns the path to the data dir chrome/test/data.""" |
| + return os.path.normpath( |
| + os.path.join(os.path.dirname(__file__), os.pardir, "data")) |
| + |
| + @staticmethod |
| + def GetFileURLForPath(path): |
| + """Get file:// url for the given path. |
| + Also quotes the url using urllib.quote(). |
| + """ |
| + abs_path = os.path.abspath(path) |
| + if sys.platform == 'win32': |
| + # Don't quote the ':' in drive letter ( say, C: ) on win. |
| + # Also, replace '\' with '/' as expected in a file:/// url. |
| + drive, rest = os.path.splitdrive(abs_path) |
| + quoted_path = drive.upper() + urllib.quote((rest.replace('\\', '/'))) |
| + return 'file:///' + quoted_path |
| + else: |
| + quoted_path = urllib.quote(abs_path) |
| + return 'file://' + quoted_path |
| + |
| def testShouldReturn404WhenSentAnUnknownCommandURL(self): |
| request_url = self._launcher.GetURL() + '/foo' |
| try: |
| @@ -148,6 +172,40 @@ class CookieTest(unittest.TestCase): |
| self.assertEqual(cookie_dict, None) |
| +class ScreenshotTest(unittest.TestCase): |
| + """Tests to verify screenshot retrieval""" |
| + |
| + SEARCH = "http://www.google.com/webhp?hl=en" |
| + NEWS = "http://www.google.com/news" |
| + REDBOX = "automation_proxy_snapshot/set_size.html" |
| + |
| + def setUp(self): |
| + self._launcher = ChromeDriverLauncher() |
| + self._driver = WebDriver(self._launcher.GetURL(), {}) |
| + |
| + def tearDown(self): |
| + self._driver.quit() |
| + self._launcher.Kill() |
| + |
| + def testScreenCapture(self): |
| + self._driver.get(self.SEARCH) |
|
kkania
2011/03/17 18:35:11
we should not use public sites on the bots unless
Joe
2011/03/18 00:33:32
Done.
kkania
2011/03/18 19:18:22
remove the SEARCH and NEW constants above too
|
| + s1 = self._driver.get_screenshot_as_base64() |
| + self._driver.get(self.NEWS) |
| + s2 = self._driver.get_screenshot_as_base64() |
| + self.assertTrue(len(s1) > 0 and len(s2) > 0) |
| + self.assertTrue(len(s1) != len(s2)) |
| + |
| + def testScreenCaptureAgainstReference(self): |
| + # Create a red square of 2000x2000 pixels. |
| + url = BasicTest.GetFileURLForPath(os.path.join(BasicTest.DataDir(), |
| + self.REDBOX)) |
| + url = url + "?2000,2000" |
| + self._driver.get(url) |
| + s = self._driver.get_screenshot_as_base64(); |
| + h = hashlib.md5(s).hexdigest() |
| + # Compare the PNG created to the reference hash. |
| + self.assertTrue(h, '12c0ade27e3875da3d8866f52d2fa84f') |
|
kkania
2011/03/17 18:35:11
did this work on all platforms?
Joe
2011/03/18 00:33:32
Yah all platforms gave me the same PNG file with t
|
| + |
| class SessionTest(unittest.TestCase): |
| """Tests dealing with WebDriver sessions.""" |