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