| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import os | 5 import os |
| 6 | 6 |
| 7 from telemetry.testing import serially_executed_browser_test_case | 7 from telemetry.testing import serially_executed_browser_test_case |
| 8 | 8 |
| 9 | 9 |
| 10 def ConvertPathToTestName(url): | 10 def ConvertPathToTestName(url): |
| 11 return url.replace('.', '_') | 11 return url.replace('.', '_') |
| 12 | 12 |
| 13 | 13 |
| 14 class SimpleBrowserTest( | 14 class SimpleBrowserTest( |
| 15 serially_executed_browser_test_case.SeriallyBrowserTestCase): | 15 serially_executed_browser_test_case.SeriallyExecutedBrowserTestCase): |
| 16 | 16 |
| 17 @classmethod | 17 @classmethod |
| 18 def GenerateTestCases_JavascriptTest(cls, options): | 18 def GenerateTestCases_JavascriptTest(cls, options): |
| 19 del options # unused | 19 del options # unused |
| 20 for path in ['page_with_link.html', 'page_with_clickables.html']: | 20 for path in ['page_with_link.html', 'page_with_clickables.html']: |
| 21 yield 'add_1_and_2_' + ConvertPathToTestName(path), (path, 1, 2, 3) | 21 yield 'add_1_and_2_' + ConvertPathToTestName(path), (path, 1, 2, 3) |
| 22 | 22 |
| 23 @classmethod | 23 @classmethod |
| 24 def setUpClass(cls): | 24 def setUpClass(cls): |
| 25 super(cls, SimpleBrowserTest).setUpClass() | 25 super(cls, SimpleBrowserTest).setUpClass() |
| 26 cls.StartBrowser(cls._finder_options) | 26 cls.SetBrowserOptions(cls._finder_options) |
| 27 cls.action_runner = cls._browser.tabs[0].action_runner | 27 cls.StartBrowser() |
| 28 cls.action_runner = cls.browser.tabs[0].action_runner |
| 28 cls.SetStaticServerDir( | 29 cls.SetStaticServerDir( |
| 29 os.path.join(os.path.abspath(__file__), '..', 'pages')) | 30 os.path.join(os.path.abspath(__file__), '..', 'pages')) |
| 30 | 31 |
| 31 def JavascriptTest(self, file_path, num_1, num_2, expected_sum): | 32 def JavascriptTest(self, file_path, num_1, num_2, expected_sum): |
| 32 url = self.UrlOfStaticFilePath(file_path) | 33 url = self.UrlOfStaticFilePath(file_path) |
| 33 self.action_runner.Navigate(url) | 34 self.action_runner.Navigate(url) |
| 34 actual_sum = self.action_runner.EvaluateJavaScript( | 35 actual_sum = self.action_runner.EvaluateJavaScript( |
| 35 '%i + %i' % (num_1, num_2)) | 36 '%i + %i' % (num_1, num_2)) |
| 36 self.assertEquals(expected_sum, actual_sum) | 37 self.assertEquals(expected_sum, actual_sum) |
| 37 | 38 |
| 38 def TestClickablePage(self): | 39 def TestClickablePage(self): |
| 39 url = self.UrlOfStaticFilePath('page_with_clickables.html') | 40 url = self.UrlOfStaticFilePath('page_with_clickables.html') |
| 40 self.action_runner.Navigate(url) | 41 self.action_runner.Navigate(url) |
| 41 self.action_runner.ExecuteJavaScript('valueSettableByTest = 1997') | 42 self.action_runner.ExecuteJavaScript('valueSettableByTest = 1997') |
| 42 self.action_runner.ClickElement(text='Click/tap me') | 43 self.action_runner.ClickElement(text='Click/tap me') |
| 43 self.assertEqual(1997, self.action_runner.EvaluateJavaScript('valueToTest')) | 44 self.assertEqual(1997, self.action_runner.EvaluateJavaScript('valueToTest')) |
| 44 | 45 |
| 45 def TestAndroidUI(self): | 46 def TestAndroidUI(self): |
| 46 if self._platform.GetOSName() != 'android': | 47 if self.platform.GetOSName() != 'android': |
| 47 self.skipTest('The test is for android only') | 48 self.skipTest('The test is for android only') |
| 48 url = self.UrlOfStaticFilePath('page_with_clickables.html') | 49 url = self.UrlOfStaticFilePath('page_with_clickables.html') |
| 49 # Nativgate to page_with_clickables.html | 50 # Nativgate to page_with_clickables.html |
| 50 self.action_runner.Navigate(url) | 51 self.action_runner.Navigate(url) |
| 51 # Click on history | 52 # Click on history |
| 52 self._platform.system_ui.WaitForUiNode( | 53 self.platform.system_ui.WaitForUiNode( |
| 53 resource_id='com.google.android.apps.chrome:id/menu_button') | 54 resource_id='com.google.android.apps.chrome:id/menu_button') |
| 54 self._platform.system_ui.GetUiNode( | 55 self.platform.system_ui.GetUiNode( |
| 55 resource_id='com.google.android.apps.chrome:id/menu_button').Tap() | 56 resource_id='com.google.android.apps.chrome:id/menu_button').Tap() |
| 56 self._platform.system_ui.WaitForUiNode(content_desc='History') | 57 self.platform.system_ui.WaitForUiNode(content_desc='History') |
| 57 self._platform.system_ui.GetUiNode(content_desc='History').Tap() | 58 self.platform.system_ui.GetUiNode(content_desc='History').Tap() |
| 58 # Click on the first entry of the history (page_with_clickables.html) | 59 # Click on the first entry of the history (page_with_clickables.html) |
| 59 self.action_runner.WaitForElement('#id-0') | 60 self.action_runner.WaitForElement('#id-0') |
| 60 self.action_runner.ClickElement('#id-0') | 61 self.action_runner.ClickElement('#id-0') |
| 61 # Verify that the page's js is interactable | 62 # Verify that the page's js is interactable |
| 62 self.action_runner.WaitForElement(text='Click/tap me') | 63 self.action_runner.WaitForElement(text='Click/tap me') |
| 63 self.action_runner.ExecuteJavaScript('valueSettableByTest = 1997') | 64 self.action_runner.ExecuteJavaScript('valueSettableByTest = 1997') |
| 64 self.action_runner.ClickElement(text='Click/tap me') | 65 self.action_runner.ClickElement(text='Click/tap me') |
| 65 self.assertEqual(1997, self.action_runner.EvaluateJavaScript('valueToTest')) | 66 self.assertEqual(1997, self.action_runner.EvaluateJavaScript('valueToTest')) |
| OLD | NEW |