Commit 7a9bfe40 authored by Eric Seckler's avatar Eric Seckler Committed by Commit Bot

tracing: Deflake TracingPreferencesTest#testSelectCategories further

Previous attempts to deflake this test weren't successful yet, so here's
another one. Replaces actually clicking on the categories pref and
waiting for the new activity + fragment with starting it directly via
startActivitySync instead.

TBR=twellington@chromium.org

Bug: 908118
Change-Id: I3c91dea54b8628d71bedab687e727fc791f8da6b
Reviewed-on: https://chromium-review.googlesource.com/c/1350188Reviewed-by: default avatarEric Seckler <eseckler@chromium.org>
Reviewed-by: default avatarSami Kyöstilä <skyostil@chromium.org>
Commit-Queue: Eric Seckler <eseckler@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610828}
parent 95179d37
...@@ -12,6 +12,7 @@ import android.app.AlertDialog; ...@@ -12,6 +12,7 @@ import android.app.AlertDialog;
import android.app.Notification; import android.app.Notification;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.preference.CheckBoxPreference; import android.preference.CheckBoxPreference;
import android.preference.ListPreference; import android.preference.ListPreference;
import android.preference.Preference; import android.preference.Preference;
...@@ -41,13 +42,13 @@ import org.chromium.chrome.browser.ChromeFeatureList; ...@@ -41,13 +42,13 @@ import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.ChromeSwitches; import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.preferences.ButtonPreference; import org.chromium.chrome.browser.preferences.ButtonPreference;
import org.chromium.chrome.browser.preferences.Preferences; import org.chromium.chrome.browser.preferences.Preferences;
import org.chromium.chrome.browser.preferences.PreferencesLauncher;
import org.chromium.chrome.browser.preferences.PreferencesTest; import org.chromium.chrome.browser.preferences.PreferencesTest;
import org.chromium.chrome.browser.preferences.TextMessagePreference; import org.chromium.chrome.browser.preferences.TextMessagePreference;
import org.chromium.chrome.browser.tracing.TracingController; import org.chromium.chrome.browser.tracing.TracingController;
import org.chromium.chrome.browser.tracing.TracingNotificationManager; import org.chromium.chrome.browser.tracing.TracingNotificationManager;
import org.chromium.chrome.test.ChromeActivityTestRule; import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.ActivityUtils;
import org.chromium.chrome.test.util.browser.Features; import org.chromium.chrome.test.util.browser.Features;
import org.chromium.chrome.test.util.browser.notifications.MockNotificationManagerProxy; import org.chromium.chrome.test.util.browser.notifications.MockNotificationManagerProxy;
import org.chromium.content_public.browser.test.util.Criteria; import org.chromium.content_public.browser.test.util.Criteria;
...@@ -276,9 +277,7 @@ public class TracingPreferencesTest { ...@@ -276,9 +277,7 @@ public class TracingPreferencesTest {
@MediumTest @MediumTest
@Feature({"Preferences"}) @Feature({"Preferences"})
@Features.EnableFeatures(ChromeFeatureList.DEVELOPER_PREFERENCES) @Features.EnableFeatures(ChromeFeatureList.DEVELOPER_PREFERENCES)
@DisableIf.Build(sdk_is_less_than = 21, message = "crbug.com/908118")
public void testSelectCategories() throws Exception { public void testSelectCategories() throws Exception {
Context context = ContextUtils.getApplicationContext();
// We need a renderer so that its tracing categories will be populated. // We need a renderer so that its tracing categories will be populated.
mActivityTestRule.startMainActivityOnBlankPage(); mActivityTestRule.startMainActivityOnBlankPage();
Preferences activity = Preferences activity =
...@@ -304,16 +303,19 @@ public class TracingPreferencesTest { ...@@ -304,16 +303,19 @@ public class TracingPreferencesTest {
Preference categoriesPref = categoriesPrefAndSampleCategory.first; Preference categoriesPref = categoriesPrefAndSampleCategory.first;
String sampleCategoryName = categoriesPrefAndSampleCategory.second; String sampleCategoryName = categoriesPrefAndSampleCategory.second;
// Click the preference, which should open a new preferences fragment in a new activity. // Simulate clicking the preference, which should open a new preferences fragment in
Preferences categoriesActivity = ActivityUtils.waitForActivity( // a new activity.
InstrumentationRegistry.getInstrumentation(), Preferences.class, () -> { Context context = InstrumentationRegistry.getTargetContext();
ThreadUtils.runOnUiThreadBlocking(() -> { Assert.assertNotNull(categoriesPref.getExtras());
PreferencesTest.clickPreference(fragment, categoriesPref); Assert.assertFalse(categoriesPref.getExtras().isEmpty());
}); Intent intent = PreferencesLauncher.createIntentForSettingsPage(context,
}); TracingCategoriesPreferences.class.getName(), categoriesPref.getExtras());
Preferences categoriesActivity =
PreferenceFragment categoriesFragment = ActivityUtils.waitForFragmentToAttach( (Preferences) InstrumentationRegistry.getInstrumentation().startActivitySync(
categoriesActivity, PreferenceFragment.class); intent);
PreferenceFragment categoriesFragment =
(PreferenceFragment) categoriesActivity.getFragmentForTest();
Assert.assertEquals(TracingCategoriesPreferences.class, categoriesFragment.getClass()); Assert.assertEquals(TracingCategoriesPreferences.class, categoriesFragment.getClass());
CheckBoxPreference sampleCategoryPref = CheckBoxPreference sampleCategoryPref =
...@@ -332,14 +334,6 @@ public class TracingPreferencesTest { ...@@ -332,14 +334,6 @@ public class TracingPreferencesTest {
boolean finallyEnabled = boolean finallyEnabled =
TracingPreferences.getEnabledCategories().contains(sampleCategoryName); TracingPreferences.getEnabledCategories().contains(sampleCategoryName);
Assert.assertNotEquals(originallyEnabled, finallyEnabled); Assert.assertNotEquals(originallyEnabled, finallyEnabled);
// Return to original activity.
Preferences originalActivity = ActivityUtils.waitForActivity(
InstrumentationRegistry.getInstrumentation(), Preferences.class, () -> {
ThreadUtils.runOnUiThreadBlocking(() -> { categoriesActivity.finish(); });
});
Assert.assertEquals(activity, originalActivity);
} }
} }
......
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