Bug 1279203 - Make Get Page Source command spec conformant; r?ato draft
authorVangelis Katsikaros <vkatsikaros@gmail.com>
Mon, 28 Nov 2016 18:48:58 +0200
changeset 445837 f0f197c7fe9de7ed2d1b7d301a4029db1eb6b58d
parent 445717 a69583d2dbc6fdc18f63761a89cf539c356668be
child 538638 9804a8070056dc30cf988d11efb4ba1857d82b3a
push id37630
push userbmo:ato@mozilla.com
push dateWed, 30 Nov 2016 10:27:07 +0000
reviewersato
bugs1279203
milestone53.0a1
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
testing/marionette/harness/marionette/tests/unit/test_pagesource.py
testing/marionette/listener.js
--- 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();