Commit 2cb37fe0 authored by zmin's avatar zmin Committed by Commit bot

Revert of Break page load metrics test dependency on IPC. (patchset #2...

Revert of Break page load metrics test dependency on IPC. (patchset #2 id:20001 of https://codereview.chromium.org/2847513002/ )

Reason for revert:
PageLoadMetricsBrowserTest.DocumentWriteReloada is flaky

https://luci-milo.appspot.com/buildbot/chromium.memory/Linux%20MSan%20Tests/387

Original issue's description:
> Break page load metrics test dependency on IPC.
>
> This change breaks direct dependencies on IPC for page load metrics
> tests, in order to ease the transition to mojo.
>
> Previously, unit tests exercised the IPC dispatch path. This
> achieved slightly increased coverage but coupled unit tests to
> IPC. We now dispatch simulated timing events directly to callbacks,
> bypassing the IPC dispatch.
>
> Additionally, we break the browsertest dependency on IPC and add
> a MetricsWebContentsObserver::TestingObserver, which can observe
> state changes at the observer level, instead of watching for IPC
> messages. This both simplifies the logic and more directly verifies
> expected behavior at the appropriate level.
>
> BUG=715744
> TBR=csharrison
>
> Review-Url: https://codereview.chromium.org/2847513002
> Cr-Commit-Position: refs/heads/master@{#467687}
> Committed: https://chromium.googlesource.com/chromium/src/+/9567f9fa3fcfcaa50fc7b6a6adf66106a2eb6be5

TBR=lpy@chromium.org,bmcquade@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=715744

Review-Url: https://codereview.chromium.org/2847803002
Cr-Commit-Position: refs/heads/master@{#467691}
parent dccdf8bf
......@@ -64,6 +64,7 @@ UserInitiatedInfo CreateUserInitiatedInfo(
} // namespace
// static
MetricsWebContentsObserver::MetricsWebContentsObserver(
content::WebContents* web_contents,
std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface)
......@@ -74,7 +75,6 @@ MetricsWebContentsObserver::MetricsWebContentsObserver(
RegisterInputEventObserver(web_contents->GetRenderViewHost());
}
// static
MetricsWebContentsObserver* MetricsWebContentsObserver::CreateForWebContents(
content::WebContents* web_contents,
std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface) {
......@@ -92,9 +92,6 @@ MetricsWebContentsObserver* MetricsWebContentsObserver::CreateForWebContents(
MetricsWebContentsObserver::~MetricsWebContentsObserver() {
// TODO(csharrison): Use a more user-initiated signal for CLOSE.
NotifyPageEndAllLoads(END_CLOSE, UserInitiatedInfo::NotUserInitiated());
for (auto& observer : testing_observers_)
observer.OnGoingAway();
}
void MetricsWebContentsObserver::RegisterInputEventObserver(
......@@ -600,9 +597,6 @@ void MetricsWebContentsObserver::OnTimingUpdated(
}
committed_load_->UpdateTiming(timing, metadata);
for (auto& observer : testing_observers_)
observer.OnTimingUpdated(timing, metadata);
}
bool MetricsWebContentsObserver::ShouldTrackNavigation(
......@@ -615,32 +609,4 @@ bool MetricsWebContentsObserver::ShouldTrackNavigation(
navigation_handle).ShouldTrack();
}
void MetricsWebContentsObserver::AddTestingObserver(TestingObserver* observer) {
if (!testing_observers_.HasObserver(observer))
testing_observers_.AddObserver(observer);
}
void MetricsWebContentsObserver::RemoveTestingObserver(
TestingObserver* observer) {
testing_observers_.RemoveObserver(observer);
}
MetricsWebContentsObserver::TestingObserver::TestingObserver(
content::WebContents* web_contents)
: observer_(page_load_metrics::MetricsWebContentsObserver::FromWebContents(
web_contents)) {
observer_->AddTestingObserver(this);
}
MetricsWebContentsObserver::TestingObserver::~TestingObserver() {
if (observer_) {
observer_->RemoveTestingObserver(this);
observer_ = nullptr;
}
}
void MetricsWebContentsObserver::TestingObserver::OnGoingAway() {
observer_ = nullptr;
}
} // namespace page_load_metrics
......@@ -10,7 +10,6 @@
#include <vector>
#include "base/macros.h"
#include "base/observer_list.h"
#include "base/time/time.h"
#include "chrome/browser/page_load_metrics/page_load_metrics_observer.h"
#include "chrome/common/page_load_metrics/page_load_timing.h"
......@@ -44,27 +43,6 @@ class MetricsWebContentsObserver
public content::WebContentsUserData<MetricsWebContentsObserver>,
public content::RenderWidgetHost::InputEventObserver {
public:
// TestingObserver allows tests to observe MetricsWebContentsObserver state
// changes. Tests may use TestingObserver to wait until certain state changes,
// such as the arrivial of PageLoadTiming messages from the render process,
// have been observed.
class TestingObserver {
public:
explicit TestingObserver(content::WebContents* web_contents);
virtual ~TestingObserver();
void OnGoingAway();
// Invoked when a new PageLoadTiming update has been received and processed.
virtual void OnTimingUpdated(const PageLoadTiming& timing,
const PageLoadMetadata& metadata) {}
private:
page_load_metrics::MetricsWebContentsObserver* observer_;
DISALLOW_COPY_AND_ASSIGN(TestingObserver);
};
// Note that the returned metrics is owned by the web contents.
static MetricsWebContentsObserver* CreateForWebContents(
content::WebContents* web_contents,
......@@ -131,15 +109,6 @@ class MetricsWebContentsObserver
// This getter function is required for testing.
const PageLoadExtraInfo GetPageLoadExtraInfoForCommittedLoad();
// Register / unregister TestingObservers. Should only be called from tests.
void AddTestingObserver(TestingObserver* observer);
void RemoveTestingObserver(TestingObserver* observer);
// public only for testing
void OnTimingUpdated(content::RenderFrameHost* render_frame_host,
const PageLoadTiming& timing,
const PageLoadMetadata& metadata);
private:
friend class content::WebContentsUserData<MetricsWebContentsObserver>;
......@@ -180,6 +149,10 @@ class MetricsWebContentsObserver
content::NavigationHandle* new_navigation,
UserInitiatedInfo user_initiated_info);
void OnTimingUpdated(content::RenderFrameHost*,
const PageLoadTiming& timing,
const PageLoadMetadata& metadata);
bool ShouldTrackNavigation(
content::NavigationHandle* navigation_handle) const;
......@@ -209,8 +182,6 @@ class MetricsWebContentsObserver
// Has the MWCO observed at least one navigation?
bool has_navigated_;
base::ObserverList<TestingObserver> testing_observers_;
DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver);
};
......
......@@ -167,7 +167,10 @@ class MetricsWebContentsObserverTest : public ChromeRenderViewHostTestHarness {
void SimulateTimingUpdate(const PageLoadTiming& timing,
content::RenderFrameHost* render_frame_host) {
observer_->OnTimingUpdated(render_frame_host, timing, PageLoadMetadata());
ASSERT_TRUE(observer_->OnMessageReceived(
PageLoadMetricsMsg_TimingUpdated(observer_->routing_id(), timing,
PageLoadMetadata()),
render_frame_host));
}
void AttachObserver() {
......
......@@ -144,7 +144,9 @@ void PageLoadMetricsObserverTestHarness::SimulateTimingUpdate(
void PageLoadMetricsObserverTestHarness::SimulateTimingAndMetadataUpdate(
const PageLoadTiming& timing,
const PageLoadMetadata& metadata) {
observer_->OnTimingUpdated(web_contents()->GetMainFrame(), timing, metadata);
observer_->OnMessageReceived(PageLoadMetricsMsg_TimingUpdated(
observer_->routing_id(), timing, metadata),
web_contents()->GetMainFrame());
}
void PageLoadMetricsObserverTestHarness::SimulateStartedResource(
......
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