Skip to content
This repository has been archived by the owner on Apr 21, 2021. It is now read-only.

Commit

Permalink
Uses title HTML tag whenever is possible to update the page title. Cl…
Browse files Browse the repository at this point in the history
…oses #185 (#186)

* Uses title HTML tag whenever is possible to update the page title. Closes #185

* Saves the unescaped title string
  • Loading branch information
fernandosouza authored and eduardolundgren committed Jan 6, 2017
1 parent 1a78abb commit 63fac13
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/app/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,14 @@ class App extends EventEmitter {
} else {
globals.window.history.pushState(state, title, path);
}
globals.document.title = title;

let titleNode = globals.document.querySelector('title');
if (titleNode) {
titleNode.innerHTML = title;
}
else {
globals.document.title = title;
}
}

}
Expand Down
2 changes: 1 addition & 1 deletion src/screen/HtmlScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down
19 changes: 19 additions & 0 deletions test/screen/HtmlScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,25 @@ describe('HtmlScreen', function() {
this.requests[0].respond(200, null, '<link id="style" data-senna-track="temporary" rel="stylesheet" href="/base/src/senna.js">');
});

it('should have correct title', (done) => {
var screen = new HtmlScreen();
screen.allocateVirtualDocumentForContent('<title>left</title>');
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('<title>left &amp; right</title>');
screen.resolveTitleFromVirtualDocument();
screen.flip([]).then(() => {
assert.strictEqual('left & right', screen.getTitle());
done();
});
});
});

function enterDocumentSurfaceElement(surfaceId, opt_content) {
Expand Down

0 comments on commit 63fac13

Please sign in to comment.