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

Commit

Permalink
Adding tests for URL bar
Browse files Browse the repository at this point in the history
  • Loading branch information
evertonfraga committed Jan 13, 2017
1 parent c33b55c commit 5c62fde
Show file tree
Hide file tree
Showing 34 changed files with 346 additions and 222 deletions.
9 changes: 7 additions & 2 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ settings:
import/core-modules: ## don't lint for these missing packages in package.json
- electron ## 'electron' is only needed as devDependency / global installation


rules:
# "off" or 0 - turn the rule off
# "warn" or 1 - turn the rule on as a warning (doesn’t affect exit code)
Expand All @@ -22,7 +21,13 @@ rules:
no-underscore-dangle: off
comma-dangle:
- error
- only-multiline
- only-multiline ## no comma after last item if one line, though allow comma if multiline
import/no-extraneous-dependencies: ## checks if required modules are missing in packages.json
- error
- devDependencies: ## declares files, whose imports belong to devDependencies
- "**/scripts/build-dist.js"
- "**/tests/_base.js"
- "**/*.test.js"

globals: # don't warn about missing declarations
i18n: true
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
[![Join the chat at https://gitter.im/ethereum/mist](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/ethereum/mist?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Build Status develop branch](https://travis-ci.org/ethereum/mist.svg?branch=develop)](https://travis-ci.org/ethereum/mist)
[![Code Climate](https://codeclimate.com/github/ethereum/mist/badges/gpa.svg)](https://codeclimate.com/github/ethereum/mist)
[![dependencies Status](https://david-dm.org/ethereum/mist/status.svg)](https://david-dm.org/ethereum/mist)
[![devDependencies Status](https://david-dm.org/ethereum/mist/dev-status.svg)](https://david-dm.org/ethereum/mist?type=dev)

The Mist browser is the tool of choice to browse and use Ðapps.

Expand Down
9 changes: 4 additions & 5 deletions customProtocols.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const electron = require('electron');
const protocol = electron.protocol;
const path = require('path');
const { protocol } = require('electron');


protocol.registerHttpProtocol('mist', (request, callback) => {
Expand All @@ -19,8 +17,9 @@ protocol.registerHttpProtocol('mist', (request, callback) => {

callback(call);
}, (error) => {
if (error)
{ console.error('Failed to register protocol'); }
if (error) {
console.error('Failed to register protocol');
}
});


Expand Down
2 changes: 1 addition & 1 deletion errorPages/400.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
background-color: #f0f0f0;
color: #ACACAC;
text-shadow: 0 -1px #fff;
font: 20px Helvetica Neue, Arial;
font: 20px Source Sans Pro, Helvetica Neue, Arial;
font-weight: 200;
text-align: center;
padding: 10px;
Expand Down
19 changes: 19 additions & 0 deletions errorPages/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<html>
<head>
<title>Error 404</title>
<meta charset="utf-8">
</head>
<body style="
background-color: #f0f0f0;
color: #ACACAC;
text-shadow: 0 -1px #fff;
font: 20px Source Sans Pro, Helvetica Neue, Arial;
font-weight: 200;
text-align: center;
padding: 10px;
padding-top: 100px;
">
<span style="font-size: 80px; font-family: 'Courier New', monospace;">﴾๏๏﴿</span><br><br>
URL not found.
</body>
</html>
19 changes: 19 additions & 0 deletions errorPages/500.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<html>
<head>
<title>Error 500</title>
<meta charset="utf-8">
</head>
<body style="
background-color: #f0f0f0;
color: #ACACAC;
text-shadow: 0 -1px #fff;
font: 20px Source Sans Pro, Helvetica Neue, Arial;
font-weight: 200;
text-align: center;
padding: 10px;
padding-top: 100px;
">
<span style="font-size: 80px; font-family: 'Courier New', monospace;">(ノಠ益ಠ)ノ</span><br><br>
Oops.. Something went wrong!
</body>
</html>
8 changes: 5 additions & 3 deletions interface/client/styles/networkIndicator.import.less
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Applies to both onboarding and splash screen
.network-indicator {
position: absolute;
top: 10px;
Expand All @@ -9,8 +10,10 @@
opacity: 0.8;
color: @colorGrey;
text-transform: uppercase;
}

.unknown {
// Applies only to the splash screen
.splash-screen .network-indicator .unknown {
position: absolute;
top: 155px;
text-align: center;
Expand All @@ -21,5 +24,4 @@
font-weight: normal;
text-transform: none;
color: #fff;
}
}
}
23 changes: 10 additions & 13 deletions interface/client/templates/popupWindows/onboardingScreen.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,27 +113,24 @@ <h1> {{i18n "mist.popupWindows.onboarding.learnIt"}} </h1>
<footer>
<progress value="{{#with TemplateVar.get 'syncing'}}{{progress}}{{/with}}" max="100"></progress>
<progress class='stateBar' value="{{#with TemplateVar.get 'syncing'}}{{_displayStatesDownload}}{{/with}}" max="1"></progress>

{{#with TemplateVar.get "syncing"}}
<div class="status"> {{i18n "mist.popupWindows.onboarding.downloadingBlocks"}} ({{TemplateVar.get "peerCount"}} {{i18n 'mist.nodeInfo.peers'}})</div>
<div class="blocks">

{{ syncStatus }}

</div>

{{syncStatus}}
{{#if TemplateVar.get 'readyToLaunch'}}
<button class="launch-app"> {{i18n "mist.popupWindows.onboarding.buttons.launchApp"}} </button>
{{else}}
{{#if TemplateVar.get 'readyToLaunch'}}
<button class="launch-app"> {{i18n "mist.popupWindows.onboarding.buttons.launchApp"}} </button>
{{#with TemplateVar.get "syncing"}}
<div class="status"> {{i18n "mist.popupWindows.onboarding.downloadingBlocks"}} ({{TemplateVar.get "peerCount"}} {{i18n 'mist.nodeInfo.peers'}})</div>
<div class="blocks"> {{syncStatusMessage}} </div>
{{else}}
<div class="status">
{{#if TemplateVar.get "peerCount"}}
{{TemplateVar.get "peerCount"}} {{i18n 'mist.nodeInfo.peers'}}
{{i18n 'mist.startScreen.nodeSyncFoundPeers' peers=(TemplateVar.get 'peerCount')}}
{{else}}
{{i18n 'mist.startScreen.nodeSyncConnecting'}}
{{/if}}
</div>
{{/if}}
{{/with}}
{{/with}}
{{/if}}

</footer>
</div>
Expand Down
78 changes: 51 additions & 27 deletions interface/client/templates/popupWindows/onboardingScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ Template['popupWindows_onboardingScreen'].onCreated(function(){

if(syncing === true) {
web3.reset(true);

} else if(_.isObject(syncing)) {
// loads syncing data and adds it to old by using 'extend'
var oldData = TemplateVar.get(template, 'syncing');

TemplateVar.set(template, 'syncing', _.extend(oldData||{}, syncing||{}));

} else {
TemplateVar.set(template, 'syncing', false);
}
Expand Down Expand Up @@ -78,50 +78,69 @@ Template['popupWindows_onboardingScreen'].helpers({
return (account) ? account.toLowerCase() : '';
},
/**
Updates the Sync Message live
Updates the Sync Data
@method syncStatus
*/
'syncStatus' : function() {

// This functions loops trhough numbers while waiting for the node to respond
var template = Template.instance();

Meteor.clearInterval(template._intervalId);

// Create an interval to quickly iterate trough the numbers
template._intervalId = Meteor.setInterval(function(){
// load the sync information
var syncing = TemplateVar.get(template, 'syncing');

// Calculates a block t display that is always getting 1% closer to target
syncing._displayBlock = (syncing._displayBlock + (syncing.currentBlock - syncing._displayBlock) / 100 )|| syncing.currentBlock;

syncing._displayStatesDownload = Number(syncing._displayStatesDownload + (syncing.pulledStates/syncing.knownStates - syncing._displayStatesDownload) / 100 ) || syncing.pulledStates/syncing.knownStates;
if (syncing) {
// If it's syncing, then it's not ready
TemplateVar.set(template, 'readyToLaunch', false);

// Calculates a block t display that is always getting a few % closer to target
syncing._displayBlock = (syncing._displayBlock + 2*(syncing.currentBlock - syncing._displayBlock) / 100 ) || Number(syncing.startingBlock);

// Calculates progress
syncing.progress = Math.round(((syncing._displayBlock - syncing.startingBlock) / (syncing.highestBlock - syncing.startingBlock)) * 100);

// Makes fancy strings
syncing.blockDiff = numeral(syncing.highestBlock - syncing.currentBlock).format('0,0');
syncing.highestBlockString = numeral(syncing.highestBlock).format('0,0');
syncing.displayBlock = numeral(Math.round(syncing._displayBlock)).format('0,0');
syncing.statesPercent = numeral(Math.round(syncing._displayStatesDownload*10000)/100).format('0.00');
syncing._displayStatesDownload = Number(syncing._displayStatesDownload + (syncing.pulledStates/(1 +syncing.knownStates) - syncing._displayStatesDownload) / 100 ) || Number(syncing.pulledStates)/Number(syncing.knownStates + 1);

// Saves the data back to the object
TemplateVar.set(template, 'syncing', syncing);
// Calculates progress
syncing.progress = 100 * (syncing._displayBlock - syncing.startingBlock) / (1 + Number(syncing.highestBlock) - syncing.startingBlock);

// Makes fancy strings
syncing.blockDiff = numeral(syncing.highestBlock - syncing.currentBlock).format('0,0');
syncing.highestBlockString = numeral(syncing.highestBlock).format('0,0');
syncing.displayBlock = numeral(Math.round(syncing._displayBlock)).format('0,0');
syncing.statesPercent = numeral(Math.round(syncing._displayStatesDownload*10000)/100).format('0.00');

// Saves the data back to the object
TemplateVar.set(template, 'syncing', syncing);

// Only show states if they are less than 50% downloaded
if (Math.round(1000*Number(syncing._displayStatesDownload)) !== Math.round(1000*Number(syncing.pulledStates/syncing.knownStates))) {
TemplateVar.set(template, "syncStatusMessageLive", TAPi18n.__('mist.popupWindows.onboarding.syncMessageWithStates', syncing));
} else {
TemplateVar.set(template, "syncStatusMessageLive", TAPi18n.__('mist.popupWindows.onboarding.syncMessage', syncing));
}

// If it's close enough, show the synced button

if (Number(syncing.highestBlock) - syncing.currentBlock < 100 ) {
TemplateVar.set(template, 'readyToLaunch', true);
}

// Only show states if they are changing
if (Math.round(1000*Number(syncing._displayStatesDownload)) !== Math.round(1000*Number(syncing.pulledStates/(syncing.knownStates+1)))) {
TemplateVar.set(template, "syncStatusMessageLive", TAPi18n.__('mist.popupWindows.onboarding.syncMessageWithStates', syncing));
} else if (syncing.displayBlock == '0') {
TemplateVar.set(template, "syncStatusMessageLive", '');
} else {
TemplateVar.set(template, "syncStatusMessageLive", TAPi18n.__('mist.popupWindows.onboarding.syncMessage', syncing));
}
}

}, 50);
},
/**
Updates the Sync Message live
return TemplateVar.get(template, "syncStatusMessageLive");
@method syncStatusMessage
*/
'syncStatusMessage' : function() {
return TemplateVar.get("syncStatusMessageLive");
}
});

Expand All @@ -136,12 +155,14 @@ Template['popupWindows_onboardingScreen'].events({
if(TemplateVar.get('testnet')) {
ipc.send('onBoarding_changeNet', false);
TemplateVar.set('testnet', false);
TemplateVar.set('syncing', null);
}
},
'click .start-testnet': function(e, template){
if(!TemplateVar.get('testnet')) {
ipc.send('onBoarding_changeNet', true);
TemplateVar.set('testnet', true);
TemplateVar.set('syncing', null);
}

TemplateVar.set('currentActive','testnet');
Expand All @@ -156,15 +177,18 @@ Template['popupWindows_onboardingScreen'].events({
},
'click .goto-tutorial-1': function(){
TemplateVar.set('currentActive','tutorial-1');
TemplateVar.set('readyToLaunch', true);
if (!TemplateVar.get('syncing'))
TemplateVar.set('readyToLaunch', true);
},
'click .goto-tutorial-2': function(){
TemplateVar.set('currentActive','tutorial-2');
TemplateVar.set('readyToLaunch', true);
if (!TemplateVar.get('syncing'))
TemplateVar.set('readyToLaunch', true);
},
'click .goto-tutorial-3': function(){
TemplateVar.set('currentActive','tutorial-3');
TemplateVar.set('readyToLaunch', true);
if (!TemplateVar.get('syncing'))
TemplateVar.set('readyToLaunch', true);
},
/**
Start the application
Expand Down
8 changes: 4 additions & 4 deletions interface/client/templates/popupWindows/splashScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ Template['popupWindows_splashScreen'].helpers({
syncData._displayKnownStates = Number(syncData.knownStates || 0);
} else {
// Increment each them slowly to match target number
syncData._displayBlock += (Number(syncData.currentBlock) - syncData._displayBlock) / 10;
syncData._displayState += (Number(syncData.pulledStates || 0) - syncData._displayState) / 10;
syncData._displayKnownStates += (Number(syncData.knownStates || 0) - syncData._displayKnownStates) / 10;
syncData._displayBlock += (Number(syncData.currentBlock) - syncData._displayBlock) / 100;
syncData._displayState += (Number(syncData.pulledStates || 0) - syncData._displayState) / 100;
syncData._displayKnownStates += (Number(syncData.knownStates || 0) - syncData._displayKnownStates) / 100;
}

// Create the fancy strings
Expand Down Expand Up @@ -224,7 +224,7 @@ Template['popupWindows_splashScreen'].helpers({
}
}

}, 100);
}, 10);

return TemplateVar.get(template, "syncStatusMessageLive");
}
Expand Down
10 changes: 9 additions & 1 deletion interface/client/templates/views/webview.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ Template['views_webview'].onRendered(function(){
webviewLoadStop.call(this, tabId, e);
});

// show error pages
webview.addEventListener('did-fail-load', showError.bind(webview, tabId));
webview.addEventListener('crashed', showError.bind(webview, tabId));

// navigate page, and redirect to browser tab if necessary
webview.addEventListener('will-navigate', webviewLoadStart.bind(webview, tabId));
webview.addEventListener('did-get-redirect-request', webviewLoadStart.bind(webview, tabId));
Expand Down Expand Up @@ -122,6 +126,10 @@ Template['views_webview'].helpers({
}});
}

// allow error pages
if(url && url.indexOf('file://'+ dirname + '/errorPages/') === 0) {
return url;
}

// CHECK URL and throw error if not allowed
if(!Helpers.sanitizeUrl(url, true)) {
Expand All @@ -137,7 +145,7 @@ Template['views_webview'].helpers({
return 'file://'+ dirname + '/errorPages/400.html';
}

// remove redirect
// add url
if(url) {
template.url = url;
Tabs.update(this._id, {$set: {
Expand Down
27 changes: 27 additions & 0 deletions interface/client/templates/webviewEvents.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@

showError = function(tabId, e){
if(e.isMainFrame || e.killed) {
var url,
path = 'file://'+ dirname + '/errorPages/';

if(e.killed) {
e.errorCode = 500;
}

switch(e.errorCode) {
case -105:
url = path +'404.html';
break;
case 500:
url = path +'500.html';
break;
}

if(url) {
Tabs.update(tabId, {$set: {
redirect: url
}});
}
}
};


webviewChangeUrl = function(tabId, e){
if(e.type === 'did-navigate-in-page' && !e.isMainFrame)
return;
Expand Down
Loading

0 comments on commit 5c62fde

Please sign in to comment.