зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1291320 - Make refresh command synchronous. r=ato,automatedtester
Update the refresh command to make it synchronous, and let it return once the target page has been loaded. This can be accomplished by using the loadListener object in listener.js. MozReview-Commit-ID: Lc8QoGFeQrY --HG-- extra : rebase_source : afb2bd3f10fd08b6eff85f7583d2cbb535f4f154
This commit is contained in:
Родитель
51a98f5c1b
Коммит
66f4253300
|
@ -1128,12 +1128,14 @@ GeckoDriver.prototype.goForward = function* (cmd, resp) {
|
|||
yield goForward;
|
||||
};
|
||||
|
||||
/** Refresh the page. */
|
||||
GeckoDriver.prototype.refresh = function*(cmd, resp) {
|
||||
/**
|
||||
* Causes the browser to reload the page in in current top-level browsing context.
|
||||
*/
|
||||
GeckoDriver.prototype.refresh = function* (cmd, resp) {
|
||||
assert.content(this.context);
|
||||
assert.window(this.getCurrentWindow());
|
||||
|
||||
yield this.listener.refresh();
|
||||
yield this.listener.refresh({pageTimeout: this.timeouts.pageLoad});
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
import contextlib
|
||||
import time
|
||||
import urllib
|
||||
|
||||
from marionette_driver import By, errors, expected, Wait
|
||||
|
@ -27,6 +26,7 @@ class BaseNavigationTestCase(WindowManagerMixin, MarionetteTestCase):
|
|||
def setUp(self):
|
||||
super(BaseNavigationTestCase, self).setUp()
|
||||
|
||||
self.test_page_frameset = self.marionette.absolute_url("frameset.html")
|
||||
self.test_page_insecure = self.fixtures.where_is("test.html", on="https")
|
||||
self.test_page_not_remote = "about:robots"
|
||||
self.test_page_remote = self.marionette.absolute_url("test.html")
|
||||
|
@ -126,31 +126,14 @@ class TestNavigate(BaseNavigationTestCase):
|
|||
self.marionette.navigate("about:blank")
|
||||
self.assertEqual("about:blank", self.marionette.get_url())
|
||||
|
||||
def test_refresh(self):
|
||||
self.marionette.navigate(self.test_page_remote)
|
||||
self.assertEqual("Marionette Test", self.marionette.title)
|
||||
self.assertTrue(self.marionette.execute_script(
|
||||
"""var elem = window.document.createElement('div'); elem.id = 'someDiv';
|
||||
window.document.body.appendChild(elem); return true;"""))
|
||||
self.assertFalse(self.marionette.execute_script(
|
||||
"return window.document.getElementById('someDiv') == undefined"))
|
||||
self.marionette.refresh()
|
||||
# TODO(ato): Bug 1291320
|
||||
time.sleep(0.2)
|
||||
self.assertEqual("Marionette Test", self.marionette.title)
|
||||
self.assertTrue(self.marionette.execute_script(
|
||||
"return window.document.getElementById('someDiv') == undefined"))
|
||||
|
||||
def test_navigate_in_child_frame_changes_to_top(self):
|
||||
page_frameset = self.marionette.absolute_url("frameset.html")
|
||||
|
||||
self.marionette.navigate(page_frameset)
|
||||
self.marionette.navigate(self.test_page_frameset)
|
||||
frame = self.marionette.find_element(By.NAME, "third")
|
||||
self.marionette.switch_to_frame(frame)
|
||||
self.assertRaises(errors.NoSuchElementException,
|
||||
self.marionette.find_element, By.NAME, "third")
|
||||
|
||||
self.marionette.navigate(page_frameset)
|
||||
self.marionette.navigate(self.test_page_frameset)
|
||||
self.marionette.find_element(By.NAME, "third")
|
||||
|
||||
def test_invalid_url(self):
|
||||
|
@ -490,6 +473,65 @@ class TestBackForwardNavigation(BaseNavigationTestCase):
|
|||
self.run_bfcache_test(test_pages)
|
||||
|
||||
|
||||
class TestRefresh(BaseNavigationTestCase):
|
||||
|
||||
def test_basic(self):
|
||||
self.marionette.navigate(self.test_page_remote)
|
||||
self.assertEqual(self.test_page_remote, self.marionette.get_url())
|
||||
|
||||
self.marionette.execute_script("""
|
||||
let elem = window.document.createElement('div');
|
||||
elem.id = 'someDiv';
|
||||
window.document.body.appendChild(elem);
|
||||
""")
|
||||
self.marionette.find_element(By.ID, "someDiv")
|
||||
|
||||
self.marionette.refresh()
|
||||
self.assertEqual(self.test_page_remote, self.marionette.get_url())
|
||||
with self.assertRaises(errors.NoSuchElementException):
|
||||
self.marionette.find_element(By.ID, "someDiv")
|
||||
|
||||
def test_refresh_in_child_frame_navigates_to_top(self):
|
||||
self.marionette.navigate(self.test_page_frameset)
|
||||
self.assertEqual(self.test_page_frameset, self.marionette.get_url())
|
||||
|
||||
frame = self.marionette.find_element(By.NAME, "third")
|
||||
self.marionette.switch_to_frame(frame)
|
||||
self.assertRaises(errors.NoSuchElementException,
|
||||
self.marionette.find_element, By.NAME, "third")
|
||||
|
||||
self.marionette.refresh()
|
||||
self.marionette.find_element(By.NAME, "third")
|
||||
|
||||
def test_image(self):
|
||||
image = self.marionette.absolute_url('black.png')
|
||||
|
||||
self.marionette.navigate(image)
|
||||
self.assertEqual(image, self.marionette.get_url())
|
||||
|
||||
self.marionette.refresh()
|
||||
self.assertEqual(image, self.marionette.get_url())
|
||||
|
||||
def test_timeout_error(self):
|
||||
slow_page = self.marionette.absolute_url("slow?delay=3")
|
||||
|
||||
self.marionette.navigate(slow_page)
|
||||
self.assertEqual(slow_page, self.marionette.get_url())
|
||||
|
||||
self.marionette.timeout.page_load = 0.5
|
||||
with self.assertRaises(errors.TimeoutException):
|
||||
self.marionette.refresh()
|
||||
self.assertEqual(slow_page, self.marionette.get_url())
|
||||
|
||||
def test_insecure_error(self):
|
||||
with self.assertRaises(errors.InsecureCertificateException):
|
||||
self.marionette.navigate(self.test_page_insecure)
|
||||
self.assertEqual(self.test_page_insecure, self.marionette.get_url())
|
||||
|
||||
with self.assertRaises(errors.InsecureCertificateException):
|
||||
self.marionette.refresh()
|
||||
|
||||
|
||||
class TestTLSNavigation(MarionetteTestCase):
|
||||
insecure_tls = {"acceptInsecureCerts": True}
|
||||
secure_tls = {"acceptInsecureCerts": False}
|
||||
|
|
|
@ -1141,6 +1141,26 @@ function goForward(msg) {
|
|||
}, command_id, pageTimeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Causes the browser to reload the page in in current top-level browsing context.
|
||||
*
|
||||
* @param {number} command_id
|
||||
* ID of the currently handled message between the driver and listener.
|
||||
* @param {number} pageTimeout
|
||||
* Timeout in milliseconds the method has to wait for the page being finished loading.
|
||||
*/
|
||||
function refresh(msg) {
|
||||
let {command_id, pageTimeout} = msg.json;
|
||||
|
||||
// We need to move to the top frame before navigating
|
||||
sendSyncMessage("Marionette:switchedToFrame", {frameValue: null});
|
||||
curContainer.frame = content;
|
||||
|
||||
loadListener.navigate(() => {
|
||||
curContainer.frame.location.reload(true);
|
||||
}, command_id, pageTimeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL of the top-level browsing context.
|
||||
*/
|
||||
|
@ -1162,19 +1182,6 @@ function getPageSource() {
|
|||
return curContainer.frame.document.documentElement.outerHTML;
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh the page
|
||||
*/
|
||||
function refresh(msg) {
|
||||
let command_id = msg.json.command_id;
|
||||
curContainer.frame.location.reload(true);
|
||||
let listen = function() {
|
||||
removeEventListener("DOMContentLoaded", listen, false);
|
||||
sendOk(command_id);
|
||||
};
|
||||
addEventListener("DOMContentLoaded", listen, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find an element in the current browsing context's document using the
|
||||
* given search strategy.
|
||||
|
|
Загрузка…
Ссылка в новой задаче