Bug 1279203 - Make Get Page Source command spec conformant; r?ato
This change aligns the Marionette command for getting the page's source
with the WebDriver specification, which mandates that we should return
the current browsing context's active document's outerHTML.
MozReview-Commit-ID: CYd3BIphn5G
--- a/testing/marionette/harness/marionette/tests/unit/test_pagesource.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_pagesource.py
@@ -5,23 +5,29 @@
from marionette import MarionetteTestCase
class TestPageSource(MarionetteTestCase):
def testShouldReturnTheSourceOfAPage(self):
test_html = self.marionette.absolute_url("testPageSource.html")
self.marionette.navigate(test_html)
source = self.marionette.page_source
+ from_web_api = self.marionette.execute_script("return document.documentElement.outerHTML")
self.assertTrue("<html" in source)
self.assertTrue("PageSource" in source)
+ self.assertEqual(source, from_web_api)
def testShouldReturnTheSourceOfAPageWhenThereAreUnicodeChars(self):
test_html = self.marionette.absolute_url("testPageSourceWithUnicodeChars.html")
self.marionette.navigate(test_html)
# if we don't throw on the next line we are good!
- self.marionette.page_source
+ source = self.marionette.page_source
+ from_web_api = self.marionette.execute_script("return document.documentElement.outerHTML")
+ self.assertEqual(source, from_web_api)
def testShouldReturnAXMLDocumentSource(self):
test_xml = self.marionette.absolute_url("testPageSource.xml")
self.marionette.navigate(test_xml)
source = self.marionette.page_source
+ from_web_api = self.marionette.execute_script("return document.documentElement.outerHTML")
import re
self.assertEqual(re.sub("\s", "", source), "<xml><foo><bar>baz</bar></foo></xml>")
+ self.assertEqual(source, from_web_api)
--- a/testing/marionette/listener.js
+++ b/testing/marionette/listener.js
@@ -1065,19 +1065,17 @@ function getCurrentUrl(isB2G) {
function getTitle() {
return curContainer.frame.top.document.title;
}
/**
* Get source of the current browsing context's DOM.
*/
function getPageSource() {
- let XMLSerializer = curContainer.frame.XMLSerializer;
- let source = new XMLSerializer().serializeToString(curContainer.frame.document);
- return source;
+ return curContainer.frame.document.documentElement.outerHTML;
}
/**
* Cause the browser to traverse one step backward in the joint history
* of the current top-level browsing context.
*/
function goBack() {
curContainer.frame.history.back();