Commit 23484e80 authored by Caitlin Fischer's avatar Caitlin Fischer Committed by Commit Bot

Enables the C++ test HistoryDeleteCheck on Android.

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

Bug: 1049736
Change-Id: Ib8fb2833128d88c6fc6189ab2e45bbb245a8d697
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2208597Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Reviewed-by: default avatarAlexei Svitkine <asvitkine@chromium.org>
Commit-Queue: Caitlin Fischer <caitlinfischer@google.com>
Cr-Commit-Position: refs/heads/master@{#771794}
parent 452f39c6
......@@ -904,8 +904,6 @@ android_library("chrome_test_java") {
"//chrome/android/webapk/libs/common:common_java",
"//chrome/browser/android/crypto:java",
"//chrome/browser/android/lifecycle:java",
"//chrome/browser/android/metrics:ukm_java_test_support",
"//chrome/browser/android/metrics:ukm_javatests",
"//chrome/browser/download/android:java",
"//chrome/browser/enterprise/util:java",
"//chrome/browser/flags:java",
......@@ -1383,7 +1381,6 @@ chrome_common_shared_library("libchromefortest") {
":chrome_jni_for_test_registration($default_toolchain)",
"//base/test:test_support",
"//chrome:chrome_android_core",
"//chrome/browser/android/metrics:ukm_utils_for_test",
"//chrome/browser/password_manager/android_test_helpers:android_wrappers",
"//chrome/browser/subresource_filter:test_support",
"//components/autofill_assistant/browser:test_support",
......@@ -1708,7 +1705,6 @@ java_group("chrome_public_base_module_java_for_test") {
":browser_java_test_support",
":chrome_public_base_module_java",
"//chrome/android/features/autofill_assistant:autofill_assistant_java_test_support",
"//chrome/browser/android/metrics:ukm_java_test_support",
"//chrome/browser/password_manager/android_test_helpers:test_support_java",
"//chrome/browser/subresource_filter:subresource_filter_java_test_support",
"//chrome/browser/thumbnail:thumbnail_java_test_support",
......
......@@ -52,11 +52,6 @@ public class UkmTest {
() -> UmaSessionStats.unSetMetricsAndCrashReportingForTesting());
}
// TODO(rkaplow): Swap these methods with the JNI methods in UkmUtilsForTest.
/*
* These helper method should stay in sync with
* chrome/browser/metrics/UkmTest.java.
*/
public String getElementContent(Tab normalTab, String elementId) throws Exception {
mSyncTestRule.loadUrlInTab(
DEBUG_PAGE, PageTransition.TYPED | PageTransition.FROM_ADDRESS_BAR, normalTab);
......@@ -77,7 +72,9 @@ public class UkmTest {
@Test
@SmallTest
public void testMetricConsent() throws Exception {
// TODO(crbug/1049736): Enable the corrersponding C++ test and delete this
// test.
public void testMetricsConsent() throws Exception {
// Keep in sync with UkmBrowserTest.MetricsConsentCheck in
// chrome/browser/metrics/ukm_browsertest.cc.
// Make sure that UKM is disabled when metrics consent is revoked.
......@@ -112,6 +109,8 @@ public class UkmTest {
@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.
......@@ -134,6 +133,8 @@ public class UkmTest {
@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.
......@@ -160,6 +161,8 @@ public class UkmTest {
@Test
@SmallTest
// TODO(crbug/1049736): Enable the corrersponding C++ test and delete this
// test.
public void singleDisableHistorySyncCheck() throws Exception {
// Keep in sync with UkmBrowserTest.SingleDisableHistorySyncCheck in
// chrome/browser/metrics/ukm_browsertest.cc.
......
# 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.
if (is_android) {
import("//build/config/android/rules.gni")
_jni_sources = [ "javatests/src/org/chromium/chrome/browser/metrics/util/UkmUtilsForTest.java" ]
static_library("ukm_utils_for_test") {
testonly = true
sources = [ "ukm_utils_for_test.cc" ]
deps = [
"//chrome/browser",
"//chrome/browser/android/metrics:jni_headers",
"//components/metrics_services_manager:metrics_services_manager",
"//components/ukm",
]
}
generate_jni("jni_headers") {
testonly = true
sources = _jni_sources
}
android_library("ukm_java_test_support") {
testonly = true
sources = _jni_sources
deps = [ "//base:base_java" ]
}
android_library("ukm_javatests") {
testonly = true
sources =
[ "javatests/src/org/chromium/chrome/browser/metrics/UkmTest.java" ]
deps = [
":ukm_java_test_support",
"//base:base_java_test_support",
"//chrome/android:chrome_java",
"//chrome/browser/tab:java",
"//chrome/test/android:chrome_java_test_support",
"//components/metrics:metrics_java",
"//content/public/test/android:content_java_test_support",
"//third_party/android_support_test_runner:rules_java",
"//third_party/android_support_test_runner:runner_java",
"//third_party/junit",
]
}
}
// Copyright 2017 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.metrics;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
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.CallbackHelper;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.chrome.browser.browsing_data.BrowsingDataBridge;
import org.chromium.chrome.browser.browsing_data.BrowsingDataBridge.OnClearBrowsingDataListener;
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.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.chrome.test.util.ChromeTabUtils;
import org.chromium.components.metrics.MetricsSwitches;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
/**
* Android UKM tests.
*/
@RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.
Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE, MetricsSwitches.FORCE_ENABLE_METRICS_REPORTING})
public class UkmTest {
@Rule
public ChromeTabbedActivityTestRule mActivityTestRule = new ChromeTabbedActivityTestRule();
@Before
public void setUp() throws InterruptedException {
mActivityTestRule.startMainActivityOnBlankPage();
}
// TODO(crbug/1049736): Move this to ukm_browsertest.cc.
@Test
@SmallTest
public void testHistoryDeleteCheck() throws Exception {
// Keep in sync with UkmBrowserTest.HistoryDeleteCheck in
// chrome/browser/metrics/ukm_browsertest.cc.
// Start by closing all tabs.
ChromeTabUtils.closeAllTabs(
InstrumentationRegistry.getInstrumentation(), mActivityTestRule.getActivity());
TestThreadUtils.runOnUiThreadBlocking(
() -> { Assert.assertTrue(UkmUtilsForTest.isEnabled()); });
long originalClientId =
TestThreadUtils
.runOnUiThreadBlocking(() -> { return UkmUtilsForTest.getClientId(); })
.longValue();
Assert.assertFalse("Non-zero client id: " + originalClientId, originalClientId == 0);
// Record some dummy UKM data (adding a Source).
final long sourceId = 0x54321;
TestThreadUtils.runOnUiThreadBlocking(() -> {
// Write data under a dummy sourceId and verify it is there.
UkmUtilsForTest.recordSourceWithId(sourceId);
Assert.assertTrue(UkmUtilsForTest.hasSourceWithId(sourceId));
});
CallbackHelper callbackHelper = new CallbackHelper();
// Clear all browsing history.
TestThreadUtils.runOnUiThreadBlocking(() -> {
BrowsingDataBridge.getInstance().clearBrowsingData(new OnClearBrowsingDataListener() {
@Override
public void onBrowsingDataCleared() {
callbackHelper.notifyCalled();
}
}, new int[] {BrowsingDataType.HISTORY}, TimePeriod.ALL_TIME);
});
callbackHelper.waitForCallback(0);
TestThreadUtils.runOnUiThreadBlocking(() -> {
// Verify that UKM is still running.
Assert.assertTrue(UkmUtilsForTest.isEnabled());
// The source under sourceId should be removed.
Assert.assertFalse(UkmUtilsForTest.hasSourceWithId(sourceId));
// Client ID should not have been reset.
Assert.assertEquals("Client id:", originalClientId, UkmUtilsForTest.getClientId());
});
}
}
// 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.
#include "base/android/jni_string.h"
#include "base/stl_util.h"
#include "chrome/browser/android/metrics/jni_headers/UkmUtilsForTest_jni.h"
#include "chrome/browser/browser_process.h"
#include "components/metrics_services_manager/metrics_services_manager.h"
#include "components/ukm/ukm_service.h"
#include "chrome/browser/android/metrics/ukm_utils_for_test.h"
using base::android::JavaParamRef;
namespace ukm {
// static
bool UkmUtilsForTest::IsEnabled() {
auto* service =
g_browser_process->GetMetricsServicesManager()->GetUkmService();
return service ? service->recording_enabled_ : false;
}
// static
bool UkmUtilsForTest::HasSourceWithId(SourceId source_id) {
auto* service =
g_browser_process->GetMetricsServicesManager()->GetUkmService();
DCHECK(service);
return base::Contains(service->sources(), source_id);
}
// static
void UkmUtilsForTest::RecordSourceWithId(SourceId source_id) {
auto* service =
g_browser_process->GetMetricsServicesManager()->GetUkmService();
DCHECK(service);
service->UpdateSourceURL(source_id, GURL("http://example.com"));
}
// static
uint64_t UkmUtilsForTest::GetClientId() {
auto* service =
g_browser_process->GetMetricsServicesManager()->GetUkmService();
DCHECK(service);
return service->client_id_;
}
} // namespace ukm
static jboolean JNI_UkmUtilsForTest_IsEnabled(JNIEnv*) {
return ukm::UkmUtilsForTest::IsEnabled();
}
static jboolean JNI_UkmUtilsForTest_HasSourceWithId(JNIEnv*,
jlong source_id) {
ukm::SourceId source = static_cast<ukm::SourceId>(source_id);
return ukm::UkmUtilsForTest::HasSourceWithId(source);
}
static void JNI_UkmUtilsForTest_RecordSourceWithId(JNIEnv*,
jlong source_id) {
ukm::SourceId source = static_cast<ukm::SourceId>(source_id);
ukm::UkmUtilsForTest::RecordSourceWithId(source);
}
static jlong JNI_UkmUtilsForTest_GetClientId(JNIEnv*) {
return ukm::UkmUtilsForTest::GetClientId();
}
// 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.
#ifndef CHROME_BROWSER_ANDROID_METRICS_UKM_UTILS_FOR_TEST_H_
#define CHROME_BROWSER_ANDROID_METRICS_UKM_UTILS_FOR_TEST_H_
#include <stdint.h>
#include "base/macros.h"
namespace ukm {
// The native part of java UkmUtilsForTest class.
class UkmUtilsForTest {
public:
static bool IsEnabled();
static bool HasSourceWithId(SourceId source_id);
static void RecordSourceWithId(SourceId source_id);
static uint64_t GetClientId();
private:
// Should never be needed, as this class is setup to let it be a friend to
// access UKM internals for testing.
UkmUtilsForTest();
~UkmUtilsForTest();
DISALLOW_COPY_AND_ASSIGN(UkmUtilsForTest);
};
} // namespace ukm
#endif // CHROME_BROWSER_ANDROID_METRICS_UKM_UTILS_FOR_TEST_H_
......@@ -88,7 +88,6 @@ typedef std::unique_ptr<TestTabModel> PlatformBrowser;
#endif // !defined(OS_ANDROID)
// Clears the specified data using BrowsingDataRemover.
#if !defined(OS_ANDROID)
void ClearBrowsingData(Profile* profile) {
content::BrowsingDataRemover* remover =
content::BrowserContext::GetBrowsingDataRemover(profile);
......@@ -101,7 +100,6 @@ void ClearBrowsingData(Profile* profile) {
// Make sure HistoryServiceObservers have a chance to be notified.
content::RunAllTasksUntilIdle();
}
#endif // !defined(OS_ANDROID)
ukm::UkmService* GetUkmService() {
return g_browser_process->GetMetricsServicesManager()->GetUkmService();
......@@ -1121,11 +1119,8 @@ IN_PROC_BROWSER_TEST_F(UkmBrowserTest, MetricsReportingCheck) {
#endif // !defined(OS_ANDROID)
// Make sure that pending data is deleted when user deletes history.
// Keep in sync with testHistoryDeleteCheck in chrome/android/javatests/src/org/
// chromium/chrome/browser/metrics/UkmTest.java and testHistoryDelete in
// ios/chrome/browser/metrics/ukm_egtest.mm.
// TODO(crbug/1049736): Enable this on Android.
#if !defined(OS_ANDROID)
// Keep in sync with testHistoryDelete in ios/chrome/browser/metrics/
// ukm_egtest.mm.
IN_PROC_BROWSER_TEST_F(UkmBrowserTest, HistoryDeleteCheck) {
ukm::UkmTestHelper ukm_test_helper(GetUkmService());
MetricsConsentOverride metrics_consent(true);
......@@ -1134,7 +1129,7 @@ IN_PROC_BROWSER_TEST_F(UkmBrowserTest, HistoryDeleteCheck) {
std::unique_ptr<ProfileSyncServiceHarness> harness =
EnableSyncForProfile(profile);
Browser* sync_browser = CreateBrowser(profile);
PlatformBrowser browser = CreatePlatformBrowser(profile);
EXPECT_TRUE(ukm_test_helper.IsRecordingEnabled());
uint64_t original_client_id = ukm_test_helper.GetClientId();
EXPECT_NE(0U, original_client_id);
......@@ -1152,9 +1147,8 @@ IN_PROC_BROWSER_TEST_F(UkmBrowserTest, HistoryDeleteCheck) {
EXPECT_TRUE(ukm_test_helper.IsRecordingEnabled());
harness->service()->GetUserSettings()->SetSyncRequested(false);
CloseBrowserSynchronously(sync_browser);
ClosePlatformBrowser(browser);
}
#endif // !defined(OS_ANDROID)
// On ChromeOS, the test profile starts with a primary account already set, so
// this test doesn't apply.
......
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