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

Unified Diff: chrome/test/chromedriver/run_py_tests.py

Issue 12226026: [ChromeDriver] Select the main frame if a non-existant child frame is targeted. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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: chrome/test/chromedriver/run_py_tests.py
diff --git a/chrome/test/chromedriver/run_py_tests.py b/chrome/test/chromedriver/run_py_tests.py
index 88ac936c5005e2ff57389ed42ec70bf1def8f06f..a93b8f63af9c724283bbc86c2b4db416e21cbc7f 100755
--- a/chrome/test/chromedriver/run_py_tests.py
+++ b/chrome/test/chromedriver/run_py_tests.py
@@ -9,6 +9,7 @@ import ctypes
import optparse
import os
import sys
+import time
import unittest
import chromedriver
@@ -84,6 +85,34 @@ class ChromeDriverTest(unittest.TestCase):
self._driver.SwitchToFrameByIndex(0)
self.assertTrue(self._driver.ExecuteScript('return window.top != window'))
+ def testExecuteInRemovedFrame(self):
+ self._driver.ExecuteScript(
+ 'var frame = document.createElement("iframe");'
+ 'frame.id="id";'
+ 'frame.name="name";'
+ 'document.body.appendChild(frame);')
+ self.assertTrue(self._driver.ExecuteScript('return window.top == window'))
+ self._driver.SwitchToFrame('id')
+ self.assertTrue(self._driver.ExecuteScript('return window.top != window'))
+ self._driver.SwitchToMainFrame()
+ self._driver.ExecuteScript(
+ 'var frame = document.getElementById("id");'
+ 'window.setTimeout(function() {'
+ ' document.body.removeChild(frame);'
+ '}, 1000);')
kkania 2013/02/06 01:41:25 is there a non racy way to do this?
craigdh 2013/02/06 18:52:49 Yeah, just realized I can probably do it with a po
+ self._driver.SwitchToFrame('id')
+
+ def _BecomesTrue(func, sec):
+ timeout = time.time() + sec
+ while time.time() < timeout:
+ if func():
+ return True
+ time.sleep(0.01)
+ return False
+
+ self.assertTrue(_BecomesTrue(
+ lambda: self._driver.ExecuteScript('return window.top == window'), 5))
chrisgao (Use stgao instead) 2013/02/06 01:32:14 Are 5 seconds long enough if the bot is in heavy l
craigdh 2013/02/06 18:52:49 Done.
+
def testGetTitle(self):
script = 'document.title = "title"; return 1;'
self.assertEquals(1, self._driver.ExecuteScript(script))

Powered by Google App Engine
This is Rietveld 408576698