Commit ab5f5c91 authored by Chris Lu's avatar Chris Lu Committed by Commit Bot

[ios] Return early if Translate is already in desired state

This change checks the current state of Translate and returns early if
the TranslateInfobarViewDelegate action methods are attempting to
execute either a translate or revert when Translate is already in that state.

Bug: 1014959, 1029120
Change-Id: Ifdbfe587f215876eb09d46a4dea41e6590b0f160
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1940171
Commit-Queue: Chris Lu <thegreenfrog@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Reviewed-by: default avatarPeter Lee <pkl@chromium.org>
Cr-Commit-Position: refs/heads/master@{#720095}
parent e69bf268
...@@ -1158,6 +1158,8 @@ class FakeNetworkChangeNotifier : public net::NetworkChangeNotifier { ...@@ -1158,6 +1158,8 @@ class FakeNetworkChangeNotifier : public net::NetworkChangeNotifier {
[[EarlGrey [[EarlGrey
selectElementWithMatcher:ButtonWithAccessibilityLabel(@"English")] selectElementWithMatcher:ButtonWithAccessibilityLabel(@"English")]
performAction:grey_tap()]; performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:ButtonWithAccessibilityLabel(@"French")]
performAction:grey_tap()];
} }
// Make sure that French to English translation is not automatic yet. // Make sure that French to English translation is not automatic yet.
...@@ -1211,6 +1213,9 @@ class FakeNetworkChangeNotifier : public net::NetworkChangeNotifier { ...@@ -1211,6 +1213,9 @@ class FakeNetworkChangeNotifier : public net::NetworkChangeNotifier {
[[EarlGrey [[EarlGrey
selectElementWithMatcher:ButtonWithAccessibilityLabel(@"English")] selectElementWithMatcher:ButtonWithAccessibilityLabel(@"English")]
performAction:grey_tap()]; performAction:grey_tap()];
[[EarlGrey
selectElementWithMatcher:ButtonWithAccessibilityLabel(@"French")]
performAction:grey_tap()];
} }
// Tap the notification snackbar's "UNDO" button. // Tap the notification snackbar's "UNDO" button.
[[EarlGrey selectElementWithMatcher:UndoButton()] performAction:grey_tap()]; [[EarlGrey selectElementWithMatcher:UndoButton()] performAction:grey_tap()];
......
...@@ -147,6 +147,9 @@ const char kTranslationCountHistogram[] = ...@@ -147,6 +147,9 @@ const char kTranslationCountHistogram[] =
- (void)translateInfobarViewDidTapSourceLangugage: - (void)translateInfobarViewDidTapSourceLangugage:
(TranslateInfobarView*)sender { (TranslateInfobarView*)sender {
// If already showing original language, no need to revert translate.
if (sender.state == TranslateInfobarViewStateBeforeTranslate)
return;
if ([self shouldIgnoreUserInteraction]) if ([self shouldIgnoreUserInteraction])
return; return;
...@@ -161,6 +164,9 @@ const char kTranslationCountHistogram[] = ...@@ -161,6 +164,9 @@ const char kTranslationCountHistogram[] =
- (void)translateInfobarViewDidTapTargetLangugage: - (void)translateInfobarViewDidTapTargetLangugage:
(TranslateInfobarView*)sender { (TranslateInfobarView*)sender {
// If already showing target language, no need to translate.
if (sender.state == TranslateInfobarViewStateAfterTranslate)
return;
if ([self shouldIgnoreUserInteraction]) if ([self shouldIgnoreUserInteraction])
return; return;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment