implement mochitests for openpgp message compose
Categories
(MailNews Core :: Security: OpenPGP, enhancement)
Tracking
(thunderbird_esr78 wontfix)
Tracking | Status | |
---|---|---|
thunderbird_esr78 | --- | wontfix |
People
(Reporter: mkmelin, Assigned: lasana)
References
Details
Attachments
(1 file, 8 obsolete files)
34.15 KB,
patch
|
mkmelin
:
review+
|
Details | Diff | Splinter Review |
We should add mochitests to test various scenarios for message composition where OpenPGP is involved:
-
Create + send (use Send Later) a signed message + open in Outbox, verify it's signed
-
Create + send an encrypted+signed message + open in Outbox, verify it's encrypted+signed
-
Create + send an encrypted (only) + open in Outbox, verify it's encrypted+signed
-
Try to send to encrypted when
** recipient key is not available
** recipient key is available but not (yet) trusted
** more than one recipient, one recipient key available but other not
** more than one recipient, one recipient key available, some not yet trusted
(Note that this flow is clunky and should be improved, so too much details may not be worth testing, the basics still would be the same.) -
Reply to an encrypted message should use encryption by default
Assignee | ||
Comment 1•3 years ago
|
||
Here are the tests I wrote for this. They work locally but there are failures on the try server I'm trying to figure out.
Assignee | ||
Updated•3 years ago
|
Assignee | ||
Comment 2•3 years ago
|
||
Fixed some typos.
Reporter | ||
Comment 3•3 years ago
|
||
Comment on attachment 9190513 [details] [diff] [review] bug1673652.patch Review of attachment 9190513 [details] [diff] [review]: ----------------------------------------------------------------- ::: mail/test/browser/openpgp/composition/head.js @@ +6,5 @@ > + > +/** > + * Used to intercept the alert prompt that comes before the key status dialog. > + */ > +async function getAlertPromise() { Please rename this to something like unableToSendEncryptedDialog @@ +19,5 @@ > + ), > + "send message with encryption error prompt found" > + ); > + > + let closePromise = BrowserTestUtils.domWindowClosed(win); I find these easier to read if I name it e.g. let closed = ... await closed; Having the type (Promise) in the variable name is not super good practice. @@ +30,5 @@ > +/** > + * Used to intercept the dialog that displays the key statuses when an error > + * is encountered. > + */ > +async function getKeyStatusDialogPromise(callback) { It's a bit odd to mix callbacks and async Can't you just let this function resolve(win); Then let win = await getKeyStatusDialog; win.dowhatever() @@ +42,5 @@ > + > + // Used in some of the tests to verify key status display. > + win.MozXULElement.insertFTLIfNeeded( > + "messenger/openpgp/composeKeyStatus.ftl" > + ); I think you shouldn't add translations to a document. Who knows if it would cause side effects. Better to just create new Localization() and use that for accessing needed Fluent strings.
Assignee | ||
Comment 4•3 years ago
•
|
||
I find these easier to read if I name it e.g.
let closed = ...
await closed;
Having the type (Promise) in the variable name is not super good practice.
closed
seems kind of vague to me, anyone unfamiliar with BrowserTestUtils might think it's a boolean at first glance. In fact await <boolean>
is valid syntax (probably due to the automatic wrapping) so they won't be wrong in thinking that. The reason I put "Promise" in the names is to be descriptive as possible. It isn't always clear that something is a Promise without reading the source, especially when we assign them to variables before awaiting.
It's a bit odd to mix callbacks and async
Can't you just let this function resolve(win);
Then let win = await getKeyStatusDialog; win.dowhatever()
The goDoCommand
call blocks until the dialog is closed so we need to close it in the handler of promiseAlertDialogOpen
or the test will timeout. I'll add a comment about that.
Reporter | ||
Comment 5•3 years ago
|
||
Well, having type in the variable name is generally frowned upon. We don't write things like enabledBoolean
either. Your right that sometimes keeping in mind what type it is is important, but here it's usually not many lines between.
Assignee | ||
Comment 6•3 years ago
|
||
Changes made, cleaned up the tests a bit.
Assignee | ||
Comment 7•3 years ago
|
||
Finally got the tests to pass on try server (debug builds most likely fail due to being slower) except for OSX. The screenshot made also shows blank windows so I'm not sure what its problem is.
Reporter | ||
Comment 8•3 years ago
|
||
Comment on attachment 9191677 [details] [diff] [review] bug1673652v2.patch Review of attachment 9191677 [details] [diff] [review]: ----------------------------------------------------------------- Looks pretty good. If you can't get the debug builds to pass, we could consider disabling this test for debug. ::: mail/test/browser/openpgp/composition/browser_composeEncrypted.js @@ +47,5 @@ > + * @param {Function} callback - A function that is called with the dialog window > + * when it's intercepted. Opening the dialog will block until it's closed so > + * this function must close the dialog or tests will timeout. > + */ > +async function handleKeyStatusDialog(callback) { instead of passing in a callback, maybe it would be better to have this return the window? So return new Promise(resolve => { ..... resolve(win); }); @@ +324,5 @@ > + ); > + > + await OpenPGPTestUtils.toggleMessageEncryption(composeWin); > + > + let alert = handleUnableToSendEncryptedDialog(); risky using a built in function name as variable name... @@ +347,5 @@ > + > + Assert.equal( > + richItem.textContent, > + txt, > + "key acceptance status is correct" Confusing message once it fails. Please change to "... should be correct" @@ +518,5 @@ > + > + Assert.equal( > + infoList.itemChildren.length, > + 2, > + "key statuses are displayed" should be. There are similar messages elsewhere too that would be confusing. ::: mail/test/browser/openpgp/composition/head.js @@ +13,5 @@ > + win.goDoCommand("cmd_sendLater"); > + await closePromise; > + > + // Give encryption/signing time to finish. > + return new Promise(resolve => setTimeout(resolve, 0)); 0 is default, so not needed
Assignee | ||
Comment 9•3 years ago
|
||
instead of passing in a callback, maybe it would be better to have this return the window?
It does actually return the window via promiseAlertDialogOpen
, the callback is used because the dialog is opened with the "modal" property:
https://searchfox.org/comm-central/source/mail/components/compose/content/MsgComposeCommands.js#1842
The moment it opens, the current code path will block until it is closed. We can't get a reference to the window without using await on handleKeyStatusDialog
which will also block until we open the window.
Assignee | ||
Comment 10•3 years ago
|
||
Updated some of the Assert messages.
Assignee | ||
Comment 11•3 years ago
|
||
Reporter | ||
Comment 12•3 years ago
|
||
Comment on attachment 9192239 [details] [diff] [review] bug1673652v3.patch Review of attachment 9192239 [details] [diff] [review]: ----------------------------------------------------------------- Looks good bug osx still fails
Assignee | ||
Comment 13•3 years ago
|
||
I suspect the failure here is related to the L10Registry error message. If you look at the stack trace being logged it looks like the same kind of issue I brought up in bug 1679213:
2020-12-14T18:17:01.408Z] 18:17:01 INFO - L10nRegistry.loadSync@resource://gre/modules/L10nRegistry.jsm:692:19
[task 2020-12-14T18:17:01.408Z] 18:17:01 INFO - fetchFile@resource://gre/modules/L10nRegistry.jsm:607:31
[task 2020-12-14T18:17:01.408Z] 18:17:01 INFO - generateResourceSetSync/<@resource://gre/modules/L10nRegistry.jsm:512:19
[task 2020-12-14T18:17:01.408Z] 18:17:01 INFO - generateResourceSetSync@resource://gre/modules/L10nRegistry.jsm:507:22
[task 2020-12-14T18:17:01.408Z] 18:17:01 INFO - generateResourceSetsForLocaleSync@resource://gre/modules/L10nRegistry.jsm:449:44
[task 2020-12-14T18:17:01.408Z] 18:17:01 INFO - generateBundlesSync@resource://gre/modules/L10nRegistry.jsm:186:7
[task 2020-12-14T18:17:01.409Z] 18:17:01 INFO - touchNext@resource://gre/modules/Localization.jsm:167:37
[task 2020-12-14T18:17:01.409Z] 18:17:01 INFO - generateBundles@resource://gre/modules/Localization.jsm:473:15
[task 2020-12-14T18:17:01.409Z] 18:17:01 INFO - @chrome://messenger/content/messengercompose/MsgComposeCommands.js:61:19
[task 2020-12-14T18:17:01.409Z] 18:17:01 INFO - waitFor@resource://testing-common/mozmill/utils.jsm:166:12
[task 2020-12-14T18:17:01.409Z] 18:17:01 INFO - WindowWatcher_waitForWindowOpen@resource://testing-common/mozmill/WindowHelpers.jsm:266:11
[task 2020-12-14T18:17:01.409Z] 18:17:01 INFO - wait_for_new_window@resource://testing-common/mozmill/WindowHelpers.jsm:637:19
[task 2020-12-14T18:17:01.409Z] 18:17:01 INFO - wait_for_compose_window@resource://testing-common/mozmill/ComposeHelpers.jsm:277:34
[task 2020-12-14T18:17:01.409Z] 18:17:01 INFO - open_compose_new_mail@resource://testing-common/mozmill/ComposeHelpers.jsm:80:10
[task 2020-12-14T18:17:01.409Z] 18:17:01 INFO - testEncryptedMessageComposition@chrome://mochitests/content/browser/comm/mail/test/browser/openpgp/composition/browser_composeEncrypted.js:153:13
[task 2020-12-14T18:17:01.409Z] 18:17:01 INFO - Tester_execTest/<@chrome://mochikit/content/browser-test.js:1069:34
utils.waitFor
is invoked and it calls thread.processNextEvent(true)
which throws things off. Maybe it's causing things to be executed out of order? Initially I started converting waitFor to use the BrowserTestUtils functions but those changes affect other places and did break at least one test I wrote.
Should I try again? Should we land this for now?
Assignee | ||
Comment 14•3 years ago
|
||
Bug 422451 comment 0 provides some insight into the problem with nextThread. Bug 1359923 says it should not be called from JS. Looking more and more like it needs to be replaced.
Assignee | ||
Comment 15•3 years ago
|
||
Looks like we don't use it much in core but in quite a few tests:
https://searchfox.org/comm-central/search?q=processNextEvent&path=&case=true®exp=false
Reporter | ||
Comment 16•3 years ago
|
||
Maybe something like await promiseAnimationFrame
needs to be added`? IIRC I read localization is guaranteed to be ready after that (unless there are bugs).
But yes, let's try to get it landed, with potentially debug+osx disabled if they are refusing to work.
Assignee | ||
Comment 17•3 years ago
|
||
I set the test to skip on osx.
Assignee | ||
Comment 18•3 years ago
|
||
Assignee | ||
Comment 19•3 years ago
|
||
Follow up fix for typo causing bct5
Reporter | ||
Comment 20•3 years ago
|
||
Comment on attachment 9194676 [details] [diff] [review] bug1673652v5.patch Review of attachment 9194676 [details] [diff] [review]: ----------------------------------------------------------------- ::: mail/test/browser/openpgp/composition/browser.ini @@ +11,5 @@ > +support-files = ../data/** > + > +[browser_composeSigned.js] > +[browser_composeEncrypted.js] > +skip-if = os == "mac" # L10NRegistry throws NS_ERROR_FILE_UNRECOGNIZED_PATH Apparently browser_composeSigned.js also fails on osx, based on the try run I did. When we disable, also add the bug number for reference., like `skip-if = os == "mac" # Bug 1673652 - L10NRegistry throws NS_ERROR_FILE_UNRECOGNIZED_PATH` And you also needed to disable for debug, no? And, there's an ES failure ::: mail/test/browser/openpgp/composition/browser_composeEncrypted.js @@ +651,5 @@ > + ); > +}); > + > +registerCleanupFunction(function tearDown() { > + bobIdentity.setUnicharAttribute("openpgp_key_id", initialKeyIdPref); initialKeyIdPref is pretty pointless to keep around since you'll setup and remove the account anyway ::: mail/test/browser/shared-modules/OpenPGPTestUtils.jsm @@ +234,5 @@ > + > +async function clickMenuOption(win, selector) { > + let menu = win.document.querySelector("#optionsMenu"); > + EventUtils.synthesizeMouseAtCenter(menu, {}, win); > + await BrowserTestUtils.waitForEvent(menu, "popupshown"); This is wrong, maybe the thing that is causing the problems? You need to set up the waiting before clicking, otherwise you can easily wait for something that already happened, which won't work. So ` let popupshown = BrowserTestUtils.waitForEvent(menu, "popupshown"); EventUtils.synthesizeMouseAtCenter(menu, {}, win); await popupshown; ` @@ +242,5 @@ > + {}, > + win > + ); > + > + await BrowserTestUtils.waitForEvent(menu, "popuphidden"); same thing here, you need to set up the waiting before clicking.
Assignee | ||
Comment 21•3 years ago
|
||
Changes made, disabled all the tests on debug and mac.
Assignee | ||
Comment 22•3 years ago
|
||
Please note; this now needs the patch from bug 1633726 to land before applying.
Assignee | ||
Comment 23•3 years ago
|
||
Try run looks healthy (lint error already fixed).
https://treeherder.mozilla.org/jobs?repo=try-comm-central&revision=d0858d16280980864268b08cc6e1b835be2baabf
Reporter | ||
Comment 24•3 years ago
|
||
Comment on attachment 9194942 [details] [diff] [review] bug1673652v6.patch Review of attachment 9194942 [details] [diff] [review]: ----------------------------------------------------------------- r=mkmelin with the below fixed ::: mail/test/browser/openpgp/composition/browser.ini @@ +6,5 @@ > + mail.spotlight.firstRunDone=true > + mail.winsearch.firstRunDone=true > + mailnews.start_page.override_url=about:blank > + mailnews.start_page.url=about:blank > +skip-if = os == "mac" || debug # Bug 1673652 - L10NRegistry throws NS_ERROR_FILE_UNRECOGNIZED_PATH I'm surprised if this works, at least it's unusual to place it here. You should put this line *below* each test you want to disable.
Reporter | ||
Updated•3 years ago
|
Assignee | ||
Comment 25•3 years ago
|
||
I'm surprised if this works, at least it's unusual to place it here. You should put this line below each test you want to disable.
I saw it done like that elsewhere, example:
https://searchfox.org/comm-central/source/mail/test/browser/account/browser.ini#45
https://searchfox.org/comm-central/source/mozilla/accessible/tests/browser/browser.ini#2
Reporter | ||
Comment 26•3 years ago
|
||
Ah, ok. I'd still prefer these to be disabled on a per-test basis.
The tests of https://searchfox.org/comm-central/rev/e385c646e9890c5f9722489a5305fda7e9bf0ebb/mail/test/browser/account/browser.ini#45 look like they could be re-enabled since bug 1265637 is now fixed.
Assignee | ||
Comment 27•3 years ago
|
||
Change made.
Reporter | ||
Comment 28•3 years ago
|
||
Comment on attachment 9194946 [details] [diff] [review] bug1673652v8.patch Review of attachment 9194946 [details] [diff] [review]: ----------------------------------------------------------------- ::: mail/test/browser/openpgp/composition/browser.ini @@ +6,5 @@ > + mail.spotlight.firstRunDone=true > + mail.winsearch.firstRunDone=true > + mailnews.start_page.override_url=about:blank > + mailnews.start_page.url=about:blank > +skip-if = os == "mac" || debug # Bug 1673652 - L10NRegistry throws NS_ERROR_FILE_UNRECOGNIZED_PATH This is still the in the wrong place.
Assignee | ||
Comment 29•3 years ago
|
||
Sorry uploaded the wrong file, I have way too many bookmarks and patches lying around.
Reporter | ||
Updated•3 years ago
|
Comment 30•3 years ago
|
||
Pushed by mkmelin@iki.fi:
https://hg.mozilla.org/comm-central/rev/6e53cb981c40
Add tests for OpenPGP message composition. r=mkmelin
Description
•