This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15802 from jankeromnes/layers
Bug 960933 - Show app debug information in a devtools overlay. r=vingtetun
- Loading branch information
Showing
7 changed files
with
181 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
(function(window) { | ||
|
||
'use strict'; | ||
|
||
window.addEventListener('widget-panel-update', function updateHandler(e){ | ||
display(e.detail); | ||
e.preventDefault(); | ||
}); | ||
|
||
function display(data) { | ||
var target = 'iframe[mozapp="' + data.manifestURL + '"]'; | ||
var iframe = document.querySelector(target); | ||
if (!iframe) { | ||
return; | ||
} | ||
|
||
var appwindow = iframe.parentElement; | ||
var overlay = appwindow.querySelector('.devtools-layer'); | ||
|
||
if (!overlay) { | ||
overlay = document.createElement('div'); | ||
overlay.classList.add('devtools-layer'); | ||
appwindow.appendChild(overlay); | ||
} | ||
|
||
if (!data.metrics || data.metrics.length < 1) { | ||
overlay.remove(); | ||
return; | ||
} | ||
|
||
var html = ''; | ||
|
||
data.metrics.forEach(function(metric) { | ||
html += widget(metric); | ||
}); | ||
|
||
overlay.innerHTML = html; | ||
} | ||
|
||
function widget(metric) { | ||
var value = metric.value; | ||
if (!value) { | ||
return ''; | ||
} | ||
|
||
var color; | ||
switch(metric.name) { | ||
case 'errors': | ||
color = 'red'; | ||
break; | ||
|
||
case 'warnings': | ||
color = 'orange'; | ||
break; | ||
|
||
case 'reflows': | ||
color = 'purple'; | ||
break; | ||
|
||
default: | ||
color = colorHash(metric.name); | ||
break; | ||
} | ||
|
||
return '<div class=widget style="background-color: ' + color + '">' + | ||
value + '</div>'; | ||
} | ||
|
||
function colorHash(name) { | ||
var hue = 0; | ||
for (var i = 0; i < name.length; i++) { | ||
hue += name.charCodeAt(i); | ||
} | ||
return 'hsl(' + (hue % 360) + ', 75%, 50%)'; | ||
} | ||
|
||
})(this); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
.appWindow > .devtools-layer { | ||
z-index: 2; | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 100%; | ||
pointer-events: none; | ||
display: flex; | ||
|
||
flex-wrap: wrap-reverse; | ||
align-content: flex-start; | ||
justify-content: flex-end; | ||
} | ||
|
||
.appWindow > .devtools-layer > .widget { | ||
font-size: 1.8rem; | ||
padding: 0 5px; | ||
line-height: 30px; | ||
height: 30px; | ||
min-width: 30px; | ||
text-align: center; | ||
opacity: 0.8; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
'use strict'; | ||
|
||
require('/js/devtools_layers.js'); | ||
|
||
suite('devtoolsWidgetPanel', function() { | ||
|
||
var manifest = 'app://fakeapp.gaiamobile.org/fake.html'; | ||
|
||
function updateMetrics(metrics) { | ||
var data = { | ||
detail: {manifestURL: manifest, metrics: metrics} | ||
}; | ||
var evt = new CustomEvent('widget-panel-update', data); | ||
window.dispatchEvent(evt); | ||
} | ||
|
||
function getWidgetLayer() { | ||
var iframe = document.querySelector('iframe[mozapp="' + manifest + '"]'); | ||
var appwindow = iframe.parentElement; | ||
return appwindow.querySelector('.devtools-layer'); | ||
} | ||
|
||
suite('display()', function() { | ||
|
||
setup(function() { | ||
document.body.innerHTML = '<div><iframe mozapp="' + manifest + | ||
'"></iframe></div>'; | ||
}); | ||
|
||
teardown(function() { | ||
document.body.innerHTML = ''; | ||
}); | ||
|
||
test('show one widget', function() { | ||
updateMetrics([ | ||
{name: 'bugs', value: 42} | ||
]); | ||
var layer = getWidgetLayer(); | ||
assert.isDefined(layer); | ||
var widget = layer.querySelector('.widget'); | ||
assert.isDefined(widget); | ||
assert.equal(widget.textContent, '42'); | ||
}); | ||
|
||
test('show two widgets', function() { | ||
updateMetrics([ | ||
{name: 'errors', value: 23}, | ||
{name: 'warnings', value: 16} | ||
]); | ||
var layer = getWidgetLayer(); | ||
assert.isDefined(layer); | ||
var widgets = layer.querySelectorAll('.widget'); | ||
assert.equal(widgets.length, 2); | ||
}); | ||
|
||
test('show widgets and tear down', function() { | ||
updateMetrics([ | ||
{name: 'explosions', value: 15}, | ||
{name: 'armageddon', value: 8}, | ||
{name: 'chaos', value: 4} | ||
]); | ||
updateMetrics(); | ||
assert.isNull(getWidgetLayer()); | ||
}); | ||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters