Bug 1311347 - Enable eslint of browser/components/sessionstore/. Initial changes by Sourav, updated by Standard8. r=jaws

MozReview-Commit-ID: 4RFxoV8SkIa

--HG--
extra : rebase_source : 96b24b172cfa957489df37943171ddae07145e84
This commit is contained in:
jordan9769 2016-10-28 02:48:50 +05:30
parent 3d9dca980f
commit 5761e9b0d1
27 changed files with 92 additions and 80 deletions

View file

@ -61,7 +61,9 @@ browser/base/content/test/general/file_csp_block_all_mixedcontent.html
browser/base/content/test/urlbar/file_blank_but_not_blank.html
browser/base/content/newtab/**
browser/components/downloads/**
browser/components/sessionstore/**
# Test files that are really json not js, and don't need to be linted.
browser/components/sessionstore/test/unit/data/sessionstore_valid.js
browser/components/sessionstore/test/unit/data/sessionstore_invalid.js
browser/components/tabview/**
# generated & special files in cld2
browser/components/translation/cld2/**

View file

@ -243,11 +243,14 @@ ContentRestoreInternal.prototype = {
}
return true;
} catch (ex if ex instanceof Ci.nsIException) {
// Ignore page load errors, but return false to signal that the load never
// happened.
return false;
} catch (ex) {
if (ex instanceof Ci.nsIException) {
// Ignore page load errors, but return false to signal that the load never
// happened.
return false;
}
}
return null;
},
/**

View file

@ -51,7 +51,7 @@ this.PrivacyFilter = Object.freeze({
// allowed to store data for, bail out. We explicitly discard data for any
// children as well even if storing data for those frames would be allowed.
if (data.url && !PrivacyLevel.check(data.url)) {
return;
return null;
}
let retval = {};

View file

@ -241,17 +241,19 @@ var SessionFileInternal = {
Telemetry.getHistogramById("FX_SESSION_RESTORE_READ_FILE_MS").
add(Date.now() - startMs);
break;
} catch (ex if ex instanceof OS.File.Error && ex.becauseNoSuchFile) {
exists = false;
} catch (ex if ex instanceof OS.File.Error) {
// The file might be inaccessible due to wrong permissions
// or similar failures. We'll just count it as "corrupted".
console.error("Could not read session file ", ex, ex.stack);
corrupted = true;
} catch (ex if ex instanceof SyntaxError) {
console.error("Corrupt session file (invalid JSON found) ", ex, ex.stack);
// File is corrupted, try next file
corrupted = true;
} catch (ex) {
if (ex instanceof OS.File.Error && ex.becauseNoSuchFile) {
exists = false;
} else if (ex instanceof OS.File.Error) {
// The file might be inaccessible due to wrong permissions
// or similar failures. We'll just count it as "corrupted".
console.error("Could not read session file ", ex, ex.stack);
corrupted = true;
} else if (ex instanceof SyntaxError) {
console.error("Corrupt session file (invalid JSON found) ", ex, ex.stack);
// File is corrupted, try next file
corrupted = true;
}
} finally {
if (exists) {
noFilesFound = false;
@ -382,7 +384,7 @@ var SessionFileInternal = {
},
_recordTelemetry: function(telemetry) {
for (let id of Object.keys(telemetry)){
for (let id of Object.keys(telemetry)) {
let value = telemetry[id];
let samples = [];
if (Array.isArray(value)) {

View file

@ -958,7 +958,7 @@ var SessionStoreInternal = {
* value to be recorded for that ID,
*/
recordTelemetry: function (telemetry) {
for (let histogramId in telemetry){
for (let histogramId in telemetry) {
Telemetry.getHistogramById(histogramId).add(telemetry[histogramId]);
}
},
@ -1651,7 +1651,7 @@ var SessionStoreInternal = {
yield promise;
this._collectWindowData(win);
progress.current++;
};
}
// We must cache this because _getMostRecentBrowserWindow will always
// return null by the time quit-application occurs.
@ -2858,6 +2858,7 @@ var SessionStoreInternal = {
let tabState = TabState.collect(tab);
return { index: tabState.index - 1, entries: tabState.entries }
}
return null;
},
/**

View file

@ -241,9 +241,15 @@ function toggleRowChecked(aIx) {
}
}
else {
// update the window's checkmark as well (0 means "partially checked")
item.parent.checked = item.parent.tabs.every(isChecked) ? true :
item.parent.tabs.some(isChecked) ? 0 : false;
// Update the window's checkmark as well (0 means "partially checked").
let state = false;
if (item.parent.tabs.every(isChecked)) {
state = true;
} else if (item.parent.tabs.some(isChecked)) {
state = 0;
}
item.parent.checked = state;
treeView.treeBox.invalidateRow(gTreeData.indexOf(item.parent));
}
@ -281,7 +287,7 @@ var treeView = {
setTree: function(treeBox) { this.treeBox = treeBox; },
getCellText: function(idx, column) { return gTreeData[idx].label; },
isContainer: function(idx) { return "open" in gTreeData[idx]; },
getCellValue: function(idx, column){ return gTreeData[idx].checked; },
getCellValue: function(idx, column) { return gTreeData[idx].checked; },
isContainerOpen: function(idx) { return gTreeData[idx].open; },
isContainerEmpty: function(idx) { return false; },
isSeparator: function(idx) { return false; },

View file

@ -832,13 +832,15 @@ var MessageQueue = {
isFinal: options.isFinal || false,
epoch: gCurrentEpoch
});
} catch (ex if ex && ex.result == Cr.NS_ERROR_OUT_OF_MEMORY) {
let telemetry = {
FX_SESSION_RESTORE_SEND_UPDATE_CAUSED_OOM: 1
};
sendAsyncMessage("SessionStore:error", {
telemetry
});
} catch (ex) {
if (ex && ex.result == Cr.NS_ERROR_OUT_OF_MEMORY) {
let telemetry = {
FX_SESSION_RESTORE_SEND_UPDATE_CAUSED_OOM: 1
};
sendAsyncMessage("SessionStore:error", {
telemetry
});
}
}
},
};

View file

@ -173,35 +173,30 @@ SessionStartup.prototype = {
// If the previous session finished writing the final state, we'll
// assume there was no crash.
this._previousSessionCrashed = !checkpoints["sessionstore-final-state-write-complete"];
} else {
} else if (noFilesFound) {
// If the Crash Monitor could not load a checkpoints file it will
// provide null. This could occur on the first run after updating to
// a version including the Crash Monitor, or if the checkpoints file
// was removed, or on first startup with this profile, or after Firefox Reset.
if (noFilesFound) {
// There was no checkpoints file and no sessionstore.js or its backups
// so we will assume that this was a fresh profile.
this._previousSessionCrashed = false;
// There was no checkpoints file and no sessionstore.js or its backups
// so we will assume that this was a fresh profile.
this._previousSessionCrashed = false;
} else {
// If this is the first run after an update, sessionstore.js should
// still contain the session.state flag to indicate if the session
// crashed. If it is not present, we will assume this was not the first
// run after update and the checkpoints file was somehow corrupted or
// removed by a crash.
//
// If the session.state flag is present, we will fallback to using it
// for crash detection - If the last write of sessionstore.js had it
// set to "running", we crashed.
let stateFlagPresent = (this._initialState.session &&
this._initialState.session.state);
} else {
// If this is the first run after an update, sessionstore.js should
// still contain the session.state flag to indicate if the session
// crashed. If it is not present, we will assume this was not the first
// run after update and the checkpoints file was somehow corrupted or
// removed by a crash.
//
// If the session.state flag is present, we will fallback to using it
// for crash detection - If the last write of sessionstore.js had it
// set to "running", we crashed.
let stateFlagPresent = (this._initialState.session &&
this._initialState.session.state);
this._previousSessionCrashed = !stateFlagPresent ||
(this._initialState.session.state == STATE_RUNNING_STR);
}
this._previousSessionCrashed = !stateFlagPresent ||
(this._initialState.session.state == STATE_RUNNING_STR);
}
// Report shutdown success via telemetry. Shortcoming here are

View file

@ -35,7 +35,7 @@ function test() {
function test(aLambda) {
try {
return aLambda() || true;
} catch(ex) { }
} catch (ex) { }
return false;
}

View file

@ -73,4 +73,4 @@ add_task(function* test_closed_window_states() {
other: {popup: 0, normal: 3}};
yield testWindows(windowsToOpen2, expectedResults2);
});
});

View file

@ -36,6 +36,6 @@
});
frames[1].document.designMode = "on";
};
}
</script>
</body>

View file

@ -51,6 +51,6 @@
frames[0].document.addEventListener("DOMNodeInserted", done, true);
frames[0].document.designMode = "on";
};
}
</script>
</body>

View file

@ -19,10 +19,10 @@ function test() {
}
function getSessionstorejsModificationTime() {
let file = getSessionstoreFile();
if (file.exists())
if (file.exists()) {
return file.lastModifiedTime;
else
return -1;
}
return -1;
}
// delete existing sessionstore.js, to make sure we're not reading

View file

@ -194,7 +194,7 @@ function test() {
let inputText = "example.org";
gURLBar.focus();
gURLBar.value = inputText.slice(0, -1);
EventUtils.synthesizeKey(inputText.slice(-1) , {});
EventUtils.synthesizeKey(inputText.slice(-1), {});
executeSoon(function () {
is(browser.userTypedValue, "example.org",

View file

@ -8,7 +8,7 @@ function observeOneRestore(callback) {
Services.obs.removeObserver(onRestore, topic);
callback();
}, topic, false);
};
}
function test() {
waitForExplicitFinish();

View file

@ -5,7 +5,7 @@
* Bug 597071 - Closed windows should only be resurrected when there is a single
* popup window
*/
add_task(function test_close_last_nonpopup_window() {
add_task(function* test_close_last_nonpopup_window() {
// Purge the list of closed windows.
forgetClosedWindows();

View file

@ -19,19 +19,19 @@ function test() {
// new format
// index doesn't match value (testing an option in between (two))
{ id:{ "select_id": {"selectedIndex":0,"value":"val2"} } },
{ id:{ "select_id": {"selectedIndex":0, "value":"val2"} } },
// index doesn't match value (testing an invalid value)
{ id:{ "select_id": {"selectedIndex":4,"value":"val8"} } },
{ id:{ "select_id": {"selectedIndex":4, "value":"val8"} } },
// index doesn't match value (testing an invalid index)
{ id:{ "select_id": {"selectedIndex":8,"value":"val5"} } },
{ id:{ "select_id": {"selectedIndex":8, "value":"val5"} } },
// index and value match position zero
{ id:{ "select_id": {"selectedIndex":0,"value":"val0"} }, xpath: {} },
{ id:{ "select_id": {"selectedIndex":0, "value":"val0"} }, xpath: {} },
// index doesn't match value (testing the last option (seven))
{ id:{},"xpath":{ "/xhtml:html/xhtml:body/xhtml:select[@name='select_name']": {"selectedIndex":1,"value":"val7"} } },
{ id:{}, "xpath":{ "/xhtml:html/xhtml:body/xhtml:select[@name='select_name']": {"selectedIndex":1, "value":"val7"} } },
// index and value match the default option "selectedIndex":3,"value":"val3"
{ xpath: { "/xhtml:html/xhtml:body/xhtml:select[@name='select_name']" : {"selectedIndex":3,"value":"val3"} } },
{ xpath: { "/xhtml:html/xhtml:body/xhtml:select[@name='select_name']" : {"selectedIndex":3, "value":"val3"} } },
// index matches default option however it doesn't match value
{ id:{ "select_id": {"selectedIndex":3,"value":"val4"} } },
{ id:{ "select_id": {"selectedIndex":3, "value":"val4"} } },
];
let expectedValues = [

View file

@ -16,7 +16,7 @@ add_task(function* test() {
// this is a baseline to ensure CSP is active
// attempt to inject and run a script via inline (pre-restore, allowed)
injectInlineScript(browser,'document.getElementById("test_id").value = "fail";');
injectInlineScript(browser, 'document.getElementById("test_id").value = "fail";');
is(browser.contentDocument.getElementById("test_id").value, "ok",
"CSP should block the inline script that modifies test_id");

View file

@ -28,7 +28,7 @@ function promiseCleanup () {
info("Cleaning up browser");
return promiseBrowserState(getClosedState());
};
}
function getClosedState() {
return Cu.cloneInto(CLOSED_STATE, {});

View file

@ -63,4 +63,5 @@ function shouldThrow(f) {
} catch (e) {
return true;
}
return null;
}

View file

@ -29,7 +29,7 @@ add_task(function*() {
// select
yield setSelectedIndex(browser, {id: "modify06", index: 1});
yield setMultipleSelected(browser, {id: "modify07", indices: [0,1,2]});
yield setMultipleSelected(browser, {id: "modify07", indices: [0, 1, 2]});
// checkbox
yield setInputChecked(browser, {id: "modify08", checked: true});

View file

@ -31,7 +31,7 @@ function test() {
{ "#input1" : "value31", "/xhtml:html/xhtml:body/xhtml:input[@name='input2']" : "value32", xpath: { "/xhtml:html/xhtml:body/xhtml:input[@name='input2']" : "value33" } }
]
let expectedValues = [
[ "" , "" ],
[ "", "" ],
// old format
[ "value0", "" ],
[ "value1", "value2" ],

View file

@ -142,7 +142,7 @@ add_task(function*() {
info("Check in the state that we have not stored this history");
let state = ss.getBrowserState();
info(JSON.stringify(JSON.parse(state), null, "\t"));
is(state.indexOf("c1.html"), -1, "History entry was not stored in the session state");;
is(state.indexOf("c1.html"), -1, "History entry was not stored in the session state");
gBrowser.removeTab(tab);
});

View file

@ -66,7 +66,7 @@ add_task(function* () {
// Ignore about:blank loads.
let docStop = Ci.nsIWebProgressListener.STATE_STOP |
Ci.nsIWebProgressListener.STATE_IS_NETWORK;
if (location.spec == "about:blank" || (state & docStop == docStop)) {
if (location.spec == "about:blank" || (state & docStop) != docStop) {
return;
}
is(location.spec, TESTURL, "Got the expected URL");

View file

@ -10,7 +10,7 @@ function test() {
// Purging the list of closed windows
forgetClosedWindows();
// Load a private window, then close it
// Load a private window, then close it
// and verify it doesn't get remembered for restoring
whenNewWindowLoaded({private: true}, function (win) {
info("The private window got loaded");

View file

@ -29,4 +29,4 @@ function afterSessionStartupInitialization(cb) {
Services.obs.addObserver(startup, "quit-application", false);
Services.obs.notifyObservers(null, "final-ui-startup", "");
Services.obs.addObserver(observer, "sessionstore-state-finalized", false);
};
}

View file

@ -19,4 +19,4 @@ function run_test() {
do_check_eq(startup.sessionType, Ci.nsISessionStartup.NO_SESSION);
do_test_finished();
});
}
}