Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lib/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,24 @@ exports.open = function(url, method) {
});
};

/**
* Load HTML content with fake URL in Phantom.
* @param {string} html HTML Content to set
* @param {string} url URL to use for page
* @see {@link http://phantomjs.org/api/webpage/method/set-content.html|PhantomJS API}
*/
exports.setContent = function(html, url) {
var self = this;
self.targetUrl = url;

return this.ready.then(function() {
debug('.setContent()', html, url);
return HorsemanPromise.fromCallback(function(done) {
self.page.setContent(html, url, done);
});
});
};

/**
* Set headers sent to the remote server during an 'open'.
* @param {Object[]} headers
Expand Down
10 changes: 10 additions & 0 deletions test/files/set-content-test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Testing Page</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
25 changes: 25 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,31 @@ function navigation(bool) {
.have.properties(size);
});

it('should set content and url', function() {
var horseman = new Horseman({
timeout: defaultTimeout,
injectJquery: bool
});

var fakeHtml = fs.readFileSync(__dirname + '/files/set-content-test.html').toString();
var fakeDomain = 'http://fakedomain.com/';

return horseman
.setContent(fakeHtml, fakeDomain)
.evaluate(function() {
return {
href: location.href,
title: document.title
};
})
.close()
.should.eventually
.have.properties({
href: fakeDomain,
title: 'Testing Page'
});
});

it('should let you scroll', function() {
var horseman = new Horseman({
timeout: defaultTimeout,
Expand Down