зеркало из https://github.com/mozilla/gecko-dev.git
Bug 993906 - Package and send appropriate data with remotely hosted links request [r=adw]
Save a copy of the directory links count to send with the links request.
This commit is contained in:
Родитель
0c6293c666
Коммит
04c483b8bd
|
@ -166,7 +166,10 @@ let DirectoryLinksProvider = {
|
|||
|
||||
try {
|
||||
xmlHttp.open('POST', uri);
|
||||
xmlHttp.send(JSON.stringify({ locale: this.locale }));
|
||||
xmlHttp.send(JSON.stringify({
|
||||
locale: this.locale,
|
||||
directoryCount: this._directoryCount,
|
||||
}));
|
||||
} catch (e) {
|
||||
deferred.reject("Error fetching " + uri);
|
||||
Cu.reportError(e);
|
||||
|
@ -247,6 +250,8 @@ let DirectoryLinksProvider = {
|
|||
* @return download promise
|
||||
*/
|
||||
reportShownCount: function DirectoryLinksProvider_reportShownCount(directoryCount) {
|
||||
// make a deep copy of directoryCount to avoid a leak
|
||||
this._directoryCount = Cu.cloneInto(directoryCount, {});
|
||||
if (directoryCount.sponsored > 0
|
||||
|| directoryCount.affiliate > 0
|
||||
|| directoryCount.organic > 0) {
|
||||
|
@ -292,6 +297,7 @@ let DirectoryLinksProvider = {
|
|||
*/
|
||||
reset: function DirectoryLinksProvider_reset() {
|
||||
delete this.__linksURL;
|
||||
delete this._directoryCount;
|
||||
this._removePrefsObserver();
|
||||
this._removeObservers();
|
||||
},
|
||||
|
|
|
@ -47,7 +47,7 @@ const kFailURL = kBaseUrl + kFailPath;
|
|||
const kHttpHandlerData = {};
|
||||
kHttpHandlerData[kExamplePath] = {"en-US": [{"url":"http://example.com","title":"RemoteSource"}]};
|
||||
|
||||
const bodyData = JSON.stringify({ locale: DirectoryLinksProvider.locale });
|
||||
const expectedBodyObject = {locale: DirectoryLinksProvider.locale};
|
||||
const BinaryInputStream = CC("@mozilla.org/binaryinputstream;1",
|
||||
"nsIBinaryInputStream",
|
||||
"setInputStream");
|
||||
|
@ -60,7 +60,8 @@ function getHttpHandler(path) {
|
|||
}
|
||||
return function(aRequest, aResponse) {
|
||||
let bodyStream = new BinaryInputStream(aRequest.bodyInputStream);
|
||||
do_check_eq(NetUtil.readInputStreamToString(bodyStream, bodyStream.available()), bodyData);
|
||||
let bodyObject = JSON.parse(NetUtil.readInputStreamToString(bodyStream, bodyStream.available()));
|
||||
isIdentical(bodyObject, expectedBodyObject);
|
||||
|
||||
aResponse.setStatusLine(null, code);
|
||||
aResponse.setHeader("Content-Type", "application/json");
|
||||
|
@ -401,6 +402,14 @@ add_task(function test_DirectoryLinksProvider_fetchDirectoryOnShowCount() {
|
|||
yield DirectoryLinksProvider.reportShownCount(directoryCount);
|
||||
do_check_true(DirectoryLinksProvider._lastDownloadMS != 0);
|
||||
|
||||
// test that directoryCount object reaches the backend server
|
||||
expectedBodyObject.directoryCount = directoryCount;
|
||||
// set kSourceUrlPref to kExampleURL, causing request to test http server
|
||||
// server handler validates that expectedBodyObject has correct directoryCount
|
||||
yield promiseDirectoryDownloadOnPrefChange(kSourceUrlPref, kExampleURL);
|
||||
// reset expectedBodyObject to its original state
|
||||
delete expectedBodyObject.directoryCount;
|
||||
|
||||
yield promiseCleanDirectoryLinksProvider();
|
||||
});
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче