-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WebUI] MetricsReporter test support enhancement
* Add HasLocalMark() used for testing the availability of mark locally. * Add mocked C++ and JS MetricsReporter. * Allow disabling JS MetricsReporter for test at runtime. This is a workaround to the restrictions on TS compilation and runtime resource loading. * Fix an issue that JS getMark() is returning null because of misuse of mojo API. Bug: 1269417 Change-Id: Ia60be3631c09079b4083eaa3d6f3aa646bea886f Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3571913 Reviewed-by: Roman Arora <romanarora@chromium.org> Reviewed-by: Demetrios Papadopoulos <dpapad@chromium.org> Commit-Queue: Keren Zhu <kerenzhu@chromium.org> Reviewed-by: Yuheng Huang <yuhengh@chromium.org> Cr-Commit-Position: refs/heads/main@{#1002056}
- Loading branch information
Showing
11 changed files
with
147 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
chrome/browser/ui/webui/metrics_reporter/mock_metrics_reporter.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright 2022 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 "chrome/browser/ui/webui/metrics_reporter/mock_metrics_reporter.h" | ||
|
||
MockMetricsReporter::MockMetricsReporter() = default; | ||
|
||
MockMetricsReporter::~MockMetricsReporter() = default; |
30 changes: 30 additions & 0 deletions
30
chrome/browser/ui/webui/metrics_reporter/mock_metrics_reporter.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2022 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_UI_WEBUI_METRICS_REPORTER_MOCK_METRICS_REPORTER_H_ | ||
#define CHROME_BROWSER_UI_WEBUI_METRICS_REPORTER_MOCK_METRICS_REPORTER_H_ | ||
|
||
#include "chrome/browser/ui/webui/metrics_reporter/metrics_reporter.h" | ||
|
||
#include "testing/gmock/include/gmock/gmock.h" | ||
|
||
class MockMetricsReporter : public MetricsReporter { | ||
public: | ||
MockMetricsReporter(); | ||
~MockMetricsReporter() override; | ||
|
||
MOCK_METHOD1(Mark, void(const std::string&)); | ||
MOCK_METHOD2(Measure, | ||
void(const std::string&, MetricsReporter::MeasureCallback)); | ||
MOCK_METHOD3(Measure, | ||
void(const std::string&, | ||
const std::string&, | ||
MetricsReporter::MeasureCallback)); | ||
MOCK_METHOD2(HasMark, | ||
void(const std::string&, MetricsReporter::HasMarkCallback)); | ||
MOCK_METHOD1(HasLocalMark, bool(const std::string&)); | ||
MOCK_METHOD1(ClearMark, void(const std::string&)); | ||
}; | ||
|
||
#endif // CHROME_BROWSER_UI_WEBUI_METRICS_REPORTER_MOCK_METRICS_REPORTER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
chrome/test/data/webui/metrics_reporter/mocked_metrics_reporter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2022 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. | ||
|
||
import {MetricsReporter} from 'chrome://resources/js/metrics_reporter/metrics_reporter.js'; | ||
|
||
export class MockedMetricsReporter implements MetricsReporter { | ||
mark(_name: string): void {} | ||
|
||
measure(_startMark: string, _endMark?: string): Promise<bigint> { | ||
return Promise.resolve(0n); | ||
} | ||
|
||
hasMark(_name: string): Promise<boolean> { | ||
return Promise.resolve(false); | ||
} | ||
|
||
hasLocalMark(_name: string): boolean { | ||
return false; | ||
} | ||
|
||
clearMark(_name: string): void {} | ||
|
||
umaReportTime(_histogram: string, _time: bigint): void {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters