Bug 1279203 - Make Get Page Source command spec conformant; r=ato
authorVangelis Katsikaros <vkatsikaros@gmail.com>
Mon, 28 Nov 2016 18:48:58 +0200
changeset 324863 f707a43789429c4bae74eb50ead0272d7b36da95
parent 324862 cd56360c0615c3484faf23257c5a5b8aba1fc110
child 324864 7a1bee2d23ac31bc03ed9742abf881a50cbbf580
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +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();