From bffc8aec0bdce18c3935e2c14ecb99163ceecaa3 Mon Sep 17 00:00:00 2001 From: Fernando Souza Date: Fri, 6 Jan 2017 13:49:22 -0300 Subject: [PATCH] Saves the unescaped title string --- src/screen/HtmlScreen.js | 2 +- test/screen/HtmlScreen.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/screen/HtmlScreen.js b/src/screen/HtmlScreen.js index f230826..b30f4ee 100644 --- a/src/screen/HtmlScreen.js +++ b/src/screen/HtmlScreen.js @@ -307,7 +307,7 @@ class HtmlScreen extends RequestScreen { resolveTitleFromVirtualDocument() { var title = this.virtualDocument.querySelector(this.titleSelector); if (title) { - this.setTitle(title.innerHTML.trim()); + this.setTitle(title.textContent.trim()); } } diff --git a/test/screen/HtmlScreen.js b/test/screen/HtmlScreen.js index c87c4be..70e4604 100644 --- a/test/screen/HtmlScreen.js +++ b/test/screen/HtmlScreen.js @@ -307,6 +307,35 @@ describe('HtmlScreen', function() { this.requests[0].respond(200, null, ''); }); + it('should have correct title', (done) => { + var screen = new HtmlScreen(); + screen.allocateVirtualDocumentForContent('left'); + screen.resolveTitleFromVirtualDocument(); + screen.flip([]).then(() => { + assert.strictEqual('left', screen.getTitle()); + done(); + }); + }); + + it('should have correct title when the title contains html entities', (done) => { + var screen = new HtmlScreen(); + screen.allocateVirtualDocumentForContent('left & right'); + screen.resolveTitleFromVirtualDocument(); + screen.flip([]).then(() => { + assert.strictEqual('left & right', screen.getTitle()); + done(); + }); + }); + + it('should return HTML markup as text from the document title', (done) => { + var screen = new HtmlScreen(); + screen.allocateVirtualDocumentForContent('left <span>&</span> right'); + screen.resolveTitleFromVirtualDocument(); + screen.flip([]).then(() => { + assert.strictEqual('left & right', screen.getTitle()); + done(); + }); + }); }); function enterDocumentSurfaceElement(surfaceId, opt_content) {