Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(263)

Unified Diff: tools/telemetry/telemetry/core/backends/chrome/inspector_runtime_unittest.py

Issue 183863007: Telemetry support for iframes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more fix for unittest Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/telemetry/telemetry/core/backends/chrome/inspector_runtime_unittest.py
diff --git a/tools/telemetry/telemetry/core/backends/chrome/inspector_runtime_unittest.py b/tools/telemetry/telemetry/core/backends/chrome/inspector_runtime_unittest.py
index c5687dd344de4c5ea2a98046b89150005fc21be8..ef45bab0575bebfcca1f8e49aae42c6ea2d99a55 100644
--- a/tools/telemetry/telemetry/core/backends/chrome/inspector_runtime_unittest.py
+++ b/tools/telemetry/telemetry/core/backends/chrome/inspector_runtime_unittest.py
@@ -2,6 +2,7 @@
# 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):
@@ -29,3 +30,39 @@ 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.
+ test_defined_js = "typeof(testVar) != 'undefined'"
+ self._tab.WaitForJavaScriptExpression(test_defined_js, timeout=5)
+ self.assertEquals(self._tab.EvaluateJavaScript('testVar'), 'host')
+
+ def TestVarReady(context_id):
+ """Returns True if the context and testVar are both ready."""
+ try:
+ return self._tab.EvaluateJavaScriptInContext(test_defined_js,
+ context_id)
+ except exceptions.EvaluateException:
+ # This happens when the context is not ready.
+ return False
+
+ def TestVar(context_id):
+ """Waits for testVar and the context to be ready, then returns the value
+ of testVar."""
+ util.WaitFor(lambda: TestVarReady(context_id), timeout=10)
+ return self._tab.EvaluateJavaScriptInContext('testVar', context_id)
+
+ # Access parent page using EvaluateJavaScriptInContext.
+ self.assertEquals(TestVar(context_id=1), 'host')
+
+ # Access the iframes.
+ self.assertEquals(TestVar(context_id=2), 'iframe1')
+ self.assertTrue(TestVar(context_id=3) in ['iframe2', 'iframe3'])
+ self.assertTrue(TestVar(context_id=4) in ['iframe2', 'iframe3'])
+
+ # Accessing a non-existent iframe throws an exception.
+ self.assertRaises(exceptions.EvaluateException,
+ lambda: self._tab.EvaluateJavaScriptInContext('1+1', context_id=5))
« no previous file with comments | « tools/telemetry/telemetry/core/backends/chrome/inspector_runtime.py ('k') | tools/telemetry/telemetry/core/web_contents.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698