Skip to content
This repository has been archived by the owner on Sep 5, 2020. It is now read-only.

Commit

Permalink
More spectron ETH-01 tests. (#1689)
Browse files Browse the repository at this point in the history
* Spectron iteration

* Updating spectron

* Creating switch for mist.lokidb for automated tests

* Adding chai-as-expected

* Changing IPC flag

* Pairing spectron and electron versions

* [ESLint] Minor fixes

* Adding chai-string

* Couple of tests passing

* update .eslintrc.yml

* Simplifying code

* Removing delay in favor of better window management

* Adding tests for URL bar

* Focusing window before each test

* Minor fixes

* Improving mist setup and teardown

* Fixing wallet test

* adding html fixture

* Improving test helpers

* Tests for ETH-01-002

* Updating tests

* Starting local HTTP server to deal with html fixtures

* Updating tests setup

* Adding more tests

* Updating travis file to run spectron tests

* Refactoring tests

* Tests for ETH-01-007

* Downloading geth on the fly

* Fine-tuning geth download during tests

* Changing linux binary dir

* Fixing binary path on linux

* Travis debug

* Travis debug

* Changing fixtures

* Fixing tests

* Fixing travis file

* More tests

* Adjusting timeouts

* Adjusting GULP_PLATFORM test env variable

* Adjusting timeouts

* Disabling some tests for now

* Disabling a test

* updating yarn

* Tests for ETH-01-009

* More tests

* Adding test for ETH-01-008

* simplify '--test' flag evaluation

* revert unnecessary changes to yarn.lock (no changes to package.json)

* Minor comment changes

* consistent use of 'protocol' in test titles

* Update js-redirect.html
  • Loading branch information
evertonfraga authored Mar 27, 2017
1 parent 5d3b371 commit d4eb221
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 56 deletions.
6 changes: 4 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ const cmp = require('semver-compare');
const parseJson = require('xml2js').parseString;

const options = minimist(process.argv.slice(2), {
string: ['platform', 'walletSource'],
string: ['platform', 'walletSource', 'test'],
default: {
platform: 'all',
walletSource: 'master',
test: 'basic',
},
});

Expand Down Expand Up @@ -548,8 +549,9 @@ gulp.task('build-nsis', (cb) => {


const testApp = (app) => {
// gulp test-mist [--test TESTFILEPREFIX]
return gulp.src([
`./tests/${app}/*.test.js`,
`./tests/${app}/${options.test}.test.js`,
]).pipe(mocha({
timeout: 60000,
ui: 'exports',
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/fixture-popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</head>
<body>
<h1>Fixture Popup</h1>
<a href="/index.html" target="_blank" id="link-01">Target blank</a>
<a href="/index.html" target="_popup" id="link-02">Target popup</a>
<a href="/index.html" target="_blank">Target blank</a>
<a href="/index.html" target="_popup">Target popup</a>
</body>
</html>
17 changes: 17 additions & 0 deletions tests/fixtures/js-redirect.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<html>
<head>
<title>JS redirect fixture</title>
</head>
<body>
<h1>JS redirect fixture</h1>

<script>
window.onerror = function(e){
console.log('e', e);
alert(e);
};

window.location.href = 'file:///Users/ev/Projects/Ethereum/officialMist/tests/fixtures/fixture-popup.html';
</script>
</body>
</html>
9 changes: 9 additions & 0 deletions tests/fixtures/meta-redirect.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<html>
<head>
<title>Meta redirect fixture</title>
<meta http-equiv="refresh" content="0; url=file:///Users/ev/Projects/Ethereum/officialMist/tests/fixtures/fixture-popup.html">
</head>
<body>
<h1>Meta redirect fixture</h1>
</body>
</html>
146 changes: 94 additions & 52 deletions tests/mist/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ test['Sanity Check: main window is focused'] = function* () {
(yield client.getUrl()).should.match(/interface\/index\.html$/);
};

// FAILING ON TRAVIS
test['Browser bar should render urls with separators'] = function* () {
const client = this.client;

Expand Down Expand Up @@ -99,7 +98,7 @@ test['Load fixture page'] = function* () {
yield this.loadFixture();
};

test['"http://" protocol should be allowed on browser bar'] = function* () { // ETH-01-002
test['"http" protocol should be allowed on browser bar'] = function* () { // ETH-01-002
const client = this.client;
yield this.loadFixture();

Expand All @@ -117,7 +116,7 @@ test['"http://" protocol should be allowed on browser bar'] = function* () { //
browserBarText.should.eql('http://localhost:8080 ▸ index.html'); // checks that did change displayed URL
};

test['"javascript:" protocol should be disallowed on browser bar'] = function* () { // ETH-01-002
test['"javascript" protocol should be disallowed on browser bar'] = function* () { // ETH-01-002
const client = this.client;
yield this.loadFixture();
yield client.setValue('#url-input', 'javascript:window.close()');
Expand All @@ -134,7 +133,7 @@ test['"javascript:" protocol should be disallowed on browser bar'] = function* (
browserBarText.should.eql('http://localhost:8080'); // checks that hasn't changed displayed URL
};

test['"data:" protocol should be disallowed on browser bar'] = function* () { // ETH-01-002
test['"data" protocol should be disallowed on browser bar'] = function* () { // ETH-01-002
const client = this.client;
yield this.loadFixture();
yield client.setValue('#url-input', 'data:text/plain;charset=utf-8;base64,dGhpcyB0ZXN0IGlzIG9uIGZpcmU=');
Expand All @@ -151,15 +150,15 @@ test['"data:" protocol should be disallowed on browser bar'] = function* () { //
browserBarText.should.eql('http://localhost:8080'); // checks that hasn't changed displayed URL
};

// test['"file:///" protocol should be disallowed'] = function* () { // ETH-01-002
// const client = this.client;
// const filePath = 'file://' + path.join(__dirname, '..', 'fixtures', 'index.html');
test['"file" protocol should be disallowed on browser bar'] = function* () { // ETH-01-012
const client = this.client;
const filePath = 'file://' + path.join(__dirname, '..', 'fixtures', 'index.html');

// yield this.navigateTo(filePath);
// yield Q.delay(1500);
// const browserBarText = yield this.getBrowserBarText();
// browserBarText.should.match(/errorPages ▸ 400.html$/);
// };
yield this.navigateTo(filePath);
yield Q.delay(1500);
const browserBarText = yield this.getBrowserBarText();
browserBarText.should.match(/errorPages 400.html$/);
};

test['Pin tab test'] = function* () {
const client = this.client;
Expand All @@ -174,57 +173,100 @@ test['Pin tab test'] = function* () {
sidebarItemsAfterAdd.length.should.eql(3);
};

// test['Browse tab should be changed to pinned tab if the URL is the same'] = function* () { // ETH-01-007
// const client = this.client;
// yield this.selectTab('browser');
test['Browse tab should be changed to pinned tab if URLs are the same'] = function* () { // ETH-01-007
const client = this.client;
yield this.selectTab('browser');

// yield this.navigateTo('https://wallet.ethereum.org' );
// yield Q.delay(1000);
// const el = (yield client.element('.sidebar nav > ul > .selected'));
// console.log('el', el);
yield this.navigateTo('https://wallet.ethereum.org');
yield Q.delay(1000);
const selectedTab = (yield client.execute(() => { // code executed in browser context
return LocalStore.get('selectedTab');
})).value;

// el.getAttribute('data-tab-id').should.eql('wallet');
selectedTab.should.eql('wallet');
};

// };
test['Wallet tab shouldn\'t have the page replaced if URLs does not match'] = function* () { // ETH-01-007
const client = this.client;
const app = this;
yield this.selectTab('wallet');

// test['Wallet tab shouldn\'t have the page replaced if URLs does not match'] = function* () { // ETH-01-007
// const client = this.client;
// const app = this;
// yield this.selectTab('wallet');
yield this.navigateTo(`${this.fixtureBaseUrl}index.html?https://wallet.ethereum.org`);
yield client.waitUntil(() => {
return client.execute(() => {
return LocalStore.get('selectedTab') === 'browser';
});
}, 2000);
};

// yield this.navigateTo(`${this.fixtureBaseUrl}index.html?https://wallet.ethereum.org`);
// yield client.waitUntil(() => {
// return client.element('.sidebar nav > ul > .selected').then((e) => {
// console.log('e', e);
// return e.getAttribute('data-tab-id') === 'browse';
// });
// }, 2000);
// };
test['Wallet tab shouldn\'t have the page replaced if URLs does not match - 2'] = function* () { // ETH-01-007
const client = this.client;
const app = this;
yield this.selectTab('wallet');

// test['Wallet tab shouldn\'t have the page replaced if URLs does not match - 2'] = function* () { // ETH-01-007
// const client = this.client;
// const app = this;
// yield this.selectTab('wallet');
// Now changing address via JS
yield client.setValue('#url-input', `${this.fixtureBaseUrl}index.html?https://wallet.ethereum.org`);
const isProtocolBlocked = yield client.execute(() => { // Code executed in context of browser
$('form.url').submit();
});

// // Now changing address via JS
// yield client.setValue('#url-input', `${this.fixtureBaseUrl}index.html?https://wallet.ethereum.org`);
// const isProtocolBlocked = yield client.execute(() => { // Code executed in context of browser
// $('form.url').submit();
// });
yield client.waitUntil(() => {
return client.execute(() => {
return LocalStore.get('selectedTab') === 'browser';
});
}, 2000);
};

// yield client.waitUntil(() => {
// return client.element('.sidebar nav > ul > .selected').then((e) => {
// console.log('e', e);
// return e.getAttribute('data-tab-id') === 'browser';
// });
// }, 2000);
// };
test['Links with target _blank should open inside Mist'] = function* () {
const client = this.client;
yield this.navigateTo(`${this.fixtureBaseUrl}/fixture-popup.html`);
yield this.getWindowByUrl(e => /fixture-popup.html$/.test(e));

test['Links with target _blank or _popup should open inside Mist'] = function* () {
yield client.click('a[target=_blank]');
yield client.waitUntil(() => {
return client.getUrl((url) => {
return /index.html$/.test(url);
});
});
};

test['Links with target _popup should open inside Mist'] = function* () {
const client = this.client;
yield this.navigateTo(`${this.fixtureBaseUrl}/fixture-popup.html`);
yield this.getWindowByUrl(e => /popup.html$/.test(e));
yield this.getWindowByUrl(e => /fixture-popup.html$/.test(e));

yield client.click('a[target=_popup]');
yield client.waitUntil(() => {
return client.getUrl((url) => {
return /index.html$/.test(url);
})
});
};

// ETH-01-005
test['Mist main webview should not redirect to arbitrary addresses'] = function* () {
const client = this.client;
const initialURL = yield client.getUrl();

yield client.execute(() => { // code executed in context of browser
window.location.href = 'http://google.com';
});

// TODO: click on the fixtures' links and assert if they opened on the same page
yield Q.delay(1000);
(yield client.getUrl()).should.eql(initialURL);
};


// ETH-01-008
test['Mist main webview should not redirect to local files'] = function* () {
const client = this.client;
const initialURL = yield client.getUrl();

yield this.navigateTo('https://cure53.de/exchange/8743653459838/ETH-01-008.php');

yield client.waitUntil(() => {
return client.getText('.url-breadcrumb').then((e) => {
return /400\.html$/.test(e);
});
}, 5000, 'expected a URL not allowed as a result');
};

0 comments on commit d4eb221

Please sign in to comment.