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