Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(513)

Side by Side Diff: chrome/test/chromedriver/test/run_py_tests.py

Issue 251933005: [ChromeDriver] Support mobile emulation on desktop Chrome. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing review comments Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2013 The Chromium Authors. All rights reserved. 2 # Copyright 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """End to end tests for ChromeDriver.""" 6 """End to end tests for ChromeDriver."""
7 7
8 import base64 8 import base64
9 import json 9 import json
10 import math 10 import math
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 # When 31 is released, will reload the tab instead. 701 # When 31 is released, will reload the tab instead.
702 # https://code.google.com/p/chromedriver/issues/detail?id=547 702 # https://code.google.com/p/chromedriver/issues/detail?id=547
703 self.assertRaises(chromedriver.UnknownError, 703 self.assertRaises(chromedriver.UnknownError,
704 self._driver.Load, 'chrome://crash') 704 self._driver.Load, 'chrome://crash')
705 self.assertRaises(chromedriver.NoSuchSession, 705 self.assertRaises(chromedriver.NoSuchSession,
706 self._driver.GetCurrentUrl) 706 self._driver.GetCurrentUrl)
707 707
708 def testDoesntHangOnDebugger(self): 708 def testDoesntHangOnDebugger(self):
709 self._driver.ExecuteScript('debugger;') 709 self._driver.ExecuteScript('debugger;')
710 710
711 def testMobileEmulationDisabledByDefault(self):
712 self.assertFalse(self._driver.capabilities['mobileEmulationEnabled'])
713
711 714
712 class ChromeDriverAndroidTest(ChromeDriverBaseTest): 715 class ChromeDriverAndroidTest(ChromeDriverBaseTest):
713 """End to end tests for Android-specific tests.""" 716 """End to end tests for Android-specific tests."""
714 717
715 def testLatestAndroidAppInstalled(self): 718 def testLatestAndroidAppInstalled(self):
716 if ('stable' not in _ANDROID_PACKAGE_KEY and 719 if ('stable' not in _ANDROID_PACKAGE_KEY and
717 'beta' not in _ANDROID_PACKAGE_KEY): 720 'beta' not in _ANDROID_PACKAGE_KEY):
718 return 721 return
719 722
720 self._driver = self.CreateDriver() 723 self._driver = self.CreateDriver()
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 805
803 Verifies that a log message is written into the specified log file. 806 Verifies that a log message is written into the specified log file.
804 """ 807 """
805 tmp_log_path = tempfile.NamedTemporaryFile() 808 tmp_log_path = tempfile.NamedTemporaryFile()
806 driver = self.CreateDriver(chrome_log_path=tmp_log_path.name) 809 driver = self.CreateDriver(chrome_log_path=tmp_log_path.name)
807 driver.ExecuteScript('console.info("%s")' % self.LOG_MESSAGE) 810 driver.ExecuteScript('console.info("%s")' % self.LOG_MESSAGE)
808 driver.Quit() 811 driver.Quit()
809 self.assertTrue(self.LOG_MESSAGE in open(tmp_log_path.name).read()) 812 self.assertTrue(self.LOG_MESSAGE in open(tmp_log_path.name).read())
810 813
811 814
815 class MobileEmulationCapabilityTest(ChromeDriverBaseTest):
stgao 2014/05/19 17:34:02 This test suite have to be disabled on Android. Pl
sam.rawlins 2014/05/20 00:25:20 Done.
816 """Tests that ChromeDriver processes chromeOptions.mobileEmulation.
817
818 Makes sure the device metrics are overridden in DevTools and user agent is
819 overridden in Chrome.
820 """
821
822 @staticmethod
823 def GlobalSetUp():
824 def respondWithUserAgentString(request):
825 return request.GetHeader('User-Agent')
826
827 MobileEmulationCapabilityTest._http_server = webserver.WebServer(
828 chrome_paths.GetTestData())
829 MobileEmulationCapabilityTest._http_server.SetCallbackForPath(
830 '/userAgent', respondWithUserAgentString)
831
832 @staticmethod
833 def GlobalTearDown():
834 MobileEmulationCapabilityTest._http_server.Shutdown()
835
836 def testDeviceMetrics(self):
837 driver = self.CreateDriver(
838 mobile_emulation = {
839 'deviceMetrics': {'width': 360, 'height': 640, 'pixelRatio': 3}})
840 self.assertTrue(driver.capabilities['mobileEmulationEnabled'])
841 self.assertEqual(360, driver.ExecuteScript('return window.innerWidth'))
842 self.assertEqual(640, driver.ExecuteScript('return window.innerHeight'))
843
844 def testUserAgent(self):
845 driver = self.CreateDriver(
846 mobile_emulation = {'userAgent': 'Agent Smith'})
847 driver.Load(self._http_server.GetUrl() + '/userAgent')
848 body_tag = driver.FindElement('tag name', 'body')
849 self.assertEqual("Agent Smith", body_tag.GetText())
850
851 def testDeviceName(self):
852 driver = self.CreateDriver(
853 mobile_emulation = {'deviceName': 'Google Nexus 5'})
854 driver.Load(self._http_server.GetUrl() + '/userAgent')
855 self.assertEqual(360, driver.ExecuteScript('return window.innerWidth'))
856 self.assertEqual(640, driver.ExecuteScript('return window.innerHeight'))
857 body_tag = driver.FindElement('tag name', 'body')
858 self.assertEqual(
859 'Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleW'
860 'ebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/53'
861 '5.19',
862 body_tag.GetText())
863
864
812 class ChromeDriverLogTest(unittest.TestCase): 865 class ChromeDriverLogTest(unittest.TestCase):
813 """Tests that chromedriver produces the expected log file.""" 866 """Tests that chromedriver produces the expected log file."""
814 867
815 UNEXPECTED_CHROMEOPTION_CAP = 'unexpected_chromeoption_capability' 868 UNEXPECTED_CHROMEOPTION_CAP = 'unexpected_chromeoption_capability'
816 LOG_MESSAGE = 'unrecognized chrome option: %s' % UNEXPECTED_CHROMEOPTION_CAP 869 LOG_MESSAGE = 'unrecognized chrome option: %s' % UNEXPECTED_CHROMEOPTION_CAP
817 870
818 def testChromeDriverLog(self): 871 def testChromeDriverLog(self):
819 _, tmp_log_path = tempfile.mkstemp(prefix='chromedriver_log_') 872 _, tmp_log_path = tempfile.mkstemp(prefix='chromedriver_log_')
820 chromedriver_server = server.Server( 873 chromedriver_server = server.Server(
821 _CHROMEDRIVER_BINARY, log_path=tmp_log_path) 874 _CHROMEDRIVER_BINARY, log_path=tmp_log_path)
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 if _ANDROID_PACKAGE_KEY: 1048 if _ANDROID_PACKAGE_KEY:
996 negative_filter = _ANDROID_NEGATIVE_FILTER[_ANDROID_PACKAGE_KEY] 1049 negative_filter = _ANDROID_NEGATIVE_FILTER[_ANDROID_PACKAGE_KEY]
997 else: 1050 else:
998 negative_filter = _GetDesktopNegativeFilter(options.chrome_version) 1051 negative_filter = _GetDesktopNegativeFilter(options.chrome_version)
999 options.filter = '*-' + ':__main__.'.join([''] + negative_filter) 1052 options.filter = '*-' + ':__main__.'.join([''] + negative_filter)
1000 1053
1001 all_tests_suite = unittest.defaultTestLoader.loadTestsFromModule( 1054 all_tests_suite = unittest.defaultTestLoader.loadTestsFromModule(
1002 sys.modules[__name__]) 1055 sys.modules[__name__])
1003 tests = unittest_util.FilterTestSuite(all_tests_suite, options.filter) 1056 tests = unittest_util.FilterTestSuite(all_tests_suite, options.filter)
1004 ChromeDriverTest.GlobalSetUp() 1057 ChromeDriverTest.GlobalSetUp()
1058 MobileEmulationCapabilityTest.GlobalSetUp()
1005 result = unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run(tests) 1059 result = unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run(tests)
1006 ChromeDriverTest.GlobalTearDown() 1060 ChromeDriverTest.GlobalTearDown()
1061 MobileEmulationCapabilityTest.GlobalTearDown()
1007 sys.exit(len(result.failures) + len(result.errors)) 1062 sys.exit(len(result.failures) + len(result.errors))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698