Merge m-c to inbound.

This commit is contained in:
Ryan VanderMeulen 2013-06-11 21:04:08 -04:00
commit 7740efe46f
11 changed files with 100 additions and 67 deletions

View File

@ -579,8 +579,10 @@ WaveReader::LoadListChunk(uint32_t aChunkSize,
break;
}
// Wrap the string, adjusting length to account for optional
// null termination in the chunk.
nsCString val(p, length);
if (val[length - 1] == '\0') {
if (length > 0 && val[length - 1] == '\0') {
val.SetLength(length - 1);
}

View File

@ -887,7 +887,12 @@ BrowserElementChild.prototype = {
}
if (stateFlags & Ci.nsIWebProgressListener.STATE_STOP) {
sendAsyncMsg('loadend');
let bgColor = 'transparent';
try {
bgColor = content.getComputedStyle(content.document.body)
.getPropertyValue('background-color');
} catch (e) {}
sendAsyncMsg('loadend', {backgroundColor: bgColor});
// Ignoring NS_BINDING_ABORTED, which is set when loading page is
// stopped.

View File

@ -24,6 +24,7 @@ MOCHITEST_FILES = \
test_browserElement_NoPref.html \
test_browserElement_NoWhitelist.html \
browserElement_LoadEvents.js \
file_browserElement_LoadEvents.html \
test_browserElement_inproc_LoadEvents.html \
browserElement_DataURI.js \
test_browserElement_inproc_DataURI.html \

View File

@ -22,7 +22,7 @@ function runTest() {
var iframe = document.createElement('iframe');
SpecialPowers.wrap(iframe).mozbrowser = true;
iframe.id = 'iframe';
iframe.src = browserElementTestHelpers.emptyPage1;
iframe.src = 'http://example.com/tests/dom/browser-element/mochitest/file_browserElement_LoadEvents.html';
function loadstart(e) {
ok(e.isTrusted, 'Event should be trusted.');
@ -46,6 +46,7 @@ function runTest() {
ok(seenLoadStart, 'loadend after loadstart.');
ok(!seenLoadEnd, 'Just one loadend event.');
ok(seenLocationChange, 'loadend after locationchange.');
is(e.detail.backgroundColor, 'rgb(0, 128, 0)', 'Expected background color reported')
seenLoadEnd = true;
}
@ -99,6 +100,7 @@ function runTest2() {
seenLoadEnd = true;
ok(seenLoadStart, 'Load end after load start.');
ok(seenLocationChange, 'Load end after location change.');
is(e.detail.backgroundColor, 'transparent', 'Expected background color reported')
});
iframe.src = browserElementTestHelpers.emptyPage2;

View File

@ -0,0 +1,14 @@
<html>
<body style="background-color:green;">
<!-- Tests rely on the fact that there's an element in here called 'url' and
that there's visible text on the page. -->
Aloha! My URL is <span id='url'></span>.
<script>
document.getElementById('url').innerHTML = window.location;
</script>
</body>
</html>

View File

@ -18,9 +18,10 @@ Cu.import("resource://gre/modules/NetworkStatsDB.jsm");
const NET_NETWORKSTATSSERVICE_CONTRACTID = "@mozilla.org/network/netstatsservice;1";
const NET_NETWORKSTATSSERVICE_CID = Components.ID("{18725604-e9ac-488a-8aa0-2471e7f6c0a4}");
const TOPIC_INTERFACE_REGISTERED = "network-interface-registered";
const NETWORK_TYPE_WIFI = Ci.nsINetworkInterface.NETWORK_TYPE_WIFI;
const NETWORK_TYPE_MOBILE = Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE;
const TOPIC_INTERFACE_REGISTERED = "network-interface-registered";
const TOPIC_INTERFACE_UNREGISTERED = "network-interface-unregistered";
const NET_TYPE_WIFI = Ci.nsINetworkInterface.NETWORK_TYPE_WIFI;
const NET_TYPE_MOBILE = Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE;
XPCOMUtils.defineLazyServiceGetter(this, "gIDBManager",
"@mozilla.org/dom/indexeddb/manager;1",
@ -44,13 +45,17 @@ this.NetworkStatsService = {
Services.obs.addObserver(this, "xpcom-shutdown", false);
Services.obs.addObserver(this, TOPIC_INTERFACE_REGISTERED, false);
Services.obs.addObserver(this, TOPIC_INTERFACE_UNREGISTERED, false);
Services.obs.addObserver(this, "profile-after-change", false);
this.timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
this._connectionTypes = Object.create(null);
this._connectionTypes[NETWORK_TYPE_WIFI] = "wifi";
this._connectionTypes[NETWORK_TYPE_MOBILE] = "mobile";
this._connectionTypes[NET_TYPE_WIFI] = { name: "wifi",
network: Object.create(null) };
this._connectionTypes[NET_TYPE_MOBILE] = { name: "mobile",
network: Object.create(null) };
this.messages = ["NetworkStats:Get",
"NetworkStats:Clear",
@ -95,7 +100,7 @@ this.NetworkStatsService = {
// This message is sync.
let types = [];
for (let i in this._connectionTypes) {
types.push(this._connectionTypes[i]);
types.push(this._connectionTypes[i].name);
}
return types;
case "NetworkStats:SampleRate":
@ -110,14 +115,18 @@ this.NetworkStatsService = {
observe: function observe(subject, topic, data) {
switch (topic) {
case TOPIC_INTERFACE_REGISTERED:
case TOPIC_INTERFACE_UNREGISTERED:
// If new interface is registered (notified from NetworkManager),
// the stats are updated for the new interface without waiting to
// complete the updating period
let network = subject.QueryInterface(Ci.nsINetworkInterface);
if (DEBUG) {
debug("Network " + network.name + " of type " + network.type + " registered");
debug("Network " + network.name + " of type " + network.type + " status change");
}
if (this._connectionTypes[network.type]) {
this._connectionTypes[network.type].network = network;
this.updateStats(network.type);
}
this.updateStats(network.type);
break;
case "xpcom-shutdown":
if (DEBUG) {
@ -130,6 +139,9 @@ this.NetworkStatsService = {
Services.obs.removeObserver(this, "xpcom-shutdown");
Services.obs.removeObserver(this, "profile-after-change");
Services.obs.removeObserver(this, TOPIC_INTERFACE_REGISTERED);
Services.obs.removeObserver(this, TOPIC_INTERFACE_UNREGISTERED);
this.timer.cancel();
this.timer = null;
@ -172,7 +184,7 @@ this.NetworkStatsService = {
}
for (let i in this._connectionTypes) {
if (this._connectionTypes[i] == options.connectionType) {
if (this._connectionTypes[i].name == options.connectionType) {
this._db.find(function onStatsFound(error, result) {
mm.sendAsyncMessage("NetworkStats:Get:Return",
{ id: msg.id, error: error, result: result });
@ -308,10 +320,6 @@ this.NetworkStatsService = {
},
update: function update(connectionType, callback) {
if (DEBUG) {
debug("Update stats for " + this._connectionTypes[connectionType]);
}
// Check if connection type is valid.
if (!this._connectionTypes[connectionType]) {
if (callback) {
@ -320,25 +328,27 @@ this.NetworkStatsService = {
return;
}
if (DEBUG) {
debug("Update stats for " + this._connectionTypes[connectionType].name);
}
// Request stats to NetworkManager, which will get stats from netd, passing
// 'networkStatsAvailable' as a callback.
if (!networkManager.getNetworkInterfaceStats(connectionType,
this.networkStatsAvailable
.bind(this, callback))) {
if (DEBUG) {
debug("There is no interface registered for network type " +
this._connectionTypes[connectionType]);
}
// Interface is not registered (up), so nothing to do.
callback(true, "OK");
let networkName = this._connectionTypes[connectionType].network.name;
if (networkName) {
networkManager.getNetworkInterfaceStats(networkName,
this.networkStatsAvailable.bind(this, callback, connectionType));
return;
}
if (callback) {
callback(true, "ok");
}
},
/*
* Callback of request stats. Store stats in database.
*/
networkStatsAvailable: function networkStatsAvailable(callback, result, connType, rxBytes, txBytes, date) {
networkStatsAvailable: function networkStatsAvailable(callback, connType, result, rxBytes, txBytes, date) {
if (!result) {
if (callback) {
callback(false, "Netd IPC error");
@ -346,7 +356,7 @@ this.NetworkStatsService = {
return;
}
let stats = { connectionType: this._connectionTypes[connType],
let stats = { connectionType: this._connectionTypes[connType].name,
date: date,
rxBytes: txBytes,
txBytes: rxBytes};

View File

@ -10,7 +10,7 @@ const netStatsDb = new NetworkStatsDB(this);
function filterTimestamp(date) {
var sampleRate = netStatsDb.sampleRate;
var offset = date.getTimezoneOffset() * 60 * 1000;
return Math.floor((date.getTime() - offset) / sampleRate) * sampleRate + offset;
return Math.floor((date.getTime() - offset) / sampleRate) * sampleRate;
}
add_test(function test_sampleRate() {
@ -335,8 +335,8 @@ add_test(function test_find () {
var sampleRate = netStatsDb.sampleRate;
var start = Date.now();
var saveDate = filterTimestamp(new Date());
var end = start + (sampleRate * (samples - 1));
start -= sampleRate;
var end = new Date(start + (sampleRate * (samples - 1)));
start = new Date(start - sampleRate);
var stats = [];
for (var i = 0; i < samples; i++) {i
stats.push({connectionType: "wifi", timestamp: saveDate + (sampleRate * i),
@ -353,8 +353,8 @@ add_test(function test_find () {
netStatsDb.find(function (error, result) {
do_check_eq(error, null);
do_check_eq(result.connectionType, "wifi");
do_check_eq(result.start.getTime(), start);
do_check_eq(result.end.getTime(), end);
do_check_eq(result.start.getTime(), start.getTime());
do_check_eq(result.end.getTime(), end.getTime());
do_check_eq(result.data.length, samples + 1);
do_check_eq(result.data[0].rxBytes, null);
do_check_eq(result.data[1].rxBytes, 0);
@ -363,8 +363,8 @@ add_test(function test_find () {
netStatsDb.findAll(function (error, result) {
do_check_eq(error, null);
do_check_eq(result.connectionType, null);
do_check_eq(result.start.getTime(), start);
do_check_eq(result.end.getTime(), end);
do_check_eq(result.start.getTime(), start.getTime());
do_check_eq(result.end.getTime(), end.getTime());
do_check_eq(result.data.length, samples + 1);
do_check_eq(result.data[0].rxBytes, null);
do_check_eq(result.data[1].rxBytes, 0);

View File

@ -15,14 +15,14 @@ add_test(function test_networkStatsAvailable_ok() {
NetworkStatsService.networkStatsAvailable(function (success, msg) {
do_check_eq(success, true);
run_next_test();
}, true, Ci.nsINetworkInterface.NETWORK_TYPE_WIFI, 1234, 4321, new Date());
}, Ci.nsINetworkInterface.NETWORK_TYPE_WIFI, true, 1234, 4321, new Date());
});
add_test(function test_networkStatsAvailable_failure() {
NetworkStatsService.networkStatsAvailable(function (success, msg) {
do_check_eq(success, false);
run_next_test();
}, false, Ci.nsINetworkInterface.NETWORK_TYPE_WIFI, 1234, 4321, new Date());
}, Ci.nsINetworkInterface.NETWORK_TYPE_WIFI, false, 1234, 4321, new Date());
});
add_test(function test_update_invalidConnection() {
@ -77,24 +77,31 @@ add_test(function test_updateStats_failure() {
});
add_test(function test_queue() {
// Fill connections with fake network interfaces (wlan0 and rmnet0)
// to enable netd async requests
NetworkStatsService._connectionTypes[Ci.nsINetworkInterface.NETWORK_TYPE_WIFI]
.network.name = 'wlan0';
NetworkStatsService._connectionTypes[Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE]
.network.name = 'rmnet0';
NetworkStatsService.updateStats(Ci.nsINetworkInterface.NETWORK_TYPE_WIFI);
NetworkStatsService.updateStats(Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE);
do_check_eq(NetworkStatsService.updateQueue.length, 2);
do_check_eq(NetworkStatsService.updateQueue[0].callbacks.length, 1);
NetworkStatsService.updateStats(Ci.nsINetworkInterface.NETWORK_TYPE_WIFI, function(success, msg){
do_check_eq(NetworkStatsService.updateQueue.length, 1);
});
var callback = function(success, msg) {
return;
};
NetworkStatsService.updateStats(Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE, function(success, msg){
do_check_eq(NetworkStatsService.updateQueue.length, 0);
run_next_test();
});
NetworkStatsService.updateStats(Ci.nsINetworkInterface.NETWORK_TYPE_WIFI, callback);
NetworkStatsService.updateStats(Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE, callback);
do_check_eq(NetworkStatsService.updateQueue.length, 2);
do_check_eq(NetworkStatsService.updateQueue[0].callbacks.length, 2);
do_check_eq(NetworkStatsService.updateQueue[0].callbacks[0], null);
do_check_neq(NetworkStatsService.updateQueue[0].callbacks[1], null);
run_next_test();
});
function run_test() {

View File

@ -406,31 +406,23 @@ NetworkManager.prototype = {
this.setAndConfigureActive();
},
getNetworkInterfaceStats: function getNetworkInterfaceStats(connectionType, callback) {
let iface = this.getNetworkInterface(connectionType);
if (!iface) {
debug("There is no interface registered for network type " + connectionType);
return false;
}
debug("getNetworkInterfaceStats for " + iface.name);
getNetworkInterfaceStats: function getNetworkInterfaceStats(networkName, callback) {
debug("getNetworkInterfaceStats for " + networkName);
let params = {
cmd: "getNetworkInterfaceStats",
ifname: iface.name,
connType: connectionType
ifname: networkName
};
params.report = true;
params.isAsync = true;
this.controlMessage(params, function(result) {
let success = result.resultCode >= NETD_COMMAND_OKAY && result.resultCode < NETD_COMMAND_ERROR;
callback.networkStatsAvailable(success, result.connType, result.rxBytes, result.txBytes, result.date);
let success = result.resultCode >= NETD_COMMAND_OKAY &&
result.resultCode < NETD_COMMAND_ERROR;
callback.networkStatsAvailable(success, result.rxBytes,
result.txBytes, result.date);
});
return true;
},
// Helpers

View File

@ -99,11 +99,10 @@ interface nsIWifiTetheringCallback : nsISupports
void wifiTetheringEnabledChange(in jsval error);
};
[scriptable, function, uuid(9a887e18-b879-4bb1-8663-238bc4234ba0)]
[scriptable, function, uuid(e079aa2a-ec0a-4bbd-b1a4-d81a9faae464)]
interface nsINetworkStatsCallback : nsISupports
{
void networkStatsAvailable(in boolean success,
in short connType,
in unsigned long rxBytes,
in unsigned long txBytes,
in jsval date);
@ -112,7 +111,7 @@ interface nsINetworkStatsCallback : nsISupports
/**
* Manage network interfaces.
*/
[scriptable, uuid(24f8ede0-c862-11e2-8b8b-0800200c9a66)]
[scriptable, uuid(f39a0fb6-2752-47d2-943e-a0cdd3e43494)]
interface nsINetworkManager : nsISupports
{
/**
@ -200,15 +199,13 @@ interface nsINetworkManager : nsISupports
/**
* Retrieve network interface stats.
*
* @param networkType
* @param networkName
* Select the Network interface to request estats.
*
* @param callback
* Callback to notify result and provide stats, connectionType
* and the date when stats are retrieved
*
* @return false if there is no interface registered for the networkType param.
*/
boolean getNetworkInterfaceStats(in short networkType, in nsINetworkStatsCallback callback);
void getNetworkInterfaceStats(in DOMString networkName, in nsINetworkStatsCallback callback);
};

View File

@ -30,7 +30,9 @@
#include "base/basictypes.h"
#include "nscore.h"
#ifdef MOZ_OMX_DECODER
#include "MediaResourceManagerService.h"
#endif
#include "mozilla/FileUtils.h"
#include "mozilla/Hal.h"
#include "mozilla/Mutex.h"
@ -640,10 +642,11 @@ nsAppShell::Init()
InitGonkMemoryPressureMonitoring();
#ifdef MOZ_OMX_DECODER
if (XRE_GetProcessType() == GeckoProcessType_Default) {
android::MediaResourceManagerService::instantiate();
}
#endif
nsCOMPtr<nsIObserverService> obsServ = GetObserverService();
if (obsServ) {
obsServ->AddObserver(this, "browser-ui-startup-complete", false);