1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045 |
- /* 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';
- let { Cc, Ci } = require("chrome");
- require("sdk/context-menu");
- const { Loader } = require('sdk/test/loader');
- const timer = require("sdk/timers");
- const { merge } = require("sdk/util/object");
- // These should match the same constants in the module.
- const ITEM_CLASS = "addon-context-menu-item";
- const SEPARATOR_CLASS = "addon-context-menu-separator";
- const OVERFLOW_THRESH_DEFAULT = 10;
- const OVERFLOW_THRESH_PREF =
- "extensions.addon-sdk.context-menu.overflowThreshold";
- const OVERFLOW_MENU_CLASS = "addon-content-menu-overflow-menu";
- const OVERFLOW_POPUP_CLASS = "addon-content-menu-overflow-popup";
- const TEST_DOC_URL = module.uri.replace(/\.js$/, ".html");
- const data = require("./fixtures");
- // Tests that when present the separator is placed before the separator from
- // the old context-menu module
- exports.testSeparatorPosition = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- // Create the old separator
- let oldSeparator = test.contextMenuPopup.ownerDocument.createElement("menuseparator");
- oldSeparator.id = "jetpack-context-menu-separator";
- test.contextMenuPopup.appendChild(oldSeparator);
- // Create an item.
- let item = new loader.cm.Item({ label: "item" });
- test.showMenu(null, function (popup) {
- assert.equal(test.contextMenuSeparator.nextSibling.nextSibling, oldSeparator,
- "New separator should appear before the old one");
- test.contextMenuPopup.removeChild(oldSeparator);
- test.done();
- });
- };
- // Destroying items that were previously created should cause them to be absent
- // from the menu.
- exports.testConstructDestroy = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- // Create an item.
- let item = new loader.cm.Item({ label: "item" });
- assert.equal(item.parentMenu, loader.cm.contentContextMenu,
- "item's parent menu should be correct");
- test.showMenu(null, function (popup) {
- // It should be present when the menu is shown.
- test.checkMenu([item], [], []);
- popup.hidePopup();
- // Destroy the item. Multiple destroys should be harmless.
- item.destroy();
- item.destroy();
- test.showMenu(null, function (popup) {
- // It should be removed from the menu.
- test.checkMenu([item], [], [item]);
- test.done();
- });
- });
- };
- // Destroying an item twice should not cause an error.
- exports.testDestroyTwice = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let item = new loader.cm.Item({ label: "item" });
- item.destroy();
- item.destroy();
- test.pass("Destroying an item twice should not cause an error.");
- test.done();
- };
- // CSS selector contexts should cause their items to be present in the menu
- // when the menu is invoked on nodes that match the selectors.
- exports.testSelectorContextMatch = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let item = new loader.cm.Item({
- label: "item",
- data: "item",
- context: loader.cm.SelectorContext("img")
- });
- test.withTestDoc(function (window, doc) {
- test.showMenu(doc.getElementById("image"), function (popup) {
- test.checkMenu([item], [], []);
- test.done();
- });
- });
- };
- // CSS selector contexts should cause their items to be present in the menu
- // when the menu is invoked on nodes that have ancestors that match the
- // selectors.
- exports.testSelectorAncestorContextMatch = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let item = new loader.cm.Item({
- label: "item",
- data: "item",
- context: loader.cm.SelectorContext("a[href]")
- });
- test.withTestDoc(function (window, doc) {
- test.showMenu(doc.getElementById("span-link"), function (popup) {
- test.checkMenu([item], [], []);
- test.done();
- });
- });
- };
- // CSS selector contexts should cause their items to be absent from the menu
- // when the menu is not invoked on nodes that match or have ancestors that
- // match the selectors.
- exports.testSelectorContextNoMatch = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let item = new loader.cm.Item({
- label: "item",
- data: "item",
- context: loader.cm.SelectorContext("img")
- });
- test.showMenu(null, function (popup) {
- test.checkMenu([item], [item], []);
- test.done();
- });
- };
- // Page contexts should cause their items to be present in the menu when the
- // menu is not invoked on an active element.
- exports.testPageContextMatch = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let items = [
- new loader.cm.Item({
- label: "item 0"
- }),
- new loader.cm.Item({
- label: "item 1",
- context: undefined
- }),
- new loader.cm.Item({
- label: "item 2",
- context: loader.cm.PageContext()
- }),
- new loader.cm.Item({
- label: "item 3",
- context: [loader.cm.PageContext()]
- })
- ];
- test.showMenu(null, function (popup) {
- test.checkMenu(items, [], []);
- test.done();
- });
- };
- // Page contexts should cause their items to be absent from the menu when the
- // menu is invoked on an active element.
- exports.testPageContextNoMatch = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let items = [
- new loader.cm.Item({
- label: "item 0"
- }),
- new loader.cm.Item({
- label: "item 1",
- context: undefined
- }),
- new loader.cm.Item({
- label: "item 2",
- context: loader.cm.PageContext()
- }),
- new loader.cm.Item({
- label: "item 3",
- context: [loader.cm.PageContext()]
- })
- ];
- test.withTestDoc(function (window, doc) {
- test.showMenu(doc.getElementById("image"), function (popup) {
- test.checkMenu(items, items, []);
- test.done();
- });
- });
- };
- // Selection contexts should cause items to appear when a selection exists.
- exports.testSelectionContextMatch = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let item = loader.cm.Item({
- label: "item",
- context: loader.cm.SelectionContext()
- });
- test.withTestDoc(function (window, doc) {
- window.getSelection().selectAllChildren(doc.body);
- test.showMenu(null, function (popup) {
- test.checkMenu([item], [], []);
- test.done();
- });
- });
- };
- // Selection contexts should cause items to appear when a selection exists in
- // a text field.
- exports.testSelectionContextMatchInTextField = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let item = loader.cm.Item({
- label: "item",
- context: loader.cm.SelectionContext()
- });
- test.withTestDoc(function (window, doc) {
- let textfield = doc.getElementById("textfield");
- textfield.setSelectionRange(0, textfield.value.length);
- test.showMenu(textfield, function (popup) {
- test.checkMenu([item], [], []);
- test.done();
- });
- });
- };
- // Selection contexts should not cause items to appear when a selection does
- // not exist in a text field.
- exports.testSelectionContextNoMatchInTextField = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let item = loader.cm.Item({
- label: "item",
- context: loader.cm.SelectionContext()
- });
- test.withTestDoc(function (window, doc) {
- let textfield = doc.getElementById("textfield");
- textfield.setSelectionRange(0, 0);
- test.showMenu(textfield, function (popup) {
- test.checkMenu([item], [item], []);
- test.done();
- });
- });
- };
- // Selection contexts should not cause items to appear when a selection does
- // not exist.
- exports.testSelectionContextNoMatch = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let item = loader.cm.Item({
- label: "item",
- context: loader.cm.SelectionContext()
- });
- test.showMenu(null, function (popup) {
- test.checkMenu([item], [item], []);
- test.done();
- });
- };
- // Selection contexts should cause items to appear when a selection exists even
- // for newly opened pages
- exports.testSelectionContextInNewTab = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let item = loader.cm.Item({
- label: "item",
- context: loader.cm.SelectionContext()
- });
- test.withTestDoc(function (window, doc) {
- let link = doc.getElementById("targetlink");
- link.click();
- test.delayedEventListener(this.tabBrowser, "load", function () {
- let browser = test.tabBrowser.selectedBrowser;
- let window = browser.contentWindow;
- let doc = browser.contentDocument;
- window.getSelection().selectAllChildren(doc.body);
- test.showMenu(null, function (popup) {
- test.checkMenu([item], [], []);
- popup.hidePopup();
- test.tabBrowser.removeTab(test.tabBrowser.selectedTab);
- test.tabBrowser.selectedTab = test.tab;
- test.showMenu(null, function (popup) {
- test.checkMenu([item], [item], []);
- test.done();
- });
- });
- }, true);
- });
- };
- // Selection contexts should work when right clicking a form button
- exports.testSelectionContextButtonMatch = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let item = loader.cm.Item({
- label: "item",
- context: loader.cm.SelectionContext()
- });
- test.withTestDoc(function (window, doc) {
- window.getSelection().selectAllChildren(doc.body);
- let button = doc.getElementById("button");
- test.showMenu(button, function (popup) {
- test.checkMenu([item], [], []);
- test.done();
- });
- });
- };
- //Selection contexts should work when right clicking a form button
- exports.testSelectionContextButtonNoMatch = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let item = loader.cm.Item({
- label: "item",
- context: loader.cm.SelectionContext()
- });
- test.withTestDoc(function (window, doc) {
- let button = doc.getElementById("button");
- test.showMenu(button, function (popup) {
- test.checkMenu([item], [item], []);
- test.done();
- });
- });
- };
- // URL contexts should cause items to appear on pages that match.
- exports.testURLContextMatch = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let items = [
- loader.cm.Item({
- label: "item 0",
- context: loader.cm.URLContext(TEST_DOC_URL)
- }),
- loader.cm.Item({
- label: "item 1",
- context: loader.cm.URLContext([TEST_DOC_URL, "*.bogus.com"])
- }),
- loader.cm.Item({
- label: "item 2",
- context: loader.cm.URLContext([new RegExp(".*\\.html")])
- })
- ];
- test.withTestDoc(function (window, doc) {
- test.showMenu(null, function (popup) {
- test.checkMenu(items, [], []);
- test.done();
- });
- });
- };
- // URL contexts should not cause items to appear on pages that do not match.
- exports.testURLContextNoMatch = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let items = [
- loader.cm.Item({
- label: "item 0",
- context: loader.cm.URLContext("*.bogus.com")
- }),
- loader.cm.Item({
- label: "item 1",
- context: loader.cm.URLContext(["*.bogus.com", "*.gnarly.com"])
- }),
- loader.cm.Item({
- label: "item 2",
- context: loader.cm.URLContext([new RegExp(".*\\.js")])
- })
- ];
- test.withTestDoc(function (window, doc) {
- test.showMenu(null, function (popup) {
- test.checkMenu(items, items, []);
- test.done();
- });
- });
- };
- // Removing a non-matching URL context after its item is created and the page is
- // loaded should cause the item's content script to be evaluated when the
- // context menu is next opened.
- exports.testURLContextRemove = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let shouldBeEvaled = false;
- let context = loader.cm.URLContext("*.bogus.com");
- let item = loader.cm.Item({
- label: "item",
- context: context,
- contentScript: 'self.postMessage("ok"); self.on("context", function () true);',
- onMessage: function (msg) {
- assert.ok(shouldBeEvaled,
- "content script should be evaluated when expected");
- assert.equal(msg, "ok", "Should have received the right message");
- shouldBeEvaled = false;
- }
- });
- test.withTestDoc(function (window, doc) {
- test.showMenu(null, function (popup) {
- test.checkMenu([item], [item], []);
- item.context.remove(context);
- shouldBeEvaled = true;
- test.hideMenu(function () {
- test.showMenu(null, function (popup) {
- test.checkMenu([item], [], []);
- assert.ok(!shouldBeEvaled,
- "content script should have been evaluated");
- test.hideMenu(function () {
- // Shouldn't get evaluated again
- test.showMenu(null, function (popup) {
- test.checkMenu([item], [], []);
- test.done();
- });
- });
- });
- });
- });
- });
- };
- // Loading a new page in the same tab should correctly start a new worker for
- // any content scripts
- exports.testPageReload = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let item = loader.cm.Item({
- label: "Item",
- contentScript: "var doc = document; self.on('context', function(node) doc.body.getAttribute('showItem') == 'true');"
- });
- test.withTestDoc(function (window, doc) {
- // Set a flag on the document that the item uses
- doc.body.setAttribute("showItem", "true");
- test.showMenu(null, function (popup) {
- // With the attribute true the item should be visible in the menu
- test.checkMenu([item], [], []);
- test.hideMenu(function() {
- let browser = this.tabBrowser.getBrowserForTab(this.tab)
- test.delayedEventListener(browser, "load", function() {
- test.delayedEventListener(browser, "load", function() {
- window = browser.contentWindow;
- doc = window.document;
- // Set a flag on the document that the item uses
- doc.body.setAttribute("showItem", "false");
- test.showMenu(null, function (popup) {
- // In the new document with the attribute false the item should be
- // hidden, but if the contentScript hasn't been reloaded it will
- // still see the old value
- test.checkMenu([item], [item], []);
- test.done();
- });
- }, true);
- browser.loadURI(TEST_DOC_URL, null, null);
- }, true);
- // Required to make sure we load a new page in history rather than
- // just reloading the current page which would unload it
- browser.loadURI("about:blank", null, null);
- });
- });
- });
- };
- // Closing a page after it's been used with a worker should cause the worker
- // to be destroyed
- /*exports.testWorkerDestroy = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let loadExpected = false;
- let item = loader.cm.Item({
- label: "item",
- contentScript: 'self.postMessage("loaded"); self.on("detach", function () { console.log("saw detach"); self.postMessage("detach") });',
- onMessage: function (msg) {
- console.log("Saw " + msg)
- switch (msg) {
- case "loaded":
- assert.ok(loadExpected, "Should have seen the load event at the right time");
- loadExpected = false;
- break;
- case "detach":
- test.done();
- break;
- }
- }
- });
- test.withTestDoc(function (window, doc) {
- loadExpected = true;
- test.showMenu(null, function (popup) {
- assert.ok(!loadExpected, "Should have seen a message");
- test.checkMenu([item], [], []);
- test.closeTab();
- });
- });
- };*/
- // Content contexts that return true should cause their items to be present
- // in the menu.
- exports.testContentContextMatch = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let item = new loader.cm.Item({
- label: "item",
- contentScript: 'self.on("context", function () true);'
- });
- test.showMenu(null, function (popup) {
- test.checkMenu([item], [], []);
- test.done();
- });
- };
- // Content contexts that return false should cause their items to be absent
- // from the menu.
- exports.testContentContextNoMatch = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let item = new loader.cm.Item({
- label: "item",
- contentScript: 'self.on("context", function () false);'
- });
- test.showMenu(null, function (popup) {
- test.checkMenu([item], [item], []);
- test.done();
- });
- };
- // Content contexts that return undefined should cause their items to be absent
- // from the menu.
- exports.testContentContextUndefined = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let item = new loader.cm.Item({
- label: "item",
- contentScript: 'self.on("context", function () {});'
- });
- test.showMenu(null, function (popup) {
- test.checkMenu([item], [item], []);
- test.done();
- });
- };
- // Content contexts that return an empty string should cause their items to be
- // absent from the menu and shouldn't wipe the label
- exports.testContentContextEmptyString = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let item = new loader.cm.Item({
- label: "item",
- contentScript: 'self.on("context", function () "");'
- });
- test.showMenu(null, function (popup) {
- test.checkMenu([item], [item], []);
- assert.equal(item.label, "item", "Label should still be correct");
- test.done();
- });
- };
- // If any content contexts returns true then their items should be present in
- // the menu.
- exports.testMultipleContentContextMatch1 = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let item = new loader.cm.Item({
- label: "item",
- contentScript: 'self.on("context", function () true); ' +
- 'self.on("context", function () false);',
- onMessage: function() {
- test.fail("Should not have called the second context listener");
- }
- });
- test.showMenu(null, function (popup) {
- test.checkMenu([item], [], []);
- test.done();
- });
- };
- // If any content contexts returns true then their items should be present in
- // the menu.
- exports.testMultipleContentContextMatch2 = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let item = new loader.cm.Item({
- label: "item",
- contentScript: 'self.on("context", function () false); ' +
- 'self.on("context", function () true);'
- });
- test.showMenu(null, function (popup) {
- test.checkMenu([item], [], []);
- test.done();
- });
- };
- // If any content contexts returns a string then their items should be present
- // in the menu.
- exports.testMultipleContentContextString1 = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let item = new loader.cm.Item({
- label: "item",
- contentScript: 'self.on("context", function () "new label"); ' +
- 'self.on("context", function () false);'
- });
- test.showMenu(null, function (popup) {
- test.checkMenu([item], [], []);
- assert.equal(item.label, "new label", "Label should have changed");
- test.done();
- });
- };
- // If any content contexts returns a string then their items should be present
- // in the menu.
- exports.testMultipleContentContextString2 = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let item = new loader.cm.Item({
- label: "item",
- contentScript: 'self.on("context", function () false); ' +
- 'self.on("context", function () "new label");'
- });
- test.showMenu(null, function (popup) {
- test.checkMenu([item], [], []);
- assert.equal(item.label, "new label", "Label should have changed");
- test.done();
- });
- };
- // If many content contexts returns a string then the first should take effect
- exports.testMultipleContentContextString3 = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let item = new loader.cm.Item({
- label: "item",
- contentScript: 'self.on("context", function () "new label 1"); ' +
- 'self.on("context", function () "new label 2");'
- });
- test.showMenu(null, function (popup) {
- test.checkMenu([item], [], []);
- assert.equal(item.label, "new label 1", "Label should have changed");
- test.done();
- });
- };
- // Content contexts that return true should cause their items to be present
- // in the menu when context clicking an active element.
- exports.testContentContextMatchActiveElement = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let items = [
- new loader.cm.Item({
- label: "item 1",
- contentScript: 'self.on("context", function () true);'
- }),
- new loader.cm.Item({
- label: "item 2",
- context: undefined,
- contentScript: 'self.on("context", function () true);'
- }),
- // These items will always be hidden by the declarative usage of PageContext
- new loader.cm.Item({
- label: "item 3",
- context: loader.cm.PageContext(),
- contentScript: 'self.on("context", function () true);'
- }),
- new loader.cm.Item({
- label: "item 4",
- context: [loader.cm.PageContext()],
- contentScript: 'self.on("context", function () true);'
- })
- ];
- test.withTestDoc(function (window, doc) {
- test.showMenu(doc.getElementById("image"), function (popup) {
- test.checkMenu(items, [items[2], items[3]], []);
- test.done();
- });
- });
- };
- // Content contexts that return false should cause their items to be absent
- // from the menu when context clicking an active element.
- exports.testContentContextNoMatchActiveElement = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let items = [
- new loader.cm.Item({
- label: "item 1",
- contentScript: 'self.on("context", function () false);'
- }),
- new loader.cm.Item({
- label: "item 2",
- context: undefined,
- contentScript: 'self.on("context", function () false);'
- }),
- // These items will always be hidden by the declarative usage of PageContext
- new loader.cm.Item({
- label: "item 3",
- context: loader.cm.PageContext(),
- contentScript: 'self.on("context", function () false);'
- }),
- new loader.cm.Item({
- label: "item 4",
- context: [loader.cm.PageContext()],
- contentScript: 'self.on("context", function () false);'
- })
- ];
- test.withTestDoc(function (window, doc) {
- test.showMenu(doc.getElementById("image"), function (popup) {
- test.checkMenu(items, items, []);
- test.done();
- });
- });
- };
- // Content contexts that return undefined should cause their items to be absent
- // from the menu when context clicking an active element.
- exports.testContentContextNoMatchActiveElement = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let items = [
- new loader.cm.Item({
- label: "item 1",
- contentScript: 'self.on("context", function () {});'
- }),
- new loader.cm.Item({
- label: "item 2",
- context: undefined,
- contentScript: 'self.on("context", function () {});'
- }),
- // These items will always be hidden by the declarative usage of PageContext
- new loader.cm.Item({
- label: "item 3",
- context: loader.cm.PageContext(),
- contentScript: 'self.on("context", function () {});'
- }),
- new loader.cm.Item({
- label: "item 4",
- context: [loader.cm.PageContext()],
- contentScript: 'self.on("context", function () {});'
- })
- ];
- test.withTestDoc(function (window, doc) {
- test.showMenu(doc.getElementById("image"), function (popup) {
- test.checkMenu(items, items, []);
- test.done();
- });
- });
- };
- // Content contexts that return a string should cause their items to be present
- // in the menu and the items' labels to be updated.
- exports.testContentContextMatchString = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let item = new loader.cm.Item({
- label: "first label",
- contentScript: 'self.on("context", function () "second label");'
- });
- test.showMenu(null, function (popup) {
- test.checkMenu([item], [], []);
- assert.equal(item.label, "second label",
- "item's label should be updated");
- test.done();
- });
- };
- // Ensure that contentScriptFile is working correctly
- exports.testContentScriptFile = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- // Reject remote files
- assert.throws(function() {
- new loader.cm.Item({
- label: "item",
- contentScriptFile: "http://mozilla.com/context-menu.js"
- });
- },
- new RegExp("The 'contentScriptFile' option must be a local file URL " +
- "or an array of local file URLs."),
- "Item throws when contentScriptFile is a remote URL");
- // But accept files from data folder
- let item = new loader.cm.Item({
- label: "item",
- contentScriptFile: data.url("test-context-menu.js")
- });
- test.showMenu(null, function (popup) {
- test.checkMenu([item], [], []);
- test.done();
- });
- };
- // The args passed to context listeners should be correct.
- exports.testContentContextArgs = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let callbacks = 0;
- let item = new loader.cm.Item({
- label: "item",
- contentScript: 'self.on("context", function (node) {' +
- ' self.postMessage(node.tagName);' +
- ' return false;' +
- '});',
- onMessage: function (tagName) {
- assert.equal(tagName, "HTML", "node should be an HTML element");
- if (++callbacks == 2) test.done();
- }
- });
- test.showMenu(null, function () {
- if (++callbacks == 2) test.done();
- });
- };
- // Multiple contexts imply intersection, not union, and content context
- // listeners should not be called if all declarative contexts are not current.
- exports.testMultipleContexts = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let item = new loader.cm.Item({
- label: "item",
- context: [loader.cm.SelectorContext("a[href]"), loader.cm.PageContext()],
- contentScript: 'self.on("context", function () self.postMessage());',
- onMessage: function () {
- test.fail("Context listener should not be called");
- }
- });
- test.withTestDoc(function (window, doc) {
- test.showMenu(doc.getElementById("span-link"), function (popup) {
- test.checkMenu([item], [item], []);
- test.done();
- });
- });
- };
- // Once a context is removed, it should no longer cause its item to appear.
- exports.testRemoveContext = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let ctxt = loader.cm.SelectorContext("img");
- let item = new loader.cm.Item({
- label: "item",
- context: ctxt
- });
- test.withTestDoc(function (window, doc) {
- test.showMenu(doc.getElementById("image"), function (popup) {
- // The item should be present at first.
- test.checkMenu([item], [], []);
- popup.hidePopup();
- // Remove the img context and check again.
- item.context.remove(ctxt);
- test.showMenu(doc.getElementById("image"), function (popup) {
- test.checkMenu([item], [item], []);
- test.done();
- });
- });
- });
- };
- // Lots of items should overflow into the overflow submenu.
- exports.testOverflow = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let items = [];
- for (let i = 0; i < OVERFLOW_THRESH_DEFAULT + 1; i++) {
- let item = new loader.cm.Item({ label: "item " + i });
- items.push(item);
- }
- test.showMenu(null, function (popup) {
- test.checkMenu(items, [], []);
- test.done();
- });
- };
- // Module unload should cause all items to be removed.
- exports.testUnload = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let item = new loader.cm.Item({ label: "item" });
- test.showMenu(null, function (popup) {
- // The menu should contain the item.
- test.checkMenu([item], [], []);
- popup.hidePopup();
- // Unload the module.
- loader.unload();
- test.showMenu(null, function (popup) {
- // The item should be removed from the menu.
- test.checkMenu([item], [], [item]);
- test.done();
- });
- });
- };
- // Using multiple module instances to add items without causing overflow should
- // work OK. Assumes OVERFLOW_THRESH_DEFAULT >= 2.
- exports.testMultipleModulesAdd = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader0 = test.newLoader();
- let loader1 = test.newLoader();
- // Use each module to add an item, then unload each module in turn.
- let item0 = new loader0.cm.Item({ label: "item 0" });
- let item1 = new loader1.cm.Item({ label: "item 1" });
- test.showMenu(null, function (popup) {
- // The menu should contain both items.
- test.checkMenu([item0, item1], [], []);
- popup.hidePopup();
- // Unload the first module.
- loader0.unload();
- test.showMenu(null, function (popup) {
- // The first item should be removed from the menu.
- test.checkMenu([item0, item1], [], [item0]);
- popup.hidePopup();
- // Unload the second module.
- loader1.unload();
- test.showMenu(null, function (popup) {
- // Both items should be removed from the menu.
- test.checkMenu([item0, item1], [], [item0, item1]);
- test.done();
- });
- });
- });
- };
- // Using multiple module instances to add items causing overflow should work OK.
- exports.testMultipleModulesAddOverflow = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader0 = test.newLoader();
- let loader1 = test.newLoader();
- // Use module 0 to add OVERFLOW_THRESH_DEFAULT items.
- let items0 = [];
- for (let i = 0; i < OVERFLOW_THRESH_DEFAULT; i++) {
- let item = new loader0.cm.Item({ label: "item 0 " + i });
- items0.push(item);
- }
- // Use module 1 to add one item.
- let item1 = new loader1.cm.Item({ label: "item 1" });
- let allItems = items0.concat(item1);
- test.showMenu(null, function (popup) {
- // The menu should contain all items in overflow.
- test.checkMenu(allItems, [], []);
- popup.hidePopup();
- // Unload the first module.
- loader0.unload();
- test.showMenu(null, function (popup) {
- // The first items should be removed from the menu, which should not
- // overflow.
- test.checkMenu(allItems, [], items0);
- popup.hidePopup();
- // Unload the second module.
- loader1.unload();
- test.showMenu(null, function (popup) {
- // All items should be removed from the menu.
- test.checkMenu(allItems, [], allItems);
- test.done();
- });
- });
- });
- };
- // Using multiple module instances to modify the menu without causing overflow
- // should work OK. This test creates two loaders and:
- // loader0 create item -> loader1 create item -> loader0.unload ->
- // loader1.unload
- exports.testMultipleModulesDiffContexts1 = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader0 = test.newLoader();
- let loader1 = test.newLoader();
- let item0 = new loader0.cm.Item({
- label: "item 0",
- context: loader0.cm.SelectorContext("img")
- });
- let item1 = new loader1.cm.Item({ label: "item 1" });
- test.showMenu(null, function (popup) {
- // The menu should contain item1.
- test.checkMenu([item0, item1], [item0], []);
- popup.hidePopup();
- // Unload module 0.
- loader0.unload();
- test.showMenu(null, function (popup) {
- // item0 should be removed from the menu.
- test.checkMenu([item0, item1], [], [item0]);
- popup.hidePopup();
- // Unload module 1.
- loader1.unload();
- test.showMenu(null, function (popup) {
- // Both items should be removed from the menu.
- test.checkMenu([item0, item1], [], [item0, item1]);
- test.done();
- });
- });
- });
- };
- // Using multiple module instances to modify the menu without causing overflow
- // should work OK. This test creates two loaders and:
- // loader1 create item -> loader0 create item -> loader0.unload ->
- // loader1.unload
- exports.testMultipleModulesDiffContexts2 = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader0 = test.newLoader();
- let loader1 = test.newLoader();
- let item1 = new loader1.cm.Item({ label: "item 1" });
- let item0 = new loader0.cm.Item({
- label: "item 0",
- context: loader0.cm.SelectorContext("img")
- });
- test.showMenu(null, function (popup) {
- // The menu should contain item1.
- test.checkMenu([item0, item1], [item0], []);
- popup.hidePopup();
- // Unload module 0.
- loader0.unload();
- test.showMenu(null, function (popup) {
- // item0 should be removed from the menu.
- test.checkMenu([item0, item1], [], [item0]);
- popup.hidePopup();
- // Unload module 1.
- loader1.unload();
- test.showMenu(null, function (popup) {
- // Both items should be removed from the menu.
- test.checkMenu([item0, item1], [], [item0, item1]);
- test.done();
- });
- });
- });
- };
- // Using multiple module instances to modify the menu without causing overflow
- // should work OK. This test creates two loaders and:
- // loader0 create item -> loader1 create item -> loader1.unload ->
- // loader0.unload
- exports.testMultipleModulesDiffContexts3 = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader0 = test.newLoader();
- let loader1 = test.newLoader();
- let item0 = new loader0.cm.Item({
- label: "item 0",
- context: loader0.cm.SelectorContext("img")
- });
- let item1 = new loader1.cm.Item({ label: "item 1" });
- test.showMenu(null, function (popup) {
- // The menu should contain item1.
- test.checkMenu([item0, item1], [item0], []);
- popup.hidePopup();
- // Unload module 1.
- loader1.unload();
- test.showMenu(null, function (popup) {
- // item1 should be removed from the menu.
- test.checkMenu([item0, item1], [item0], [item1]);
- popup.hidePopup();
- // Unload module 0.
- loader0.unload();
- test.showMenu(null, function (popup) {
- // Both items should be removed from the menu.
- test.checkMenu([item0, item1], [], [item0, item1]);
- test.done();
- });
- });
- });
- };
- // Using multiple module instances to modify the menu without causing overflow
- // should work OK. This test creates two loaders and:
- // loader1 create item -> loader0 create item -> loader1.unload ->
- // loader0.unload
- exports.testMultipleModulesDiffContexts4 = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader0 = test.newLoader();
- let loader1 = test.newLoader();
- let item1 = new loader1.cm.Item({ label: "item 1" });
- let item0 = new loader0.cm.Item({
- label: "item 0",
- context: loader0.cm.SelectorContext("img")
- });
- test.showMenu(null, function (popup) {
- // The menu should contain item1.
- test.checkMenu([item0, item1], [item0], []);
- popup.hidePopup();
- // Unload module 1.
- loader1.unload();
- test.showMenu(null, function (popup) {
- // item1 should be removed from the menu.
- test.checkMenu([item0, item1], [item0], [item1]);
- popup.hidePopup();
- // Unload module 0.
- loader0.unload();
- test.showMenu(null, function (popup) {
- // Both items should be removed from the menu.
- test.checkMenu([item0, item1], [], [item0, item1]);
- test.done();
- });
- });
- });
- };
- // Test interactions between a loaded module, unloading another module, and the
- // menu separator and overflow submenu.
- exports.testMultipleModulesAddRemove = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader0 = test.newLoader();
- let loader1 = test.newLoader();
- let item = new loader0.cm.Item({ label: "item" });
- test.showMenu(null, function (popup) {
- // The menu should contain the item.
- test.checkMenu([item], [], []);
- popup.hidePopup();
- // Remove the item.
- item.destroy();
- test.showMenu(null, function (popup) {
- // The item should be removed from the menu.
- test.checkMenu([item], [], [item]);
- popup.hidePopup();
- // Unload module 1.
- loader1.unload();
- test.showMenu(null, function (popup) {
- // There shouldn't be any errors involving the menu separator or
- // overflow submenu.
- test.checkMenu([item], [], [item]);
- test.done();
- });
- });
- });
- };
- // Checks that the order of menu items is correct when adding/removing across
- // multiple modules. All items from a single module should remain in a group
- exports.testMultipleModulesOrder = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader0 = test.newLoader();
- let loader1 = test.newLoader();
- // Use each module to add an item, then unload each module in turn.
- let item0 = new loader0.cm.Item({ label: "item 0" });
- let item1 = new loader1.cm.Item({ label: "item 1" });
- test.showMenu(null, function (popup) {
- // The menu should contain both items.
- test.checkMenu([item0, item1], [], []);
- popup.hidePopup();
- let item2 = new loader0.cm.Item({ label: "item 2" });
- test.showMenu(null, function (popup) {
- // The new item should be grouped with the same items from loader0.
- test.checkMenu([item0, item2, item1], [], []);
- popup.hidePopup();
- let item3 = new loader1.cm.Item({ label: "item 3" });
- test.showMenu(null, function (popup) {
- // Same again
- test.checkMenu([item0, item2, item1, item3], [], []);
- test.done();
- });
- });
- });
- };
- // Checks that the order of menu items is correct when adding/removing across
- // multiple modules when overflowing. All items from a single module should
- // remain in a group
- exports.testMultipleModulesOrderOverflow = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader0 = test.newLoader();
- let loader1 = test.newLoader();
- let prefs = loader0.loader.require("sdk/preferences/service");
- prefs.set(OVERFLOW_THRESH_PREF, 0);
- // Use each module to add an item, then unload each module in turn.
- let item0 = new loader0.cm.Item({ label: "item 0" });
- let item1 = new loader1.cm.Item({ label: "item 1" });
- test.showMenu(null, function (popup) {
- // The menu should contain both items.
- test.checkMenu([item0, item1], [], []);
- popup.hidePopup();
- let item2 = new loader0.cm.Item({ label: "item 2" });
- test.showMenu(null, function (popup) {
- // The new item should be grouped with the same items from loader0.
- test.checkMenu([item0, item2, item1], [], []);
- popup.hidePopup();
- let item3 = new loader1.cm.Item({ label: "item 3" });
- test.showMenu(null, function (popup) {
- // Same again
- test.checkMenu([item0, item2, item1, item3], [], []);
- test.done();
- });
- });
- });
- };
- // Checks that if a module's items are all hidden then the overflow menu doesn't
- // get hidden
- exports.testMultipleModulesOverflowHidden = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader0 = test.newLoader();
- let loader1 = test.newLoader();
- let prefs = loader0.loader.require("sdk/preferences/service");
- prefs.set(OVERFLOW_THRESH_PREF, 0);
- // Use each module to add an item, then unload each module in turn.
- let item0 = new loader0.cm.Item({ label: "item 0" });
- let item1 = new loader1.cm.Item({
- label: "item 1",
- context: loader1.cm.SelectorContext("a")
- });
- test.showMenu(null, function (popup) {
- // One should be hidden
- test.checkMenu([item0, item1], [item1], []);
- test.done();
- });
- };
- // Checks that if a module's items are all hidden then the overflow menu doesn't
- // get hidden (reverse order to above)
- exports.testMultipleModulesOverflowHidden2 = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader0 = test.newLoader();
- let loader1 = test.newLoader();
- let prefs = loader0.loader.require("sdk/preferences/service");
- prefs.set(OVERFLOW_THRESH_PREF, 0);
- // Use each module to add an item, then unload each module in turn.
- let item0 = new loader0.cm.Item({
- label: "item 0",
- context: loader0.cm.SelectorContext("a")
- });
- let item1 = new loader1.cm.Item({ label: "item 1" });
- test.showMenu(null, function (popup) {
- // One should be hidden
- test.checkMenu([item0, item1], [item0], []);
- test.done();
- });
- };
- // Checks that we don't overflow if there are more items than the overflow
- // threshold but not all of them are visible
- exports.testOverflowIgnoresHidden = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let prefs = loader.loader.require("sdk/preferences/service");
- prefs.set(OVERFLOW_THRESH_PREF, 2);
- let allItems = [
- new loader.cm.Item({
- label: "item 0"
- }),
- new loader.cm.Item({
- label: "item 1"
- }),
- new loader.cm.Item({
- label: "item 2",
- context: loader.cm.SelectorContext("a")
- })
- ];
- test.showMenu(null, function (popup) {
- // One should be hidden
- test.checkMenu(allItems, [allItems[2]], []);
- test.done();
- });
- };
- // Checks that we don't overflow if there are more items than the overflow
- // threshold but not all of them are visible
- exports.testOverflowIgnoresHiddenMultipleModules1 = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader0 = test.newLoader();
- let loader1 = test.newLoader();
- let prefs = loader0.loader.require("sdk/preferences/service");
- prefs.set(OVERFLOW_THRESH_PREF, 2);
- let allItems = [
- new loader0.cm.Item({
- label: "item 0"
- }),
- new loader0.cm.Item({
- label: "item 1"
- }),
- new loader1.cm.Item({
- label: "item 2",
- context: loader1.cm.SelectorContext("a")
- }),
- new loader1.cm.Item({
- label: "item 3",
- context: loader1.cm.SelectorContext("a")
- })
- ];
- test.showMenu(null, function (popup) {
- // One should be hidden
- test.checkMenu(allItems, [allItems[2], allItems[3]], []);
- test.done();
- });
- };
- // Checks that we don't overflow if there are more items than the overflow
- // threshold but not all of them are visible
- exports.testOverflowIgnoresHiddenMultipleModules2 = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader0 = test.newLoader();
- let loader1 = test.newLoader();
- let prefs = loader0.loader.require("sdk/preferences/service");
- prefs.set(OVERFLOW_THRESH_PREF, 2);
- let allItems = [
- new loader0.cm.Item({
- label: "item 0"
- }),
- new loader0.cm.Item({
- label: "item 1",
- context: loader0.cm.SelectorContext("a")
- }),
- new loader1.cm.Item({
- label: "item 2"
- }),
- new loader1.cm.Item({
- label: "item 3",
- context: loader1.cm.SelectorContext("a")
- })
- ];
- test.showMenu(null, function (popup) {
- // One should be hidden
- test.checkMenu(allItems, [allItems[1], allItems[3]], []);
- test.done();
- });
- };
- // Checks that we don't overflow if there are more items than the overflow
- // threshold but not all of them are visible
- exports.testOverflowIgnoresHiddenMultipleModules3 = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader0 = test.newLoader();
- let loader1 = test.newLoader();
- let prefs = loader0.loader.require("sdk/preferences/service");
- prefs.set(OVERFLOW_THRESH_PREF, 2);
- let allItems = [
- new loader0.cm.Item({
- label: "item 0",
- context: loader0.cm.SelectorContext("a")
- }),
- new loader0.cm.Item({
- label: "item 1",
- context: loader0.cm.SelectorContext("a")
- }),
- new loader1.cm.Item({
- label: "item 2"
- }),
- new loader1.cm.Item({
- label: "item 3"
- })
- ];
- test.showMenu(null, function (popup) {
- // One should be hidden
- test.checkMenu(allItems, [allItems[0], allItems[1]], []);
- test.done();
- });
- };
- // Tests that we transition between overflowing to non-overflowing to no items
- // and back again
- exports.testOverflowTransition = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let prefs = loader.loader.require("sdk/preferences/service");
- prefs.set(OVERFLOW_THRESH_PREF, 2);
- let pItems = [
- new loader.cm.Item({
- label: "item 0",
- context: loader.cm.SelectorContext("p")
- }),
- new loader.cm.Item({
- label: "item 1",
- context: loader.cm.SelectorContext("p")
- })
- ];
- let aItems = [
- new loader.cm.Item({
- label: "item 2",
- context: loader.cm.SelectorContext("a")
- }),
- new loader.cm.Item({
- label: "item 3",
- context: loader.cm.SelectorContext("a")
- })
- ];
- let allItems = pItems.concat(aItems);
- test.withTestDoc(function (window, doc) {
- test.showMenu(doc.getElementById("link"), function (popup) {
- // The menu should contain all items and will overflow
- test.checkMenu(allItems, [], []);
- popup.hidePopup();
- test.showMenu(doc.getElementById("text"), function (popup) {
- // Only contains hald the items and will not overflow
- test.checkMenu(allItems, aItems, []);
- popup.hidePopup();
- test.showMenu(null, function (popup) {
- // None of the items will be visible
- test.checkMenu(allItems, allItems, []);
- popup.hidePopup();
- test.showMenu(doc.getElementById("text"), function (popup) {
- // Only contains hald the items and will not overflow
- test.checkMenu(allItems, aItems, []);
- popup.hidePopup();
- test.showMenu(doc.getElementById("link"), function (popup) {
- // The menu should contain all items and will overflow
- test.checkMenu(allItems, [], []);
- popup.hidePopup();
- test.showMenu(null, function (popup) {
- // None of the items will be visible
- test.checkMenu(allItems, allItems, []);
- popup.hidePopup();
- test.showMenu(doc.getElementById("link"), function (popup) {
- // The menu should contain all items and will overflow
- test.checkMenu(allItems, [], []);
- test.done();
- });
- });
- });
- });
- });
- });
- });
- });
- };
- // An item's command listener should work.
- exports.testItemCommand = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let item = new loader.cm.Item({
- label: "item",
- data: "item data",
- contentScript: 'self.on("click", function (node, data) {' +
- ' self.postMessage({' +
- ' tagName: node.tagName,' +
- ' data: data' +
- ' });' +
- '});',
- onMessage: function (data) {
- assert.equal(this, item, "`this` inside onMessage should be item");
- assert.equal(data.tagName, "HTML", "node should be an HTML element");
- assert.equal(data.data, item.data, "data should be item data");
- test.done();
- }
- });
- test.showMenu(null, function (popup) {
- test.checkMenu([item], [], []);
- let elt = test.getItemElt(popup, item);
- // create a command event
- let evt = elt.ownerDocument.createEvent('Event');
- evt.initEvent('command', true, true);
- elt.dispatchEvent(evt);
- });
- };
- // A menu's click listener should work and receive bubbling 'command' events from
- // sub-items appropriately. This also tests menus and ensures that when a CSS
- // selector context matches the clicked node's ancestor, the matching ancestor
- // is passed to listeners as the clicked node.
- exports.testMenuCommand = function (assert, done) {
- // Create a top-level menu, submenu, and item, like this:
- // topMenu -> submenu -> item
- // Click the item and make sure the click bubbles.
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let item = new loader.cm.Item({
- label: "submenu item",
- data: "submenu item data",
- context: loader.cm.SelectorContext("a"),
- });
- let submenu = new loader.cm.Menu({
- label: "submenu",
- context: loader.cm.SelectorContext("a"),
- items: [item]
- });
- let topMenu = new loader.cm.Menu({
- label: "top menu",
- contentScript: 'self.on("click", function (node, data) {' +
- ' self.postMessage({' +
- ' tagName: node.tagName,' +
- ' data: data' +
- ' });' +
- '});',
- onMessage: function (data) {
- assert.equal(this, topMenu, "`this` inside top menu should be menu");
- assert.equal(data.tagName, "A", "Clicked node should be anchor");
- assert.equal(data.data, item.data,
- "Clicked item data should be correct");
- test.done();
- },
- items: [submenu],
- context: loader.cm.SelectorContext("a")
- });
- test.withTestDoc(function (window, doc) {
- test.showMenu(doc.getElementById("span-link"), function (popup) {
- test.checkMenu([topMenu], [], []);
- let topMenuElt = test.getItemElt(popup, topMenu);
- let topMenuPopup = topMenuElt.firstChild;
- let submenuElt = test.getItemElt(topMenuPopup, submenu);
- let submenuPopup = submenuElt.firstChild;
- let itemElt = test.getItemElt(submenuPopup, item);
- // create a command event
- let evt = itemElt.ownerDocument.createEvent('Event');
- evt.initEvent('command', true, true);
- itemElt.dispatchEvent(evt);
- });
- });
- };
- // Click listeners should work when multiple modules are loaded.
- exports.testItemCommandMultipleModules = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader0 = test.newLoader();
- let loader1 = test.newLoader();
- let item0 = loader0.cm.Item({
- label: "loader 0 item",
- contentScript: 'self.on("click", self.postMessage);',
- onMessage: function () {
- test.fail("loader 0 item should not emit click event");
- }
- });
- let item1 = loader1.cm.Item({
- label: "loader 1 item",
- contentScript: 'self.on("click", self.postMessage);',
- onMessage: function () {
- test.pass("loader 1 item clicked as expected");
- test.done();
- }
- });
- test.showMenu(null, function (popup) {
- test.checkMenu([item0, item1], [], []);
- let item1Elt = test.getItemElt(popup, item1);
- // create a command event
- let evt = item1Elt.ownerDocument.createEvent('Event');
- evt.initEvent('command', true, true);
- item1Elt.dispatchEvent(evt);
- });
- };
- // An item's click listener should work.
- exports.testItemClick = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let item = new loader.cm.Item({
- label: "item",
- data: "item data",
- contentScript: 'self.on("click", function (node, data) {' +
- ' self.postMessage({' +
- ' tagName: node.tagName,' +
- ' data: data' +
- ' });' +
- '});',
- onMessage: function (data) {
- assert.equal(this, item, "`this` inside onMessage should be item");
- assert.equal(data.tagName, "HTML", "node should be an HTML element");
- assert.equal(data.data, item.data, "data should be item data");
- test.done();
- }
- });
- test.showMenu(null, function (popup) {
- test.checkMenu([item], [], []);
- let elt = test.getItemElt(popup, item);
- elt.click();
- });
- };
- // A menu's click listener should work and receive bubbling clicks from
- // sub-items appropriately. This also tests menus and ensures that when a CSS
- // selector context matches the clicked node's ancestor, the matching ancestor
- // is passed to listeners as the clicked node.
- exports.testMenuClick = function (assert, done) {
- // Create a top-level menu, submenu, and item, like this:
- // topMenu -> submenu -> item
- // Click the item and make sure the click bubbles.
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let item = new loader.cm.Item({
- label: "submenu item",
- data: "submenu item data",
- context: loader.cm.SelectorContext("a"),
- });
- let submenu = new loader.cm.Menu({
- label: "submenu",
- context: loader.cm.SelectorContext("a"),
- items: [item]
- });
- let topMenu = new loader.cm.Menu({
- label: "top menu",
- contentScript: 'self.on("click", function (node, data) {' +
- ' self.postMessage({' +
- ' tagName: node.tagName,' +
- ' data: data' +
- ' });' +
- '});',
- onMessage: function (data) {
- assert.equal(this, topMenu, "`this` inside top menu should be menu");
- assert.equal(data.tagName, "A", "Clicked node should be anchor");
- assert.equal(data.data, item.data,
- "Clicked item data should be correct");
- test.done();
- },
- items: [submenu],
- context: loader.cm.SelectorContext("a")
- });
- test.withTestDoc(function (window, doc) {
- test.showMenu(doc.getElementById("span-link"), function (popup) {
- test.checkMenu([topMenu], [], []);
- let topMenuElt = test.getItemElt(popup, topMenu);
- let topMenuPopup = topMenuElt.firstChild;
- let submenuElt = test.getItemElt(topMenuPopup, submenu);
- let submenuPopup = submenuElt.firstChild;
- let itemElt = test.getItemElt(submenuPopup, item);
- itemElt.click();
- });
- });
- };
- // Click listeners should work when multiple modules are loaded.
- exports.testItemClickMultipleModules = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader0 = test.newLoader();
- let loader1 = test.newLoader();
- let item0 = loader0.cm.Item({
- label: "loader 0 item",
- contentScript: 'self.on("click", self.postMessage);',
- onMessage: function () {
- test.fail("loader 0 item should not emit click event");
- }
- });
- let item1 = loader1.cm.Item({
- label: "loader 1 item",
- contentScript: 'self.on("click", self.postMessage);',
- onMessage: function () {
- test.pass("loader 1 item clicked as expected");
- test.done();
- }
- });
- test.showMenu(null, function (popup) {
- test.checkMenu([item0, item1], [], []);
- let item1Elt = test.getItemElt(popup, item1);
- item1Elt.click();
- });
- };
- // Adding a separator to a submenu should work OK.
- exports.testSeparator = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let menu = new loader.cm.Menu({
- label: "submenu",
- items: [new loader.cm.Separator()]
- });
- test.showMenu(null, function (popup) {
- test.checkMenu([menu], [], []);
- test.done();
- });
- };
- // The parentMenu option should work
- exports.testParentMenu = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let menu = new loader.cm.Menu({
- label: "submenu",
- items: [loader.cm.Item({ label: "item 1" })],
- parentMenu: loader.cm.contentContextMenu
- });
- let item = loader.cm.Item({
- label: "item 2",
- parentMenu: menu,
- });
- assert.equal(menu.items[1], item, "Item should be in the sub menu");
- test.showMenu(null, function (popup) {
- test.checkMenu([menu], [], []);
- test.done();
- });
- };
- // Existing context menu modifications should apply to new windows.
- exports.testNewWindow = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let item = new loader.cm.Item({ label: "item" });
- test.withNewWindow(function () {
- test.showMenu(null, function (popup) {
- test.checkMenu([item], [], []);
- test.done();
- });
- });
- };
- // When a new window is opened, items added by an unloaded module should not
- // be present in the menu.
- exports.testNewWindowMultipleModules = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let item = new loader.cm.Item({ label: "item" });
- test.showMenu(null, function (popup) {
- test.checkMenu([item], [], []);
- popup.hidePopup();
- loader.unload();
- test.withNewWindow(function () {
- test.showMenu(null, function (popup) {
- test.checkMenu([item], [], [item]);
- test.done();
- });
- });
- });
- };
- // Existing context menu modifications should not apply to new private windows.
- exports.testNewPrivateWindow = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let item = new loader.cm.Item({ label: "item" });
- test.showMenu(null, function (popup) {
- test.checkMenu([item], [], []);
- popup.hidePopup();
- test.withNewPrivateWindow(function () {
- test.showMenu(null, function (popup) {
- test.checkMenu([], [], []);
- test.done();
- });
- });
- });
- };
- // Existing context menu modifications should apply to new private windows when
- // private browsing support is enabled.
- exports.testNewPrivateEnabledWindow = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newPrivateLoader();
- let item = new loader.cm.Item({ label: "item" });
- test.showMenu(null, function (popup) {
- test.checkMenu([item], [], []);
- popup.hidePopup();
- test.withNewPrivateWindow(function () {
- test.showMenu(null, function (popup) {
- test.checkMenu([item], [], []);
- test.done();
- });
- });
- });
- };
- // Existing context menu modifications should apply to new private windows when
- // private browsing support is enabled unless unloaded.
- exports.testNewPrivateEnabledWindowUnloaded = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newPrivateLoader();
- let item = new loader.cm.Item({ label: "item" });
- test.showMenu(null, function (popup) {
- test.checkMenu([item], [], []);
- popup.hidePopup();
- loader.unload();
- test.withNewPrivateWindow(function () {
- test.showMenu(null, function (popup) {
- test.checkMenu([], [], []);
- test.done();
- });
- });
- });
- };
- // Items in the context menu should be sorted according to locale.
- exports.testSorting = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- // Make an unsorted items list. It'll look like this:
- // item 1, item 0, item 3, item 2, item 5, item 4, ...
- let items = [];
- for (let i = 0; i < OVERFLOW_THRESH_DEFAULT; i += 2) {
- items.push(new loader.cm.Item({ label: "item " + (i + 1) }));
- items.push(new loader.cm.Item({ label: "item " + i }));
- }
- test.showMenu(null, function (popup) {
- test.checkMenu(items, [], []);
- test.done();
- });
- };
- // Items in the overflow menu should be sorted according to locale.
- exports.testSortingOverflow = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- // Make an unsorted items list. It'll look like this:
- // item 1, item 0, item 3, item 2, item 5, item 4, ...
- let items = [];
- for (let i = 0; i < OVERFLOW_THRESH_DEFAULT * 2; i += 2) {
- items.push(new loader.cm.Item({ label: "item " + (i + 1) }));
- items.push(new loader.cm.Item({ label: "item " + i }));
- }
- test.showMenu(null, function (popup) {
- test.checkMenu(items, [], []);
- test.done();
- });
- };
- // Multiple modules shouldn't interfere with sorting.
- exports.testSortingMultipleModules = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader0 = test.newLoader();
- let loader1 = test.newLoader();
- let items0 = [];
- let items1 = [];
- for (let i = 0; i < OVERFLOW_THRESH_DEFAULT; i++) {
- if (i % 2) {
- let item = new loader0.cm.Item({ label: "item " + i });
- items0.push(item);
- }
- else {
- let item = new loader1.cm.Item({ label: "item " + i });
- items1.push(item);
- }
- }
- let allItems = items0.concat(items1);
- test.showMenu(null, function (popup) {
- // All items should be present and sorted.
- test.checkMenu(allItems, [], []);
- popup.hidePopup();
- loader0.unload();
- loader1.unload();
- test.showMenu(null, function (popup) {
- // All items should be removed.
- test.checkMenu(allItems, [], allItems);
- test.done();
- });
- });
- };
- // Content click handlers and context handlers should be able to communicate,
- // i.e., they're eval'ed in the same worker and sandbox.
- exports.testContentCommunication = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let item = new loader.cm.Item({
- label: "item",
- contentScript: 'var potato;' +
- 'self.on("context", function () {' +
- ' potato = "potato";' +
- ' return true;' +
- '});' +
- 'self.on("click", function () {' +
- ' self.postMessage(potato);' +
- '});',
- });
- item.on("message", function (data) {
- assert.equal(data, "potato", "That's a lot of potatoes!");
- test.done();
- });
- test.showMenu(null, function (popup) {
- test.checkMenu([item], [], []);
- let elt = test.getItemElt(popup, item);
- elt.click();
- });
- };
- // When the context menu is invoked on a tab that was already open when the
- // module was loaded, it should contain the expected items and content workers
- // should function as expected.
- exports.testLoadWithOpenTab = function (assert, done) {
- let test = new TestHelper(assert, done);
- test.withTestDoc(function (window, doc) {
- let loader = test.newLoader();
- let item = new loader.cm.Item({
- label: "item",
- contentScript:
- 'self.on("click", function () self.postMessage("click"));',
- onMessage: function (msg) {
- if (msg === "click")
- test.done();
- }
- });
- test.showMenu(null, function (popup) {
- test.checkMenu([item], [], []);
- test.getItemElt(popup, item).click();
- });
- });
- };
- // Bug 732716: Ensure that the node given in `click` event works fine
- // (i.e. is correctly wrapped)
- exports.testDrawImageOnClickNode = function (assert, done) {
- let test = new TestHelper(assert, done);
- test.withTestDoc(function (window, doc) {
- let loader = test.newLoader();
- let item = new loader.cm.Item({
- label: "item",
- context: loader.cm.SelectorContext("img"),
- contentScript: "new " + function() {
- self.on("click", function (img, data) {
- let ctx = document.createElement("canvas").getContext("2d");
- ctx.drawImage(img, 1, 1, 1, 1);
- self.postMessage("done");
- });
- },
- onMessage: function (msg) {
- if (msg === "done")
- test.done();
- }
- });
- test.showMenu(doc.getElementById("image"), function (popup) {
- test.checkMenu([item], [], []);
- test.getItemElt(popup, item).click();
- });
- });
- };
- // Setting an item's label before the menu is ever shown should correctly change
- // its label.
- exports.testSetLabelBeforeShow = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let items = [
- new loader.cm.Item({ label: "a" }),
- new loader.cm.Item({ label: "b" })
- ]
- items[0].label = "z";
- assert.equal(items[0].label, "z");
- test.showMenu(null, function (popup) {
- test.checkMenu(items, [], []);
- test.done();
- });
- };
- // Setting an item's label after the menu is shown should correctly change its
- // label.
- exports.testSetLabelAfterShow = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let items = [
- new loader.cm.Item({ label: "a" }),
- new loader.cm.Item({ label: "b" })
- ];
- test.showMenu(null, function (popup) {
- test.checkMenu(items, [], []);
- popup.hidePopup();
- items[0].label = "z";
- assert.equal(items[0].label, "z");
- test.showMenu(null, function (popup) {
- test.checkMenu(items, [], []);
- test.done();
- });
- });
- };
- // Setting an item's label before the menu is ever shown should correctly change
- // its label.
- exports.testSetLabelBeforeShowOverflow = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let prefs = loader.loader.require("sdk/preferences/service");
- prefs.set(OVERFLOW_THRESH_PREF, 0);
- let items = [
- new loader.cm.Item({ label: "a" }),
- new loader.cm.Item({ label: "b" })
- ]
- items[0].label = "z";
- assert.equal(items[0].label, "z");
- test.showMenu(null, function (popup) {
- test.checkMenu(items, [], []);
- test.done();
- });
- };
- // Setting an item's label after the menu is shown should correctly change its
- // label.
- exports.testSetLabelAfterShowOverflow = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let prefs = loader.loader.require("sdk/preferences/service");
- prefs.set(OVERFLOW_THRESH_PREF, 0);
- let items = [
- new loader.cm.Item({ label: "a" }),
- new loader.cm.Item({ label: "b" })
- ];
- test.showMenu(null, function (popup) {
- test.checkMenu(items, [], []);
- popup.hidePopup();
- items[0].label = "z";
- assert.equal(items[0].label, "z");
- test.showMenu(null, function (popup) {
- test.checkMenu(items, [], []);
- test.done();
- });
- });
- };
- // Setting the label of an item in a Menu should work.
- exports.testSetLabelMenuItem = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let menu = loader.cm.Menu({
- label: "menu",
- items: [loader.cm.Item({ label: "a" })]
- });
- menu.items[0].label = "z";
- assert.equal(menu.items[0].label, "z");
- test.showMenu(null, function (popup) {
- test.checkMenu([menu], [], []);
- test.done();
- });
- };
- // Menu.addItem() should work.
- exports.testMenuAddItem = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let menu = loader.cm.Menu({
- label: "menu",
- items: [
- loader.cm.Item({ label: "item 0" })
- ]
- });
- menu.addItem(loader.cm.Item({ label: "item 1" }));
- menu.addItem(loader.cm.Item({ label: "item 2" }));
- assert.equal(menu.items.length, 3,
- "menu should have correct number of items");
- for (let i = 0; i < 3; i++) {
- assert.equal(menu.items[i].label, "item " + i,
- "item label should be correct");
- assert.equal(menu.items[i].parentMenu, menu,
- "item's parent menu should be correct");
- }
- test.showMenu(null, function (popup) {
- test.checkMenu([menu], [], []);
- test.done();
- });
- };
- // Adding the same item twice to a menu should work as expected.
- exports.testMenuAddItemTwice = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let menu = loader.cm.Menu({
- label: "menu",
- items: []
- });
- let subitem = loader.cm.Item({ label: "item 1" })
- menu.addItem(subitem);
- menu.addItem(loader.cm.Item({ label: "item 0" }));
- menu.addItem(subitem);
- assert.equal(menu.items.length, 2,
- "menu should have correct number of items");
- for (let i = 0; i < 2; i++) {
- assert.equal(menu.items[i].label, "item " + i,
- "item label should be correct");
- }
- test.showMenu(null, function (popup) {
- test.checkMenu([menu], [], []);
- test.done();
- });
- };
- // Menu.removeItem() should work.
- exports.testMenuRemoveItem = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let subitem = loader.cm.Item({ label: "item 1" });
- let menu = loader.cm.Menu({
- label: "menu",
- items: [
- loader.cm.Item({ label: "item 0" }),
- subitem,
- loader.cm.Item({ label: "item 2" })
- ]
- });
- // Removing twice should be harmless.
- menu.removeItem(subitem);
- menu.removeItem(subitem);
- assert.equal(subitem.parentMenu, null,
- "item's parent menu should be correct");
- assert.equal(menu.items.length, 2,
- "menu should have correct number of items");
- assert.equal(menu.items[0].label, "item 0",
- "item label should be correct");
- assert.equal(menu.items[1].label, "item 2",
- "item label should be correct");
- test.showMenu(null, function (popup) {
- test.checkMenu([menu], [], []);
- test.done();
- });
- };
- // Adding an item currently contained in one menu to another menu should work.
- exports.testMenuItemSwap = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let subitem = loader.cm.Item({ label: "item" });
- let menu0 = loader.cm.Menu({
- label: "menu 0",
- items: [subitem]
- });
- let menu1 = loader.cm.Menu({
- label: "menu 1",
- items: []
- });
- menu1.addItem(subitem);
- assert.equal(menu0.items.length, 0,
- "menu should have correct number of items");
- assert.equal(menu1.items.length, 1,
- "menu should have correct number of items");
- assert.equal(menu1.items[0].label, "item",
- "item label should be correct");
- assert.equal(subitem.parentMenu, menu1,
- "item's parent menu should be correct");
- test.showMenu(null, function (popup) {
- test.checkMenu([menu0, menu1], [menu0], []);
- test.done();
- });
- };
- // Destroying an item should remove it from its parent menu.
- exports.testMenuItemDestroy = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let subitem = loader.cm.Item({ label: "item" });
- let menu = loader.cm.Menu({
- label: "menu",
- items: [subitem]
- });
- subitem.destroy();
- assert.equal(menu.items.length, 0,
- "menu should have correct number of items");
- assert.equal(subitem.parentMenu, null,
- "item's parent menu should be correct");
- test.showMenu(null, function (popup) {
- test.checkMenu([menu], [menu], []);
- test.done();
- });
- };
- // Setting Menu.items should work.
- exports.testMenuItemsSetter = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let menu = loader.cm.Menu({
- label: "menu",
- items: [
- loader.cm.Item({ label: "old item 0" }),
- loader.cm.Item({ label: "old item 1" })
- ]
- });
- menu.items = [
- loader.cm.Item({ label: "new item 0" }),
- loader.cm.Item({ label: "new item 1" }),
- loader.cm.Item({ label: "new item 2" })
- ];
- assert.equal(menu.items.length, 3,
- "menu should have correct number of items");
- for (let i = 0; i < 3; i++) {
- assert.equal(menu.items[i].label, "new item " + i,
- "item label should be correct");
- assert.equal(menu.items[i].parentMenu, menu,
- "item's parent menu should be correct");
- }
- test.showMenu(null, function (popup) {
- test.checkMenu([menu], [], []);
- test.done();
- });
- };
- // Setting Item.data should work.
- exports.testItemDataSetter = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let item = loader.cm.Item({ label: "old item 0", data: "old" });
- item.data = "new";
- assert.equal(item.data, "new", "item should have correct data");
- test.showMenu(null, function (popup) {
- test.checkMenu([item], [], []);
- test.done();
- });
- };
- // Open the test doc, load the module, make sure items appear when context-
- // clicking the iframe.
- exports.testAlreadyOpenIframe = function (assert, done) {
- let test = new TestHelper(assert, done);
- test.withTestDoc(function (window, doc) {
- let loader = test.newLoader();
- let item = new loader.cm.Item({
- label: "item"
- });
- test.showMenu(doc.getElementById("iframe"), function (popup) {
- test.checkMenu([item], [], []);
- test.done();
- });
- });
- };
- // Tests that a missing label throws an exception
- exports.testItemNoLabel = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- try {
- new loader.cm.Item({});
- assert.ok(false, "Should have seen exception");
- }
- catch (e) {
- assert.ok(true, "Should have seen exception");
- }
- try {
- new loader.cm.Item({ label: null });
- assert.ok(false, "Should have seen exception");
- }
- catch (e) {
- assert.ok(true, "Should have seen exception");
- }
- try {
- new loader.cm.Item({ label: undefined });
- assert.ok(false, "Should have seen exception");
- }
- catch (e) {
- assert.ok(true, "Should have seen exception");
- }
- try {
- new loader.cm.Item({ label: "" });
- assert.ok(false, "Should have seen exception");
- }
- catch (e) {
- assert.ok(true, "Should have seen exception");
- }
- test.done();
- }
- // Tests that items can have an empty data property
- exports.testItemNoData = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- function checkData(data) {
- assert.equal(data, undefined, "Data should be undefined");
- }
- let item1 = new loader.cm.Item({
- label: "item 1",
- contentScript: 'self.on("click", function(node, data) self.postMessage(data))',
- onMessage: checkData
- });
- let item2 = new loader.cm.Item({
- label: "item 2",
- data: null,
- contentScript: 'self.on("click", function(node, data) self.postMessage(data))',
- onMessage: checkData
- });
- let item3 = new loader.cm.Item({
- label: "item 3",
- data: undefined,
- contentScript: 'self.on("click", function(node, data) self.postMessage(data))',
- onMessage: checkData
- });
- assert.equal(item1.data, undefined, "Should be no defined data");
- assert.equal(item2.data, null, "Should be no defined data");
- assert.equal(item3.data, undefined, "Should be no defined data");
- test.showMenu(null, function (popup) {
- test.checkMenu([item1, item2, item3], [], []);
- let itemElt = test.getItemElt(popup, item1);
- itemElt.click();
- test.hideMenu(function() {
- test.showMenu(null, function (popup) {
- let itemElt = test.getItemElt(popup, item2);
- itemElt.click();
- test.hideMenu(function() {
- test.showMenu(null, function (popup) {
- let itemElt = test.getItemElt(popup, item3);
- itemElt.click();
- test.done();
- });
- });
- });
- });
- });
- }
- // Tests that items without an image don't attempt to show one
- exports.testItemNoImage = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let item1 = new loader.cm.Item({ label: "item 1" });
- let item2 = new loader.cm.Item({ label: "item 2", image: null });
- let item3 = new loader.cm.Item({ label: "item 3", image: undefined });
- assert.equal(item1.image, undefined, "Should be no defined image");
- assert.equal(item2.image, null, "Should be no defined image");
- assert.equal(item3.image, undefined, "Should be no defined image");
- test.showMenu(null, function (popup) {
- test.checkMenu([item1, item2, item3], [], []);
- test.done();
- });
- }
- // Test image support.
- exports.testItemImage = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let imageURL = data.url("moz_favicon.ico");
- let item = new loader.cm.Item({ label: "item", image: imageURL });
- let menu = new loader.cm.Menu({ label: "menu", image: imageURL, items: [
- loader.cm.Item({ label: "subitem" })
- ]});
- assert.equal(item.image, imageURL, "Should have set the image correctly");
- assert.equal(menu.image, imageURL, "Should have set the image correctly");
- test.showMenu(null, function (popup) {
- test.checkMenu([item, menu], [], []);
- let imageURL2 = data.url("dummy.ico");
- item.image = imageURL2;
- menu.image = imageURL2;
- assert.equal(item.image, imageURL2, "Should have set the image correctly");
- assert.equal(menu.image, imageURL2, "Should have set the image correctly");
- test.checkMenu([item, menu], [], []);
- item.image = null;
- menu.image = null;
- assert.equal(item.image, null, "Should have set the image correctly");
- assert.equal(menu.image, null, "Should have set the image correctly");
- test.checkMenu([item, menu], [], []);
- test.done();
- });
- };
- // Test image URL validation.
- exports.testItemImageValidURL = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- assert.throws(function(){
- new loader.cm.Item({
- label: "item 1",
- image: "foo"
- })
- }, /Image URL validation failed/
- );
- assert.throws(function(){
- new loader.cm.Item({
- label: "item 2",
- image: false
- })
- }, /Image URL validation failed/
- );
- assert.throws(function(){
- new loader.cm.Item({
- label: "item 3",
- image: 0
- })
- }, /Image URL validation failed/
- );
- let imageURL = data.url("moz_favicon.ico");
- let item4 = new loader.cm.Item({ label: "item 4", image: imageURL });
- let item5 = new loader.cm.Item({ label: "item 5", image: null });
- let item6 = new loader.cm.Item({ label: "item 6", image: undefined });
- assert.equal(item4.image, imageURL, "Should be proper image URL");
- assert.equal(item5.image, null, "Should be null image");
- assert.equal(item6.image, undefined, "Should be undefined image");
- test.done();
- };
- // Menu.destroy should destroy the item tree rooted at that menu.
- exports.testMenuDestroy = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let menu = loader.cm.Menu({
- label: "menu",
- items: [
- loader.cm.Item({ label: "item 0" }),
- loader.cm.Menu({
- label: "item 1",
- items: [
- loader.cm.Item({ label: "subitem 0" }),
- loader.cm.Item({ label: "subitem 1" }),
- loader.cm.Item({ label: "subitem 2" })
- ]
- }),
- loader.cm.Item({ label: "item 2" })
- ]
- });
- menu.destroy();
- /*let numRegistryEntries = 0;
- loader.globalScope.browserManager.browserWins.forEach(function (bwin) {
- for (let itemID in bwin.items)
- numRegistryEntries++;
- });
- assert.equal(numRegistryEntries, 0, "All items should be unregistered.");*/
- test.showMenu(null, function (popup) {
- test.checkMenu([menu], [], [menu]);
- test.done();
- });
- };
- // Checks that if a menu contains sub items that are hidden then the menu is
- // hidden too. Also checks that content scripts and contexts work for sub items.
- exports.testSubItemContextNoMatchHideMenu = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let items = [
- loader.cm.Menu({
- label: "menu 1",
- items: [
- loader.cm.Item({
- label: "subitem 1",
- context: loader.cm.SelectorContext(".foo")
- })
- ]
- }),
- loader.cm.Menu({
- label: "menu 2",
- items: [
- loader.cm.Item({
- label: "subitem 2",
- contentScript: 'self.on("context", function () false);'
- })
- ]
- }),
- loader.cm.Menu({
- label: "menu 3",
- items: [
- loader.cm.Item({
- label: "subitem 3",
- context: loader.cm.SelectorContext(".foo")
- }),
- loader.cm.Item({
- label: "subitem 4",
- contentScript: 'self.on("context", function () false);'
- })
- ]
- })
- ];
- test.showMenu(null, function (popup) {
- test.checkMenu(items, items, []);
- test.done();
- });
- };
- // Checks that if a menu contains a combination of hidden and visible sub items
- // then the menu is still visible too.
- exports.testSubItemContextMatch = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let hiddenItems = [
- loader.cm.Item({
- label: "subitem 3",
- context: loader.cm.SelectorContext(".foo")
- }),
- loader.cm.Item({
- label: "subitem 6",
- contentScript: 'self.on("context", function () false);'
- })
- ];
- let items = [
- loader.cm.Menu({
- label: "menu 1",
- items: [
- loader.cm.Item({
- label: "subitem 1",
- context: loader.cm.URLContext(TEST_DOC_URL)
- })
- ]
- }),
- loader.cm.Menu({
- label: "menu 2",
- items: [
- loader.cm.Item({
- label: "subitem 2",
- contentScript: 'self.on("context", function () true);'
- })
- ]
- }),
- loader.cm.Menu({
- label: "menu 3",
- items: [
- hiddenItems[0],
- loader.cm.Item({
- label: "subitem 4",
- contentScript: 'self.on("context", function () true);'
- })
- ]
- }),
- loader.cm.Menu({
- label: "menu 4",
- items: [
- loader.cm.Item({
- label: "subitem 5",
- context: loader.cm.URLContext(TEST_DOC_URL)
- }),
- hiddenItems[1]
- ]
- }),
- loader.cm.Menu({
- label: "menu 5",
- items: [
- loader.cm.Item({
- label: "subitem 7",
- context: loader.cm.URLContext(TEST_DOC_URL)
- }),
- loader.cm.Item({
- label: "subitem 8",
- contentScript: 'self.on("context", function () true);'
- })
- ]
- })
- ];
- test.withTestDoc(function (window, doc) {
- test.showMenu(null, function (popup) {
- test.checkMenu(items, hiddenItems, []);
- test.done();
- });
- });
- };
- // Child items should default to visible, not to PageContext
- exports.testSubItemDefaultVisible = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let items = [
- loader.cm.Menu({
- label: "menu 1",
- context: loader.cm.SelectorContext("img"),
- items: [
- loader.cm.Item({
- label: "subitem 1"
- }),
- loader.cm.Item({
- label: "subitem 2",
- context: loader.cm.SelectorContext("img")
- }),
- loader.cm.Item({
- label: "subitem 3",
- context: loader.cm.SelectorContext("a")
- })
- ]
- })
- ];
- // subitem 3 will be hidden
- let hiddenItems = [items[0].items[2]];
- test.withTestDoc(function (window, doc) {
- test.showMenu(doc.getElementById("image"), function (popup) {
- test.checkMenu(items, hiddenItems, []);
- test.done();
- });
- });
- };
- // Tests that the click event on sub menuitem
- // tiggers the click event for the sub menuitem and the parent menu
- exports.testSubItemClick = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let state = 0;
- let items = [
- loader.cm.Menu({
- label: "menu 1",
- items: [
- loader.cm.Item({
- label: "subitem 1",
- data: "foobar",
- contentScript: 'self.on("click", function (node, data) {' +
- ' self.postMessage({' +
- ' tagName: node.tagName,' +
- ' data: data' +
- ' });' +
- '});',
- onMessage: function(msg) {
- assert.equal(msg.tagName, "HTML", "should have seen the right node");
- assert.equal(msg.data, "foobar", "should have seen the right data");
- assert.equal(state, 0, "should have seen the event at the right time");
- state++;
- }
- })
- ],
- contentScript: 'self.on("click", function (node, data) {' +
- ' self.postMessage({' +
- ' tagName: node.tagName,' +
- ' data: data' +
- ' });' +
- '});',
- onMessage: function(msg) {
- assert.equal(msg.tagName, "HTML", "should have seen the right node");
- assert.equal(msg.data, "foobar", "should have seen the right data");
- assert.equal(state, 1, "should have seen the event at the right time");
- test.done();
- }
- })
- ];
- test.withTestDoc(function (window, doc) {
- test.showMenu(null, function (popup) {
- test.checkMenu(items, [], []);
- let topMenuElt = test.getItemElt(popup, items[0]);
- let topMenuPopup = topMenuElt.firstChild;
- let itemElt = test.getItemElt(topMenuPopup, items[0].items[0]);
- itemElt.click();
- });
- });
- };
- // Tests that the command event on sub menuitem
- // tiggers the click event for the sub menuitem and the parent menu
- exports.testSubItemCommand = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let state = 0;
- let items = [
- loader.cm.Menu({
- label: "menu 1",
- items: [
- loader.cm.Item({
- label: "subitem 1",
- data: "foobar",
- contentScript: 'self.on("click", function (node, data) {' +
- ' self.postMessage({' +
- ' tagName: node.tagName,' +
- ' data: data' +
- ' });' +
- '});',
- onMessage: function(msg) {
- assert.equal(msg.tagName, "HTML", "should have seen the right node");
- assert.equal(msg.data, "foobar", "should have seen the right data");
- assert.equal(state, 0, "should have seen the event at the right time");
- state++;
- }
- })
- ],
- contentScript: 'self.on("click", function (node, data) {' +
- ' self.postMessage({' +
- ' tagName: node.tagName,' +
- ' data: data' +
- ' });' +
- '});',
- onMessage: function(msg) {
- assert.equal(msg.tagName, "HTML", "should have seen the right node");
- assert.equal(msg.data, "foobar", "should have seen the right data");
- assert.equal(state, 1, "should have seen the event at the right time");
- state++
- test.done();
- }
- })
- ];
- test.withTestDoc(function (window, doc) {
- test.showMenu(null, function (popup) {
- test.checkMenu(items, [], []);
- let topMenuElt = test.getItemElt(popup, items[0]);
- let topMenuPopup = topMenuElt.firstChild;
- let itemElt = test.getItemElt(topMenuPopup, items[0].items[0]);
- // create a command event
- let evt = itemElt.ownerDocument.createEvent('Event');
- evt.initEvent('command', true, true);
- itemElt.dispatchEvent(evt);
- });
- });
- };
- // Tests that opening a context menu for an outer frame when an inner frame
- // has a selection doesn't activate the SelectionContext
- exports.testSelectionInInnerFrameNoMatch = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let state = 0;
- let items = [
- loader.cm.Item({
- label: "test item",
- context: loader.cm.SelectionContext()
- })
- ];
- test.withTestDoc(function (window, doc) {
- let frame = doc.getElementById("iframe");
- frame.contentWindow.getSelection().selectAllChildren(frame.contentDocument.body);
- test.showMenu(null, function (popup) {
- test.checkMenu(items, items, []);
- test.done();
- });
- });
- };
- // Tests that opening a context menu for an inner frame when the inner frame
- // has a selection does activate the SelectionContext
- exports.testSelectionInInnerFrameMatch = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let state = 0;
- let items = [
- loader.cm.Item({
- label: "test item",
- context: loader.cm.SelectionContext()
- })
- ];
- test.withTestDoc(function (window, doc) {
- let frame = doc.getElementById("iframe");
- frame.contentWindow.getSelection().selectAllChildren(frame.contentDocument.body);
- test.showMenu(frame.contentDocument.getElementById("text"), function (popup) {
- test.checkMenu(items, [], []);
- test.done();
- });
- });
- };
- // Tests that opening a context menu for an inner frame when the outer frame
- // has a selection doesn't activate the SelectionContext
- exports.testSelectionInOuterFrameNoMatch = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let state = 0;
- let items = [
- loader.cm.Item({
- label: "test item",
- context: loader.cm.SelectionContext()
- })
- ];
- test.withTestDoc(function (window, doc) {
- let frame = doc.getElementById("iframe");
- window.getSelection().selectAllChildren(doc.body);
- test.showMenu(frame.contentDocument.getElementById("text"), function (popup) {
- test.checkMenu(items, items, []);
- test.done();
- });
- });
- };
- // Test that the return value of the predicate function determines if
- // item is shown
- exports.testPredicateContextControl = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let itemTrue = loader.cm.Item({
- label: "visible",
- context: loader.cm.PredicateContext(function () { return true; })
- });
- let itemFalse = loader.cm.Item({
- label: "hidden",
- context: loader.cm.PredicateContext(function () { return false; })
- });
- test.showMenu(null, function (popup) {
- test.checkMenu([itemTrue, itemFalse], [itemFalse], []);
- test.done();
- });
- };
- // Test that the data object has the correct document type
- exports.testPredicateContextDocumentType = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let items = [loader.cm.Item({
- label: "item",
- context: loader.cm.PredicateContext(function (data) {
- assert.equal(data.documentType, 'text/html');
- return true;
- })
- })];
- test.withTestDoc(function (window, doc) {
- test.showMenu(null, function (popup) {
- test.checkMenu(items, [], []);
- test.done();
- });
- });
- };
- // Test that the data object has the correct document URL
- exports.testPredicateContextDocumentURL = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let items = [loader.cm.Item({
- label: "item",
- context: loader.cm.PredicateContext(function (data) {
- assert.equal(data.documentURL, TEST_DOC_URL);
- return true;
- })
- })];
- test.withTestDoc(function (window, doc) {
- test.showMenu(null, function (popup) {
- test.checkMenu(items, [], []);
- test.done();
- });
- });
- };
- // Test that the data object has the correct element name
- exports.testPredicateContextTargetName = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let items = [loader.cm.Item({
- label: "item",
- context: loader.cm.PredicateContext(function (data) {
- assert.strictEqual(data.targetName, "input");
- return true;
- })
- })];
- test.withTestDoc(function (window, doc) {
- test.showMenu(doc.getElementById("button"), function (popup) {
- test.checkMenu(items, [], []);
- test.done();
- });
- });
- };
- // Test that the data object has the correct ID
- exports.testPredicateContextTargetIDSet = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let items = [loader.cm.Item({
- label: "item",
- context: loader.cm.PredicateContext(function (data) {
- assert.strictEqual(data.targetID, "button");
- return true;
- })
- })];
- test.withTestDoc(function (window, doc) {
- test.showMenu(doc.getElementById("button"), function (popup) {
- test.checkMenu(items, [], []);
- test.done();
- });
- });
- };
- // Test that the data object has the correct ID
- exports.testPredicateContextTargetIDNotSet = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let items = [loader.cm.Item({
- label: "item",
- context: loader.cm.PredicateContext(function (data) {
- assert.strictEqual(data.targetID, null);
- return true;
- })
- })];
- test.withTestDoc(function (window, doc) {
- test.showMenu(doc.getElementsByClassName("predicate-test-a")[0], function (popup) {
- test.checkMenu(items, [], []);
- test.done();
- });
- });
- };
- // Test that the data object is showing editable correctly for regular text inputs
- exports.testPredicateContextTextBoxIsEditable = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let items = [loader.cm.Item({
- label: "item",
- context: loader.cm.PredicateContext(function (data) {
- assert.strictEqual(data.isEditable, true);
- return true;
- })
- })];
- test.withTestDoc(function (window, doc) {
- test.showMenu(doc.getElementById("textbox"), function (popup) {
- test.checkMenu(items, [], []);
- test.done();
- });
- });
- };
- // Test that the data object is showing editable correctly for readonly text inputs
- exports.testPredicateContextReadonlyTextBoxIsNotEditable = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let items = [loader.cm.Item({
- label: "item",
- context: loader.cm.PredicateContext(function (data) {
- assert.strictEqual(data.isEditable, false);
- return true;
- })
- })];
- test.withTestDoc(function (window, doc) {
- test.showMenu(doc.getElementById("readonly-textbox"), function (popup) {
- test.checkMenu(items, [], []);
- test.done();
- });
- });
- };
- // Test that the data object is showing editable correctly for disabled text inputs
- exports.testPredicateContextDisabledTextBoxIsNotEditable = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let items = [loader.cm.Item({
- label: "item",
- context: loader.cm.PredicateContext(function (data) {
- assert.strictEqual(data.isEditable, false);
- return true;
- })
- })];
- test.withTestDoc(function (window, doc) {
- test.showMenu(doc.getElementById("disabled-textbox"), function (popup) {
- test.checkMenu(items, [], []);
- test.done();
- });
- });
- };
- // Test that the data object is showing editable correctly for text areas
- exports.testPredicateContextTextAreaIsEditable = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let items = [loader.cm.Item({
- label: "item",
- context: loader.cm.PredicateContext(function (data) {
- assert.strictEqual(data.isEditable, true);
- return true;
- })
- })];
- test.withTestDoc(function (window, doc) {
- test.showMenu(doc.getElementById("textfield"), function (popup) {
- test.checkMenu(items, [], []);
- test.done();
- });
- });
- };
- // Test that non-text inputs are not considered editable
- exports.testPredicateContextButtonIsNotEditable = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let items = [loader.cm.Item({
- label: "item",
- context: loader.cm.PredicateContext(function (data) {
- assert.strictEqual(data.isEditable, false);
- return true;
- })
- })];
- test.withTestDoc(function (window, doc) {
- test.showMenu(doc.getElementById("button"), function (popup) {
- test.checkMenu(items, [], []);
- test.done();
- });
- });
- };
- // Test that the data object is showing editable correctly
- exports.testPredicateContextNonInputIsNotEditable = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let items = [loader.cm.Item({
- label: "item",
- context: loader.cm.PredicateContext(function (data) {
- assert.strictEqual(data.isEditable, false);
- return true;
- })
- })];
- test.withTestDoc(function (window, doc) {
- test.showMenu(doc.getElementById("image"), function (popup) {
- test.checkMenu(items, [], []);
- test.done();
- });
- });
- };
- // Test that the data object is showing editable correctly for HTML contenteditable elements
- exports.testPredicateContextEditableElement = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let items = [loader.cm.Item({
- label: "item",
- context: loader.cm.PredicateContext(function (data) {
- assert.strictEqual(data.isEditable, true);
- return true;
- })
- })];
- test.withTestDoc(function (window, doc) {
- test.showMenu(doc.getElementById("editable"), function (popup) {
- test.checkMenu(items, [], []);
- test.done();
- });
- });
- };
- // Test that the data object does not have a selection when there is none
- exports.testPredicateContextNoSelectionInPage = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let items = [loader.cm.Item({
- label: "item",
- context: loader.cm.PredicateContext(function (data) {
- assert.strictEqual(data.selectionText, null);
- return true;
- })
- })];
- test.withTestDoc(function (window, doc) {
- test.showMenu(null, function (popup) {
- test.checkMenu(items, [], []);
- test.done();
- });
- });
- };
- // Test that the data object includes the selected page text
- exports.testPredicateContextSelectionInPage = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let items = [loader.cm.Item({
- label: "item",
- context: loader.cm.PredicateContext(function (data) {
- // since we might get whitespace
- assert.ok(data.selectionText && data.selectionText.search(/^\s*Some text.\s*$/) != -1,
- 'Expected "Some text.", got "' + data.selectionText + '"');
- return true;
- })
- })];
- test.withTestDoc(function (window, doc) {
- window.getSelection().selectAllChildren(doc.getElementById("text"));
- test.showMenu(null, function (popup) {
- test.checkMenu(items, [], []);
- test.done();
- });
- });
- };
- // Test that the data object includes the selected input text
- exports.testPredicateContextSelectionInTextBox = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let items = [loader.cm.Item({
- label: "item",
- context: loader.cm.PredicateContext(function (data) {
- // since we might get whitespace
- assert.strictEqual(data.selectionText, "t v");
- return true;
- })
- })];
- test.withTestDoc(function (window, doc) {
- let textbox = doc.getElementById("textbox");
- textbox.focus();
- textbox.setSelectionRange(3, 6);
- test.showMenu(textbox, function (popup) {
- test.checkMenu(items, [], []);
- test.done();
- });
- });
- };
- // Test that the data object has the correct src for an image
- exports.testPredicateContextTargetSrcSet = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let image;
-
- let items = [loader.cm.Item({
- label: "item",
- context: loader.cm.PredicateContext(function (data) {
- assert.strictEqual(data.srcURL, image.src);
- return true;
- })
- })];
- test.withTestDoc(function (window, doc) {
- image = doc.getElementById("image");
- test.showMenu(image, function (popup) {
- test.checkMenu(items, [], []);
- test.done();
- });
- });
- };
- // Test that the data object has no src for a link
- exports.testPredicateContextTargetSrcNotSet = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
-
- let items = [loader.cm.Item({
- label: "item",
- context: loader.cm.PredicateContext(function (data) {
- assert.strictEqual(data.srcURL, null);
- return true;
- })
- })];
- test.withTestDoc(function (window, doc) {
- test.showMenu(doc.getElementById("link"), function (popup) {
- test.checkMenu(items, [], []);
- test.done();
- });
- });
- };
- // Test that the data object has the correct link set
- exports.testPredicateContextTargetLinkSet = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let image;
-
- let items = [loader.cm.Item({
- label: "item",
- context: loader.cm.PredicateContext(function (data) {
- assert.strictEqual(data.linkURL, TEST_DOC_URL + "#test");
- return true;
- })
- })];
- test.withTestDoc(function (window, doc) {
- test.showMenu(doc.getElementsByClassName("predicate-test-a")[0], function (popup) {
- test.checkMenu(items, [], []);
- test.done();
- });
- });
- };
- // Test that the data object has no link for an image
- exports.testPredicateContextTargetLinkNotSet = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
-
- let items = [loader.cm.Item({
- label: "item",
- context: loader.cm.PredicateContext(function (data) {
- assert.strictEqual(data.linkURL, null);
- return true;
- })
- })];
- test.withTestDoc(function (window, doc) {
- test.showMenu(doc.getElementById("image"), function (popup) {
- test.checkMenu(items, [], []);
- test.done();
- });
- });
- };
- // Test that the data object has the value for an input textbox
- exports.testPredicateContextTargetValueSet = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
- let image;
-
- let items = [loader.cm.Item({
- label: "item",
- context: loader.cm.PredicateContext(function (data) {
- assert.strictEqual(data.value, "test value");
- return true;
- })
- })];
- test.withTestDoc(function (window, doc) {
- test.showMenu(doc.getElementById("textbox"), function (popup) {
- test.checkMenu(items, [], []);
- test.done();
- });
- });
- };
- // Test that the data object has no value for an image
- exports.testPredicateContextTargetValueNotSet = function (assert, done) {
- let test = new TestHelper(assert, done);
- let loader = test.newLoader();
-
- let items = [loader.cm.Item({
- label: "item",
- context: loader.cm.PredicateContext(function (data) {
- assert.strictEqual(data.value, null);
- return true;
- })
- })];
- test.withTestDoc(function (window, doc) {
- test.showMenu(doc.getElementById("image"), function (popup) {
- test.checkMenu(items, [], []);
- test.done();
- });
- });
- };
- // NO TESTS BELOW THIS LINE! ///////////////////////////////////////////////////
- // This makes it easier to run tests by handling things like opening the menu,
- // opening new windows, making assertions, etc. Methods on |test| can be called
- // on instances of this class. Don't forget to call done() to end the test!
- // WARNING: This looks up items in popups by comparing labels, so don't give two
- // items the same label.
- function TestHelper(assert, done) {
- this.assert = assert;
- this.end = done;
- this.loaders = [];
- this.browserWindow = Cc["@mozilla.org/appshell/window-mediator;1"].
- getService(Ci.nsIWindowMediator).
- getMostRecentWindow("navigator:browser");
- this.overflowThreshValue = require("sdk/preferences/service").
- get(OVERFLOW_THRESH_PREF, OVERFLOW_THRESH_DEFAULT);
- }
- TestHelper.prototype = {
- get contextMenuPopup() {
- return this.browserWindow.document.getElementById("contentAreaContextMenu");
- },
- get contextMenuSeparator() {
- return this.browserWindow.document.querySelector("." + SEPARATOR_CLASS);
- },
- get overflowPopup() {
- return this.browserWindow.document.querySelector("." + OVERFLOW_POPUP_CLASS);
- },
- get overflowSubmenu() {
- return this.browserWindow.document.querySelector("." + OVERFLOW_MENU_CLASS);
- },
- get tabBrowser() {
- return this.browserWindow.gBrowser;
- },
- // Methods on the wrapped test can be called on this object.
- __noSuchMethod__: function (methodName, args) {
- this.assert[methodName].apply(this.assert, args);
- },
- // Asserts that elt, a DOM element representing item, looks OK.
- checkItemElt: function (elt, item) {
- let itemType = this.getItemType(item);
- switch (itemType) {
- case "Item":
- this.assert.equal(elt.localName, "menuitem",
- "Item DOM element should be a xul:menuitem");
- if (typeof(item.data) === "string") {
- this.assert.equal(elt.getAttribute("value"), item.data,
- "Item should have correct data");
- }
- break
- case "Menu":
- this.assert.equal(elt.localName, "menu",
- "Menu DOM element should be a xul:menu");
- let subPopup = elt.firstChild;
- this.assert.ok(subPopup, "xul:menu should have a child");
- this.assert.equal(subPopup.localName, "menupopup",
- "xul:menu's first child should be a menupopup");
- break;
- case "Separator":
- this.assert.equal(elt.localName, "menuseparator",
- "Separator DOM element should be a xul:menuseparator");
- break;
- }
- if (itemType === "Item" || itemType === "Menu") {
- this.assert.equal(elt.getAttribute("label"), item.label,
- "Item should have correct title");
- if (typeof(item.image) === "string") {
- this.assert.equal(elt.getAttribute("image"), item.image,
- "Item should have correct image");
- if (itemType === "Menu")
- this.assert.ok(elt.classList.contains("menu-iconic"),
- "Menus with images should have the correct class")
- else
- this.assert.ok(elt.classList.contains("menuitem-iconic"),
- "Items with images should have the correct class")
- }
- else {
- this.assert.ok(!elt.getAttribute("image"),
- "Item should not have image");
- this.assert.ok(!elt.classList.contains("menu-iconic") && !elt.classList.contains("menuitem-iconic"),
- "The iconic classes should not be present")
- }
- }
- },
- // Asserts that the context menu looks OK given the arguments. presentItems
- // are items that have been added to the menu. absentItems are items that
- // shouldn't match the current context. removedItems are items that have been
- // removed from the menu.
- checkMenu: function (presentItems, absentItems, removedItems) {
- // Count up how many top-level items there are
- let total = 0;
- for (let item of presentItems) {
- if (absentItems.indexOf(item) < 0 && removedItems.indexOf(item) < 0)
- total++;
- }
- let separator = this.contextMenuSeparator;
- if (total == 0) {
- this.assert.ok(!separator || separator.hidden,
- "separator should not be present");
- }
- else {
- this.assert.ok(separator && !separator.hidden,
- "separator should be present");
- }
- let mainNodes = this.browserWindow.document.querySelectorAll("#contentAreaContextMenu > ." + ITEM_CLASS);
- let overflowNodes = this.browserWindow.document.querySelectorAll("." + OVERFLOW_POPUP_CLASS + " > ." + ITEM_CLASS);
- this.assert.ok(mainNodes.length == 0 || overflowNodes.length == 0,
- "Should only see nodes at the top level or in overflow");
- let overflow = this.overflowSubmenu;
- if (this.shouldOverflow(total)) {
- this.assert.ok(overflow && !overflow.hidden,
- "overflow menu should be present");
- this.assert.equal(mainNodes.length, 0,
- "should be no items in the main context menu");
- }
- else {
- this.assert.ok(!overflow || overflow.hidden,
- "overflow menu should not be present");
- // When visible nodes == 0 they could be in overflow or top level
- if (total > 0) {
- this.assert.equal(overflowNodes.length, 0,
- "should be no items in the overflow context menu");
- }
- }
- // Iterate over wherever the nodes have ended up
- let nodes = mainNodes.length ? mainNodes : overflowNodes;
- this.checkNodes(nodes, presentItems, absentItems, removedItems)
- let pos = 0;
- },
- // Recurses through the item hierarchy of presentItems comparing it to the
- // node hierarchy of nodes. Any items in removedItems will be skipped (so
- // should not exist in the XUL), any items in absentItems must exist and be
- // hidden
- checkNodes: function (nodes, presentItems, absentItems, removedItems) {
- let pos = 0;
- for (let item of presentItems) {
- // Removed items shouldn't be in the list
- if (removedItems.indexOf(item) >= 0)
- continue;
- if (nodes.length <= pos) {
- this.assert.ok(false, "Not enough nodes");
- return;
- }
- let hidden = absentItems.indexOf(item) >= 0;
- this.checkItemElt(nodes[pos], item);
- this.assert.equal(nodes[pos].hidden, hidden,
- "hidden should be set correctly");
- // The contents of hidden menus doesn't matter so much
- if (!hidden && this.getItemType(item) == "Menu") {
- this.assert.equal(nodes[pos].firstChild.localName, "menupopup",
- "menu XUL should contain a menupopup");
- this.checkNodes(nodes[pos].firstChild.childNodes, item.items, absentItems, removedItems);
- }
- if (pos > 0)
- this.assert.equal(nodes[pos].previousSibling, nodes[pos - 1],
- "nodes should all be in the same group");
- pos++;
- }
- this.assert.equal(nodes.length, pos,
- "should have checked all the XUL nodes");
- },
- // Attaches an event listener to node. The listener is automatically removed
- // when it's fired (so it's assumed it will fire), and callback is called
- // after a short delay. Since the module we're testing relies on the same
- // event listeners to do its work, this is to give them a little breathing
- // room before callback runs. Inside callback |this| is this object.
- // Optionally you can pass a function to test if the event is the event you
- // want.
- delayedEventListener: function (node, event, callback, useCapture, isValid) {
- const self = this;
- node.addEventListener(event, function handler(evt) {
- if (isValid && !isValid(evt))
- return;
- node.removeEventListener(event, handler, useCapture);
- timer.setTimeout(function () {
- try {
- callback.call(self, evt);
- }
- catch (err) {
- self.assert.fail(err);
- self.end();
- }
- }, 20);
- }, useCapture);
- },
- // Call to finish the test.
- done: function () {
- const self = this;
- function commonDone() {
- this.closeTab();
- while (this.loaders.length) {
- this.loaders[0].unload();
- }
- require("sdk/preferences/service").set(OVERFLOW_THRESH_PREF, self.overflowThreshValue);
- this.end();
- }
- function closeBrowserWindow() {
- if (this.oldBrowserWindow) {
- this.delayedEventListener(this.browserWindow, "unload", commonDone,
- false);
- this.browserWindow.close();
- this.browserWindow = this.oldBrowserWindow;
- delete this.oldBrowserWindow;
- }
- else {
- commonDone.call(this);
- }
- };
- if (this.contextMenuPopup.state == "closed") {
- closeBrowserWindow.call(this);
- }
- else {
- this.delayedEventListener(this.contextMenuPopup, "popuphidden",
- function () closeBrowserWindow.call(this),
- false);
- this.contextMenuPopup.hidePopup();
- }
- },
- closeTab: function() {
- if (this.tab) {
- this.tabBrowser.removeTab(this.tab);
- this.tabBrowser.selectedTab = this.oldSelectedTab;
- this.tab = null;
- }
- },
- // Returns the DOM element in popup corresponding to item.
- // WARNING: The element is found by comparing labels, so don't give two items
- // the same label.
- getItemElt: function (popup, item) {
- let nodes = popup.childNodes;
- for (let i = nodes.length - 1; i >= 0; i--) {
- if (this.getItemType(item) === "Separator") {
- if (nodes[i].localName === "menuseparator")
- return nodes[i];
- }
- else if (nodes[i].getAttribute("label") === item.label)
- return nodes[i];
- }
- return null;
- },
- // Returns "Item", "Menu", or "Separator".
- getItemType: function (item) {
- // Could use instanceof here, but that would require accessing the loader
- // that created the item, and I don't want to A) somehow search through the
- // this.loaders list to find it, and B) assume there are any live loaders at
- // all.
- return /^\[object (Item|Menu|Separator)/.exec(item.toString())[1];
- },
- // Returns a wrapper around a new loader: { loader, cm, unload, globalScope }.
- // loader is a Cuddlefish sandboxed loader, cm is the context menu module,
- // globalScope is the context menu module's global scope, and unload is a
- // function that unloads the loader and associated resources.
- newLoader: function () {
- const self = this;
- let loader = Loader(module);
- let wrapper = {
- loader: loader,
- cm: loader.require("sdk/context-menu"),
- globalScope: loader.sandbox("sdk/context-menu"),
- unload: function () {
- loader.unload();
- let idx = self.loaders.indexOf(wrapper);
- if (idx < 0)
- throw new Error("Test error: tried to unload nonexistent loader");
- self.loaders.splice(idx, 1);
- }
- };
- this.loaders.push(wrapper);
- return wrapper;
- },
- // As above but the loader has private-browsing support enabled.
- newPrivateLoader: function() {
- let base = require("@loader/options");
- // Clone current loader's options adding the private-browsing permission
- let options = merge({}, base, {
- metadata: merge({}, base.metadata || {}, {
- permissions: merge({}, base.metadata.permissions || {}, {
- 'private-browsing': true
- })
- })
- });
- const self = this;
- let loader = Loader(module, null, options);
- let wrapper = {
- loader: loader,
- cm: loader.require("sdk/context-menu"),
- globalScope: loader.sandbox("sdk/context-menu"),
- unload: function () {
- loader.unload();
- let idx = self.loaders.indexOf(wrapper);
- if (idx < 0)
- throw new Error("Test error: tried to unload nonexistent loader");
- self.loaders.splice(idx, 1);
- }
- };
- this.loaders.push(wrapper);
- return wrapper;
- },
- // Returns true if the count crosses the overflow threshold.
- shouldOverflow: function (count) {
- return count >
- (this.loaders.length ?
- this.loaders[0].loader.require("sdk/preferences/service").
- get(OVERFLOW_THRESH_PREF, OVERFLOW_THRESH_DEFAULT) :
- OVERFLOW_THRESH_DEFAULT);
- },
- // Opens the context menu on the current page. If targetNode is null, the
- // menu is opened in the top-left corner. onShowncallback is passed the
- // popup.
- showMenu: function(targetNode, onshownCallback) {
- function sendEvent() {
- this.delayedEventListener(this.browserWindow, "popupshowing",
- function (e) {
- let popup = e.target;
- onshownCallback.call(this, popup);
- }, false);
- let rect = targetNode ?
- targetNode.getBoundingClientRect() :
- { left: 0, top: 0, width: 0, height: 0 };
- let contentWin = targetNode ? targetNode.ownerDocument.defaultView
- : this.browserWindow.content;
- contentWin.
- QueryInterface(Ci.nsIInterfaceRequestor).
- getInterface(Ci.nsIDOMWindowUtils).
- sendMouseEvent("contextmenu",
- rect.left + (rect.width / 2),
- rect.top + (rect.height / 2),
- 2, 1, 0);
- }
- // If a new tab or window has not yet been opened, open a new tab now. For
- // some reason using the tab already opened when the test starts causes
- // leaks. See bug 566351 for details.
- if (!targetNode && !this.oldSelectedTab && !this.oldBrowserWindow) {
- this.oldSelectedTab = this.tabBrowser.selectedTab;
- this.tab = this.tabBrowser.addTab("about:blank");
- let browser = this.tabBrowser.getBrowserForTab(this.tab);
- this.delayedEventListener(browser, "load", function () {
- this.tabBrowser.selectedTab = this.tab;
- sendEvent.call(this);
- }, true);
- }
- else
- sendEvent.call(this);
- },
- hideMenu: function(onhiddenCallback) {
- this.delayedEventListener(this.browserWindow, "popuphidden", onhiddenCallback);
- this.contextMenuPopup.hidePopup();
- },
- // Opens a new browser window. The window will be closed automatically when
- // done() is called.
- withNewWindow: function (onloadCallback) {
- let win = this.browserWindow.OpenBrowserWindow();
- this.delayedEventListener(win, "load", onloadCallback, true);
- this.oldBrowserWindow = this.browserWindow;
- this.browserWindow = win;
- },
- // Opens a new private browser window. The window will be closed
- // automatically when done() is called.
- withNewPrivateWindow: function (onloadCallback) {
- let win = this.browserWindow.OpenBrowserWindow({private: true});
- this.delayedEventListener(win, "load", onloadCallback, true);
- this.oldBrowserWindow = this.browserWindow;
- this.browserWindow = win;
- },
- // Opens a new tab with our test page in the current window. The tab will
- // be closed automatically when done() is called.
- withTestDoc: function (onloadCallback) {
- this.oldSelectedTab = this.tabBrowser.selectedTab;
- this.tab = this.tabBrowser.addTab(TEST_DOC_URL);
- let browser = this.tabBrowser.getBrowserForTab(this.tab);
- this.delayedEventListener(browser, "load", function () {
- this.tabBrowser.selectedTab = this.tab;
- onloadCallback.call(this, browser.contentWindow, browser.contentDocument);
- }, true, function(evt) {
- return evt.target.location == TEST_DOC_URL;
- });
- }
- };
- require('sdk/test').run(exports);
|