Commit 61ce0261 authored by Caitlin Fischer's avatar Caitlin Fischer Committed by Chromium LUCI CQ

Re-adds the UkmTest.java file and re-adds two tests.

This partially reverts crrev.com/c/2247706 and crrev.com/c/2245049.

A couple of the Android tests that were ported to
chrome/browser/metrics/ukm_browsertest.cc are flaky. Temporarily
re-adding this test file ensures we have coverage while we fix the
tests. The tests being re-added are consentAddedButNoSyncCheck and
singleSyncSignoutCheck.

Also, note that mSyncTestRule.startMainActivityOnBlankPage(); is being
removed from setUp() because this is done before setUp() here [1].
Calling startMainActivityOnBlankPage() twice, once via SyncTestRule and
again via setUp(), results in a TimeoutException [2] the second time
startMainActivityOnBlankPage() is called. A log is in [3].

[1] https://source.chromium.org/chromium/chromium/src/+/master:chrome/android/javatests/src/org/chromium/chrome/browser/sync/SyncTestRule.java;l=358
[2] java.lang.RuntimeException: java.util.concurrent.TimeoutException: No Activity reached target state.
[3] https://paste.googleplex.com/6459114528964608

Original change's description:
> Remove a UKM test that should have been deleted.
>
> In the below comment, it was requested that the corresponding Android
> test be removed.
> https://chromium-review.googlesource.com/c/chromium/src/+/1869007/12/chrome/browser/metrics/ukm_browsertest.cc#b646
>
> Bug: 1049736
> Change-Id: Iac3ff27fc4d8145bef53d45aecb54efeda5e55f6
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2245049
> Commit-Queue: Caitlin Fischer <caitlinfischer@google.com>
> Reviewed-by: Robert Kaplow <rkaplow@chromium.org>
> Reviewed-by: Marc Treib <treib@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#779285}

TBR=rkaplow@chromium.org,treib@chromium.org,caitlinfischer@google.com

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: 1049736
Change-Id: I7dbc36f70ec7b9a567c7c0bb1594081c5e08dadd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2578057Reviewed-by: default avatarRobert Kaplow <rkaplow@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Reviewed-by: default avatarCaitlin Fischer <caitlinfischer@google.com>
Commit-Queue: Caitlin Fischer <caitlinfischer@google.com>
Cr-Commit-Position: refs/heads/master@{#835201}
parent 3f466911
......@@ -545,6 +545,7 @@ chrome_test_java_sources = [
"javatests/src/org/chromium/chrome/browser/sync/SyncTest.java",
"javatests/src/org/chromium/chrome/browser/sync/SyncTestRule.java",
"javatests/src/org/chromium/chrome/browser/sync/TypedUrlsTest.java",
"javatests/src/org/chromium/chrome/browser/sync/UkmTest.java",
"javatests/src/org/chromium/chrome/browser/sync/ui/PassphraseActivityTest.java",
"javatests/src/org/chromium/chrome/browser/sync/ui/PassphraseTypeDialogFragmentTest.java",
"javatests/src/org/chromium/chrome/browser/tab/InterceptNavigationDelegateTest.java",
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.sync;
import androidx.test.filters.SmallTest;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.metrics.UmaSessionStats;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.components.signin.base.CoreAccountInfo;
import org.chromium.content_public.browser.test.util.JavaScriptUtils;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.ui.base.PageTransition;
/**
* Tests for UKM Sync integration.
*/
@RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
// Note we do not use the 'force-enable-metrics-reporting' flag for these tests as they would
// ignore the Sync setting we are verifying.
public class UkmTest {
@Rule
public SyncTestRule mSyncTestRule = new SyncTestRule();
private static final String DEBUG_PAGE = "chrome://ukm/";
@Before
public void setUp() {
TestThreadUtils.runOnUiThreadBlocking(
() -> UmaSessionStats.initMetricsAndCrashReportingForTesting());
}
@After
public void tearDown() {
TestThreadUtils.runOnUiThreadBlocking(
() -> UmaSessionStats.unSetMetricsAndCrashReportingForTesting());
}
public String getElementContent(Tab normalTab, String elementId) throws Exception {
mSyncTestRule.loadUrlInTab(
DEBUG_PAGE, PageTransition.TYPED | PageTransition.FROM_ADDRESS_BAR, normalTab);
return JavaScriptUtils.executeJavaScriptAndWaitForResult(normalTab.getWebContents(),
"document.getElementById('" + elementId + "').textContent");
}
public boolean isUkmEnabled(Tab normalTab) throws Exception {
String state = getElementContent(normalTab, "state");
Assert.assertTrue(
"UKM state: " + state, state.equals("\"ENABLED\"") || state.equals("\"DISABLED\""));
return state.equals("\"ENABLED\"");
}
public String getUkmClientId(Tab normalTab) throws Exception {
return getElementContent(normalTab, "clientid");
}
@Test
@SmallTest
// TODO(crbug/1049736): Enable the corrersponding C++ test and delete this
// test.
public void consentAddedButNoSyncCheck() throws Exception {
// Keep in sync with UkmBrowserTest.ConsentAddedButNoSyncCheck in
// chrome/browser/metrics/ukm_browsertest.cc.
// Make sure that providing consent doesn't enable UKM when sync is disabled.
TestThreadUtils.runOnUiThreadBlocking(
() -> UmaSessionStats.updateMetricsAndCrashReportingForTesting(false));
Tab normalTab = mSyncTestRule.getActivity().getActivityTab();
Assert.assertFalse("UKM Enabled:", isUkmEnabled(normalTab));
// Enable consent, Sync still not enabled so UKM should be disabled.
TestThreadUtils.runOnUiThreadBlocking(
() -> UmaSessionStats.updateMetricsAndCrashReportingForTesting(true));
Assert.assertFalse("UKM Enabled:", isUkmEnabled(normalTab));
// Finally, sign in and UKM is enabled.
CoreAccountInfo account = mSyncTestRule.setUpAccountAndSignInForTesting();
Assert.assertTrue("UKM Enabled:", isUkmEnabled(normalTab));
}
@Test
@SmallTest
// TODO(crbug/1049736): Enable the corrersponding C++ test and delete this
// test.
public void singleSyncSignoutCheck() throws Exception {
// Keep in sync with UkmBrowserTest.SingleSyncSignoutCheck in
// chrome/browser/metrics/ukm_browsertest.cc.
// Make sure that UKM is disabled when an secondary passphrase is set.
TestThreadUtils.runOnUiThreadBlocking(
() -> UmaSessionStats.updateMetricsAndCrashReportingForTesting(true));
// Enable a Syncing account.
CoreAccountInfo account = mSyncTestRule.setUpAccountAndSignInForTesting();
Tab normalTab = mSyncTestRule.getActivity().getActivityTab();
Assert.assertTrue("UKM Enabled:", isUkmEnabled(normalTab));
String clientId = getUkmClientId(normalTab);
// Signing out should disable UKM.
mSyncTestRule.signOut();
Assert.assertFalse("UKM Enabled:", isUkmEnabled(normalTab));
// Client ID should have been reset.
Assert.assertNotEquals("Client id:", clientId, getUkmClientId(normalTab));
}
}
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