Best Python code snippet using slash
test_install.js
Source:test_install.js
...85 "onInstallEnded",86 ], function() {87 check_test_1(install.addon.syncGUID);88 });89 install.install();90 });91 });92 });93 });94}95function check_test_1(installSyncGUID) {96 ensure_test_completed();97 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(olda1) {98 do_check_eq(olda1, null);99 AddonManager.getAddonsWithOperationsByTypes(null, callback_soon(async function(pendingAddons) {100 do_check_eq(pendingAddons.length, 1);101 do_check_eq(pendingAddons[0].id, "addon1@tests.mozilla.org");102 let uri = NetUtil.newURI(pendingAddons[0].iconURL);103 if (uri instanceof AM_Ci.nsIJARURI) {104 let jarURI = uri.QueryInterface(AM_Ci.nsIJARURI);105 let archiveURI = jarURI.JARFile;106 let archiveFile = archiveURI.QueryInterface(AM_Ci.nsIFileURL).file;107 let zipReader = Cc["@mozilla.org/libjar/zip-reader;1"].108 createInstance(Ci.nsIZipReader);109 try {110 zipReader.open(archiveFile);111 do_check_true(zipReader.hasEntry(jarURI.JAREntry));112 } finally {113 zipReader.close();114 }115 } else {116 let iconFile = uri.QueryInterface(AM_Ci.nsIFileURL).file;117 do_check_true(iconFile.exists());118 // Make the iconFile predictably old.119 iconFile.lastModifiedTime = Date.now() - MAKE_FILE_OLD_DIFFERENCE;120 }121 // Make the pending install have a sensible date122 let updateDate = Date.now();123 let extURI = pendingAddons[0].getResourceURI("");124 let ext = extURI.QueryInterface(AM_Ci.nsIFileURL).file;125 setExtensionModifiedTime(ext, updateDate);126 // The pending add-on cannot be disabled or enabled.127 do_check_false(hasFlag(pendingAddons[0].permissions, AddonManager.PERM_CAN_ENABLE));128 do_check_false(hasFlag(pendingAddons[0].permissions, AddonManager.PERM_CAN_DISABLE));129 await promiseRestartManager();130 AddonManager.getAllInstalls(function(activeInstalls) {131 do_check_eq(activeInstalls, 0);132 AddonManager.getAddonByID("addon1@tests.mozilla.org", callback_soon(function(a1) {133 do_check_neq(a1, null);134 do_check_neq(a1.syncGUID, null);135 do_check_true(a1.syncGUID.length >= 9);136 do_check_eq(a1.syncGUID, installSyncGUID);137 do_check_eq(a1.type, "extension");138 do_check_eq(a1.version, "1.0");139 do_check_eq(a1.name, "Test 1");140 do_check_true(isExtensionInAddonsList(profileDir, a1.id));141 do_check_true(do_get_addon("test_install1").exists());142 do_check_in_crash_annotation(a1.id, a1.version);143 do_check_eq(a1.size, ADDON1_SIZE);144 do_check_false(a1.foreignInstall);145 do_check_eq(a1.sourceURI.spec,146 Services.io.newFileURI(do_get_addon("test_install1")).spec);147 let difference = a1.installDate.getTime() - updateDate;148 if (Math.abs(difference) > MAX_TIME_DIFFERENCE)149 do_throw("Add-on install time was out by " + difference + "ms");150 difference = a1.updateDate.getTime() - updateDate;151 if (Math.abs(difference) > MAX_TIME_DIFFERENCE)152 do_throw("Add-on update time was out by " + difference + "ms");153 do_check_true(a1.hasResource("install.rdf"));154 do_check_false(a1.hasResource("foo.bar"));155 let uri2 = do_get_addon_root_uri(profileDir, "addon1@tests.mozilla.org");156 do_check_eq(a1.getResourceURI("install.rdf").spec, uri2 + "install.rdf");157 do_check_eq(a1.iconURL, uri2 + "icon.png");158 do_check_eq(a1.icon64URL, uri2 + "icon64.png");159 // Ensure that extension bundle (or icon if unpacked) has updated160 // lastModifiedDate.161 let testURI = a1.getResourceURI(TEST_UNPACKED ? "icon.png" : "");162 let testFile = testURI.QueryInterface(Components.interfaces.nsIFileURL).file;163 do_check_true(testFile.exists());164 difference = testFile.lastModifiedTime - Date.now();165 do_check_true(Math.abs(difference) < MAX_TIME_DIFFERENCE);166 a1.uninstall();167 let { id, version } = a1;168 restartManager();169 do_check_not_in_crash_annotation(id, version);170 do_execute_soon(run_test_2);171 }));172 });173 }));174 });175}176// Tests that an install from a url downloads.177function run_test_2() {178 let url = "http://localhost:" + gPort + "/addons/test_install2_1.xpi";179 AddonManager.getInstallForURL(url, function(install) {180 do_check_neq(install, null);181 do_check_eq(install.version, "1.0");182 do_check_eq(install.name, "Test 2");183 do_check_eq(install.state, AddonManager.STATE_AVAILABLE);184 do_check_eq(install.iconURL, null);185 do_check_eq(install.sourceURI.spec, url);186 AddonManager.getAllInstalls(function(activeInstalls) {187 do_check_eq(activeInstalls.length, 1);188 do_check_eq(activeInstalls[0], install);189 prepare_test({}, [190 "onDownloadStarted",191 "onDownloadEnded",192 ], check_test_2);193 install.addListener({194 onDownloadProgress() {195 do_execute_soon(function() {196 Components.utils.forceGC();197 });198 }199 });200 install.install();201 });202 }, "application/x-xpinstall", null, "Test 2", null, "1.0");203}204function check_test_2(install) {205 ensure_test_completed();206 do_check_eq(install.version, "2.0");207 do_check_eq(install.name, "Real Test 2");208 do_check_eq(install.state, AddonManager.STATE_DOWNLOADED);209 do_check_eq(install.addon.install, install);210 do_check_true(hasFlag(install.addon.operationsRequiringRestart,211 AddonManager.OP_NEEDS_RESTART_INSTALL));212 do_check_eq(install.iconURL, null);213 // Pause the install here and start it again in run_test_3214 do_execute_soon(function() { run_test_3(install); });215 return false;216}217// Tests that the downloaded XPI installs ok218function run_test_3(install) {219 prepare_test({220 "addon2@tests.mozilla.org": [221 "onInstalling"222 ]223 }, [224 "onInstallStarted",225 "onInstallEnded",226 ], check_test_3);227 install.install();228}229function check_test_3(aInstall) {230 // Make the pending install have a sensible date231 let updateDate = Date.now();232 let extURI = aInstall.addon.getResourceURI("");233 let ext = extURI.QueryInterface(AM_Ci.nsIFileURL).file;234 setExtensionModifiedTime(ext, updateDate);235 ensure_test_completed();236 AddonManager.getAddonByID("addon2@tests.mozilla.org", callback_soon(async function(olda2) {237 do_check_eq(olda2, null);238 await promiseRestartManager();239 AddonManager.getAllInstalls(function(installs) {240 do_check_eq(installs, 0);241 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {242 do_check_neq(a2, null);243 do_check_neq(a2.syncGUID, null);244 do_check_eq(a2.type, "extension");245 do_check_eq(a2.version, "2.0");246 do_check_eq(a2.name, "Real Test 2");247 do_check_true(isExtensionInAddonsList(profileDir, a2.id));248 do_check_true(do_get_addon("test_install2_1").exists());249 do_check_in_crash_annotation(a2.id, a2.version);250 do_check_eq(a2.sourceURI.spec,251 "http://localhost:" + gPort + "/addons/test_install2_1.xpi");252 let difference = a2.installDate.getTime() - updateDate;253 if (Math.abs(difference) > MAX_TIME_DIFFERENCE)254 do_throw("Add-on install time was out by " + difference + "ms");255 difference = a2.updateDate.getTime() - updateDate;256 if (Math.abs(difference) > MAX_TIME_DIFFERENCE)257 do_throw("Add-on update time was out by " + difference + "ms");258 gInstallDate = a2.installDate.getTime();259 run_test_4();260 });261 });262 }));263}264// Tests that installing a new version of an existing add-on works265function run_test_4() {266 prepare_test({ }, [267 "onNewInstall"268 ]);269 let url = "http://localhost:" + gPort + "/addons/test_install2_2.xpi";270 AddonManager.getInstallForURL(url, function(install) {271 ensure_test_completed();272 do_check_neq(install, null);273 do_check_eq(install.version, "3.0");274 do_check_eq(install.name, "Test 3");275 do_check_eq(install.state, AddonManager.STATE_AVAILABLE);276 AddonManager.getAllInstalls(function(activeInstalls) {277 do_check_eq(activeInstalls.length, 1);278 do_check_eq(activeInstalls[0], install);279 do_check_eq(install.existingAddon, null);280 prepare_test({}, [281 "onDownloadStarted",282 "onDownloadEnded",283 ], check_test_4);284 install.install();285 });286 }, "application/x-xpinstall", null, "Test 3", null, "3.0");287}288function check_test_4(install) {289 ensure_test_completed();290 do_check_eq(install.version, "3.0");291 do_check_eq(install.name, "Real Test 3");292 do_check_eq(install.state, AddonManager.STATE_DOWNLOADED);293 do_check_neq(install.existingAddon);294 do_check_eq(install.existingAddon.id, "addon2@tests.mozilla.org");295 do_check_eq(install.addon.install, install);296 do_check_true(hasFlag(install.addon.operationsRequiringRestart,297 AddonManager.OP_NEEDS_RESTART_INSTALL));298 run_test_5();299 // Installation will continue when there is nothing returned.300}301// Continue installing the new version302function run_test_5() {303 prepare_test({304 "addon2@tests.mozilla.org": [305 "onInstalling"306 ]307 }, [308 "onInstallStarted",309 "onInstallEnded",310 ], check_test_5);311}312function check_test_5(install) {313 ensure_test_completed();314 do_check_eq(install.existingAddon.pendingUpgrade.install, install);315 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(olda2) {316 do_check_neq(olda2, null);317 do_check_true(hasFlag(olda2.pendingOperations, AddonManager.PENDING_UPGRADE));318 AddonManager.getInstallsByTypes(null, callback_soon(function(installs) {319 do_check_eq(installs.length, 1);320 do_check_eq(installs[0].addon, olda2.pendingUpgrade);321 restartManager();322 AddonManager.getInstallsByTypes(null, function(installs2) {323 do_check_eq(installs2.length, 0);324 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {325 do_check_neq(a2, null);326 do_check_eq(a2.type, "extension");327 do_check_eq(a2.version, "3.0");328 do_check_eq(a2.name, "Real Test 3");329 do_check_true(a2.isActive);330 do_check_true(isExtensionInAddonsList(profileDir, a2.id));331 do_check_true(do_get_addon("test_install2_2").exists());332 do_check_in_crash_annotation(a2.id, a2.version);333 do_check_eq(a2.sourceURI.spec,334 "http://localhost:" + gPort + "/addons/test_install2_2.xpi");335 do_check_false(a2.foreignInstall);336 do_check_eq(a2.installDate.getTime(), gInstallDate);337 // Update date should be later (or the same if this test is too fast)338 do_check_true(a2.installDate <= a2.updateDate);339 a2.uninstall();340 do_execute_soon(run_test_6);341 });342 });343 }));344 });345}346// Tests that an install that requires a compatibility update works347function run_test_6() {348 restartManager();349 prepare_test({ }, [350 "onNewInstall"351 ]);352 let url = "http://localhost:" + gPort + "/addons/test_install3.xpi";353 AddonManager.getInstallForURL(url, function(install) {354 ensure_test_completed();355 do_check_neq(install, null);356 do_check_eq(install.version, "1.0");357 do_check_eq(install.name, "Real Test 4");358 do_check_eq(install.state, AddonManager.STATE_AVAILABLE);359 AddonManager.getInstallsByTypes(null, function(activeInstalls) {360 do_check_eq(activeInstalls.length, 1);361 do_check_eq(activeInstalls[0], install);362 prepare_test({}, [363 "onDownloadStarted",364 "onDownloadEnded",365 ], check_test_6);366 install.install();367 });368 }, "application/x-xpinstall", null, "Real Test 4", null, "1.0");369}370function check_test_6(install) {371 ensure_test_completed();372 do_check_eq(install.version, "1.0");373 do_check_eq(install.name, "Real Test 4");374 do_check_eq(install.state, AddonManager.STATE_DOWNLOADED);375 do_check_eq(install.existingAddon, null);376 do_check_false(install.addon.appDisabled);377 run_test_7();378 return true;379}380// Continue the install381function run_test_7() {382 prepare_test({383 "addon3@tests.mozilla.org": [384 "onInstalling"385 ]386 }, [387 "onInstallStarted",388 "onInstallEnded",389 ], check_test_7);390}391function check_test_7() {392 ensure_test_completed();393 AddonManager.getAddonByID("addon3@tests.mozilla.org", callback_soon(async function(olda3) {394 do_check_eq(olda3, null);395 await promiseRestartManager();396 AddonManager.getAllInstalls(function(installs) {397 do_check_eq(installs, 0);398 AddonManager.getAddonByID("addon3@tests.mozilla.org", function(a3) {399 do_check_neq(a3, null);400 do_check_neq(a3.syncGUID, null);401 do_check_eq(a3.type, "extension");402 do_check_eq(a3.version, "1.0");403 do_check_eq(a3.name, "Real Test 4");404 do_check_true(a3.isActive);405 do_check_false(a3.appDisabled);406 do_check_true(isExtensionInAddonsList(profileDir, a3.id));407 do_check_true(do_get_addon("test_install3").exists());408 a3.uninstall();409 do_execute_soon(run_test_8);410 });411 });412 }));413}414function run_test_8() {415 restartManager();416 AddonManager.addInstallListener(InstallListener);417 AddonManager.addAddonListener(AddonListener);418 prepare_test({ }, [419 "onNewInstall"420 ]);421 AddonManager.getInstallForFile(do_get_addon("test_install3"), function(install) {422 do_check_true(install.addon.isCompatible);423 prepare_test({424 "addon3@tests.mozilla.org": [425 "onInstalling"426 ]427 }, [428 "onInstallStarted",429 "onInstallEnded",430 ], callback_soon(check_test_8));431 install.install();432 });433}434async function check_test_8() {435 await promiseRestartManager();436 AddonManager.getAddonByID("addon3@tests.mozilla.org", function(a3) {437 do_check_neq(a3, null);438 do_check_neq(a3.syncGUID, null);439 do_check_eq(a3.type, "extension");440 do_check_eq(a3.version, "1.0");441 do_check_eq(a3.name, "Real Test 4");442 do_check_true(a3.isActive);443 do_check_false(a3.appDisabled);444 do_check_true(isExtensionInAddonsList(profileDir, a3.id));445 do_check_true(do_get_addon("test_install3").exists());446 a3.uninstall();447 do_execute_soon(run_test_9);448 });449}450// Test that after cancelling a download it is removed from the active installs451function run_test_9() {452 restartManager();453 prepare_test({ }, [454 "onNewInstall"455 ]);456 let url = "http://localhost:" + gPort + "/addons/test_install3.xpi";457 AddonManager.getInstallForURL(url, function(install) {458 ensure_test_completed();459 do_check_neq(install, null);460 do_check_eq(install.version, "1.0");461 do_check_eq(install.name, "Real Test 4");462 do_check_eq(install.state, AddonManager.STATE_AVAILABLE);463 AddonManager.getInstallsByTypes(null, function(activeInstalls) {464 do_check_eq(activeInstalls.length, 1);465 do_check_eq(activeInstalls[0], install);466 prepare_test({}, [467 "onDownloadStarted",468 "onDownloadEnded",469 ], check_test_9);470 install.install();471 });472 }, "application/x-xpinstall", null, "Real Test 4", null, "1.0");473}474function check_test_9(install) {475 prepare_test({}, [476 "onDownloadCancelled"477 ], function() {478 let file = install.file;479 // Allow the file removal to complete480 do_execute_soon(function() {481 AddonManager.getAllInstalls(function(activeInstalls) {482 do_check_eq(activeInstalls.length, 0);483 do_check_false(file.exists());484 run_test_10();485 });486 });487 });488 install.cancel();489}490// Tests that after cancelling a pending install it is removed from the active491// installs492function run_test_10() {493 prepare_test({ }, [494 "onNewInstall"495 ]);496 let url = "http://localhost:" + gPort + "/addons/test_install3.xpi";497 AddonManager.getInstallForURL(url, function(install) {498 ensure_test_completed();499 do_check_neq(install, null);500 do_check_eq(install.version, "1.0");501 do_check_eq(install.name, "Real Test 4");502 do_check_eq(install.state, AddonManager.STATE_AVAILABLE);503 AddonManager.getInstallsByTypes(null, function(activeInstalls) {504 do_check_eq(activeInstalls.length, 1);505 do_check_eq(activeInstalls[0], install);506 prepare_test({507 "addon3@tests.mozilla.org": [508 "onInstalling"509 ]510 }, [511 "onDownloadStarted",512 "onDownloadEnded",513 "onInstallStarted",514 "onInstallEnded"515 ], check_test_10);516 install.install();517 });518 }, "application/x-xpinstall", null, "Real Test 4", null, "1.0");519}520function check_test_10(install) {521 prepare_test({522 "addon3@tests.mozilla.org": [523 "onOperationCancelled"524 ]525 }, [526 "onInstallCancelled"527 ]);528 install.cancel();529 ensure_test_completed();530 AddonManager.getAllInstalls(callback_soon(function(activeInstalls) {531 do_check_eq(activeInstalls.length, 0);532 restartManager();533 // Check that the install did not complete534 AddonManager.getAddonByID("addon3@tests.mozilla.org", function(a3) {535 do_check_eq(a3, null);536 do_execute_soon(run_test_11);537 });538 }));539}540function run_test_11() {541 // Tests 11 and 12 were removed, to avoid churn of renumbering,542 // just jump ahead to 13 here543 run_test_13();544}545// Tests that cancelling an upgrade leaves the original add-on's pendingOperations546// correct547function run_test_13() {548 restartManager();549 installAllFiles([do_get_addon("test_install2_1")], function() {550 restartManager();551 prepare_test({ }, [552 "onNewInstall"553 ]);554 let url = "http://localhost:" + gPort + "/addons/test_install2_2.xpi";555 AddonManager.getInstallForURL(url, function(install) {556 ensure_test_completed();557 do_check_neq(install, null);558 do_check_eq(install.version, "3.0");559 do_check_eq(install.name, "Test 3");560 do_check_eq(install.state, AddonManager.STATE_AVAILABLE);561 AddonManager.getAllInstalls(function(activeInstalls) {562 do_check_eq(activeInstalls.length, 1);563 do_check_eq(activeInstalls[0], install);564 do_check_eq(install.existingAddon, null);565 prepare_test({566 "addon2@tests.mozilla.org": [567 "onInstalling"568 ]569 }, [570 "onDownloadStarted",571 "onDownloadEnded",572 "onInstallStarted",573 "onInstallEnded",574 ], check_test_13);575 install.install();576 });577 }, "application/x-xpinstall", null, "Test 3", null, "3.0");578 });579}580function check_test_13(install) {581 ensure_test_completed();582 do_check_eq(install.version, "3.0");583 do_check_eq(install.name, "Real Test 3");584 do_check_eq(install.state, AddonManager.STATE_INSTALLED);585 do_check_neq(install.existingAddon, null);586 do_check_eq(install.existingAddon.id, "addon2@tests.mozilla.org");587 do_check_eq(install.addon.install, install);588 AddonManager.getAddonByID("addon2@tests.mozilla.org", callback_soon(function(olda2) {589 do_check_neq(olda2, null);590 do_check_true(hasFlag(olda2.pendingOperations, AddonManager.PENDING_UPGRADE));591 do_check_eq(olda2.pendingUpgrade, install.addon);592 do_check_true(hasFlag(install.addon.pendingOperations,593 AddonManager.PENDING_INSTALL));594 prepare_test({595 "addon2@tests.mozilla.org": [596 "onOperationCancelled"597 ]598 }, [599 "onInstallCancelled",600 ]);601 install.cancel();602 do_check_false(hasFlag(install.addon.pendingOperations, AddonManager.PENDING_INSTALL));603 do_check_false(hasFlag(olda2.pendingOperations, AddonManager.PENDING_UPGRADE));604 do_check_eq(olda2.pendingUpgrade, null);605 restartManager();606 // Check that the upgrade did not complete607 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {608 do_check_eq(a2.version, "2.0");609 a2.uninstall();610 do_execute_soon(run_test_14);611 });612 }));613}614// Check that cancelling the install from onDownloadStarted actually cancels it615function run_test_14() {616 restartManager();617 prepare_test({ }, [618 "onNewInstall"619 ]);620 let url = "http://localhost:" + gPort + "/addons/test_install2_1.xpi";621 AddonManager.getInstallForURL(url, function(install) {622 ensure_test_completed();623 do_check_eq(install.file, null);624 prepare_test({ }, [625 "onDownloadStarted"626 ], check_test_14);627 install.install();628 }, "application/x-xpinstall");629}630function check_test_14(install) {631 prepare_test({ }, [632 "onDownloadCancelled"633 ], function() {634 let file = install.file;635 install.addListener({636 onDownloadProgress() {637 do_throw("Download should not have continued");638 },639 onDownloadEnded() {640 do_throw("Download should not have continued");641 }642 });643 // Allow the listener to return to see if it continues downloading. The644 // The listener only really tests if we give it time to see progress, the645 // file check isn't ideal either646 do_execute_soon(function() {647 do_check_false(file.exists());648 run_test_15();649 });650 });651 // Wait for the channel to be ready to cancel652 do_execute_soon(function() {653 install.cancel();654 });655}656// Checks that cancelling the install from onDownloadEnded actually cancels it657function run_test_15() {658 prepare_test({ }, [659 "onNewInstall"660 ]);661 let url = "http://localhost:" + gPort + "/addons/test_install2_1.xpi";662 AddonManager.getInstallForURL(url, function(install) {663 ensure_test_completed();664 do_check_eq(install.file, null);665 prepare_test({ }, [666 "onDownloadStarted",667 "onDownloadEnded"668 ], check_test_15);669 install.install();670 }, "application/x-xpinstall");671}672function check_test_15(install) {673 prepare_test({ }, [674 "onDownloadCancelled"675 ]);676 install.cancel();677 ensure_test_completed();678 install.addListener({679 onInstallStarted() {680 do_throw("Install should not have continued");681 }682 });683 // Allow the listener to return to see if it starts installing684 do_execute_soon(run_test_16);685}686// Verify that the userDisabled value carries over to the upgrade by default687function run_test_16() {688 restartManager();689 let url = "http://localhost:" + gPort + "/addons/test_install2_1.xpi";690 AddonManager.getInstallForURL(url, function(aInstall) {691 aInstall.addListener({692 onInstallStarted() {693 do_check_false(aInstall.addon.userDisabled);694 aInstall.addon.userDisabled = true;695 },696 onInstallEnded() {697 do_execute_soon(function install2_1_ended() {698 restartManager();699 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {700 do_check_true(a2.userDisabled);701 do_check_false(a2.isActive);702 let url_2 = "http://localhost:" + gPort + "/addons/test_install2_2.xpi";703 AddonManager.getInstallForURL(url_2, function(aInstall_2) {704 aInstall_2.addListener({705 onInstallEnded() {706 do_execute_soon(function install2_2_ended() {707 do_check_true(aInstall_2.addon.userDisabled);708 restartManager();709 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2_2) {710 do_check_true(a2_2.userDisabled);711 do_check_false(a2_2.isActive);712 a2_2.uninstall();713 do_execute_soon(run_test_17);714 });715 });716 }717 });718 aInstall_2.install();719 }, "application/x-xpinstall");720 });721 });722 }723 });724 aInstall.install();725 }, "application/x-xpinstall");726}727// Verify that changing the userDisabled value before onInstallEnded works728function run_test_17() {729 restartManager();730 let url = "http://localhost:" + gPort + "/addons/test_install2_1.xpi";731 AddonManager.getInstallForURL(url, function(aInstall) {732 aInstall.addListener({733 onInstallEnded() {734 do_execute_soon(function install2_1_ended2() {735 do_check_false(aInstall.addon.userDisabled);736 restartManager();737 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {738 do_check_false(a2.userDisabled);739 do_check_true(a2.isActive);740 let url_2 = "http://localhost:" + gPort + "/addons/test_install2_2.xpi";741 AddonManager.getInstallForURL(url_2, function(aInstall_2) {742 aInstall_2.addListener({743 onInstallStarted() {744 do_check_false(aInstall_2.addon.userDisabled);745 aInstall_2.addon.userDisabled = true;746 },747 onInstallEnded() {748 do_execute_soon(function install2_2_ended2() {749 restartManager();750 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2_2) {751 do_check_true(a2_2.userDisabled);752 do_check_false(a2_2.isActive);753 a2_2.uninstall();754 do_execute_soon(run_test_18);755 });756 });757 }758 });759 aInstall_2.install();760 }, "application/x-xpinstall");761 });762 });763 }764 });765 aInstall.install();766 }, "application/x-xpinstall");767}768// Verify that changing the userDisabled value before onInstallEnded works769function run_test_18() {770 restartManager();771 let url = "http://localhost:" + gPort + "/addons/test_install2_1.xpi";772 AddonManager.getInstallForURL(url, function(aInstall) {773 aInstall.addListener({774 onInstallStarted() {775 do_check_false(aInstall.addon.userDisabled);776 aInstall.addon.userDisabled = true;777 },778 onInstallEnded() {779 do_execute_soon(function install_2_1_ended3() {780 restartManager();781 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {782 do_check_true(a2.userDisabled);783 do_check_false(a2.isActive);784 let url_2 = "http://localhost:" + gPort + "/addons/test_install2_2.xpi";785 AddonManager.getInstallForURL(url_2, function(aInstall_2) {786 aInstall_2.addListener({787 onInstallStarted() {788 do_check_true(aInstall_2.addon.userDisabled);789 aInstall_2.addon.userDisabled = false;790 },791 onInstallEnded() {792 do_execute_soon(function install_2_2_ended3() {793 restartManager();794 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2_2) {795 do_check_false(a2_2.userDisabled);796 do_check_true(a2_2.isActive);797 a2_2.uninstall();798 do_execute_soon(run_test_18_1);799 });800 });801 }802 });803 aInstall_2.install();804 }, "application/x-xpinstall");805 });806 });807 }808 });809 aInstall.install();810 }, "application/x-xpinstall");811}812// Checks that metadata is not stored if the pref is set to false813function run_test_18_1() {814 restartManager();815 Services.prefs.setBoolPref("extensions.getAddons.cache.enabled", true);816 Services.prefs.setCharPref(PREF_GETADDONS_BYIDS,817 "http://localhost:" + gPort + "/data/test_install.xml");818 Services.prefs.setBoolPref("extensions.addon2@tests.mozilla.org.getAddons.cache.enabled", false);819 let url = "http://localhost:" + gPort + "/addons/test_install2_1.xpi";820 AddonManager.getInstallForURL(url, function(aInstall) {821 aInstall.addListener({822 onInstallEnded(unused, aAddon) {823 do_execute_soon(function test18_1_install_ended() {824 do_check_neq(aAddon.fullDescription, "Repository description");825 restartManager();826 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {827 do_check_neq(a2.fullDescription, "Repository description");828 a2.uninstall();829 do_execute_soon(run_test_19);830 });831 });832 }833 });834 aInstall.install();835 }, "application/x-xpinstall");836}837// Checks that metadata is downloaded for new installs and is visible before and838// after restart839function run_test_19() {840 restartManager();841 Services.prefs.setBoolPref("extensions.addon2@tests.mozilla.org.getAddons.cache.enabled", true);842 let url = "http://localhost:" + gPort + "/addons/test_install2_1.xpi";843 AddonManager.getInstallForURL(url, function(aInstall) {844 aInstall.addListener({845 onInstallEnded(unused, aAddon) {846 do_execute_soon(function test19_install_ended() {847 do_check_eq(aAddon.fullDescription, "Repository description");848 restartManager();849 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {850 do_check_eq(a2.fullDescription, "Repository description");851 a2.uninstall();852 do_execute_soon(run_test_20);853 });854 });855 }856 });857 aInstall.install();858 }, "application/x-xpinstall");859}860// Do the same again to make sure it works when the data is already in the cache861function run_test_20() {862 restartManager();863 let url = "http://localhost:" + gPort + "/addons/test_install2_1.xpi";864 AddonManager.getInstallForURL(url, function(aInstall) {865 aInstall.addListener({866 onInstallEnded(unused, aAddon) {867 do_execute_soon(function test20_install_ended() {868 do_check_eq(aAddon.fullDescription, "Repository description");869 restartManager();870 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {871 do_check_eq(a2.fullDescription, "Repository description");872 a2.uninstall();873 do_execute_soon(run_test_21);874 });875 });876 }877 });878 aInstall.install();879 }, "application/x-xpinstall");880}881// Verify that installing an add-on that is already pending install cancels the882// first install883function run_test_21() {884 restartManager();885 Services.prefs.setBoolPref("extensions.getAddons.cache.enabled", false);886 installAllFiles([do_get_addon("test_install2_1")], function() {887 AddonManager.getAllInstalls(function(aInstalls) {888 do_check_eq(aInstalls.length, 1);889 prepare_test({890 "addon2@tests.mozilla.org": [891 "onOperationCancelled",892 "onInstalling"893 ]894 }, [895 "onNewInstall",896 "onDownloadStarted",897 "onDownloadEnded",898 "onInstallStarted",899 "onInstallCancelled",900 "onInstallEnded",901 ], check_test_21);902 let url = "http://localhost:" + gPort + "/addons/test_install2_1.xpi";903 AddonManager.getInstallForURL(url, function(aInstall) {904 aInstall.install();905 }, "application/x-xpinstall");906 });907 });908}909function check_test_21(aInstall) {910 AddonManager.getAllInstalls(callback_soon(function(aInstalls) {911 do_check_eq(aInstalls.length, 1);912 do_check_eq(aInstalls[0], aInstall);913 prepare_test({914 "addon2@tests.mozilla.org": [915 "onOperationCancelled"916 ]917 }, [918 "onInstallCancelled",919 ]);920 aInstall.cancel();921 ensure_test_completed();922 restartManager();923 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {924 do_check_eq(a2, null);925 run_test_22();926 });927 }));928}929// Tests that an install can be restarted after being cancelled930function run_test_22() {931 prepare_test({ }, [932 "onNewInstall"933 ]);934 let url = "http://localhost:" + gPort + "/addons/test_install3.xpi";935 AddonManager.getInstallForURL(url, function(aInstall) {936 ensure_test_completed();937 do_check_neq(aInstall, null);938 do_check_eq(aInstall.state, AddonManager.STATE_AVAILABLE);939 prepare_test({}, [940 "onDownloadStarted",941 "onDownloadEnded",942 ], check_test_22);943 aInstall.install();944 }, "application/x-xpinstall");945}946function check_test_22(aInstall) {947 prepare_test({}, [948 "onDownloadCancelled"949 ]);950 aInstall.cancel();951 ensure_test_completed();952 prepare_test({953 "addon3@tests.mozilla.org": [954 "onInstalling"955 ]956 }, [957 "onDownloadStarted",958 "onDownloadEnded",959 "onInstallStarted",960 "onInstallEnded"961 ], finish_test_22);962 aInstall.install();963}964function finish_test_22(aInstall) {965 prepare_test({966 "addon3@tests.mozilla.org": [967 "onOperationCancelled"968 ]969 }, [970 "onInstallCancelled"971 ]);972 aInstall.cancel();973 ensure_test_completed();974 run_test_23();975}976// Tests that an install can be restarted after being cancelled when a hash977// was provided978function run_test_23() {979 prepare_test({ }, [980 "onNewInstall"981 ]);982 let url = "http://localhost:" + gPort + "/addons/test_install3.xpi";983 AddonManager.getInstallForURL(url, function(aInstall) {984 ensure_test_completed();985 do_check_neq(aInstall, null);986 do_check_eq(aInstall.state, AddonManager.STATE_AVAILABLE);987 prepare_test({}, [988 "onDownloadStarted",989 "onDownloadEnded",990 ], check_test_23);991 aInstall.install();992 }, "application/x-xpinstall", do_get_addon_hash("test_install3"));993}994function check_test_23(aInstall) {995 prepare_test({}, [996 "onDownloadCancelled"997 ]);998 aInstall.cancel();999 ensure_test_completed();1000 prepare_test({1001 "addon3@tests.mozilla.org": [1002 "onInstalling"1003 ]1004 }, [1005 "onDownloadStarted",1006 "onDownloadEnded",1007 "onInstallStarted",1008 "onInstallEnded"1009 ], finish_test_23);1010 aInstall.install();1011}1012function finish_test_23(aInstall) {1013 prepare_test({1014 "addon3@tests.mozilla.org": [1015 "onOperationCancelled"1016 ]1017 }, [1018 "onInstallCancelled"1019 ]);1020 aInstall.cancel();1021 ensure_test_completed();1022 run_test_24();1023}1024// Tests that an install with a bad hash can be restarted after it fails, though1025// it will only fail again1026function run_test_24() {1027 prepare_test({ }, [1028 "onNewInstall"1029 ]);1030 let url = "http://localhost:" + gPort + "/addons/test_install3.xpi";1031 AddonManager.getInstallForURL(url, function(aInstall) {1032 ensure_test_completed();1033 do_check_neq(aInstall, null);1034 do_check_eq(aInstall.state, AddonManager.STATE_AVAILABLE);1035 prepare_test({}, [1036 "onDownloadStarted",1037 "onDownloadFailed",1038 ], check_test_24);1039 aInstall.install();1040 }, "application/x-xpinstall", "sha1:foo");1041}1042function check_test_24(aInstall) {1043 prepare_test({ }, [1044 "onDownloadStarted",1045 "onDownloadFailed"1046 ], run_test_25);1047 aInstall.install();1048}1049// Tests that installs with a hash for a local file work1050function run_test_25() {1051 prepare_test({ }, [1052 "onNewInstall"1053 ]);1054 let url = Services.io.newFileURI(do_get_addon("test_install3")).spec;1055 AddonManager.getInstallForURL(url, function(aInstall) {1056 ensure_test_completed();1057 do_check_neq(aInstall, null);1058 do_check_eq(aInstall.state, AddonManager.STATE_DOWNLOADED);1059 do_check_eq(aInstall.error, 0);1060 prepare_test({ }, [1061 "onDownloadCancelled"1062 ]);1063 aInstall.cancel();1064 ensure_test_completed();1065 run_test_26();1066 }, "application/x-xpinstall", do_get_addon_hash("test_install3"));1067}1068function run_test_26() {1069 prepare_test({ }, [1070 "onNewInstall",1071 "onDownloadStarted",1072 "onDownloadCancelled"1073 ]);1074 let observerService = AM_Cc["@mozilla.org/network/http-activity-distributor;1"].1075 getService(AM_Ci.nsIHttpActivityDistributor);1076 observerService.addObserver({1077 observeActivity(aChannel, aType, aSubtype, aTimestamp, aSizeData,1078 aStringData) {1079 aChannel.QueryInterface(AM_Ci.nsIChannel);1080 // Wait for the final event for the redirected URL1081 if (aChannel.URI.spec != "http://localhost:" + gPort + "/addons/test_install1.xpi" ||1082 aType != AM_Ci.nsIHttpActivityObserver.ACTIVITY_TYPE_HTTP_TRANSACTION ||1083 aSubtype != AM_Ci.nsIHttpActivityObserver.ACTIVITY_SUBTYPE_TRANSACTION_CLOSE)1084 return;1085 // Request should have been cancelled1086 do_check_eq(aChannel.status, Components.results.NS_BINDING_ABORTED);1087 observerService.removeObserver(this);1088 run_test_27();1089 }1090 });1091 let url = "http://localhost:" + gPort + "/redirect?/addons/test_install1.xpi";1092 AddonManager.getInstallForURL(url, function(aInstall) {1093 aInstall.addListener({1094 onDownloadProgress(aDownloadProgressInstall) {1095 aDownloadProgressInstall.cancel();1096 }1097 });1098 aInstall.install();1099 }, "application/x-xpinstall");1100}1101// Tests that an install can be restarted during onDownloadCancelled after being1102// cancelled in mid-download1103function run_test_27() {1104 prepare_test({ }, [1105 "onNewInstall"1106 ]);1107 let url = "http://localhost:" + gPort + "/addons/test_install3.xpi";1108 AddonManager.getInstallForURL(url, function(aInstall) {1109 ensure_test_completed();1110 do_check_neq(aInstall, null);1111 do_check_eq(aInstall.state, AddonManager.STATE_AVAILABLE);1112 aInstall.addListener({1113 onDownloadProgress() {1114 aInstall.removeListener(this);1115 aInstall.cancel();1116 }1117 });1118 prepare_test({}, [1119 "onDownloadStarted",1120 "onDownloadCancelled",1121 ], check_test_27);1122 aInstall.install();1123 }, "application/x-xpinstall");1124}1125function check_test_27(aInstall) {1126 prepare_test({1127 "addon3@tests.mozilla.org": [1128 "onInstalling"1129 ]1130 }, [1131 "onDownloadStarted",1132 "onDownloadEnded",1133 "onInstallStarted",1134 "onInstallEnded"1135 ], finish_test_27);1136 let file = aInstall.file;1137 aInstall.install();1138 do_check_neq(file.path, aInstall.file.path);1139 do_check_false(file.exists());1140}1141function finish_test_27(aInstall) {1142 prepare_test({1143 "addon3@tests.mozilla.org": [1144 "onOperationCancelled"1145 ]1146 }, [1147 "onInstallCancelled"1148 ]);1149 aInstall.cancel();1150 ensure_test_completed();1151 run_test_28();1152}1153// Tests that an install that isn't strictly compatible and has1154// binary components correctly has appDisabled set (see bug 702868).1155function run_test_28() {1156 prepare_test({ }, [1157 "onNewInstall"1158 ]);1159 let url = "http://localhost:" + gPort + "/addons/test_install5.xpi";1160 AddonManager.getInstallForURL(url, function(install) {1161 ensure_test_completed();1162 do_check_neq(install, null);1163 do_check_eq(install.version, "1.0");1164 do_check_eq(install.name, "Real Test 5");1165 do_check_eq(install.state, AddonManager.STATE_AVAILABLE);1166 AddonManager.getInstallsByTypes(null, function(activeInstalls) {1167 do_check_eq(activeInstalls.length, 1);1168 do_check_eq(activeInstalls[0], install);1169 prepare_test({}, [1170 "onDownloadStarted",1171 "onDownloadEnded",1172 "onInstallStarted"1173 ], check_test_28);1174 install.install();1175 });1176 }, "application/x-xpinstall", null, "Real Test 5", null, "1.0");1177}1178function check_test_28(install) {1179 ensure_test_completed();1180 do_check_eq(install.version, "1.0");1181 do_check_eq(install.name, "Real Test 5");1182 do_check_eq(install.state, AddonManager.STATE_INSTALLING);1183 do_check_eq(install.existingAddon, null);1184 do_check_false(install.addon.isCompatible);1185 do_check_true(install.addon.appDisabled);1186 prepare_test({}, [1187 "onInstallCancelled"1188 ], finish_test_28);1189 return false;1190}1191function finish_test_28(install) {1192 prepare_test({}, [1193 "onDownloadCancelled"1194 ], run_test_29);1195 install.cancel();1196}1197// Tests that an install with a matching compatibility override has appDisabled1198// set correctly.1199function run_test_29() {1200 Services.prefs.setBoolPref("extensions.getAddons.cache.enabled", true);1201 prepare_test({ }, [1202 "onNewInstall"1203 ]);1204 let url = "http://localhost:" + gPort + "/addons/test_install6.xpi";1205 AddonManager.getInstallForURL(url, function(install) {1206 ensure_test_completed();1207 do_check_neq(install, null);1208 do_check_eq(install.version, "1.0");1209 do_check_eq(install.name, "Addon Test 6");1210 do_check_eq(install.state, AddonManager.STATE_AVAILABLE);1211 AddonManager.getInstallsByTypes(null, function(activeInstalls) {1212 do_check_eq(activeInstalls.length, 1);1213 do_check_eq(activeInstalls[0], install);1214 prepare_test({}, [1215 "onDownloadStarted",1216 "onDownloadEnded"1217 ], check_test_29);1218 install.install();1219 });1220 }, "application/x-xpinstall", null, "Addon Test 6", null, "1.0");1221}1222function check_test_29(install) {1223 // ensure_test_completed();1224 do_check_eq(install.state, AddonManager.STATE_DOWNLOADED);1225 do_check_neq(install.addon, null);1226 do_check_false(install.addon.isCompatible);1227 do_check_true(install.addon.appDisabled);1228 prepare_test({}, [1229 "onDownloadCancelled"1230 ], run_test_30);1231 install.cancel();1232 return false;...
test_install_strictcompat.js
Source:test_install_strictcompat.js
...81 }, [82 "onInstallStarted",83 "onInstallEnded",84 ], check_test_1);85 install.install();86 });87 });88 });89 });90}91function check_test_1() {92 ensure_test_completed();93 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(olda1) {94 do_check_eq(olda1, null);95 AddonManager.getAddonsWithOperationsByTypes(null, callback_soon(async function(pendingAddons) {96 do_check_eq(pendingAddons.length, 1);97 do_check_eq(pendingAddons[0].id, "addon1@tests.mozilla.org");98 let uri = NetUtil.newURI(pendingAddons[0].iconURL);99 if (uri instanceof AM_Ci.nsIJARURI) {100 let jarURI = uri.QueryInterface(AM_Ci.nsIJARURI);101 let archiveURI = jarURI.JARFile;102 let archiveFile = archiveURI.QueryInterface(AM_Ci.nsIFileURL).file;103 let zipReader = Cc["@mozilla.org/libjar/zip-reader;1"].104 createInstance(Ci.nsIZipReader);105 try {106 zipReader.open(archiveFile);107 do_check_true(zipReader.hasEntry(jarURI.JAREntry));108 } finally {109 zipReader.close();110 }111 } else {112 let iconFile = uri.QueryInterface(AM_Ci.nsIFileURL).file;113 do_check_true(iconFile.exists());114 }115 // Make the pending install have a sensible date116 let updateDate = Date.now();117 let extURI = pendingAddons[0].getResourceURI("");118 let ext = extURI.QueryInterface(AM_Ci.nsIFileURL).file;119 setExtensionModifiedTime(ext, updateDate);120 // The pending add-on cannot be disabled or enabled.121 do_check_false(hasFlag(pendingAddons[0].permissions, AddonManager.PERM_CAN_ENABLE));122 do_check_false(hasFlag(pendingAddons[0].permissions, AddonManager.PERM_CAN_DISABLE));123 await promiseRestartManager();124 AddonManager.getAllInstalls(function(activeInstalls) {125 do_check_eq(activeInstalls, 0);126 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {127 do_check_neq(a1, null);128 do_check_eq(a1.type, "extension");129 do_check_eq(a1.version, "1.0");130 do_check_eq(a1.name, "Test 1");131 do_check_true(isExtensionInAddonsList(profileDir, a1.id));132 do_check_true(do_get_addon("test_install1").exists());133 do_check_in_crash_annotation(a1.id, a1.version);134 do_check_eq(a1.size, ADDON1_SIZE);135 do_check_eq(a1.sourceURI.spec,136 Services.io.newFileURI(do_get_addon("test_install1")).spec);137 let difference = a1.installDate.getTime() - updateDate;138 if (Math.abs(difference) > MAX_TIME_DIFFERENCE)139 do_throw("Add-on install time was out by " + difference + "ms");140 difference = a1.updateDate.getTime() - updateDate;141 if (Math.abs(difference) > MAX_TIME_DIFFERENCE)142 do_throw("Add-on update time was out by " + difference + "ms");143 do_check_true(a1.hasResource("install.rdf"));144 do_check_false(a1.hasResource("foo.bar"));145 let root_uri = do_get_addon_root_uri(profileDir, "addon1@tests.mozilla.org");146 do_check_eq(a1.getResourceURI("install.rdf").spec, root_uri + "install.rdf");147 do_check_eq(a1.iconURL, root_uri + "icon.png");148 do_check_eq(a1.icon64URL, root_uri + "icon64.png");149 a1.uninstall();150 do_execute_soon(function() { run_test_2(a1) });151 });152 });153 }));154 });155}156// Tests that an install from a url downloads.157function run_test_2(aAddon) {158 let { id, version } = aAddon;159 restartManager();160 do_check_not_in_crash_annotation(id, version);161 let url = "http://localhost:4444/addons/test_install2_1.xpi";162 AddonManager.getInstallForURL(url, function(install) {163 do_check_neq(install, null);164 do_check_eq(install.version, "1.0");165 do_check_eq(install.name, "Test 2");166 do_check_eq(install.state, AddonManager.STATE_AVAILABLE);167 do_check_eq(install.iconURL, null);168 do_check_eq(install.sourceURI.spec, url);169 AddonManager.getAllInstalls(function(activeInstalls) {170 do_check_eq(activeInstalls.length, 1);171 do_check_eq(activeInstalls[0], install);172 prepare_test({}, [173 "onDownloadStarted",174 "onDownloadEnded",175 ], check_test_2);176 install.addListener({177 onDownloadProgress() {178 do_execute_soon(function() {179 Components.utils.forceGC();180 });181 }182 });183 install.install();184 });185 }, "application/x-xpinstall", null, "Test 2", null, "1.0");186}187function check_test_2(install) {188 ensure_test_completed();189 do_check_eq(install.version, "2.0");190 do_check_eq(install.name, "Real Test 2");191 do_check_eq(install.state, AddonManager.STATE_DOWNLOADED);192 do_check_eq(install.addon.install, install);193 do_check_true(hasFlag(install.addon.operationsRequiringRestart,194 AddonManager.OP_NEEDS_RESTART_INSTALL));195 do_check_eq(install.iconURL, null);196 // Pause the install here and start it again in run_test_3197 do_execute_soon(function() { run_test_3(install); });198 return false;199}200// Tests that the downloaded XPI installs ok201function run_test_3(install) {202 prepare_test({203 "addon2@tests.mozilla.org": [204 "onInstalling"205 ]206 }, [207 "onInstallStarted",208 "onInstallEnded",209 ], check_test_3);210 install.install();211}212function check_test_3(aInstall) {213 // Make the pending install have a sensible date214 let updateDate = Date.now();215 let extURI = aInstall.addon.getResourceURI("");216 let ext = extURI.QueryInterface(AM_Ci.nsIFileURL).file;217 setExtensionModifiedTime(ext, updateDate);218 ensure_test_completed();219 AddonManager.getAddonByID("addon2@tests.mozilla.org", callback_soon(async function(olda2) {220 do_check_eq(olda2, null);221 await promiseRestartManager();222 AddonManager.getAllInstalls(function(installs) {223 do_check_eq(installs, 0);224 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {225 do_check_neq(a2, null);226 do_check_eq(a2.type, "extension");227 do_check_eq(a2.version, "2.0");228 do_check_eq(a2.name, "Real Test 2");229 do_check_true(isExtensionInAddonsList(profileDir, a2.id));230 do_check_true(do_get_addon("test_install2_1").exists());231 do_check_in_crash_annotation(a2.id, a2.version);232 do_check_eq(a2.sourceURI.spec,233 "http://localhost:4444/addons/test_install2_1.xpi");234 let difference = a2.installDate.getTime() - updateDate;235 if (Math.abs(difference) > MAX_TIME_DIFFERENCE)236 do_throw("Add-on install time was out by " + difference + "ms");237 difference = a2.updateDate.getTime() - updateDate;238 if (Math.abs(difference) > MAX_TIME_DIFFERENCE)239 do_throw("Add-on update time was out by " + difference + "ms");240 gInstallDate = a2.installDate.getTime();241 run_test_4();242 });243 });244 }));245}246// Tests that installing a new version of an existing add-on works247function run_test_4() {248 prepare_test({ }, [249 "onNewInstall"250 ]);251 let url = "http://localhost:4444/addons/test_install2_2.xpi";252 AddonManager.getInstallForURL(url, function(install) {253 ensure_test_completed();254 do_check_neq(install, null);255 do_check_eq(install.version, "3.0");256 do_check_eq(install.name, "Test 3");257 do_check_eq(install.state, AddonManager.STATE_AVAILABLE);258 AddonManager.getAllInstalls(function(activeInstalls) {259 do_check_eq(activeInstalls.length, 1);260 do_check_eq(activeInstalls[0], install);261 do_check_eq(install.existingAddon, null);262 prepare_test({}, [263 "onDownloadStarted",264 "onDownloadEnded",265 ], check_test_4);266 install.install();267 });268 }, "application/x-xpinstall", null, "Test 3", null, "3.0");269}270function check_test_4(install) {271 ensure_test_completed();272 do_check_eq(install.version, "3.0");273 do_check_eq(install.name, "Real Test 3");274 do_check_eq(install.state, AddonManager.STATE_DOWNLOADED);275 do_check_neq(install.existingAddon);276 do_check_eq(install.existingAddon.id, "addon2@tests.mozilla.org");277 do_check_eq(install.addon.install, install);278 do_check_true(hasFlag(install.addon.operationsRequiringRestart,279 AddonManager.OP_NEEDS_RESTART_INSTALL));280 run_test_5();281 // Installation will continue when there is nothing returned.282}283// Continue installing the new version284function run_test_5() {285 prepare_test({286 "addon2@tests.mozilla.org": [287 "onInstalling"288 ]289 }, [290 "onInstallStarted",291 "onInstallEnded",292 ], check_test_5);293}294function check_test_5(install) {295 ensure_test_completed();296 do_check_eq(install.existingAddon.pendingUpgrade.install, install);297 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(olda2) {298 do_check_neq(olda2, null);299 do_check_true(hasFlag(olda2.pendingOperations, AddonManager.PENDING_UPGRADE));300 AddonManager.getInstallsByTypes(null, callback_soon(async function(installs) {301 do_check_eq(installs.length, 1);302 do_check_eq(installs[0].addon, olda2.pendingUpgrade);303 await promiseRestartManager();304 AddonManager.getInstallsByTypes(null, function(installs2) {305 do_check_eq(installs2.length, 0);306 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {307 do_check_neq(a2, null);308 do_check_eq(a2.type, "extension");309 do_check_eq(a2.version, "3.0");310 do_check_eq(a2.name, "Real Test 3");311 do_check_true(a2.isActive);312 do_check_true(isExtensionInAddonsList(profileDir, a2.id));313 do_check_true(do_get_addon("test_install2_2").exists());314 do_check_in_crash_annotation(a2.id, a2.version);315 do_check_eq(a2.sourceURI.spec,316 "http://localhost:4444/addons/test_install2_2.xpi");317 do_check_eq(a2.installDate.getTime(), gInstallDate);318 // Update date should be later (or the same if this test is too fast)319 do_check_true(a2.installDate <= a2.updateDate);320 a2.uninstall();321 do_execute_soon(run_test_6);322 });323 });324 }));325 });326}327// Tests that an install that requires a compatibility update works328function run_test_6() {329 restartManager();330 prepare_test({ }, [331 "onNewInstall"332 ]);333 let url = "http://localhost:4444/addons/test_install3.xpi";334 AddonManager.getInstallForURL(url, function(install) {335 ensure_test_completed();336 do_check_neq(install, null);337 do_check_eq(install.version, "1.0");338 do_check_eq(install.name, "Real Test 4");339 do_check_eq(install.state, AddonManager.STATE_AVAILABLE);340 AddonManager.getInstallsByTypes(null, function(activeInstalls) {341 do_check_eq(activeInstalls.length, 1);342 do_check_eq(activeInstalls[0], install);343 prepare_test({}, [344 "onDownloadStarted",345 "onDownloadEnded",346 ], check_test_6);347 install.install();348 });349 }, "application/x-xpinstall", null, "Real Test 4", null, "1.0");350}351function check_test_6(install) {352 ensure_test_completed();353 do_check_eq(install.version, "1.0");354 do_check_eq(install.name, "Real Test 4");355 do_check_eq(install.state, AddonManager.STATE_DOWNLOADED);356 do_check_eq(install.existingAddon, null);357 do_check_false(install.addon.appDisabled);358 run_test_7();359 return true;360}361// Continue the install362function run_test_7() {363 prepare_test({364 "addon3@tests.mozilla.org": [365 "onInstalling"366 ]367 }, [368 "onInstallStarted",369 "onInstallEnded",370 ], check_test_7);371}372function check_test_7() {373 ensure_test_completed();374 AddonManager.getAddonByID("addon3@tests.mozilla.org", callback_soon(async function(olda3) {375 do_check_eq(olda3, null);376 await promiseRestartManager();377 AddonManager.getAllInstalls(function(installs) {378 do_check_eq(installs, 0);379 AddonManager.getAddonByID("addon3@tests.mozilla.org", function(a3) {380 do_check_neq(a3, null);381 do_check_eq(a3.type, "extension");382 do_check_eq(a3.version, "1.0");383 do_check_eq(a3.name, "Real Test 4");384 do_check_true(a3.isActive);385 do_check_false(a3.appDisabled);386 do_check_true(isExtensionInAddonsList(profileDir, a3.id));387 do_check_true(do_get_addon("test_install3").exists());388 a3.uninstall();389 do_execute_soon(run_test_8);390 });391 });392 }));393}394function run_test_8() {395 restartManager();396 AddonManager.addInstallListener(InstallListener);397 AddonManager.addAddonListener(AddonListener);398 prepare_test({ }, [399 "onNewInstall"400 ]);401 AddonManager.getInstallForFile(do_get_addon("test_install3"), function(install) {402 do_check_true(install.addon.isCompatible);403 prepare_test({404 "addon3@tests.mozilla.org": [405 "onInstalling"406 ]407 }, [408 "onInstallStarted",409 "onInstallEnded",410 ], callback_soon(check_test_8));411 install.install();412 });413}414async function check_test_8() {415 await promiseRestartManager();416 AddonManager.getAddonByID("addon3@tests.mozilla.org", function(a3) {417 do_check_neq(a3, null);418 do_check_eq(a3.type, "extension");419 do_check_eq(a3.version, "1.0");420 do_check_eq(a3.name, "Real Test 4");421 do_check_true(a3.isActive);422 do_check_false(a3.appDisabled);423 do_check_true(isExtensionInAddonsList(profileDir, a3.id));424 do_check_true(do_get_addon("test_install3").exists());425 a3.uninstall();426 do_execute_soon(run_test_9);427 });428}429// Test that after cancelling a download it is removed from the active installs430function run_test_9() {431 restartManager();432 prepare_test({ }, [433 "onNewInstall"434 ]);435 let url = "http://localhost:4444/addons/test_install3.xpi";436 AddonManager.getInstallForURL(url, function(install) {437 ensure_test_completed();438 do_check_neq(install, null);439 do_check_eq(install.version, "1.0");440 do_check_eq(install.name, "Real Test 4");441 do_check_eq(install.state, AddonManager.STATE_AVAILABLE);442 AddonManager.getInstallsByTypes(null, function(activeInstalls) {443 do_check_eq(activeInstalls.length, 1);444 do_check_eq(activeInstalls[0], install);445 prepare_test({}, [446 "onDownloadStarted",447 "onDownloadEnded",448 ], check_test_9);449 install.install();450 });451 }, "application/x-xpinstall", null, "Real Test 4", null, "1.0");452}453function check_test_9(install) {454 prepare_test({}, [455 "onDownloadCancelled"456 ], function() {457 let file = install.file;458 // Allow the file removal to complete459 do_execute_soon(function() {460 AddonManager.getAllInstalls(function(activeInstalls) {461 do_check_eq(activeInstalls.length, 0);462 do_check_false(file.exists());463 run_test_10();464 });465 });466 });467 install.cancel();468}469// Tests that after cancelling a pending install it is removed from the active470// installs471function run_test_10() {472 prepare_test({ }, [473 "onNewInstall"474 ]);475 let url = "http://localhost:4444/addons/test_install3.xpi";476 AddonManager.getInstallForURL(url, function(install) {477 ensure_test_completed();478 do_check_neq(install, null);479 do_check_eq(install.version, "1.0");480 do_check_eq(install.name, "Real Test 4");481 do_check_eq(install.state, AddonManager.STATE_AVAILABLE);482 AddonManager.getInstallsByTypes(null, function(activeInstalls) {483 do_check_eq(activeInstalls.length, 1);484 do_check_eq(activeInstalls[0], install);485 prepare_test({486 "addon3@tests.mozilla.org": [487 "onInstalling"488 ]489 }, [490 "onDownloadStarted",491 "onDownloadEnded",492 "onInstallStarted",493 "onInstallEnded"494 ], check_test_10);495 install.install();496 });497 }, "application/x-xpinstall", null, "Real Test 4", null, "1.0");498}499function check_test_10(install) {500 prepare_test({501 "addon3@tests.mozilla.org": [502 "onOperationCancelled"503 ]504 }, [505 "onInstallCancelled"506 ]);507 install.cancel();508 ensure_test_completed();509 AddonManager.getAllInstalls(callback_soon(function(activeInstalls) {510 do_check_eq(activeInstalls.length, 0);511 restartManager();512 // Check that the install did not complete513 AddonManager.getAddonByID("addon3@tests.mozilla.org", function(a3) {514 do_check_eq(a3, null);515 run_test_11();516 });517 }));518}519function run_test_11() {520 // Tests 11 and 12 were removed, to avoid churn of renumbering,521 // just jump ahead to 13 here522 run_test_13();523}524// Tests that cancelling an upgrade leaves the original add-on's pendingOperations525// correct526function run_test_13() {527 restartManager();528 installAllFiles([do_get_addon("test_install2_1")], function() {529 restartManager();530 prepare_test({ }, [531 "onNewInstall"532 ]);533 let url = "http://localhost:4444/addons/test_install2_2.xpi";534 AddonManager.getInstallForURL(url, function(install) {535 ensure_test_completed();536 do_check_neq(install, null);537 do_check_eq(install.version, "3.0");538 do_check_eq(install.name, "Test 3");539 do_check_eq(install.state, AddonManager.STATE_AVAILABLE);540 AddonManager.getAllInstalls(function(activeInstalls) {541 do_check_eq(activeInstalls.length, 1);542 do_check_eq(activeInstalls[0], install);543 do_check_eq(install.existingAddon, null);544 prepare_test({545 "addon2@tests.mozilla.org": [546 "onInstalling"547 ]548 }, [549 "onDownloadStarted",550 "onDownloadEnded",551 "onInstallStarted",552 "onInstallEnded",553 ], check_test_13);554 install.install();555 });556 }, "application/x-xpinstall", null, "Test 3", null, "3.0");557 });558}559function check_test_13(install) {560 ensure_test_completed();561 do_check_eq(install.version, "3.0");562 do_check_eq(install.name, "Real Test 3");563 do_check_eq(install.state, AddonManager.STATE_INSTALLED);564 do_check_neq(install.existingAddon, null);565 do_check_eq(install.existingAddon.id, "addon2@tests.mozilla.org");566 do_check_eq(install.addon.install, install);567 AddonManager.getAddonByID("addon2@tests.mozilla.org", callback_soon(function(olda2) {568 do_check_neq(olda2, null);569 do_check_true(hasFlag(olda2.pendingOperations, AddonManager.PENDING_UPGRADE));570 do_check_eq(olda2.pendingUpgrade, install.addon);571 do_check_true(hasFlag(install.addon.pendingOperations,572 AddonManager.PENDING_INSTALL));573 prepare_test({574 "addon2@tests.mozilla.org": [575 "onOperationCancelled"576 ]577 }, [578 "onInstallCancelled",579 ]);580 install.cancel();581 do_check_false(hasFlag(install.addon.pendingOperations, AddonManager.PENDING_INSTALL));582 do_check_false(hasFlag(olda2.pendingOperations, AddonManager.PENDING_UPGRADE));583 do_check_eq(olda2.pendingUpgrade, null);584 restartManager();585 // Check that the upgrade did not complete586 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {587 do_check_eq(a2.version, "2.0");588 a2.uninstall();589 do_execute_soon(run_test_14);590 });591 }));592}593// Check that cancelling the install from onDownloadStarted actually cancels it594function run_test_14() {595 restartManager();596 prepare_test({ }, [597 "onNewInstall"598 ]);599 let url = "http://localhost:4444/addons/test_install2_1.xpi";600 AddonManager.getInstallForURL(url, function(install) {601 ensure_test_completed();602 do_check_eq(install.file, null);603 prepare_test({ }, [604 "onDownloadStarted"605 ], check_test_14);606 install.install();607 }, "application/x-xpinstall");608}609function check_test_14(install) {610 prepare_test({ }, [611 "onDownloadCancelled"612 ], function() {613 let file = install.file;614 install.addListener({615 onDownloadProgress() {616 do_throw("Download should not have continued");617 },618 onDownloadEnded() {619 do_throw("Download should not have continued");620 }621 });622 // Allow the listener to return to see if it continues downloading. The623 // The listener only really tests if we give it time to see progress, the624 // file check isn't ideal either625 do_execute_soon(function() {626 do_check_false(file.exists());627 run_test_15();628 });629 });630 // Wait for the channel to be ready to cancel631 do_execute_soon(function() {632 install.cancel();633 });634}635// Checks that cancelling the install from onDownloadEnded actually cancels it636function run_test_15() {637 prepare_test({ }, [638 "onNewInstall"639 ]);640 let url = "http://localhost:4444/addons/test_install2_1.xpi";641 AddonManager.getInstallForURL(url, function(install) {642 ensure_test_completed();643 do_check_eq(install.file, null);644 prepare_test({ }, [645 "onDownloadStarted",646 "onDownloadEnded"647 ], check_test_15);648 install.install();649 }, "application/x-xpinstall");650}651function check_test_15(install) {652 prepare_test({ }, [653 "onDownloadCancelled"654 ]);655 install.cancel();656 ensure_test_completed();657 install.addListener({658 onInstallStarted() {659 do_throw("Install should not have continued");660 }661 });662 // Allow the listener to return to see if it starts installing663 do_execute_soon(run_test_16);664}665// Verify that the userDisabled value carries over to the upgrade by default666function run_test_16() {667 restartManager();668 let url = "http://localhost:4444/addons/test_install2_1.xpi";669 AddonManager.getInstallForURL(url, function(aInstall) {670 aInstall.addListener({671 onInstallStarted() {672 do_check_false(aInstall.addon.userDisabled);673 aInstall.addon.userDisabled = true;674 },675 onInstallEnded() {676 do_execute_soon(function test16_install1() {677 restartManager();678 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {679 do_check_true(a2.userDisabled);680 do_check_false(a2.isActive);681 let url_2 = "http://localhost:4444/addons/test_install2_2.xpi";682 AddonManager.getInstallForURL(url_2, function(aInstall_2) {683 aInstall_2.addListener({684 onInstallEnded() {685 do_execute_soon(function test16_install2() {686 do_check_true(aInstall_2.addon.userDisabled);687 restartManager();688 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2_2) {689 do_check_true(a2_2.userDisabled);690 do_check_false(a2_2.isActive);691 a2_2.uninstall();692 do_execute_soon(run_test_17);693 });694 });695 }696 });697 aInstall_2.install();698 }, "application/x-xpinstall");699 });700 });701 }702 });703 aInstall.install();704 }, "application/x-xpinstall");705}706// Verify that changing the userDisabled value before onInstallEnded works707function run_test_17() {708 restartManager();709 let url = "http://localhost:4444/addons/test_install2_1.xpi";710 AddonManager.getInstallForURL(url, function(aInstall) {711 aInstall.addListener({712 onInstallEnded() {713 do_execute_soon(function() {714 do_check_false(aInstall.addon.userDisabled);715 restartManager();716 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {717 do_check_false(a2.userDisabled);718 do_check_true(a2.isActive);719 let url_2 = "http://localhost:4444/addons/test_install2_2.xpi";720 AddonManager.getInstallForURL(url_2, function(aInstall_2) {721 aInstall_2.addListener({722 onInstallStarted() {723 do_check_false(aInstall_2.addon.userDisabled);724 aInstall_2.addon.userDisabled = true;725 },726 onInstallEnded() {727 do_execute_soon(function() {728 restartManager();729 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2_2) {730 do_check_true(a2_2.userDisabled);731 do_check_false(a2_2.isActive);732 a2_2.uninstall();733 do_execute_soon(run_test_18);734 });735 });736 }737 });738 aInstall_2.install();739 }, "application/x-xpinstall");740 });741 });742 }743 });744 aInstall.install();745 }, "application/x-xpinstall");746}747// Verify that changing the userDisabled value before onInstallEnded works748function run_test_18() {749 restartManager();750 let url = "http://localhost:4444/addons/test_install2_1.xpi";751 AddonManager.getInstallForURL(url, function(aInstall) {752 aInstall.addListener({753 onInstallStarted() {754 do_check_false(aInstall.addon.userDisabled);755 aInstall.addon.userDisabled = true;756 },757 onInstallEnded() {758 do_execute_soon(function test18_install1() {759 restartManager();760 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {761 do_check_true(a2.userDisabled);762 do_check_false(a2.isActive);763 let url_2 = "http://localhost:4444/addons/test_install2_2.xpi";764 AddonManager.getInstallForURL(url_2, function(aInstall_2) {765 aInstall_2.addListener({766 onInstallStarted() {767 do_check_true(aInstall_2.addon.userDisabled);768 aInstall_2.addon.userDisabled = false;769 },770 onInstallEnded() {771 do_execute_soon(function test18_install2() {772 restartManager();773 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2_2) {774 do_check_false(a2_2.userDisabled);775 do_check_true(a2_2.isActive);776 a2_2.uninstall();777 do_execute_soon(run_test_18_1);778 });779 });780 }781 });782 aInstall_2.install();783 }, "application/x-xpinstall");784 });785 });786 }787 });788 aInstall.install();789 }, "application/x-xpinstall");790}791// Checks that metadata is not stored if the pref is set to false792function run_test_18_1() {793 restartManager();794 Services.prefs.setBoolPref("extensions.getAddons.cache.enabled", true);795 Services.prefs.setCharPref(PREF_GETADDONS_BYIDS,796 "http://localhost:4444/data/test_install.xml");797 Services.prefs.setBoolPref("extensions.addon2@tests.mozilla.org.getAddons.cache.enabled", false);798 let url = "http://localhost:4444/addons/test_install2_1.xpi";799 AddonManager.getInstallForURL(url, function(aInstall) {800 aInstall.addListener({801 onInstallEnded(unused, aAddon) {802 do_execute_soon(function test18_install() {803 do_check_neq(aAddon.fullDescription, "Repository description");804 restartManager();805 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {806 do_check_neq(a2.fullDescription, "Repository description");807 a2.uninstall();808 do_execute_soon(run_test_19);809 });810 });811 }812 });813 aInstall.install();814 }, "application/x-xpinstall");815}816// Checks that metadata is downloaded for new installs and is visible before and817// after restart818function run_test_19() {819 restartManager();820 Services.prefs.setBoolPref("extensions.addon2@tests.mozilla.org.getAddons.cache.enabled", true);821 let url = "http://localhost:4444/addons/test_install2_1.xpi";822 AddonManager.getInstallForURL(url, function(aInstall) {823 aInstall.addListener({824 onInstallEnded(unused, aAddon) {825 do_execute_soon(function test19_install() {826 do_check_eq(aAddon.fullDescription, "Repository description");827 restartManager();828 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {829 do_check_eq(a2.fullDescription, "Repository description");830 a2.uninstall();831 do_execute_soon(run_test_20);832 });833 });834 }835 });836 aInstall.install();837 }, "application/x-xpinstall");838}839// Do the same again to make sure it works when the data is already in the cache840function run_test_20() {841 restartManager();842 let url = "http://localhost:4444/addons/test_install2_1.xpi";843 AddonManager.getInstallForURL(url, function(aInstall) {844 aInstall.addListener({845 onInstallEnded(unused, aAddon) {846 do_execute_soon(function test20_install() {847 do_check_eq(aAddon.fullDescription, "Repository description");848 restartManager();849 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {850 do_check_eq(a2.fullDescription, "Repository description");851 a2.uninstall();852 do_execute_soon(run_test_21);853 });854 });855 }856 });857 aInstall.install();858 }, "application/x-xpinstall");859}860// Verify that installing an add-on that is already pending install cancels the861// first install862function run_test_21() {863 restartManager();864 Services.prefs.setBoolPref("extensions.getAddons.cache.enabled", false);865 installAllFiles([do_get_addon("test_install2_1")], function() {866 AddonManager.getAllInstalls(function(aInstalls) {867 do_check_eq(aInstalls.length, 1);868 prepare_test({869 "addon2@tests.mozilla.org": [870 "onOperationCancelled",871 "onInstalling"872 ]873 }, [874 "onNewInstall",875 "onDownloadStarted",876 "onDownloadEnded",877 "onInstallStarted",878 "onInstallCancelled",879 "onInstallEnded",880 ], check_test_21);881 let url = "http://localhost:4444/addons/test_install2_1.xpi";882 AddonManager.getInstallForURL(url, function(aInstall) {883 aInstall.install();884 }, "application/x-xpinstall");885 });886 });887}888function check_test_21(aInstall) {889 AddonManager.getAllInstalls(callback_soon(function(aInstalls) {890 do_check_eq(aInstalls.length, 1);891 do_check_eq(aInstalls[0], aInstall);892 prepare_test({893 "addon2@tests.mozilla.org": [894 "onOperationCancelled"895 ]896 }, [897 "onInstallCancelled",898 ]);899 aInstall.cancel();900 ensure_test_completed();901 restartManager();902 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {903 do_check_eq(a2, null);904 run_test_22();905 });906 }));907}908// Tests that an install can be restarted after being cancelled909function run_test_22() {910 prepare_test({ }, [911 "onNewInstall"912 ]);913 let url = "http://localhost:4444/addons/test_install3.xpi";914 AddonManager.getInstallForURL(url, function(aInstall) {915 ensure_test_completed();916 do_check_neq(aInstall, null);917 do_check_eq(aInstall.state, AddonManager.STATE_AVAILABLE);918 prepare_test({}, [919 "onDownloadStarted",920 "onDownloadEnded",921 ], check_test_22);922 aInstall.install();923 }, "application/x-xpinstall");924}925function check_test_22(aInstall) {926 prepare_test({}, [927 "onDownloadCancelled"928 ]);929 aInstall.cancel();930 ensure_test_completed();931 prepare_test({932 "addon3@tests.mozilla.org": [933 "onInstalling"934 ]935 }, [936 "onDownloadStarted",937 "onDownloadEnded",938 "onInstallStarted",939 "onInstallEnded"940 ], finish_test_22);941 aInstall.install();942}943function finish_test_22(aInstall) {944 prepare_test({945 "addon3@tests.mozilla.org": [946 "onOperationCancelled"947 ]948 }, [949 "onInstallCancelled"950 ]);951 aInstall.cancel();952 ensure_test_completed();953 run_test_23();954}955// Tests that an install can be restarted after being cancelled when a hash956// was provided957function run_test_23() {958 prepare_test({ }, [959 "onNewInstall"960 ]);961 let url = "http://localhost:4444/addons/test_install3.xpi";962 AddonManager.getInstallForURL(url, function(aInstall) {963 ensure_test_completed();964 do_check_neq(aInstall, null);965 do_check_eq(aInstall.state, AddonManager.STATE_AVAILABLE);966 prepare_test({}, [967 "onDownloadStarted",968 "onDownloadEnded",969 ], check_test_23);970 aInstall.install();971 }, "application/x-xpinstall", do_get_addon_hash("test_install3"));972}973function check_test_23(aInstall) {974 prepare_test({}, [975 "onDownloadCancelled"976 ]);977 aInstall.cancel();978 ensure_test_completed();979 prepare_test({980 "addon3@tests.mozilla.org": [981 "onInstalling"982 ]983 }, [984 "onDownloadStarted",985 "onDownloadEnded",986 "onInstallStarted",987 "onInstallEnded"988 ], finish_test_23);989 aInstall.install();990}991function finish_test_23(aInstall) {992 prepare_test({993 "addon3@tests.mozilla.org": [994 "onOperationCancelled"995 ]996 }, [997 "onInstallCancelled"998 ]);999 aInstall.cancel();1000 ensure_test_completed();1001 run_test_24();1002}1003// Tests that an install with a bad hash can be restarted after it fails, though1004// it will only fail again1005function run_test_24() {1006 prepare_test({ }, [1007 "onNewInstall"1008 ]);1009 let url = "http://localhost:4444/addons/test_install3.xpi";1010 AddonManager.getInstallForURL(url, function(aInstall) {1011 ensure_test_completed();1012 do_check_neq(aInstall, null);1013 do_check_eq(aInstall.state, AddonManager.STATE_AVAILABLE);1014 prepare_test({}, [1015 "onDownloadStarted",1016 "onDownloadFailed",1017 ], check_test_24);1018 aInstall.install();1019 }, "application/x-xpinstall", "sha1:foo");1020}1021function check_test_24(aInstall) {1022 prepare_test({ }, [1023 "onDownloadStarted",1024 "onDownloadFailed"1025 ], run_test_25);1026 aInstall.install();1027}1028// Tests that installs with a hash for a local file work1029function run_test_25() {1030 prepare_test({ }, [1031 "onNewInstall"1032 ]);1033 let url = Services.io.newFileURI(do_get_addon("test_install3")).spec;1034 AddonManager.getInstallForURL(url, function(aInstall) {1035 ensure_test_completed();1036 do_check_neq(aInstall, null);1037 do_check_eq(aInstall.state, AddonManager.STATE_DOWNLOADED);1038 do_check_eq(aInstall.error, 0);1039 prepare_test({ }, [1040 "onDownloadCancelled"1041 ]);1042 aInstall.cancel();1043 ensure_test_completed();1044 run_test_26();1045 }, "application/x-xpinstall", do_get_addon_hash("test_install3"));1046}1047function run_test_26() {1048 prepare_test({ }, [1049 "onNewInstall",1050 "onDownloadStarted",1051 "onDownloadCancelled"1052 ]);1053 let observerService = AM_Cc["@mozilla.org/network/http-activity-distributor;1"].1054 getService(AM_Ci.nsIHttpActivityDistributor);1055 observerService.addObserver({1056 observeActivity(aChannel, aType, aSubtype, aTimestamp, aSizeData,1057 aStringData) {1058 aChannel.QueryInterface(AM_Ci.nsIChannel);1059 // Wait for the final event for the redirected URL1060 if (aChannel.URI.spec != "http://localhost:4444/addons/test_install1.xpi" ||1061 aType != AM_Ci.nsIHttpActivityObserver.ACTIVITY_TYPE_HTTP_TRANSACTION ||1062 aSubtype != AM_Ci.nsIHttpActivityObserver.ACTIVITY_SUBTYPE_TRANSACTION_CLOSE)1063 return;1064 // Request should have been cancelled1065 do_check_eq(aChannel.status, Components.results.NS_BINDING_ABORTED);1066 observerService.removeObserver(this);1067 run_test_27();1068 }1069 });1070 let url = "http://localhost:4444/redirect?/addons/test_install1.xpi";1071 AddonManager.getInstallForURL(url, function(aInstall) {1072 aInstall.addListener({1073 onDownloadProgress(aDownloadProgressInstall) {1074 aDownloadProgressInstall.cancel();1075 }1076 });1077 aInstall.install();1078 }, "application/x-xpinstall");1079}1080// Tests that an install can be restarted during onDownloadCancelled after being1081// cancelled in mid-download1082function run_test_27() {1083 prepare_test({ }, [1084 "onNewInstall"1085 ]);1086 let url = "http://localhost:4444/addons/test_install3.xpi";1087 AddonManager.getInstallForURL(url, function(aInstall) {1088 ensure_test_completed();1089 do_check_neq(aInstall, null);1090 do_check_eq(aInstall.state, AddonManager.STATE_AVAILABLE);1091 aInstall.addListener({1092 onDownloadProgress() {1093 aInstall.removeListener(this);1094 aInstall.cancel();1095 }1096 });1097 prepare_test({}, [1098 "onDownloadStarted",1099 "onDownloadCancelled",1100 ], check_test_27);1101 aInstall.install();1102 }, "application/x-xpinstall");1103}1104function check_test_27(aInstall) {1105 prepare_test({1106 "addon3@tests.mozilla.org": [1107 "onInstalling"1108 ]1109 }, [1110 "onDownloadStarted",1111 "onDownloadEnded",1112 "onInstallStarted",1113 "onInstallEnded"1114 ], finish_test_27);1115 let file = aInstall.file;1116 aInstall.install();1117 do_check_neq(file.path, aInstall.file.path);1118 do_check_false(file.exists());1119}1120function finish_test_27(aInstall) {1121 prepare_test({1122 "addon3@tests.mozilla.org": [1123 "onOperationCancelled"1124 ]1125 }, [1126 "onInstallCancelled"1127 ]);1128 aInstall.cancel();1129 ensure_test_completed();1130 run_test_30();...
offlineinstalldialog.js
Source:offlineinstalldialog.js
1// Copyright 2007 The Closure Library Authors. All Rights Reserved.2//3// Licensed under the Apache License, Version 2.0 (the "License");4// you may not use this file except in compliance with the License.5// You may obtain a copy of the License at6//7// http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an "AS-IS" BASIS,11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12// See the License for the specific language governing permissions and13// limitations under the License.14/**15 * @fileoverview A dialog for presenting the offline (Gears) install flow. It16 * show information on how to install Gears if Gears is not already installed,17 * or will offer the option to enable the application for Gears support.18 *19 * @see ../demos/offline.html20 */21goog.provide('goog.ui.OfflineInstallDialog');22goog.provide('goog.ui.OfflineInstallDialog.ButtonKeyType');23goog.provide('goog.ui.OfflineInstallDialog.EnableScreen');24goog.provide('goog.ui.OfflineInstallDialog.InstallScreen');25goog.provide('goog.ui.OfflineInstallDialog.InstallingGearsScreen');26goog.provide('goog.ui.OfflineInstallDialog.ScreenType');27goog.provide('goog.ui.OfflineInstallDialog.UpgradeScreen');28goog.provide('goog.ui.OfflineInstallDialogScreen');29goog.require('goog.Disposable');30goog.require('goog.dom.classes');31goog.require('goog.gears');32goog.require('goog.string');33goog.require('goog.string.StringBuffer');34goog.require('goog.ui.Dialog');35goog.require('goog.ui.Dialog.ButtonSet');36goog.require('goog.ui.Dialog.EventType');37goog.require('goog.window');38/**39 * An offline install dialog.40 * @param {string=} opt_class CSS class name for the dialog element, also used41 * as a class name prefix for related elements; defaults to modal-dialog.42 * @param {boolean=} opt_useIframeMask Work around windowed controls z-index43 * issue by using an iframe instead of a div for bg element.44 * @param {goog.dom.DomHelper=} opt_domHelper Optional DOM helper.45 * @constructor46 * @extends {goog.ui.Dialog}47 */48goog.ui.OfflineInstallDialog = function(49 opt_class, opt_useIframeMask, opt_domHelper) {50 goog.ui.Dialog.call(this, opt_class, opt_useIframeMask, opt_domHelper);51 /**52 * This is used to allow more screens to be added programatically. It is a53 * map from screen type to a constructor that extends54 * goog.ui.OfflineInstallDialogScreen.55 * @type {Object}56 * @private57 */58 this.screenConstructors_ = {};59 /**60 * This is a map of constructed screens. It uses the constructors in the61 * screenConstructors_ map.62 * @type {Object}63 * @private64 */65 this.screens_ = {};66 this.currentScreenType_ = goog.gears.hasFactory() ?67 goog.ui.OfflineInstallDialog.ScreenType.ENABLE :68 goog.ui.OfflineInstallDialog.ScreenType.INSTALL;69 this.registerScreenType(goog.ui.OfflineInstallDialog.EnableScreen.TYPE,70 goog.ui.OfflineInstallDialog.EnableScreen);71 this.registerScreenType(goog.ui.OfflineInstallDialog.InstallScreen.TYPE,72 goog.ui.OfflineInstallDialog.InstallScreen);73 this.registerScreenType(goog.ui.OfflineInstallDialog.UpgradeScreen.TYPE,74 goog.ui.OfflineInstallDialog.UpgradeScreen);75 this.registerScreenType(76 goog.ui.OfflineInstallDialog.InstallingGearsScreen.TYPE,77 goog.ui.OfflineInstallDialog.InstallingGearsScreen);78};79goog.inherits(goog.ui.OfflineInstallDialog, goog.ui.Dialog);80/**81 * Buttons keys of the dialog.82 * @enum {string}83 */84goog.ui.OfflineInstallDialog.ButtonKeyType = {85 INSTALL: 'io',86 UPGRADE: 'u',87 ENABLE: 'eo',88 CANCEL: 'ca',89 CLOSE: 'cl',90 OK: 'ok'91};92/**93 * The various types of screens the dialog can display.94 * @enum {string}95 */96goog.ui.OfflineInstallDialog.ScreenType = {97 INSTALL: 'i',98 INSTALLING_GEARS: 'ig',99 ENABLE: 'e',100 UPGRADE: 'u'101};102/**103 * Whether the dialog is dirty and requires an upate to its display.104 * @type {boolean}105 * @private106 */107goog.ui.OfflineInstallDialog.prototype.dirty_ = false;108/**109 * The type of the current screen of the dialog.110 * @type {string}111 * @private112 */113goog.ui.OfflineInstallDialog.prototype.currentScreenType_;114/**115 * The url of the application.116 * @type {string}117 * @private118 */119goog.ui.OfflineInstallDialog.prototype.appUrl_ = '';120/**121 * The url of the page to download Gears from.122 * @type {string}123 * @private124 */125goog.ui.OfflineInstallDialog.prototype.gearsDownloadPageUrl_ = '';126/**127 * Marks as dirty and calls update if needed.128 * @private129 */130goog.ui.OfflineInstallDialog.prototype.invalidateAndUpdate_ = function() {131 this.dirty_ = true;132 if (this.getElement() && this.isVisible()) {133 this.update();134 }135};136/**137 * Sets the URL of the appliction to show in the dialog.138 * @param {string} url The application URL.139 */140goog.ui.OfflineInstallDialog.prototype.setAppUrl = function(url) {141 this.appUrl_ = url;142 this.invalidateAndUpdate_();143};144/**145 * @return {string} The application URL.146 */147goog.ui.OfflineInstallDialog.prototype.getAppUrl = function() {148 return this.appUrl_;149};150/**151 * Sets the Gears download page URL.152 * @param {string} url The Gears download page URL.153 */154goog.ui.OfflineInstallDialog.prototype.setGearsDownloadPageUrl = function(url) {155 this.gearsDownloadPageUrl_ = url;156 this.invalidateAndUpdate_();157};158/**159 * @return {string} The Gears download page URL.160 */161goog.ui.OfflineInstallDialog.prototype.getGearsDownloadPageUrl = function() {162 return this.gearsDownloadPageUrl_;163};164/**165 * This allows you to provide a shorter and more user friendly URL to the Gears166 * download page since the Gears download URL can get quite ugly with all its167 * params.168 * @return {string} The Gears download page friendly URL.169 */170goog.ui.OfflineInstallDialog.prototype.getGearsDownloadPageFriendlyUrl =171 function() {172 return this.gearsDownloadPageFriendlyUrl_ || this.gearsDownloadPageUrl_;173};174/**175 * Sets the Gears download page friendly URL.176 * @see #getGearsDownloadPageFriendlyUrl177 * @param {string} url The Gears download page friendly URL.178 */179goog.ui.OfflineInstallDialog.prototype.setGearsDownloadPageFriendlyUrl =180 function(url) {181 this.gearsDownloadPageFriendlyUrl_ = url;182 this.invalidateAndUpdate_();183};184/**185 * Sets the screen type.186 * @param {string} screenType The screen type.187 */188goog.ui.OfflineInstallDialog.prototype.setCurrentScreenType = function(189 screenType) {190 if (screenType != this.currentScreenType_) {191 // If we have a current screen object then call deactivate on it192 var currentScreen = this.getCurrentScreen();193 if (currentScreen && this.isInDocument()) {194 currentScreen.deactivate();195 }196 this.currentScreenType_ = screenType;197 this.invalidateAndUpdate_();198 }199};200/**201 * @return {string} The screen type.202 */203goog.ui.OfflineInstallDialog.prototype.getCurrentScreenType = function() {204 return this.currentScreenType_;205};206/**207 * @return {goog.ui.OfflineInstallDialogScreen?} The current screen object.208 */209goog.ui.OfflineInstallDialog.prototype.getCurrentScreen = function() {210 return this.getScreen(this.currentScreenType_);211};212/**213 * Returns the screen object for a given registered type or null if no such type214 * exists. This will create a screen object for a registered type as needed.215 * @param {string} type The type of screen to get.216 * @return {goog.ui.OfflineInstallDialogScreen?} The screen object.217 */218goog.ui.OfflineInstallDialog.prototype.getScreen = function(type) {219 if (this.screens_[type]) {220 return this.screens_[type];221 }222 // Construct lazily as needed223 if (this.screenConstructors_[type]) {224 return this.screens_[type] = new this.screenConstructors_[type](this);225 }226 return null;227};228/**229 * Registers a screen constructor to be usable with the dialog.230 * @param {string} type The type of this screen.231 * @param {Function} constr A function that represents a constructor that232 * extends goog.ui.OfflineInstallDialogScreen.233 */234goog.ui.OfflineInstallDialog.prototype.registerScreenType = function(type,235 constr) {236 this.screenConstructors_[type] = constr;237 // Remove screen in case it already exists.238 if (this.screens_[type]) {239 var isCurrenScreenType = this.currentScreenType_ == type;240 this.screens_[type].dispose();241 delete this.screens_[type];242 if (isCurrenScreenType) {243 this.invalidateAndUpdate_();244 }245 }246};247/**248 * Registers an instance of a screen to be usable with the dialog.249 * @param {goog.ui.OfflineInstallDialogScreen} screen The screen to register.250 */251goog.ui.OfflineInstallDialog.prototype.registerScreen = function(screen) {252 this.screens_[screen.getType()] = screen;253};254/** @override */255goog.ui.OfflineInstallDialog.prototype.setVisible = function(visible) {256 if (this.isInDocument() && visible) {257 if (this.dirty_) {258 this.update();259 }260 }261 goog.ui.OfflineInstallDialog.superClass_.setVisible.call(this, visible);262};263/** @override */264goog.ui.OfflineInstallDialog.prototype.createDom = function() {265 goog.ui.OfflineInstallDialog.superClass_.createDom.call(this);266 this.update();267};268/** @override */269goog.ui.OfflineInstallDialog.prototype.enterDocument = function() {270 goog.ui.OfflineInstallDialog.superClass_.enterDocument.call(this);271 this.getHandler().listen(272 this, goog.ui.Dialog.EventType.SELECT, this.handleSelect_);273 if (this.dirty_) {274 this.update();275 }276};277/**278 * Updates the dialog. This will ensure the correct screen is shown.279 */280goog.ui.OfflineInstallDialog.prototype.update = function() {281 if (this.getElement()) {282 var screen = this.getCurrentScreen();283 if (screen) {284 screen.activate();285 }286 // Clear the dirty state.287 this.dirty_ = false;288 }289};290/**291 * Handles the SELECT_EVENT for the current dialog. Forward the event to the292 * correct screen object and let the screen decide where to go next.293 * @param {goog.ui.Dialog.Event} e The event.294 * @private295 */296goog.ui.OfflineInstallDialog.prototype.handleSelect_ = function(e) {297 var screen = this.getCurrentScreen();298 if (screen) {299 screen.handleSelect(e);300 }301};302/**303 * Opens a new browser window with the Gears download page and changes304 * the screen to the installing gears page.305 */306goog.ui.OfflineInstallDialog.prototype.goToGearsDownloadPage = function() {307 goog.window.open(this.gearsDownloadPageUrl_);308};309/** @override */310goog.ui.OfflineInstallDialog.prototype.disposeInternal = function() {311 goog.ui.OfflineInstallDialog.superClass_.disposeInternal.call(this);312 delete this.screenConstructors_;313 for (var type in this.screens_) {314 this.screens_[type].dispose();315 }316 delete this.screens_;317};318/**319 * Represents a screen on the dialog. You can create new screens and add them320 * to the offline install dialog by calling registerScreenType and321 * setCurrentScreenType.322 * @param {goog.ui.OfflineInstallDialog} dialog The dialog this screen should323 * work with.324 * @param {string} type The screen type name.325 * @constructor326 * @extends {goog.Disposable}327 */328goog.ui.OfflineInstallDialogScreen = function(dialog, type) {329 goog.Disposable.call(this);330 /**331 * @type {goog.ui.OfflineInstallDialog}332 * @protected333 * @suppress {underscore}334 */335 this.dialog_ = dialog;336 /**337 * @type {string}338 * @private339 */340 this.type_ = type;341 /**342 * @type {goog.dom.DomHelper}343 * @private344 */345 this.dom_ = dialog.getDomHelper();346};347goog.inherits(goog.ui.OfflineInstallDialogScreen, goog.Disposable);348/**349 * The HTML content to show on the screen.350 * @type {string}351 * @private352 */353goog.ui.OfflineInstallDialogScreen.prototype.content_ = '';354/**355 * The title to show on the dialog.356 * @type {string}357 * @private358 */359goog.ui.OfflineInstallDialogScreen.prototype.title_ = '';360/**361 * The button set to use with this screen.362 * @type {goog.ui.Dialog.ButtonSet}363 * @private364 */365goog.ui.OfflineInstallDialogScreen.prototype.buttonSet_;366/**367 * @return {goog.ui.OfflineInstallDialog} The dialog the screen will be368 * displayed in.369 */370goog.ui.OfflineInstallDialogScreen.prototype.getDialog = function() {371 return this.dialog_;372};373/**374 * Returns the type of the screen. This is used to identify the screen type this375 * reflects.376 * @return {string} The type of the screen.377 */378goog.ui.OfflineInstallDialogScreen.prototype.getType = function() {379 return this.type_;380};381/**382 * @return {goog.ui.Dialog.ButtonSet} The button set to use with this screen.383 */384goog.ui.OfflineInstallDialogScreen.prototype.getButtonSet = function() {385 return this.buttonSet_;386};387/**388 * Sets the button set to use with this screen.389 * @param {goog.ui.Dialog.ButtonSet} bs The button set to use.390 */391goog.ui.OfflineInstallDialogScreen.prototype.setButtonSet = function(bs) {392 this.buttonSet_ = bs;393};394/**395 * @return {string} The HTML content to used for this screen.396 */397goog.ui.OfflineInstallDialogScreen.prototype.getContent = function() {398 return this.content_;399};400/**401 * Sets the HTML content to use for this screen.402 * @param {string} html The HTML text to use as content for the screen.403 */404goog.ui.OfflineInstallDialogScreen.prototype.setContent = function(html) {405 this.content_ = html;406};407/**408 * @return {string} The text title to used for the dialog when this screen is409 * shown.410 */411goog.ui.OfflineInstallDialogScreen.prototype.getTitle = function() {412 return this.title_ || this.dialog_.getTitle();413};414/**415 * Sets the plain text title to use for this screen.416 * @param {string} title The plain text to use as a title on the dialog.417 */418goog.ui.OfflineInstallDialogScreen.prototype.setTitle = function(title) {419 this.title_ = title;420};421/**422 * @return {string} A custom class name that should be added to the dialog when423 * this screen is active.424 */425goog.ui.OfflineInstallDialogScreen.prototype.getCustomClassName = function() {426 return this.customClassName_;427};428/**429 * Sets the custom class name that should be added to the dialog when this430 * screen is active.431 * @param {string} customClassName The custom class name.432 */433goog.ui.OfflineInstallDialogScreen.prototype.setCustomClassName = function(434 customClassName) {435 this.customClassName_ = customClassName;436};437/**438 * Called when the screen is shown. At this point the dialog is in the document.439 */440goog.ui.OfflineInstallDialogScreen.prototype.activate = function() {441 var d = this.dialog_;442 // Add custom class.443 var customClassName = this.getCustomClassName();444 if (customClassName) {445 goog.dom.classes.add(d.getElement(), customClassName);446 }447 d.setTitle(this.getTitle());448 d.setContent(this.getContent());449 d.setButtonSet(this.getButtonSet());450};451/**452 * Called when the screen is hidden. At this point the dialog is in the453 * document.454 */455goog.ui.OfflineInstallDialogScreen.prototype.deactivate = function() {456 // Remove custom class name457 var customClassName = this.getCustomClassName();458 if (customClassName) {459 goog.dom.classes.remove(this.dialog_.getElement(), customClassName);460 }461};462/**463 * Called when the user clicks any of the buttons for this dialog screen.464 * @param {goog.ui.Dialog.Event} e The dialog event.465 */466goog.ui.OfflineInstallDialogScreen.prototype.handleSelect = function(e) {467};468// Classes for some of the standard screens469/**470 * This screen is shown to users that do have Gears installed but have471 * not enabled the current application for offline access.472 * @param {goog.ui.OfflineInstallDialog} dialog The dialog this is a screen473 * for.474 * @constructor475 * @extends {goog.ui.OfflineInstallDialogScreen}476 */477goog.ui.OfflineInstallDialog.EnableScreen = function(dialog) {478 goog.ui.OfflineInstallDialogScreen.call(this, dialog,479 goog.ui.OfflineInstallDialog.EnableScreen.TYPE);480 /**481 * @desc Text of button that enables offline functionality for the app.482 * @hidden483 */484 var MSG_OFFLINE_DIALOG_ENABLE_GEARS = goog.getMsg('Enable offline access');485 /**486 * @type {string}487 * @protected488 * @suppress {underscore}489 */490 this.enableMsg_ = MSG_OFFLINE_DIALOG_ENABLE_GEARS;491};492goog.inherits(goog.ui.OfflineInstallDialog.EnableScreen,493 goog.ui.OfflineInstallDialogScreen);494/**495 * The type of this screen.496 * @type {string}497 */498goog.ui.OfflineInstallDialog.EnableScreen.TYPE =499 goog.ui.OfflineInstallDialog.ScreenType.ENABLE;500/**501 * Should enable button action be performed immediately when the user presses502 * the enter key anywhere on the dialog. This should be set to false if there503 * are other action handlers on the dialog that may stop propagation.504 * @type {boolean}505 * @protected506 */507goog.ui.OfflineInstallDialog.EnableScreen.prototype.enableOnEnter = true;508/**509 * @return {goog.ui.Dialog.ButtonSet} The button set for the enable screen.510 * @override511 */512goog.ui.OfflineInstallDialog.EnableScreen.prototype.getButtonSet = function() {513 if (!this.buttonSet_) {514 /**515 * @desc Text of button that cancels setting up Offline.516 * @hidden517 */518 var MSG_OFFLINE_DIALOG_CANCEL = goog.getMsg('Cancel');519 var buttonSet = this.buttonSet_ = new goog.ui.Dialog.ButtonSet(this.dom_);520 buttonSet.set(goog.ui.OfflineInstallDialog.ButtonKeyType.ENABLE,521 this.enableMsg_, this.enableOnEnter, false);522 buttonSet.set(goog.ui.OfflineInstallDialog.ButtonKeyType.CANCEL,523 MSG_OFFLINE_DIALOG_CANCEL, false, true);524 }525 return this.buttonSet_;526};527/**528 * This screen is shown to users that do have Gears installed but have529 * not enabled the current application for offline access.530 * @param {goog.ui.OfflineInstallDialog} dialog The dialog this is a screen531 * for.532 * @param {string=} opt_type An optional type, for specifying a more specific533 * type of dialog. Only for use by subclasses.534 * @constructor535 * @extends {goog.ui.OfflineInstallDialogScreen}536 */537goog.ui.OfflineInstallDialog.InstallScreen = function(dialog, opt_type) {538 goog.ui.OfflineInstallDialogScreen.call(this, dialog,539 opt_type || goog.ui.OfflineInstallDialog.InstallScreen.TYPE);540 /**541 * @desc The description of the the install step to perform in order to542 * enable offline access.543 * @hidden544 */545 var MSG_OFFLINE_DIALOG_INSTALL_GEARS = goog.getMsg('Install Gears');546 /**547 * @type {string}548 * @protected549 * @suppress {underscore}550 */551 this.installMsg_ = MSG_OFFLINE_DIALOG_INSTALL_GEARS;552 /**553 * @desc Text of button that opens the download page for Gears.554 * @hidden555 */556 var MSG_INSTALL_GEARS = goog.getMsg('Get Gears now');557 /**558 * @type {string}559 * @protected560 * @suppress {underscore}561 */562 this.enableMsg_ = MSG_INSTALL_GEARS;563 /**564 * @desc Text of button that cancels setting up Offline.565 * @hidden566 */567 var MSG_OFFLINE_DIALOG_CANCEL_2 = goog.getMsg('Cancel');568 /**569 * @type {string}570 * @private571 */572 this.cancelMsg_ = MSG_OFFLINE_DIALOG_CANCEL_2;573};574goog.inherits(goog.ui.OfflineInstallDialog.InstallScreen,575 goog.ui.OfflineInstallDialogScreen);576/**577 * The type of this screen.578 * @type {string}579 */580goog.ui.OfflineInstallDialog.InstallScreen.TYPE =581 goog.ui.OfflineInstallDialog.ScreenType.INSTALL;582/**583 * The text to show before the installation steps.584 * @type {string}585 * @private586 */587goog.ui.OfflineInstallDialog.InstallScreen.prototype.installDescription_ = '';588/**589 * The CSS className to use when showing the app url.590 * @type {string}591 * @private592 */593goog.ui.OfflineInstallDialog.InstallScreen.prototype.appUrlClassName_ =594 goog.getCssName('goog-offlinedialog-url');595/**596 * The CSS className for the element that contains the install steps.597 * @type {string}598 * @private599 */600goog.ui.OfflineInstallDialog.InstallScreen.prototype.stepsClassName_ =601 goog.getCssName('goog-offlinedialog-steps');602/**603 * The CSS className for each step element.604 * @type {string}605 * @private606 */607goog.ui.OfflineInstallDialog.InstallScreen.prototype.stepClassName_ =608 goog.getCssName('goog-offlinedialog-step');609/**610 * The CSS className for the element that shows the step number.611 * @type {string}612 * @private613 */614goog.ui.OfflineInstallDialog.InstallScreen.prototype.stepNumberClassName_ =615 goog.getCssName('goog-offlinedialog-step-number');616/**617 * The CSS className for the element that shows the step desccription.618 * @type {string}619 * @private620 */621goog.ui.OfflineInstallDialog.InstallScreen.prototype.stepDescriptionClassName_ =622 goog.getCssName('goog-offlinedialog-step-description');623/**624 * Should install button action be performed immediately when the user presses625 * the enter key anywhere on the dialog. This should be set to false if there626 * are other action handlers on the dialog that may stop propagation.627 * @type {boolean}628 * @protected629 */630goog.ui.OfflineInstallDialog.InstallScreen.prototype.isInstallButtonDefault =631 true;632/**633 * @return {goog.ui.Dialog.ButtonSet} The button set for the install screen.634 * @override635 */636goog.ui.OfflineInstallDialog.InstallScreen.prototype.getButtonSet = function() {637 if (!this.buttonSet_) {638 var buttonSet = this.buttonSet_ = new goog.ui.Dialog.ButtonSet(this.dom_);639 buttonSet.set(goog.ui.OfflineInstallDialog.ButtonKeyType.INSTALL,640 this.enableMsg_, this.isInstallButtonDefault, false);641 buttonSet.set(goog.ui.OfflineInstallDialog.ButtonKeyType.CANCEL,642 this.cancelMsg_, false, true);643 }644 return this.buttonSet_;645};646/**647 * Sets the install description. This is the text before the installation steps.648 * @param {string} description The install description.649 */650goog.ui.OfflineInstallDialog.InstallScreen.prototype.setInstallDescription =651 function(description) {652 this.installDescription_ = description;653};654/** @override */655goog.ui.OfflineInstallDialog.InstallScreen.prototype.getContent = function() {656 if (!this.content_) {657 var sb = new goog.string.StringBuffer(this.installDescription_);658 /**659 * @desc Header for the section that states the steps for the user to660 * perform in order to enable offline access.661 * @hidden662 */663 var MSG_OFFLINE_DIALOG_NEED_TO = goog.getMsg('You\'ll need to:');664 sb.append('<div class="', this.stepsClassName_, '">',665 MSG_OFFLINE_DIALOG_NEED_TO);666 // Create and append the html for step #1.667 sb.append(this.getStepHtml_(1, this.installMsg_));668 // Create and append the html for step #2.669 /**670 * @desc One of the steps to perform in order to enable offline access.671 * @hidden672 */673 var MSG_OFFLINE_DIALOG_RESTART_BROWSER = goog.getMsg(674 'Restart your browser');675 sb.append(this.getStepHtml_(2, MSG_OFFLINE_DIALOG_RESTART_BROWSER));676 // Create and append the html for step #3.677 /**678 * @desc One of the steps to perform in order to enable offline access.679 * @hidden680 */681 var MSG_OFFLINE_DIALOG_COME_BACK = goog.getMsg('Come back to {$appUrl}!', {682 'appUrl': '<span class="' + this.appUrlClassName_ + '">' +683 this.dialog_.getAppUrl() + '</span>'684 });685 sb.append(this.getStepHtml_(3, MSG_OFFLINE_DIALOG_COME_BACK));686 // Close the enclosing element.687 sb.append('</div>');688 this.content_ = String(sb);689 }690 return this.content_;691};692/**693 * Creats the html for a step.694 * @param {number} stepNumber The number of the step.695 * @param {string} description The description of the step.696 * @private697 * @return {string} The step HTML in string form.698 */699goog.ui.OfflineInstallDialog.InstallScreen.prototype.getStepHtml_ = function(700 stepNumber, description) {701 return goog.string.buildString('<div class="', this.stepClassName_,702 '"><span class="', this.stepNumberClassName_, '">', stepNumber,703 '</span><span class="', this.stepDescriptionClassName_, '">',704 description, '</span></div>');705};706/**707 * Overrides to go to Gears page.708 * @override709 */710goog.ui.OfflineInstallDialog.InstallScreen.prototype.handleSelect =711 function(e) {712 switch (e.key) {713 case goog.ui.OfflineInstallDialog.ButtonKeyType.INSTALL:714 case goog.ui.OfflineInstallDialog.ButtonKeyType.UPGRADE:715 e.preventDefault();716 this.dialog_.goToGearsDownloadPage();717 this.dialog_.setCurrentScreenType(718 goog.ui.OfflineInstallDialog.ScreenType.INSTALLING_GEARS);719 break;720 }721};722/**723 * This screen is shown to users that needs to update their version of Gears724 * before they can enabled the current application for offline access.725 * @param {goog.ui.OfflineInstallDialog} dialog The dialog this is a screen726 * for.727 * @constructor728 * @extends {goog.ui.OfflineInstallDialog.InstallScreen}729 */730goog.ui.OfflineInstallDialog.UpgradeScreen = function(dialog) {731 goog.ui.OfflineInstallDialog.InstallScreen.call(this, dialog,732 goog.ui.OfflineInstallDialog.UpgradeScreen.TYPE);733 /**734 * @desc The description of the the upgrade step to perform in order to enable735 * offline access.736 * @hidden737 */738 var MSG_OFFLINE_DIALOG_INSTALL_NEW_GEARS = goog.getMsg(739 'Install a new version of Gears');740 /**741 * Override to say upgrade instead of install.742 * @type {string}743 * @protected744 * @suppress {underscore}745 */746 this.installMsg_ = MSG_OFFLINE_DIALOG_INSTALL_NEW_GEARS;747 /**748 * @desc Text of button that opens the download page for Gears for an749 * upgrade.750 * @hidden751 */752 var MSG_OFFLINE_DIALOG_UPGRADE_GEARS =753 goog.getMsg('Upgrade Gears now');754 /**755 * Override the text on the button to show upgrade instead of install.756 * @type {string}757 * @protected758 * @suppress {underscore}759 */760 this.enableMsg_ = MSG_OFFLINE_DIALOG_UPGRADE_GEARS;761};762goog.inherits(goog.ui.OfflineInstallDialog.UpgradeScreen,763 goog.ui.OfflineInstallDialog.InstallScreen);764/**765 * The type of this screen.766 * @type {string}767 */768goog.ui.OfflineInstallDialog.UpgradeScreen.TYPE =769 goog.ui.OfflineInstallDialog.ScreenType.UPGRADE;770/**771 * Should upgrade button action be performed immediately when the user presses772 * the enter key anywhere on the dialog. This should be set to false if there773 * are other action handlers on the dialog that may stop propagation.774 * @type {boolean}775 * @protected776 */777goog.ui.OfflineInstallDialog.UpgradeScreen.prototype.isUpgradeButtonDefault =778 true;779/**780 * @return {goog.ui.Dialog.ButtonSet} The button set for the upgrade screen.781 * @override782 */783goog.ui.OfflineInstallDialog.UpgradeScreen.prototype.getButtonSet = function() {784 if (!this.buttonSet_) {785 /**786 * @desc Text of button that cancels setting up Offline.787 * @hidden788 */789 var MSG_OFFLINE_DIALOG_CANCEL_3 = goog.getMsg('Cancel');790 var buttonSet = this.buttonSet_ = new goog.ui.Dialog.ButtonSet(this.dom_);791 buttonSet.set(goog.ui.OfflineInstallDialog.ButtonKeyType.UPGRADE,792 this.enableMsg_, this.isUpgradeButtonDefault, false);793 buttonSet.set(goog.ui.OfflineInstallDialog.ButtonKeyType.CANCEL,794 MSG_OFFLINE_DIALOG_CANCEL_3, false, true);795 }796 return this.buttonSet_;797};798/**799 * Sets the upgrade description. This is the text before the upgrade steps.800 * @param {string} description The upgrade description.801 */802goog.ui.OfflineInstallDialog.UpgradeScreen.prototype.setUpgradeDescription =803 function(description) {804 this.setInstallDescription(description);805};806/**807 * This screen is shown to users after the window to the Gears download page has808 * been opened.809 * @param {goog.ui.OfflineInstallDialog} dialog The dialog this is a screen810 * for.811 * @constructor812 * @extends {goog.ui.OfflineInstallDialogScreen}813 */814goog.ui.OfflineInstallDialog.InstallingGearsScreen = function(dialog) {815 goog.ui.OfflineInstallDialogScreen.call(this, dialog,816 goog.ui.OfflineInstallDialog.InstallingGearsScreen.TYPE);817};818goog.inherits(goog.ui.OfflineInstallDialog.InstallingGearsScreen,819 goog.ui.OfflineInstallDialogScreen);820/**821 * The type of this screen.822 * @type {string}823 */824goog.ui.OfflineInstallDialog.InstallingGearsScreen.TYPE =825 goog.ui.OfflineInstallDialog.ScreenType.INSTALLING_GEARS;826/**827 * The CSS className to use for bold text.828 * @type {string}829 * @private830 */831goog.ui.OfflineInstallDialog.InstallingGearsScreen.prototype.boldClassName_ =832 goog.getCssName('goog-offlinedialog-bold');833/**834 * Gets the button set for the dialog when the user is suposed to be installing835 * Gears.836 * @return {goog.ui.Dialog.ButtonSet} The button set.837 * @override838 */839goog.ui.OfflineInstallDialog.InstallingGearsScreen.prototype.getButtonSet =840 function() {841 if (!this.buttonSet_) {842 /**843 * @desc Text of button that closes the dialog.844 * @hidden845 */846 var MSG_OFFLINE_DIALOG_CLOSE = goog.getMsg('Close');847 var buttonSet = this.buttonSet_ =848 new goog.ui.Dialog.ButtonSet(this.dom_);849 buttonSet.set(goog.ui.OfflineInstallDialog.ButtonKeyType.CLOSE,850 MSG_OFFLINE_DIALOG_CLOSE, false, true);851 }852 return this.buttonSet_;853};854/**855 * Gets the content for the dialog when the user is suposed to be installing856 * Gears.857 * @return {string} The content of the dialog as html.858 * @override859 */860goog.ui.OfflineInstallDialog.InstallingGearsScreen.prototype.getContent =861 function() {862 if (!this.content_) {863 /**864 * @desc Congratulate the user for trying to download Google gears,865 * and give them a push in the right direction.866 */867 var MSG_OFFLINE_DIALOG_GEARS_DOWNLOAD_OPEN = goog.getMsg(868 'Great! The Gears download page has been opened in a new ' +869 'window. If you accidentally closed it, you can {$aBegin}open the ' +870 'Gears download page again{$aEnd}.',871 {872 'aBegin': '<a ' + 'target="_blank" href="' +873 this.getDialog().getGearsDownloadPageUrl() + '">',874 'aEnd': '</a>'875 });876 /**877 * @desc Informs the user to come back to the the given site after878 * installing Gears.879 * @hidden880 */881 var MSG_OFFLINE_DIALOG_GEARS_AFTER_INSTALL = goog.getMsg('After you\'ve ' +882 'downloaded and installed Gears, {$beginTag}restart your ' +883 'browser, and then come back to {$appUrl}!{$endTag}',884 {885 'beginTag': '<div class="' + this.boldClassName_ + '">',886 'endTag': '</div>', 'appUrl': this.getDialog().getAppUrl()887 });888 // Set the content.889 this.content_ = goog.string.buildString('<div>',890 MSG_OFFLINE_DIALOG_GEARS_DOWNLOAD_OPEN, '</div><br/><div>',891 MSG_OFFLINE_DIALOG_GEARS_AFTER_INSTALL, '</div>');892 }893 return this.content_;...
head.js
Source:head.js
...237 installBlocked(installInfo) {238 ok(!!this.installBlockedCallback, "Shouldn't have been blocked by the whitelist");239 if (this.installBlockedCallback && this.installBlockedCallback(installInfo)) {240 this.installBlockedCallback = null;241 installInfo.install();242 } else {243 this.expectingCancelled = true;244 installInfo.installs.forEach(function(install) {245 install.cancel();246 });247 this.expectingCancelled = false;248 this.endTest();249 }250 },251 // nsIWindowMediatorListener252 onWindowTitleChange(window, title) {253 },254 onOpenWindow(window) {255 var domwindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!