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