Commit 6ac76270 authored by Caitlin Fischer's avatar Caitlin Fischer Committed by Commit Bot

Enables the C++ test IncognitoPlusRegularCheck on Android.

Also, deletes the corresponding Java test, which is now redundant.

Bug: 1049736
Change-Id: I5ce89369b521a6fb4b1dbd49e091db3c6d7eb6d6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2204548Reviewed-by: default avatarAlexei Svitkine <asvitkine@chromium.org>
Reviewed-by: default avatarRobert Kaplow <rkaplow@chromium.org>
Commit-Queue: Caitlin Fischer <caitlinfischer@google.com>
Cr-Commit-Position: refs/heads/master@{#770673}
parent 288ebf14
......@@ -21,7 +21,6 @@ import org.chromium.chrome.browser.browsing_data.BrowsingDataType;
import org.chromium.chrome.browser.browsing_data.TimePeriod;
import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.metrics.util.UkmUtilsForTest;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.chrome.test.util.ChromeTabUtils;
......@@ -43,50 +42,6 @@ public class UkmTest {
mActivityTestRule.startMainActivityOnBlankPage();
}
/**
* Closes the current tab.
* @param incognito Whether to close an incognito or non-incognito tab.
*/
protected void closeCurrentTab(final boolean incognito) {
TestThreadUtils.runOnUiThreadBlocking(
() -> mActivityTestRule.getActivity().getTabModelSelector().selectModel(incognito));
ChromeTabUtils.closeCurrentTab(
InstrumentationRegistry.getInstrumentation(), mActivityTestRule.getActivity());
}
protected void closeRegularTab() {
closeCurrentTab(false);
}
protected void closeIncognitoTab() {
closeCurrentTab(true);
}
// TODO(crbug/1049736): Move this to ukm_browsertest.cc.
@Test
@SmallTest
public void testIncognitoPlusRegularCheck() {
// Keep in sync with UkmBrowserTest.IncognitoPlusRegularCheck in
// chrome/browser/metrics/ukm_browsertest.cc.
// Start by closing all tabs.
ChromeTabUtils.closeAllTabs(
InstrumentationRegistry.getInstrumentation(), mActivityTestRule.getActivity());
mActivityTestRule.newIncognitoTabFromMenu();
ChromeTabUtils.newTabFromMenu(
InstrumentationRegistry.getInstrumentation(), mActivityTestRule.getActivity());
Tab normalTab = mActivityTestRule.getActivity().getActivityTab();
TestThreadUtils.runOnUiThreadBlocking(
() -> { Assert.assertFalse(UkmUtilsForTest.isEnabled()); });
closeIncognitoTab();
TestThreadUtils.runOnUiThreadBlocking(
() -> { Assert.assertTrue(UkmUtilsForTest.isEnabled()); });
}
// TODO(crbug/1049736): Move this to ukm_browsertest.cc.
@Test
@SmallTest
......
......@@ -499,11 +499,8 @@ IN_PROC_BROWSER_TEST_F(UkmBrowserTest, RegularPlusIncognitoCheck) {
}
// Make sure opening a real window after Incognito doesn't enable UKM.
// Keep in sync with testIncognitoPlusRegularCheck in chrome/android/javatests/
// src/org/chromium/chrome/browser/metrics/UkmTest.java and with
// testIncognitoPlusRegular in ios/chrome/browser/metrics/ukm_egtest.mm.
// TODO(crbug/1049736): Enable this on Android.
#if !defined(OS_ANDROID)
// Keep in sync with testIncognitoPlusRegular in ios/chrome/browser/metrics/
// ukm_egtest.mm.
IN_PROC_BROWSER_TEST_F(UkmBrowserTest, IncognitoPlusRegularCheck) {
ukm::UkmTestHelper ukm_test_helper(GetUkmService());
MetricsConsentOverride metrics_consent(true);
......@@ -512,19 +509,20 @@ IN_PROC_BROWSER_TEST_F(UkmBrowserTest, IncognitoPlusRegularCheck) {
std::unique_ptr<ProfileSyncServiceHarness> harness =
EnableSyncForProfile(profile);
Browser* incognito_browser = CreateIncognitoBrowser();
Profile* incognito_profile = profile->GetPrimaryOTRProfile();
PlatformBrowser incognito_browser =
CreateIncognitoPlatformBrowser(incognito_profile);
EXPECT_FALSE(ukm_test_helper.IsRecordingEnabled());
Browser* sync_browser = CreateBrowser(profile);
PlatformBrowser browser = CreatePlatformBrowser(profile);
EXPECT_FALSE(ukm_test_helper.IsRecordingEnabled());
CloseBrowserSynchronously(incognito_browser);
ClosePlatformBrowser(incognito_browser);
EXPECT_TRUE(ukm_test_helper.IsRecordingEnabled());
harness->service()->GetUserSettings()->SetSyncRequested(false);
CloseBrowserSynchronously(sync_browser);
ClosePlatformBrowser(browser);
}
#endif // !defined(OS_ANDROID)
// Make sure that UKM is disabled while a guest profile's window is open.
#if !defined(OS_ANDROID)
......
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