mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-08 20:47:44 +00:00
7e20285e70
The -*- file variable lines -*- establish per-file settings that Emacs will pick up. This patch makes the following changes to those lines (and touches nothing else): - Never set the buffer's mode. Years ago, Emacs did not have a good JavaScript mode, so it made sense to use Java or C++ mode in .js files. However, Emacs has had js-mode for years now; it's perfectly serviceable, and is available and enabled by default in all major Emacs packagings. Selecting a mode in the -*- file variable line -*- is almost always the wrong thing to do anyway. It overrides Emacs's default choice, which is (now) reasonable; and even worse, it overrides settings the user might have made in their '.emacs' file for that file extension. It's only useful when there's something specific about that particular file that makes a particular mode appropriate. - Correctly propagate settings that establish the correct indentation level for this file: c-basic-offset and js2-basic-offset should be js-indent-level. Whatever value they're given should be preserved; different parts of our tree use different indentation styles. - We don't use tabs in Mozilla JS code. Always set indent-tabs-mode: nil. Remove tab-width: settings, at least in files that don't contain tab characters. - Remove js2-mode settings that belong in the user's .emacs file, like js2-skip-preprocessor-directives.
152 lines
5.7 KiB
JavaScript
152 lines
5.7 KiB
JavaScript
// -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
"use strict";
|
|
|
|
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
function ok(passed, text) {
|
|
do_report_result(passed, text, Components.stack.caller, false);
|
|
}
|
|
|
|
// We use a global variable to track the <browser> where the tests are happening
|
|
let browser;
|
|
|
|
function setHandlerFunc(handler, test) {
|
|
browser.addEventListener("DOMLinkAdded", function linkAdded(event) {
|
|
browser.removeEventListener("DOMLinkAdded", linkAdded, false);
|
|
Services.tm.mainThread.dispatch(handler.bind(this, test), Ci.nsIThread.DISPATCH_NORMAL);
|
|
}, false);
|
|
}
|
|
|
|
add_test(function setup_browser() {
|
|
let BrowserApp = Services.wm.getMostRecentWindow("navigator:browser").BrowserApp;
|
|
do_register_cleanup(function cleanup() {
|
|
BrowserApp.closeTab(BrowserApp.getTabForBrowser(browser));
|
|
});
|
|
|
|
let url = "http://mochi.test:8888/tests/robocop/link_discovery.html";
|
|
browser = BrowserApp.addTab(url, { selected: true, parentId: BrowserApp.selectedTab.id }).browser;
|
|
browser.addEventListener("load", function startTests(event) {
|
|
browser.removeEventListener("load", startTests, true);
|
|
Services.tm.mainThread.dispatch(run_next_test, Ci.nsIThread.DISPATCH_NORMAL);
|
|
}, true);
|
|
});
|
|
|
|
let searchDiscoveryTests = [
|
|
{ text: "rel search discovered" },
|
|
{ rel: "SEARCH", text: "rel is case insensitive" },
|
|
{ rel: "-search-", pass: false, text: "rel -search- not discovered" },
|
|
{ rel: "foo bar baz search quux", text: "rel may contain additional rels separated by spaces" },
|
|
{ href: "https://not.mozilla.com", text: "HTTPS ok" },
|
|
{ href: "ftp://not.mozilla.com", text: "FTP ok" },
|
|
{ href: "data:text/foo,foo", pass: false, text: "data URI not permitted" },
|
|
{ href: "javascript:alert(0)", pass: false, text: "JS URI not permitted" },
|
|
{ type: "APPLICATION/OPENSEARCHDESCRIPTION+XML", text: "type is case insensitve" },
|
|
{ type: " application/opensearchdescription+xml ", text: "type may contain extra whitespace" },
|
|
{ type: "application/opensearchdescription+xml; charset=utf-8", text: "type may have optional parameters (RFC2046)" },
|
|
{ type: "aapplication/opensearchdescription+xml", pass: false, text: "type should not be loosely matched" },
|
|
{ rel: "search search search", count: 1, text: "only one engine should be added" }
|
|
];
|
|
|
|
function execute_search_test(test) {
|
|
if (browser.engines) {
|
|
let matchCount = (!("count" in test) || browser.engines.length === test.count);
|
|
let matchTitle = (test.title == browser.engines[0].title);
|
|
ok(matchCount && matchTitle, test.text);
|
|
browser.engines = null;
|
|
} else {
|
|
ok(!test.pass, test.text);
|
|
}
|
|
run_next_test();
|
|
}
|
|
|
|
function prep_search_test(test) {
|
|
setHandlerFunc(execute_search_test, test);
|
|
|
|
let rel = test.rel || "search";
|
|
let href = test.href || "http://so.not.here.mozilla.com/search.xml";
|
|
let type = test.type || "application/opensearchdescription+xml";
|
|
let title = test.title;
|
|
if (!("pass" in test)) {
|
|
test.pass = true;
|
|
}
|
|
|
|
let head = browser.contentDocument.getElementById("linkparent");
|
|
let link = browser.contentDocument.createElement("link");
|
|
link.rel = rel;
|
|
link.href = href;
|
|
link.type = type;
|
|
link.title = title;
|
|
head.appendChild(link);
|
|
}
|
|
|
|
let feedDiscoveryTests = [
|
|
{ text: "rel feed discovered" },
|
|
{ rel: "ALTERNATE", text: "rel is case insensitive" },
|
|
{ rel: "-alternate-", pass: false, text: "rel -alternate- not discovered" },
|
|
{ rel: "foo bar baz alternate quux", text: "rel may contain additional rels separated by spaces" },
|
|
{ href: "https://not.mozilla.com", text: "HTTPS ok" },
|
|
{ href: "ftp://not.mozilla.com", text: "FTP ok" },
|
|
{ href: "data:text/foo,foo", pass: false, text: "data URI not permitted" },
|
|
{ href: "javascript:alert(0)", pass: false, text: "JS URI not permitted" },
|
|
{ type: "application/rss+xml", text: "type can be RSS" },
|
|
{ type: "aPPliCAtion/RSS+xml", text: "type is case insensitve" },
|
|
{ type: " application/atom+xml ", text: "type may contain extra whitespace" },
|
|
{ type: "application/atom+xml; charset=utf-8", text: "type may have optional parameters (RFC2046)" },
|
|
{ type: "aapplication/atom+xml", pass: false, text: "type should not be loosely matched" },
|
|
{ rel: "alternate alternate alternate", count: 1, text: "only one feed should be added" }
|
|
];
|
|
|
|
function execute_feed_test(test) {
|
|
if (browser.feeds) {
|
|
let matchCount = (!("count" in test) || browser.feeds.length === test.count);
|
|
let matchTitle = (test.title == browser.feeds[0].title);
|
|
ok(matchCount && matchTitle, test.text);
|
|
browser.feeds = null;
|
|
} else {
|
|
ok(!test.pass, test.text);
|
|
}
|
|
run_next_test();
|
|
}
|
|
|
|
function prep_feed_test(test) {
|
|
setHandlerFunc(execute_feed_test, test);
|
|
|
|
let rel = test.rel || "alternate";
|
|
let href = test.href || "http://so.not.here.mozilla.com/feed.xml";
|
|
let type = test.type || "application/atom+xml";
|
|
let title = test.title;
|
|
if (!("pass" in test)) {
|
|
test.pass = true;
|
|
}
|
|
|
|
let head = browser.contentDocument.getElementById("linkparent");
|
|
let link = browser.contentDocument.createElement("link");
|
|
link.rel = rel;
|
|
link.href = href;
|
|
link.type = type;
|
|
link.title = title;
|
|
head.appendChild(link);
|
|
}
|
|
|
|
let searchTest;
|
|
while ((searchTest = searchDiscoveryTests.shift())) {
|
|
let title = searchTest.title || searchDiscoveryTests.length;
|
|
searchTest.title = title;
|
|
add_test(prep_search_test.bind(this, searchTest));
|
|
}
|
|
|
|
let feedTest;
|
|
while ((feedTest = feedDiscoveryTests.shift())) {
|
|
let title = feedTest.title || feedDiscoveryTests.length;
|
|
feedTest.title = title;
|
|
add_test(prep_feed_test.bind(this, feedTest));
|
|
}
|
|
|
|
run_next_test();
|