Commit 43434893 authored by nednguyen@google.com's avatar nednguyen@google.com

Add page.CanRunOnBrowser. Add WebGL check for tough_webgl_cases pages

BUG=373812

Review URL: https://codereview.chromium.org/288313005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272620 0039d316-1c4b-4281-b951-d872f2087c98
parent 56286613
# Copyright 2014 The Chromium Authors. All rights reserved. # Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
import logging
# pylint: disable=W0401,W0614 # pylint: disable=W0401,W0614
from telemetry.page.actions.all_page_actions import * from telemetry.page.actions.all_page_actions import *
from telemetry.page import page as page_module from telemetry.page import page as page_module
...@@ -13,6 +15,12 @@ class ToughWebglCasesPage(page_module.Page): ...@@ -13,6 +15,12 @@ class ToughWebglCasesPage(page_module.Page):
super(ToughWebglCasesPage, self).__init__(url=url, page_set=page_set) super(ToughWebglCasesPage, self).__init__(url=url, page_set=page_set)
self.archive_data_file = 'data/tough_webgl_cases.json' self.archive_data_file = 'data/tough_webgl_cases.json'
def CanRunOnBrowser(self, browser_info):
if not browser_info.HasWebGLSupport():
logging.warning('Browser does not support webgl, skipping test')
return False
return True
def RunNavigateSteps(self, action_runner): def RunNavigateSteps(self, action_runner):
action_runner.NavigateToPage(self) action_runner.NavigateToPage(self)
action_runner.RunAction(WaitAction( action_runner.RunAction(WaitAction(
......
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
_check_webgl_supported_script = """
(function () {
var c = document.createElement('canvas');
var gl = c.getContext('webgl');
if (gl == null) {
gl = c.getContext("experimental-webgl");
if (gl == null) {
return false;
}
}
return true;
})();
"""
class BrowserInfo(object):
"""A wrapper around browser object that allows looking up infos of the
browser.
"""
def __init__(self, browser):
self._browser = browser
def HasWebGLSupport(self):
result = False
# If no tab is opened, open one and close it after evaluate
# _check_webgl_supported_script
if len(self._browser.tabs) == 0 and self._browser.supports_tab_control:
self._browser.tabs.New()
tab = self._browser.tabs[0]
result = tab.EvaluateJavaScript(_check_webgl_supported_script)
tab.Close()
elif len(self._browser.tabs) > 0:
tab = self._browser.tabs[0]
result = tab.EvaluateJavaScript(_check_webgl_supported_script)
return result
...@@ -41,6 +41,16 @@ class Page(object): ...@@ -41,6 +41,16 @@ class Page(object):
def RunNavigateSteps(self, action_runner): def RunNavigateSteps(self, action_runner):
action_runner.NavigateToPage(self) action_runner.NavigateToPage(self)
def CanRunOnBrowser(self, browser_info):
"""Override this to returns whether this page can be run on specific
browser.
Args:
browser_info: an instance of telemetry.core.browser_info.BrowserInfo
"""
assert browser_info
return True
@property @property
def page_set(self): def page_set(self):
return self._page_set return self._page_set
......
...@@ -14,6 +14,7 @@ import time ...@@ -14,6 +14,7 @@ import time
from telemetry import decorators from telemetry import decorators
from telemetry.core import browser_finder from telemetry.core import browser_finder
from telemetry.core import browser_info
from telemetry.core import exceptions from telemetry.core import exceptions
from telemetry.core import util from telemetry.core import util
from telemetry.core import wpr_modes from telemetry.core import wpr_modes
...@@ -251,6 +252,11 @@ def _PrepareAndRunPage(test, page_set, expectations, finder_options, ...@@ -251,6 +252,11 @@ def _PrepareAndRunPage(test, page_set, expectations, finder_options,
# options for just the current page before starting the browser. # options for just the current page before starting the browser.
state.StartBrowserIfNeeded(test, page_set, page, possible_browser, state.StartBrowserIfNeeded(test, page_set, page, possible_browser,
credentials_path, page.archive_path) credentials_path, page.archive_path)
if not page.CanRunOnBrowser(browser_info.BrowserInfo(state.browser)):
logging.info('Skip test for page %s because browser is not supported.'
% page.url)
results_for_current_run.StopTest(page)
return results
expectation = expectations.GetExpectationForPage(state.browser, page) expectation = expectations.GetExpectationForPage(state.browser, page)
......
...@@ -438,3 +438,42 @@ class PageRunnerTests(unittest.TestCase): ...@@ -438,3 +438,42 @@ class PageRunnerTests(unittest.TestCase):
SetUpPageRunnerArguments(options) SetUpPageRunnerArguments(options)
page_runner.Run(test, ps, expectations, options) page_runner.Run(test, ps, expectations, options)
assert test.did_call_clean_up assert test.did_call_clean_up
# Ensure skipping the test if page cannot be run on the browser
def testPageCannotRunOnBrowser(self):
ps = page_set.PageSet()
expectations = test_expectations.TestExpectations()
class PageThatCannotRunOnBrowser(page_module.Page):
def __init__(self):
super(PageThatCannotRunOnBrowser, self).__init__(
url='file://blank.html', page_set=ps,
base_dir=util.GetUnittestDataDir())
def CanRunOnBrowser(self, _):
return False
def ValidatePage(self, _):
pass
class Test(page_test.PageTest):
def __init__(self, *args, **kwargs):
super(Test, self).__init__(*args, **kwargs)
self.will_navigate_to_page_called = False
def ValidatePage(self, *args):
pass
def WillNavigateToPage(self, _1, _2):
self.will_navigate_to_page_called = True
test = Test()
options = options_for_unittests.GetCopy()
options.output_format = 'none'
SetUpPageRunnerArguments(options)
results = page_runner.Run(test, ps, expectations, options)
self.assertFalse(test.will_navigate_to_page_called)
self.assertEquals(0, len(results.successes))
self.assertEquals(0, len(results.failures))
self.assertEquals(0, len(results.errors))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment