Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Bug 1074683 - Status bar signal strength update triggers reflow/restyles
Browse files Browse the repository at this point in the history
  • Loading branch information
gmarty authored and rvandermeulen committed Oct 21, 2014
1 parent 5ef3450 commit 9c32587
Show file tree
Hide file tree
Showing 2 changed files with 159 additions and 19 deletions.
65 changes: 48 additions & 17 deletions apps/system/js/statusbar.js
Expand Up @@ -597,7 +597,7 @@ var StatusBar = {
var maximizedStatusBarWidth = this._getMaximizedStatusBarWidth();
var minimizedStatusBarWidth = this._minimizedStatusBarWidth;

this.PRIORITIES.forEach(function(iconObj) {
this.PRIORITIES.forEach(function sb_updateIconVisibilityForEach(iconObj) {
var iconId = iconObj[0];
var icon = this.icons[this.toCamelCase(iconId)];

Expand Down Expand Up @@ -1030,14 +1030,17 @@ var StatusBar = {
var icon = this.icons.networkActivity;

clearTimeout(this._networkActivityTimer);
icon.hidden = false;

this._networkActivityTimer = setTimeout(function hideNetActivityIcon() {
icon.hidden = true;
this._updateIconVisibility();
}.bind(this), 500);

this._updateIconVisibility();
if (icon.hidden) {
icon.hidden = false;

this._updateIconVisibility();
}
},

flightMode: function sb_flightMode() {
Expand All @@ -1054,24 +1057,32 @@ var StatusBar = {
},

signal: function sb_updateSignal() {
var self = this;
var simSlots = SIMSlotManager.getSlots();
var isDirty = false; // Whether to reprioritise icons afterwards.
for (var index = 0; index < simSlots.length; index++) {
var simslot = simSlots[index];
var conn = simslot.conn;
var voice = conn.voice;
var data = conn.data;
var icon = self.icons.signals[index];
var roaming = self.icons.roaming[index];
var icon = this.icons.signals[index];
var roaming = this.icons.roaming[index];

var _ = navigator.mozL10n.get;

if (!voice) {
continue;
}

if (self.settingValues['ril.radio.disabled']) {
var previousHiddenState = icon.hidden;
var previousRoamingHiddenState = roaming.hidden;

if (this.settingValues['ril.radio.disabled']) {
icon.hidden = true;

if (previousHiddenState !== icon.hidden) {
isDirty = true;
}

continue;
}

Expand All @@ -1091,7 +1102,7 @@ var StatusBar = {
// "Carrier" / "Carrier (Roaming)" (EVDO)
// Show signal strength of data call as EVDO only supports data call.
this.updateSignalIcon(icon, data);
} else if (voice.connected || self.hasActiveCall() &&
} else if (voice.connected || this.hasActiveCall() &&
navigator.mozTelephony.active.serviceId === index) {
// "Carrier" / "Carrier (Roaming)"
// If voice.connected is false but there is an active call, we should
Expand All @@ -1117,12 +1128,19 @@ var StatusBar = {
icon.setAttribute('aria-label', _(icon.dataset.searching ?
'statusbarSignalNoneSearching' : 'emergencyCallsOnly'));
}

if (previousHiddenState !== icon.hidden ||
previousRoamingHiddenState !== roaming.hidden) {
isDirty = true;
}
}

this.updateConnectionsVisibility();
this.refreshCallListener();

this._updateIconVisibility();
if (isDirty) {
this._updateIconVisibility();
}
},

data: function sb_updateSignal() {
Expand All @@ -1132,29 +1150,36 @@ var StatusBar = {
return;
}

var self = this;
var isDirty = false; // Whether to reprioritise icons afterwards.
for (var index = 0; index < conns.length; index++) {
var conn = conns[index];
var data = conn.data;
var icon = self.icons.data[index];
var icon = this.icons.data[index];

if (!data) {
continue;
}

if (self.settingValues['ril.radio.disabled'] ||
!self.settingValues['ril.data.enabled'] ||
!self.icons.wifi.hidden || !data.connected) {
var previousHiddenState = icon.hidden;

if (this.settingValues['ril.radio.disabled'] ||
!this.settingValues['ril.data.enabled'] ||
!this.icons.wifi.hidden || !data.connected) {
icon.hidden = true;

if (previousHiddenState !== icon.hidden) {
isDirty = true;
}

continue;
}

var type = self.mobileDataIconTypes[data.type];
var type = this.mobileDataIconTypes[data.type];
icon.hidden = false;
icon.textContent = '';
icon.classList.remove('sb-icon-data-circle');
if (type) {
if (self.dataExclusiveCDMATypes[data.type]) {
if (this.dataExclusiveCDMATypes[data.type]) {
// If the current data connection is CDMA types, we need to check
// if there exist any calls. If yes, we have to set the status
// text to empty.
Expand All @@ -1171,12 +1196,18 @@ var StatusBar = {
icon.classList.add('sb-icon-data-circle');
}
icon.setAttribute('aria-hidden', !!icon.textContent);

if (previousHiddenState !== icon.hidden) {
isDirty = true;
}
}

this.updateConnectionsVisibility();
this.refreshCallListener();

this._updateIconVisibility();
if (isDirty) {
this._updateIconVisibility();
}
},

wifi: function sb_updateWifi() {
Expand Down
113 changes: 111 additions & 2 deletions apps/system/test/unit/statusbar_test.js
Expand Up @@ -2,7 +2,7 @@
MockNavigatorMozMobileConnections, MockNavigatorMozTelephony,
MockSettingsListener, MocksHelper, MockSIMSlot, MockSIMSlotManager,
MockSystem, MockTouchForwarder, StatusBar, System,
AppWindowManager, MockNfcManager */
AppWindowManager, MockNfcManager, MockMobileconnection */

'use strict';

Expand All @@ -16,6 +16,7 @@ require('/shared/test/unit/mocks/mock_l10n.js');
require('/shared/test/unit/mocks/mock_system.js');
require('/shared/test/unit/mocks/mock_simslot.js');
require('/shared/test/unit/mocks/mock_simslot_manager.js');
require('/shared/test/unit/mocks/mock_l10n.js');
require('/test/unit/mock_app_window_manager.js');
require('/test/unit/mock_ftu_launcher.js');
require('/test/unit/mock_nfc_manager.js');
Expand All @@ -42,7 +43,7 @@ suite('system/Statusbar', function() {
fakeStatusBarConnections, fakeStatusBarCallForwardings, fakeStatusBarTime,
fakeStatusBarLabel, fakeStatusBarBattery;
var realMozL10n, realMozMobileConnections, realMozTelephony, fakeIcons = [],
realNfcManager;
realNfcManager, realL10n;

function prepareDOM() {
for (var i = 1; i < mobileConnectionCount; i++) {
Expand Down Expand Up @@ -114,6 +115,8 @@ suite('system/Statusbar', function() {
navigator.mozMobileConnections = MockNavigatorMozMobileConnections;
realMozTelephony = navigator.mozTelephony;
navigator.mozTelephony = MockNavigatorMozTelephony;
realL10n = navigator.mozL10n;
navigator.mozL10n = MockL10n;

realNfcManager = window.nfcManager;
window.nfcManager = new MockNfcManager();
Expand Down Expand Up @@ -181,6 +184,7 @@ suite('system/Statusbar', function() {
navigator.mozL10n = realMozL10n;
navigator.mozMobileConnections = realMozMobileConnections;
navigator.mozTelephony = realMozTelephony;
navigator.mozL10n = realL10n;
window.nfcManager.isActive.restore();
window.nfcManager = realNfcManager;
});
Expand Down Expand Up @@ -2385,4 +2389,109 @@ suite('system/Statusbar', function() {
}.bind(this));
});
});

suite('Signal icons', function() {
var slots;
var mockMobileConnection;
var updateIconSpy;

setup(function() {
mockMobileConnection = MockMobileconnection();
mockMobileConnection.voice = {
network: {
mcc: 123
}
};
mockMobileConnection.simCard = {
cardState: 'ready',
iccInfo: {
iccid: 'iccid1'
}
};
slots = [new MockSIMSlot(mockMobileConnection, 0)];
MockSIMSlotManager.mInstances = slots;

StatusBar.settingValues['ril.radio.disabled'] = false;
StatusBar.update.signal.call(StatusBar);

updateIconSpy = this.sinon.spy(StatusBar, '_updateIconVisibility');
});

teardown(function() {
MockSIMSlotManager.mTeardown();
});

test('should call reprioritise function when changed', function() {
StatusBar.settingValues['ril.radio.disabled'] = true;
StatusBar.update.signal.call(StatusBar);

assert.isTrue(updateIconSpy.called);
});

test('should not call reprioritise function when not changed', function() {
StatusBar.settingValues['ril.radio.disabled'] = false;
StatusBar.update.signal.call(StatusBar);

assert.isFalse(updateIconSpy.called);
});
});

suite('Data icons', function() {
var updateIconSpy;

setup(function() {
MockNavigatorMozMobileConnections[0].data = {
connected: true,
type: 'lte'
};

StatusBar.settingValues['ril.radio.disabled'] = false;
StatusBar.settingValues['ril.data.enabled'] = true;
StatusBar.icons.wifi.hidden = true;
StatusBar.update.data.call(StatusBar);

updateIconSpy = this.sinon.spy(StatusBar, '_updateIconVisibility');
});

test('should call reprioritise function when changed', function() {
StatusBar.settingValues['ril.data.enabled'] = false;
StatusBar.update.data.call(StatusBar);

assert.isTrue(updateIconSpy.called);
});

test('should not call reprioritise function when not changed', function() {
StatusBar.settingValues['ril.data.enabled'] = true;
StatusBar.update.data.call(StatusBar);

assert.isFalse(updateIconSpy.called);
});
});

suite('Network activity icons', function() {
var updateIconSpy;
var clock;

setup(function() {
updateIconSpy = this.sinon.spy(StatusBar, '_updateIconVisibility');
clock = sinon.useFakeTimers();
});

teardown(function() {
clock.restore();
});

test('should call reprioritise function when changed', function() {
StatusBar.update.networkActivity.call(StatusBar);

assert.isTrue(updateIconSpy.called);
});

test('should call reprioritise function after 500ms', function() {
StatusBar.update.networkActivity.call(StatusBar);
clock.tick(510);

assert.equal(updateIconSpy.callCount, 2);
});
});
});

0 comments on commit 9c32587

Please sign in to comment.