1# Copyright 2014 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 logging 6import time 7import unittest 8 9from telemetry.core import platform as platform_module 10from telemetry.internal.app import android_app 11from telemetry.internal.backends import android_app_backend 12from telemetry.internal.platform import android_device 13from telemetry.testing import options_for_unittests 14 15from devil.android.sdk import intent 16 17 18class AndroidAppTest(unittest.TestCase): 19 def setUp(self): 20 self._options = options_for_unittests.GetCopy() 21 self._device = android_device.GetDevice(self._options) 22 23 def CreateAndroidApp(self, start_intent): 24 platform = platform_module.GetPlatformForDevice(self._device, self._options) 25 platform_backend = platform._platform_backend 26 app_backend = android_app_backend.AndroidAppBackend( 27 platform_backend, start_intent) 28 return android_app.AndroidApp(app_backend, platform_backend) 29 30 def testWebView(self): 31 if self._device is None: 32 logging.warning('No device found, skipping test.') 33 return 34 35 start_intent = intent.Intent( 36 package='com.google.android.googlequicksearchbox', 37 activity='.SearchActivity', 38 action='com.google.android.googlequicksearchbox.GOOGLE_SEARCH', 39 data=None, 40 extras={'query': 'google'}, 41 category=None) 42 search_app = self.CreateAndroidApp(start_intent) 43 search_process = search_app.GetProcess(':search') 44 search_process._UpdateDevToolsClient() 45 46 # TODO(ariblue): Replace the app used in this test with one in which the 47 # setWebContentsDebuggingEnabled method is called on the WebView class. 48 # This will configure webviews for debugging with chrome devtools inspector 49 # and allow us to remove this check. 50 if search_process._devtools_client is None: 51 return 52 53 webview = search_app.GetProcess(':search').GetWebViews().pop() 54 webview.Navigate('https://www.google.com/search?q=flowers') 55 time.sleep(5) 56