|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
3 */ |
|
4 |
|
5 // Tests that attempting to install a corrupt XPI file doesn't break the universe |
|
6 |
|
7 const profileDir = gProfD.clone(); |
|
8 profileDir.append("extensions"); |
|
9 |
|
10 function run_test() { |
|
11 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1"); |
|
12 |
|
13 startupManager(); |
|
14 |
|
15 if (TEST_UNPACKED) |
|
16 run_test_unpacked(); |
|
17 else |
|
18 run_test_packed(); |
|
19 } |
|
20 |
|
21 // When installing packed we won't detect corruption in the XPI until we attempt |
|
22 // to load bootstrap.js so everything will look normal from the outside. |
|
23 function run_test_packed() { |
|
24 do_test_pending(); |
|
25 |
|
26 prepare_test({ |
|
27 "corrupt@tests.mozilla.org": [ |
|
28 ["onInstalling", false], |
|
29 ["onInstalled", false] |
|
30 ] |
|
31 }, [ |
|
32 "onNewInstall", |
|
33 "onInstallStarted", |
|
34 "onInstallEnded" |
|
35 ]); |
|
36 |
|
37 installAllFiles([do_get_file("data/corruptfile.xpi")], function() { |
|
38 ensure_test_completed(); |
|
39 |
|
40 AddonManager.getAddonByID("corrupt@tests.mozilla.org", function(addon) { |
|
41 do_check_neq(addon, null); |
|
42 |
|
43 do_test_finished(); |
|
44 }); |
|
45 }); |
|
46 } |
|
47 |
|
48 // When extracting the corruption will be detected and the add-on fails to |
|
49 // install |
|
50 function run_test_unpacked() { |
|
51 do_test_pending(); |
|
52 |
|
53 prepare_test({ |
|
54 "corrupt@tests.mozilla.org": [ |
|
55 ["onInstalling", false], |
|
56 "onOperationCancelled" |
|
57 ] |
|
58 }, [ |
|
59 "onNewInstall", |
|
60 "onInstallStarted", |
|
61 "onInstallFailed" |
|
62 ]); |
|
63 |
|
64 installAllFiles([do_get_file("data/corruptfile.xpi")], function() { |
|
65 ensure_test_completed(); |
|
66 |
|
67 // Check the add-on directory isn't left over |
|
68 var addonDir = profileDir.clone(); |
|
69 addonDir.append("corrupt@tests.mozilla.org"); |
|
70 pathShouldntExist(addonDir); |
|
71 |
|
72 // Check the staging directory isn't left over |
|
73 var stageDir = profileDir.clone(); |
|
74 stageDir.append("staged"); |
|
75 pathShouldntExist(stageDir); |
|
76 |
|
77 AddonManager.getAddonByID("corrupt@tests.mozilla.org", function(addon) { |
|
78 do_check_eq(addon, null); |
|
79 |
|
80 do_test_finished(); |
|
81 }); |
|
82 }); |
|
83 } |