Skip to content

Commit bd5c8af

Browse files
author
Ioan Moldovan
authored
#5904 fix: persist reply mode when switching to secure compose (#5910)
* fix: persist reply mode when switching to secure compose * feat: added ui test * increase timeout * increase timeout * fix: cleanup * fix: reply * fix: reply issue * fix: remove console.log
1 parent aeda798 commit bd5c8af

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

extension/js/content_scripts/webmail/gmail/gmail-element-replacer.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export class GmailElementReplacer extends WebmailElementReplacer {
4040
private removeNextReplyBoxBorders = false;
4141
private lastSwitchToEncryptedReply = false;
4242
private replyOption: ReplyOption | undefined;
43+
private lastReplyOption: ReplyOption | undefined;
4344

4445
private sel = {
4546
// gmail_variant=standard|new
@@ -642,6 +643,8 @@ export class GmailElementReplacer extends WebmailElementReplacer {
642643
const legacyDraftReplyRegex = new RegExp(/\[(flowcrypt|cryptup):link:draft_reply:([0-9a-fr\-]+)]/);
643644
const newReplyBoxes = $('div.nr.tMHS5d, td.amr > div.nr, div.gA td.I5').not('.reply_message_evaluated').filter(':visible').get();
644645
if (newReplyBoxes.length) {
646+
// removing this line will cause unexpected draft creation bug reappear
647+
// https://github.com/FlowCrypt/flowcrypt-browser/issues/5616#issuecomment-1972897692
645648
this.replyOption = undefined;
646649
// cache for subseqent loop runs
647650
const convoRootEl = this.getConvoRootEl(newReplyBoxes[0]);
@@ -688,6 +691,10 @@ export class GmailElementReplacer extends WebmailElementReplacer {
688691
const replyOption = this.parseReplyOption(replyBox);
689692
if (replyOption) {
690693
this.replyOption = replyOption;
694+
this.lastReplyOption = replyOption;
695+
} else if (this.lastReplyOption) {
696+
this.replyOption = this.lastReplyOption;
697+
this.lastReplyOption = undefined;
691698
}
692699
replyParams.replyOption = this.replyOption;
693700
// either is a draft in the middle, or the convo already had (last) box replaced: should also be useless draft
@@ -708,8 +715,10 @@ export class GmailElementReplacer extends WebmailElementReplacer {
708715
if (hasDraft || alreadyHasSecureReplyBox) {
709716
replyBox.addClass('reply_message_evaluated remove_borders').parent().append(secureReplyBoxXssSafe); // xss-safe-factory
710717
replyBox.hide();
718+
this.lastReplyOption = undefined;
711719
} else if (isReplyButtonView) {
712720
replyBox.replaceWith(secureReplyBoxXssSafe); // xss-safe-factory
721+
this.lastReplyOption = undefined;
713722
this.replyOption = undefined;
714723
} else {
715724
const deleteReplyEl = document.querySelector('.oh.J-Z-I.J-J5-Ji.T-I-ax7');

test/source/tests/gmail.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,29 @@ export const defineGmailTests = (testVariant: TestVariant, testWithBrowser: Test
457457
})
458458
);
459459

460+
test(
461+
'mail.google.com - switch to encrypted forward',
462+
testWithBrowser(async (t, browser) => {
463+
await BrowserRecipe.setUpCommonAcct(t, browser, 'ci.tests.gmail');
464+
const gmailPage = await openGmailPage(t, browser);
465+
await gotoGmailPage(gmailPage, '/FMfcgzGtwgfMhWTlgRwwKWzRhqNZzwXz'); // go to encrypted convo
466+
await Util.sleep(5);
467+
await gmailPage.waitAndClick('.adn [data-tooltip="More"]', { delay: 1 });
468+
await gmailPage.waitAndClick('[act="25"]', { delay: 1 }); // click forward
469+
await Util.sleep(3);
470+
await gmailPage.waitAll('[data-tooltip^="Send"]'); // The Send button from the Standard reply box
471+
await gmailPage.waitForContent(
472+
'.reply_message_evaluated .error_notification',
473+
'The last message was encrypted, but you are composing a message without encryption. Switch to encrypted compose'
474+
);
475+
await gmailPage.waitAndClick('#switch_to_encrypted_reply'); // Switch to encrypted compose
476+
await Util.sleep(3);
477+
const replyBox2 = await gmailPage.getFrame(['/chrome/elements/compose.htm'], { sleep: 5 });
478+
await Util.sleep(3);
479+
await replyBox2.waitForContent('@input-body', '---------- Forwarded message ---------');
480+
})
481+
);
482+
460483
test(
461484
'mail.google.com - secure reply and forward in dot menu',
462485
testWithBrowser(async (t, browser) => {

0 commit comments

Comments
 (0)