Commit 41bccff9 authored by xhwang@chromium.org's avatar xhwang@chromium.org

Revert 255621 "Telemetry support for iframes."

> Telemetry support for iframes.
> 
> * Add methods EvaluateJavaScriptInContext,
> ExecuteJavaScriptInContext.
> * Backend classes take an additional context_id argument, which refers to the iframe.
> * WebContents has an EnableAllContexts method, to enable access to iframes.
> * Add tests testIFrame, and unit test data files host.html, iframe*.html.
> 
> BUG=237032
> TEST=unittest
> 
> Review URL: https://codereview.chromium.org/183863007

BUG=350568
TBR=achuith@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@255715 0039d316-1c4b-4281-b951-d872f2087c98
parent b4a05271
......@@ -112,7 +112,7 @@ class InspectorBackend(object):
# Displays other than 0 mean we are likely running in something like
# xvfb where screenshotting doesn't work.
return False
return not self.EvaluateJavaScript("""
return not self._runtime.Evaluate("""
window.chrome.gpuBenchmarking === undefined ||
window.chrome.gpuBenchmarking.beginWindowSnapshotPNG === undefined
""")
......@@ -120,7 +120,7 @@ class InspectorBackend(object):
def Screenshot(self, timeout):
assert self.screenshot_supported, 'Browser does not support screenshotting'
self.EvaluateJavaScript("""
self._runtime.Evaluate("""
if(!window.__telemetry) {
window.__telemetry = {}
}
......@@ -135,12 +135,11 @@ class InspectorBackend(object):
""")
def IsSnapshotComplete():
return self.EvaluateJavaScript(
'window.__telemetry.snapshotComplete')
return self._runtime.Evaluate('window.__telemetry.snapshotComplete')
util.WaitFor(IsSnapshotComplete, timeout)
snap = self.EvaluateJavaScript("""
snap = self._runtime.Evaluate("""
(function() {
var data = window.__telemetry.snapshotData;
delete window.__telemetry.snapshotComplete;
......@@ -185,11 +184,11 @@ class InspectorBackend(object):
# Runtime public methods.
def ExecuteJavaScript(self, expr, context_id=None, timeout=60):
self._runtime.Execute(expr, context_id, timeout)
def ExecuteJavaScript(self, expr, timeout):
self._runtime.Execute(expr, timeout)
def EvaluateJavaScript(self, expr, context_id=None, timeout=60):
return self._runtime.Evaluate(expr, context_id, timeout)
def EvaluateJavaScript(self, expr, timeout):
return self._runtime.Evaluate(expr, timeout)
# Timeline public methods.
......
......@@ -10,7 +10,6 @@ class InspectorRuntime(object):
'Runtime',
self._OnNotification,
self._OnClose)
self._contexts_enabled = False
def _OnNotification(self, msg):
pass
......@@ -18,11 +17,25 @@ class InspectorRuntime(object):
def _OnClose(self):
pass
def Execute(self, expr, context_id, timeout):
self.Evaluate(expr + '; 0;', context_id, timeout)
def Execute(self, expr, timeout=60):
"""Executes expr in javascript. Does not return the result.
def Evaluate(self, expr, context_id, timeout):
self._EnableAllContexts(context_id)
If the expression failed to evaluate, EvaluateException will be raised.
"""
self.Evaluate(expr + '; 0;', timeout)
def Evaluate(self, expr, timeout=60):
"""Evalutes expr in javascript and returns the JSONized result.
Consider using Execute for cases where the result of the expression is not
needed.
If evaluation throws in javascript, a python EvaluateException will
be raised.
If the result of the evaluation cannot be JSONized, then an
EvaluationException will be raised.
"""
request = {
'method': 'Runtime.evaluate',
'params': {
......@@ -30,8 +43,6 @@ class InspectorRuntime(object):
'returnByValue': True
}
}
if context_id is not None:
request['params']['contextId'] = context_id
res = self._inspector_backend.SyncRequest(request, timeout)
if 'error' in res:
raise exceptions.EvaluateException(res['error']['message'])
......@@ -43,10 +54,3 @@ class InspectorRuntime(object):
if res['result']['result']['type'] == 'undefined':
return None
return res['result']['result']['value']
def _EnableAllContexts(self, context_id):
"""Allow access to iframes as necessary."""
if context_id is not None and not self._contexts_enabled:
self._inspector_backend.SyncRequest({'method': 'Runtime.enable'},
timeout=30)
self._contexts_enabled = True
......@@ -2,7 +2,6 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from telemetry.core import exceptions
from telemetry.core import util
from telemetry.unittest import tab_test_case
class InspectorRuntimeTest(tab_test_case.TabTestCase):
......@@ -30,28 +29,3 @@ class InspectorRuntimeTest(tab_test_case.TabTestCase):
def testRuntimeExecuteOfSomethingThatCantJSONize(self):
self._tab.ExecuteJavaScript('window')
def testIFrame(self):
self._browser.SetHTTPServerDirectories(util.GetUnittestDataDir())
self._tab.Navigate(self._browser.http_server.UrlOf('host.html'))
# Access host page.
self._tab.WaitForJavaScriptExpression(
"typeof(testVar) != 'undefined'", timeout=5)
self.assertEquals(self._tab.EvaluateJavaScript('testVar'), 'host')
# Access parent page using EvaluateJavaScriptInContext.
self.assertEquals(self._tab.EvaluateJavaScriptInContext('testVar',
context_id=1), 'host')
# Access the iframes.
self.assertEquals(self._tab.EvaluateJavaScriptInContext('testVar',
context_id=2), 'iframe1')
self.assertEquals(self._tab.EvaluateJavaScriptInContext('testVar',
context_id=3), 'iframe2')
self.assertEquals(self._tab.EvaluateJavaScriptInContext('testVar',
context_id=4), 'iframe3')
# Accessing a non-existent iframe throws an exception.
self.assertRaises(exceptions.EvaluateException,
lambda: self._tab.EvaluateJavaScriptInContext('1+1', context_id=5))
......@@ -51,8 +51,7 @@ class WebContents(object):
If the expression failed to evaluate, EvaluateException will be raised.
"""
return self.ExecuteJavaScriptInContext(
expr, context_id=None, timeout=timeout)
self._inspector_backend.ExecuteJavaScript(expr, timeout)
def EvaluateJavaScript(self, expr, timeout=DEFAULT_WEB_CONTENTS_TIMEOUT):
"""Evalutes expr in JavaScript and returns the JSONized result.
......@@ -66,24 +65,7 @@ class WebContents(object):
If the result of the evaluation cannot be JSONized, then an
EvaluationException will be raised.
"""
return self.EvaluateJavaScriptInContext(
expr, context_id=None, timeout=timeout)
def ExecuteJavaScriptInContext(self, expr, context_id,
timeout=DEFAULT_WEB_CONTENTS_TIMEOUT):
"""Similar to ExecuteJavaScript, except context_id can refer to an iframe.
The main page has context_id=1, the first iframe context_id=2, etc.
"""
return self._inspector_backend.ExecuteJavaScript(
expr, context_id=context_id, timeout=timeout)
def EvaluateJavaScriptInContext(self, expr, context_id,
timeout=DEFAULT_WEB_CONTENTS_TIMEOUT):
"""Similar to ExecuteJavaScript, except context_id can refer to an iframe.
The main page has context_id=1, the first iframe context_id=2, etc.
"""
return self._inspector_backend.EvaluateJavaScript(
expr, context_id=context_id, timeout=timeout)
return self._inspector_backend.EvaluateJavaScript(expr, timeout)
@property
def message_output_stream(self):
......
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">var testVar = "host";</script>
</head>
<body>
This is the host page.
<br>
<iframe src="iframe1.html"></iframe>
<iframe src="iframe3.html"></iframe>
</body>
</html>
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">var testVar="iframe1";</script>
</head>
<body>
This is IFrame 1.
<br>
<iframe src="iframe2.html"></iframe>
</body>
</html>
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">var testVar="iframe2";</script>
</head>
<body>
This is IFrame 2.
</body>
</html>
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">var testVar="iframe3";</script>
</head>
<body>
This is IFrame 3.
</body>
</html>
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