Commit 1235efd7 authored by Steven Holte's avatar Steven Holte Committed by Commit Bot

Re-remove deprecated UKM test APIs.

Bug: 761524
Change-Id: Ia9f024dc01732814a8b8eaf7a5284f99e899e418
Reviewed-on: https://chromium-review.googlesource.com/976948
Commit-Queue: Steven Holte <holte@chromium.org>
Reviewed-by: default avatarBryan McQuade <bmcquade@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Reviewed-by: default avatarSiddhartha S <ssid@chromium.org>
Cr-Commit-Position: refs/heads/master@{#545642}
parent a91cf580
......@@ -28,6 +28,7 @@
#include "chromeos/dbus/power_manager/power_supply_properties.pb.h"
#include "chromeos/dbus/power_manager_client.h"
#include "components/session_manager/session_manager_types.h"
#include "components/ukm/content/source_url_recorder.h"
#include "components/ukm/test_ukm_recorder.h"
#include "components/ukm/ukm_source.h"
#include "content/public/browser/web_contents.h"
......@@ -181,10 +182,10 @@ class UserActivityManagerTest : public ChromeRenderViewHostTestHarness {
// If |mime_type| is an empty string, the content has a default text type.
// TODO(jiameng): there doesn't seem to be a way to set form entry (via
// page importance signal). Check if there's some other way to set it.
void CreateTestWebContents(TabStripModel* const tab_strip_model,
const GURL& url,
bool is_active,
const std::string& mime_type = "") {
ukm::SourceId CreateTestWebContents(TabStripModel* const tab_strip_model,
const GURL& url,
bool is_active,
const std::string& mime_type = "") {
DCHECK(tab_strip_model);
DCHECK(!url.is_empty());
content::WebContents* contents =
......@@ -196,12 +197,7 @@ class UserActivityManagerTest : public ChromeRenderViewHostTestHarness {
WebContentsTester::For(contents)->SetMainFrameMimeType(mime_type);
WebContentsTester::For(contents)->TestSetIsLoading(false);
}
ukm::SourceId GetSourceIdForUrl(const GURL& url) {
const ukm::UkmSource* source = ukm_recorder_.GetSourceForUrl(url);
DCHECK(source);
return source->id();
return ukm::GetSourceIdForWebContentsDocument(contents);
}
void CheckTabsProperties(
......@@ -656,13 +652,12 @@ TEST_F(UserActivityManagerTest, BasicTabs) {
CreateTestBrowser(true /* is_visible */, true /* is_focused */);
BrowserList::GetInstance()->SetLastActive(browser.get());
TabStripModel* tab_strip_model = browser->tab_strip_model();
CreateTestWebContents(tab_strip_model, url1_, true /* is_active */,
"application/pdf");
const ukm::SourceId source_id1 = CreateTestWebContents(
tab_strip_model, url1_, true /* is_active */, "application/pdf");
SiteEngagementService::Get(profile())->ResetBaseScoreForURL(url1_, 95);
const ukm::SourceId source_id1 = GetSourceIdForUrl(url1_);
CreateTestWebContents(tab_strip_model, url2_, false /* is_active */);
const ukm::SourceId source_id2 = GetSourceIdForUrl(url2_);
const ukm::SourceId source_id2 =
CreateTestWebContents(tab_strip_model, url2_, false /* is_active */);
UpdateOpenTabsURLs();
......@@ -709,18 +704,18 @@ TEST_F(UserActivityManagerTest, MultiBrowsersAndTabs) {
BrowserList::GetInstance()->SetLastActive(browser1.get());
TabStripModel* tab_strip_model1 = browser1->tab_strip_model();
CreateTestWebContents(tab_strip_model1, url1_, false /* is_active */);
CreateTestWebContents(tab_strip_model1, url2_, true /* is_active */);
const ukm::SourceId source_id1 = GetSourceIdForUrl(url1_);
const ukm::SourceId source_id2 = GetSourceIdForUrl(url2_);
const ukm::SourceId source_id1 =
CreateTestWebContents(tab_strip_model1, url1_, false /* is_active */);
const ukm::SourceId source_id2 =
CreateTestWebContents(tab_strip_model1, url2_, true /* is_active */);
TabStripModel* tab_strip_model2 = browser2->tab_strip_model();
CreateTestWebContents(tab_strip_model2, url3_, true /* is_active */);
const ukm::SourceId source_id3 = GetSourceIdForUrl(url3_);
const ukm::SourceId source_id3 =
CreateTestWebContents(tab_strip_model2, url3_, true /* is_active */);
TabStripModel* tab_strip_model3 = browser3->tab_strip_model();
CreateTestWebContents(tab_strip_model3, url4_, true /* is_active */);
const ukm::SourceId source_id4 = GetSourceIdForUrl(url4_);
const ukm::SourceId source_id4 =
CreateTestWebContents(tab_strip_model3, url4_, true /* is_active */);
UpdateOpenTabsURLs();
......
......@@ -1302,10 +1302,10 @@ IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest,
std::vector<int64_t> ukm_features;
for (const auto* entry : entries) {
test_ukm_recorder_->ExpectEntrySourceHasUrl(entry, url);
const auto* metric =
test_ukm_recorder_->FindMetric(entry, internal::kUkmUseCounterFeature);
const auto* metric = test_ukm_recorder_->GetEntryMetric(
entry, internal::kUkmUseCounterFeature);
EXPECT_TRUE(metric);
ukm_features.push_back(metric->value);
ukm_features.push_back(*metric);
}
EXPECT_THAT(
ukm_features,
......@@ -1340,10 +1340,10 @@ IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest,
std::vector<int64_t> ukm_features;
for (const auto* entry : entries) {
test_ukm_recorder_->ExpectEntrySourceHasUrl(entry, url);
const auto* metric =
test_ukm_recorder_->FindMetric(entry, internal::kUkmUseCounterFeature);
const auto* metric = test_ukm_recorder_->GetEntryMetric(
entry, internal::kUkmUseCounterFeature);
EXPECT_TRUE(metric);
ukm_features.push_back(metric->value);
ukm_features.push_back(*metric);
}
EXPECT_THAT(ukm_features,
UnorderedElementsAre(
......
This diff is collapsed.
......@@ -73,109 +73,7 @@ class TestUkmRecorder : public UkmRecorderImpl {
static const int64_t* GetEntryMetric(const mojom::UkmEntry* entry,
base::StringPiece metric_name);
// All of the methods below are deprecated.
// Use GetEntriesByName based testing instead.
// TODO(crbug/761524): Migrate tests and remove these.
// Get all SourceIds with any data associated with them.
std::set<ukm::SourceId> GetSourceIds() const;
// Returns the UKM source for the given URL. If there are multiple sources for
// the given URL, this returns the first source that is created. If there is
// no source for the given URL, this returns nullptr.
const UkmSource* GetSourceForUrl(const char* url) const;
const UkmSource* GetSourceForUrl(const GURL& url) const {
return GetSourceForUrl(url.spec().c_str());
}
std::vector<const ukm::UkmSource*> GetSourcesForUrl(const char* url) const;
// Returns whether the given UKM |source| has an entry with the given
// |event_name|.
bool HasEntry(const ukm::UkmSource& source,
const char* event_name) const WARN_UNUSED_RESULT;
// Returns the number of metrics recorded for the given UKM |source| and
// |event_name|.
int CountMetricsForEventName(const ukm::UkmSource& source,
const char* event_name) const;
// Returns whether a metric with the given |metric_name| was recorded for the
// given UKM |source| and |event_name|.
bool HasMetric(const ukm::UkmSource& source,
const char* event_name,
const char* metric_name) const WARN_UNUSED_RESULT;
// Returns the number of metrics recorded with the given |metric_name|, for
// the given UKM |source| and |event_name|.
int CountMetrics(const ukm::UkmSource& source,
const char* event_name,
const char* metric_name) const WARN_UNUSED_RESULT;
// Expects that a single metric was recorded with the given |expected_value|,
// for the given |source| and |event_name|. This is shorthand for calling
// ExpectMetrics with a single value in the expected values vector.
void ExpectMetric(const ukm::UkmSource& source,
const char* event_name,
const char* metric_name,
int64_t expected_value) const;
// Expects that metrics were recorded with the given |expected_values|, for
// the given |source| and |event_name|. The order of |expected_values| is not
// significant.
void ExpectMetrics(const ukm::UkmSource& source,
const char* event_name,
const char* metric_name,
const std::vector<int64_t>& expected_values) const;
// Returns all recorded values of a metric for the given |source|,
// |event_name| and |metric_name|. The order of values is not specified.
std::vector<int64_t> GetMetricValues(ukm::SourceId source_id,
const char* event_name,
const char* metric_name) const;
// Deprecated.
// Returns all collected metrics for the given |source|, |event_name| and
// |metric_name|. The order of values is not specified.
std::vector<int64_t> GetMetrics(const UkmSource& source,
const char* event_name,
const char* metric_name) const;
// UKM entries that may be recorded multiple times for a single source may
// need to verify that an expected number of UKM entries were logged. The
// utility methods below can be used to verify expected entries. UKM entries
// that aren't recorded multiple times per source should prefer using
// HasMetric/CountMetrics/ExpectMetric(s) above.
// Returns the number of entries recorded with the given |event_name|, for the
// given UKM |source|.
int CountEntries(const ukm::UkmSource& source, const char* event_name) const;
// Expects that an entry with the given |expected_metrics| was recorded, for
// the given |source| and |event_name|. The order of |expected_metrics| is not
// significant. |expected_metrics| contains (metric name,metric value) pairs.
void ExpectEntry(const ukm::UkmSource& source,
const char* event_name,
const std::vector<std::pair<const char*, int64_t>>&
expected_metrics) const;
// Deprecated.
const mojom::UkmEntry* GetEntry(size_t entry_num) const;
// Deprecated.
const mojom::UkmEntry* GetEntryForEntryName(const char* entry_name) const;
// Deprecated.
static const mojom::UkmMetric* FindMetric(const mojom::UkmEntry* entry,
base::StringPiece metric_name);
private:
ukm::mojom::UkmEntryPtr GetMergedEntryForSourceID(
ukm::SourceId source_id,
const char* event_name) const;
std::vector<const ukm::mojom::UkmEntry*> GetEntriesForSourceID(
ukm::SourceId source_id,
const char* event_name) const;
DISALLOW_COPY_AND_ASSIGN(TestUkmRecorder);
};
......
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