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
5_check_webgl_supported_script = """
6(function () {
7  var c = document.createElement('canvas');
8  var gl = c.getContext('webgl', { failIfMajorPerformanceCaveat: true });
9  if (gl == null) {
10    gl = c.getContext('experimental-webgl',
11        { failIfMajorPerformanceCaveat: true });
12    if (gl == null) {
13      return false;
14    }
15  }
16  return true;
17})();
18"""
19
20class BrowserInfo(object):
21  """A wrapper around browser object that allows looking up infos of the
22  browser.
23  """
24  def __init__(self, browser):
25    self._browser = browser
26
27  def HasWebGLSupport(self):
28    result = False
29    # If no tab is opened, open one and close it after evaluate
30    # _check_webgl_supported_script
31    if len(self._browser.tabs) == 0 and self._browser.supports_tab_control:
32      self._browser.tabs.New()
33      tab = self._browser.tabs[0]
34      result = tab.EvaluateJavaScript(_check_webgl_supported_script)
35      tab.Close()
36    elif len(self._browser.tabs) > 0:
37      tab = self._browser.tabs[0]
38      result = tab.EvaluateJavaScript(_check_webgl_supported_script)
39    return result
40
41  def HasFlingGestureSupport(self):
42    # Synthetic fling gestures weren't properly tracked by telemetry until
43    # Chromium branch number 2339 (see crrev.com/1003023002).
44    # TODO(jdduke): Resolve lack of branch number support for content_shell
45    # targets, see crbug.com/470273.
46    branch_num = (
47        self._browser._browser_backend.devtools_client.GetChromeBranchNumber())
48    return branch_num >= 2339
49
50  def HasDiagonalScrollingSupport(self):
51    # Diagonal scrolling was not supported in the ScrollAction until
52    # Chromium branch number 2332
53    branch_num = (
54        self._browser._browser_backend.devtools_client.GetChromeBranchNumber())
55    return branch_num >= 2332
56
57  def HasRepeatableSynthesizeScrollGesture(self):
58    # Repeatable SynthesizeScrollGesture scrolling was not supported until
59    # Chromium branch number 2480
60    branch_num = (
61        self._browser._browser_backend.devtools_client.GetChromeBranchNumber())
62    return branch_num >= 2480
63
64  @property
65  def browser_type(self):
66    return self._browser.browser_type
67
68  @property
69  def browser(self):
70    return self._browser
71