Commit 0d5f2bdb authored by Josh Simmons's avatar Josh Simmons Committed by Commit Bot

Fixing several issues in the Translate tests to make them less flakey.

 1) Tests were failing on pie-rel bots because swarmed builds do not
    include API keys. I've updated the tests to set a flag to ignore
    these missing keys.
 2) Tests were still flaking quite a bit due to batching and state not
    being cleared between runs. I've tried a couple things (enabling
    extensive clearing, opening new tabs and closing tabs after tests)
    but the only way I've been able to get them to run without flakes is
    by disabling batching. I'll need to dig into translate internals to
    determine what the right fix is here.
 3) Tests were failing the
    network_service_out_of_process_chrome_public_test_apk phase because,
    while the network monitor _says_ it has a connection to the internet
    during these tests, tests run under this configuration will actually
    refuse to resolve any DNS requests. I've added early returns for
    when the network service is out of process, but longer term I've
    opened crbug/1134812 to track the removal of the internet
    dependency. Similar to #2 this will take digging into Translate
    internals to make them more testable.

BUG=1141160

Change-Id: I4cac8deed71235c2e2da6a6a690edbbaed047b9a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2461711
Commit-Queue: Josh Simmons <jds@google.com>
Reviewed-by: default avatarMegan Jablonski <megjablon@chromium.org>
Reviewed-by: default avatarMichael Thiessen <mthiesse@chromium.org>
Cr-Commit-Position: refs/heads/master@{#819660}
parent 88757c64
......@@ -193,6 +193,10 @@ public class TranslateBridge {
TranslateBridgeJni.get().setExplicitLanguageAskPromptShown(shown);
}
public static void setIgnoreMissingKeyForTesting(boolean ignore) {
TranslateBridgeJni.get().setIgnoreMissingKeyForTesting(ignore); // IN-TEST
}
@NativeMethods
interface Natives {
void manualTranslateWhenReady(WebContents webContents);
......@@ -213,5 +217,6 @@ public class TranslateBridge {
void setLanguageBlockedState(String language, boolean blocked);
boolean getExplicitLanguageAskPromptShown();
void setExplicitLanguageAskPromptShown(boolean shown);
void setIgnoreMissingKeyForTesting(boolean ignore);
}
}
......@@ -412,3 +412,10 @@ static void JNI_TranslateBridge_SetExplicitLanguageAskPromptShown(
ChromeTranslateClient::CreateTranslatePrefs(GetPrefService());
translate_prefs->SetExplicitLanguageAskPromptShown(shown);
}
static void JNI_TranslateBridge_SetIgnoreMissingKeyForTesting( // IN-TEST
JNIEnv* env,
jboolean ignore) {
translate::TranslateManager::SetIgnoreMissingKeyForTesting( // IN-TEST
ignore);
}
......@@ -10,6 +10,7 @@ import android.view.View;
import org.junit.Assert;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.infobar.InfoBarContainer;
import org.chromium.chrome.browser.infobar.TranslateCompactInfoBar;
import org.chromium.components.infobars.InfoBar;
import org.chromium.components.infobars.InfoBarCompactLayout;
......@@ -18,6 +19,9 @@ import org.chromium.components.translate.TranslateTabLayout;
import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
import java.util.ArrayList;
import java.util.concurrent.TimeoutException;
/**
* Utility functions for dealing with Translate InfoBars.
*/
......@@ -100,4 +104,27 @@ public class TranslateUtil {
final TranslateCompactInfoBar infoBar, final String code) {
TestThreadUtils.runOnUiThreadBlocking(() -> { infoBar.onTargetMenuItemClicked(code); });
}
/**
* Wait until the translate infobar is present in the given InfoBarContainer and is in the given
* state. Throws a TimeoutException if the given state is never reached.
*/
public static void waitForTranslateInfoBarState(
InfoBarContainer container, boolean expectTranslated) throws TimeoutException {
CriteriaHelper.pollUiThread(() -> {
ArrayList<InfoBar> infoBars = container.getInfoBarsForTesting();
if (infoBars.isEmpty()) {
return false;
}
assertCompactTranslateInfoBar(infoBars.get(0));
TranslateCompactInfoBar infoBar = (TranslateCompactInfoBar) infoBars.get(0);
if (expectTranslated) {
return !infoBar.isSourceTabSelectedForTesting()
&& infoBar.isTargetTabSelectedForTesting();
} else {
return infoBar.isSourceTabSelectedForTesting()
&& !infoBar.isTargetTabSelectedForTesting();
}
});
}
}
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