Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'main/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Konosov committed Jul 23, 2014
2 parents 42d3ac7 + d10b8dc commit f1f3cd7
Show file tree
Hide file tree
Showing 17 changed files with 213 additions and 27 deletions.
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,28 @@ language: cpp
compiler:
- gcc
cache: apt

before_install:
- sudo apt-get -yqq update #< Suggested by the Travis CI doc
- sudo apt-get -fyq install #< Fixes inconsistency of packages installed previously

install:
- sudo apt-get -yq install build-essential chrpath libssl-dev libfontconfig1-dev #< Build Dependencies

before_script:
- chmod +x ./build.sh
- chmod +x ./test/run-tests.sh
- chmod +x ./test/run-tests-ghostdriver.sh

script:
- ./build.sh --confirm --silent #< Build
- ./test/run-tests.sh #< Test (PhantomJS)
- ./test/run-tests-ghostdriver.sh #< Test (GhostDriver / PhantomJSDriver)

notifications:
irc:
channels:
- "irc.freenode.org#phantomjs"
on_success: always
on_failure: always
use_notice: true
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ The latest [stable release](http://phantomjs.org/release-1.9.html) is version 1.

| Branch | Build Status |
|:--------:|:---------------:|
| `master` | [![Build Status](https://travis-ci.org/ariya/phantomjs.png?branch=master)](https://travis-ci.org/ariya/phantomjs) |
| `1.9` | [![Build Status](https://travis-ci.org/ariya/phantomjs.png?branch=1.9)](https://travis-ci.org/ariya/phantomjs) |
| `master` | [![Build Status](https://travis-ci.org/ariya/phantomjs.svg?branch=master)](https://travis-ci.org/ariya/phantomjs) |
| `1.9` | [![Build Status](https://travis-ci.org/ariya/phantomjs.svg?branch=1.9)](https://travis-ci.org/ariya/phantomjs) |

## Use Cases

Expand Down
22 changes: 22 additions & 0 deletions examples/openurlwithproxy.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
page = require("webpage").create()
system = require("system")
host = undefined
port = undefined
address = undefined
if system.args.length < 4
console.log "Usage: openurlwithproxy.js <proxyHost> <proxyPort> <URL>"
phantom.exit 1
else
host = system.args[1]
port = system.args[2]
address = system.args[3]
phantom.setProxy host, port, "manual", "", ""
page.open address, (status) ->
if status isnt "success"
console.log "FAIL to load the address \"" + address + "\" using proxy \"" + host + ":" + port + "\""
else
console.log "Page title is " + page.evaluate(->
document.title
)
phantom.exit()
return
24 changes: 24 additions & 0 deletions examples/openurlwithproxy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
var page = require('webpage').create(),
system = require('system'),
host, port, address;

if (system.args.length < 4) {
console.log('Usage: openurlwithproxy.js <proxyHost> <proxyPort> <URL>');
phantom.exit(1);
} else {
host = system.args[1];
port = system.args[2];
address = system.args[3];
phantom.setProxy(host, port, 'manual', '', '');
page.open(address, function (status) {
if (status !== 'success') {
console.log('FAIL to load the address "' +
address + '" using proxy "' + host + ':' + port + '"');
} else {
console.log('Page title is ' + page.evaluate(function () {
return document.title;
}));
}
phantom.exit();
});
}
2 changes: 1 addition & 1 deletion examples/phantomwebintro.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ page.open("http://www.phantomjs.org", function(status) {
if ( status === "success" ) {
page.includeJs("http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js", function() {
page.evaluate(function() {
console.log("$(\"#intro\").text() -> " + $("#intro").text());
console.log("$(\".explanation\").text() -> " + $(".explanation").text());
});
phantom.exit();
});
Expand Down
92 changes: 92 additions & 0 deletions examples/run-jasmine2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
var system = require('system');

/**
* Wait until the test condition is true or a timeout occurs. Useful for waiting
* on a server response or for a ui change (fadeIn, etc.) to occur.
*
* @param testFx javascript condition that evaluates to a boolean,
* it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or
* as a callback function.
* @param onReady what to do when testFx condition is fulfilled,
* it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or
* as a callback function.
* @param timeOutMillis the max amount of time to wait. If not specified, 3 sec is used.
*/
function waitFor(testFx, onReady, timeOutMillis) {
var maxtimeOutMillis = timeOutMillis ? timeOutMillis : 3001, //< Default Max Timeout is 3s
start = new Date().getTime(),
condition = false,
interval = setInterval(function() {
if ( (new Date().getTime() - start < maxtimeOutMillis) && !condition ) {
// If not time-out yet and condition not yet fulfilled
condition = (typeof(testFx) === "string" ? eval(testFx) : testFx()); //< defensive code
} else {
if(!condition) {
// If condition still not fulfilled (timeout but condition is 'false')
console.log("'waitFor()' timeout");
phantom.exit(1);
} else {
// Condition fulfilled (timeout and/or condition is 'true')
console.log("'waitFor()' finished in " + (new Date().getTime() - start) + "ms.");
typeof(onReady) === "string" ? eval(onReady) : onReady(); //< Do what it's supposed to do once the condition is fulfilled
clearInterval(interval); //< Stop this interval
}
}
}, 100); //< repeat check every 100ms
};


if (system.args.length !== 2) {
console.log('Usage: run-jasmine.js URL');
phantom.exit(1);
}

var page = require('webpage').create();

// Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
page.onConsoleMessage = function(msg) {
console.log(msg);
};

page.open(system.args[1], function(status){
if (status !== "success") {
console.log("Unable to access network");
phantom.exit();
} else {
waitFor(function(){
return page.evaluate(function(){
return document.body.querySelector('.symbolSummary .pending') === null
});
}, function(){
var exitCode = page.evaluate(function(){
console.log('');

var el = document.body.querySelector('.banner');
var banner = el.querySelector('.title').innerText + " " +
el.querySelector('.version').innerText + " " +
el.querySelector('.duration').innerText;
console.log(banner);

var list = document.body.querySelectorAll('.results > .failures > .spec-detail.failed');
if (list && list.length > 0) {
console.log('');
console.log(list.length + ' test(s) FAILED:');
for (i = 0; i < list.length; ++i) {
var el = list[i],
desc = el.querySelector('.description'),
msg = el.querySelector('.messages > .result-message');
console.log('');
console.log(desc.innerText);
console.log(msg.innerText);
console.log('');
}
return 1;
} else {
console.log(document.body.querySelector('.alert > .bar.passed').innerText);
return 0;
}
});
phantom.exit(exitCode);
});
}
});
8 changes: 8 additions & 0 deletions rpm/phantomjs.spec
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ cp README.md %{mybuilddir}%{prefix}/share/%{name}/
%{prefix}/share/%{name}/examples/netlog.js
%{prefix}/share/%{name}/examples/netsniff.coffee
%{prefix}/share/%{name}/examples/netsniff.js
%{prefix}/share/%{name}/examples/openurlwithproxy.coffee
%{prefix}/share/%{name}/examples/openurlwithproxy.js
%{prefix}/share/%{name}/examples/outputEncoding.coffee
%{prefix}/share/%{name}/examples/outputEncoding.js
%{prefix}/share/%{name}/examples/page_events.coffee
Expand All @@ -91,6 +93,8 @@ cp README.md %{mybuilddir}%{prefix}/share/%{name}/
%{prefix}/share/%{name}/examples/pizza.js
%{prefix}/share/%{name}/examples/post.coffee
%{prefix}/share/%{name}/examples/post.js
%{prefix}/share/%{name}/examples/postjson.coffee
%{prefix}/share/%{name}/examples/postjson.js
%{prefix}/share/%{name}/examples/postserver.coffee
%{prefix}/share/%{name}/examples/postserver.js
%{prefix}/share/%{name}/examples/printenv.coffee
Expand All @@ -105,6 +109,7 @@ cp README.md %{mybuilddir}%{prefix}/share/%{name}/
%{prefix}/share/%{name}/examples/render_multi_url.js
%{prefix}/share/%{name}/examples/run-jasmine.coffee
%{prefix}/share/%{name}/examples/run-jasmine.js
%{prefix}/share/%{name}/examples/run-jasmine2.js
%{prefix}/share/%{name}/examples/run-qunit.coffee
%{prefix}/share/%{name}/examples/run-qunit.js
%{prefix}/share/%{name}/examples/scandir.coffee
Expand Down Expand Up @@ -142,6 +147,9 @@ cp README.md %{mybuilddir}%{prefix}/share/%{name}/
%{prefix}/share/%{name}/README.md

%changelog
* Fri Apr 18 2014 Eric Heydenberk <[email protected]>
- add missing filenames for examples to files section

* Tue Apr 30 2013 Eric Heydenberk <[email protected]>
- add missing filenames for examples to files section

Expand Down
2 changes: 2 additions & 0 deletions src/networkaccessmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,8 @@ void NetworkAccessManager::handleNetworkError()
data["url"] = reply->url().toString();
data["errorCode"] = reply->error();
data["errorString"] = reply->errorString();
data["status"] = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
data["statusText"] = reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute);

emit resourceError(data);
}
41 changes: 24 additions & 17 deletions src/phantom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,25 +103,10 @@ void Phantom::init()
m_page->setCookieJar(m_defaultCookieJar);
m_pages.append(m_page);

// Set up proxy if required
QString proxyType = m_config.proxyType();
if (proxyType != "none") {
if (m_config.proxyHost().isEmpty()) {
QNetworkProxyFactory::setUseSystemConfiguration(true);
} else {
QNetworkProxy::ProxyType networkProxyType = QNetworkProxy::HttpProxy;

if (proxyType == "socks5") {
networkProxyType = QNetworkProxy::Socks5Proxy;
}

if(!m_config.proxyAuthUser().isEmpty() && !m_config.proxyAuthPass().isEmpty()) {
QNetworkProxy proxy(networkProxyType, m_config.proxyHost(), m_config.proxyPort(), m_config.proxyAuthUser(), m_config.proxyAuthPass());
QNetworkProxy::setApplicationProxy(proxy);
} else {
QNetworkProxy proxy(networkProxyType, m_config.proxyHost(), m_config.proxyPort());
QNetworkProxy::setApplicationProxy(proxy);
}
}
setProxy(m_config.proxyHost(), m_config.proxyPort(), proxyType, m_config.proxyAuthUser(), m_config.proxyAuthPass());
}

// Set output encoding
Expand Down Expand Up @@ -407,6 +392,28 @@ bool Phantom::injectJs(const QString &jsFilePath)
return Utils::injectJsInFrame(pre + jsFilePath, libraryPath(), m_page->mainFrame());
}

void Phantom::setProxy(const QString &ip, const qint64 &port, const QString &proxyType, const QString &user, const QString &password)
{
qDebug() << "Set " << proxyType << " proxy to: " << ip << ":" << port;
if (ip.isEmpty()) {
QNetworkProxyFactory::setUseSystemConfiguration(true);
} else {
QNetworkProxy::ProxyType networkProxyType = QNetworkProxy::HttpProxy;

if (proxyType == "socks5") {
networkProxyType = QNetworkProxy::Socks5Proxy;
}
// Checking for passed proxy user and password
if(!user.isEmpty() && !password.isEmpty()) {
QNetworkProxy proxy(networkProxyType, ip, port, user, password);
QNetworkProxy::setApplicationProxy(proxy);
} else {
QNetworkProxy proxy(networkProxyType, ip, port);
QNetworkProxy::setApplicationProxy(proxy);
}
}
}

void Phantom::exit(int code)
{
if (m_config.debug()) {
Expand Down
9 changes: 9 additions & 0 deletions src/phantom.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,15 @@ public slots:
*/
void clearCookies();

/**
* Set the application proxy
* @brief setProxy
* @param ip The proxy ip
* @param port The proxy port
* @param proxyType The type of this proxy
*/
void setProxy(const QString &ip, const qint64 &port = 80, const QString &proxyType = "http", const QString &user = NULL, const QString &password = NULL);

// exit() will not exit in debug mode. debugExit() will always exit.
void exit(int code = 0);
void debugExit(int code = 0);
Expand Down
9 changes: 9 additions & 0 deletions src/qt/mkspecs/features/default_pre.prf
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
load(exclusive_builds)
### Qt 5: remove "uic" and "resources" - or add "qt"
CONFIG = lex yacc warn_on debug uic resources $$CONFIG

# Variables QT_GCC_MAJOR_VERSION and QT_GCC_MINOR_VERSION are undefined for QPA,
# therefore a few warning suppressions were not properly enabled.
qpa {
QT_GCC_VERSION = $$system(gcc -dumpversion)
QT_GCC_VERSION = $$split(QT_GCC_VERSION, ".")
QT_GCC_MAJOR_VERSION = $$first(QT_GCC_VERSION)
QT_GCC_MINOR_VERSION = $$member(QT_GCC_VERSION, 1)
}
2 changes: 1 addition & 1 deletion src/qt/src/3rdparty/harfbuzz/src/harfbuzz-hebrew.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ HB_Bool HB_HebrewShape(HB_ShaperItem *shaper_item)
};

assert(shaper_item->item.script == HB_Script_Hebrew);
HB_HeuristicSetGlyphAttributes(shaper_item);

#ifndef NO_OPENTYPE
if (HB_SelectScript(shaper_item, hebrew_features)) {
Expand All @@ -63,7 +64,6 @@ HB_Bool HB_HebrewShape(HB_ShaperItem *shaper_item)
if (!HB_ConvertStringToGlyphIndices(shaper_item))
return FALSE;

HB_HeuristicSetGlyphAttributes(shaper_item);
HB_OpenTypeShape(shaper_item, /*properties*/0);
return HB_OpenTypePosition(shaper_item, availableGlyphs, /*doLogClusters*/TRUE);
}
Expand Down
3 changes: 1 addition & 2 deletions src/qt/src/3rdparty/harfbuzz/src/harfbuzz-shaper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ void HB_HeuristicSetGlyphAttributes(HB_ShaperItem *item)

// ### zeroWidth and justification are missing here!!!!!

assert(item->num_glyphs <= length);
assert(length <= item->num_glyphs);

// qDebug("QScriptEngine::heuristicSetGlyphAttributes, num_glyphs=%d", item->num_glyphs);
HB_GlyphAttributes *attributes = item->attributes;
Expand All @@ -481,7 +481,6 @@ void HB_HeuristicSetGlyphAttributes(HB_ShaperItem *item)
}
++glyph_pos;
}
assert(glyph_pos == item->num_glyphs);

// first char in a run is never (treated as) a mark
int cStart = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ namespace WebCore {
// print in IE and Camino. This lets them use fewer sheets than they
// would otherwise, which is presumably why other browsers do this.
// Wide pages will be scaled down more than this.
const float printingMinimumShrinkFactor = 1.25f;
const float printingMinimumShrinkFactor = 1;

// This number determines how small we are willing to reduce the page content
// in order to accommodate the widest line. If the page would have to be
// reduced smaller to make the widest line fit, we just clip instead (this
// behavior matches MacIE and Mozilla, at least)
const float printingMaximumShrinkFactor = 2;
const float printingMaximumShrinkFactor = 1;

PrintContext::PrintContext(Frame* frame)
: m_frame(frame)
Expand Down
4 changes: 2 additions & 2 deletions src/webpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1090,8 +1090,8 @@ qreal stringToPointSize(const QString &string)
{ "mm", 72 / 25.4 },
{ "cm", 72 / 2.54 },
{ "in", 72 },
{ "px", 72.0 / PHANTOMJS_PDF_DPI / 2.54 },
{ "", 72.0 / PHANTOMJS_PDF_DPI / 2.54 }
{ "px", 72.0 / PHANTOMJS_PDF_DPI },
{ "", 72.0 / PHANTOMJS_PDF_DPI }
};
for (uint i = 0; i < sizeof(units) / sizeof(units[0]); ++i) {
if (string.endsWith(units[i].unit)) {
Expand Down
Binary file modified test/webpage-spec-renders/test.pdf
Binary file not shown.
2 changes: 2 additions & 0 deletions test/webpage-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,8 @@ describe("WebPage object", function() {
expect(errorData['url']).toEqual('http://localhost:12345/notExistResource.png');
expect(errorData['errorCode']).toEqual(203);
expect(errorData['errorString']).toContain('notExistResource.png - server replied: Not Found');
expect(errorData['status']).toEqual(404);
expect(errorData['statusText']).toContain("Not Found");
handled = true;
};

Expand Down

0 comments on commit f1f3cd7

Please sign in to comment.