1 // Copyright 2020 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/page_load_metrics/integration_tests/metric_integration_test.h"
6
7 #include "build/build_config.h"
8 #include "chrome/test/base/ui_test_utils.h"
9 #include "content/public/test/browser_test.h"
10 #include "services/metrics/public/cpp/ukm_builders.h"
11
12 using ukm::builders::PageLoad;
13
14 // http://crbug.com/1098148
IN_PROC_BROWSER_TEST_F(MetricIntegrationTest,DISABLED_FirstScrollDelay)15 IN_PROC_BROWSER_TEST_F(MetricIntegrationTest, DISABLED_FirstScrollDelay) {
16 LoadHTML(R"HTML(
17 <div id="content">
18 <p>This is some text</p>
19 </div>
20 <script>
21 // Stretch the content tall enough to be able to scroll the page.
22 content.style.height = window.innerHeight * 2;
23 </script>
24 )HTML");
25
26 // With a |RenderFrameSubmissionObsever| we can block until the scroll
27 // completes.
28 content::RenderFrameSubmissionObserver frame_observer(web_contents());
29
30 // Simulate scroll input.
31 const gfx::Point mouse_position(50, 50);
32 const float scroll_distance = 20.0;
33 content::SimulateMouseEvent(web_contents(), blink::WebInputEvent::Type::kMouseMove,
34 mouse_position);
35 content::SimulateMouseWheelEvent(web_contents(), mouse_position,
36 gfx::Vector2d(0, -scroll_distance),
37 blink::WebMouseWheelEvent::kPhaseBegan);
38 content::SimulateMouseWheelEvent(web_contents(), mouse_position,
39 gfx::Vector2d(0, 0),
40 blink::WebMouseWheelEvent::kPhaseEnded);
41
42 // Wait for the scroll to complete and the display to be updated.
43 frame_observer.WaitForScrollOffset(gfx::Vector2d(0, scroll_distance));
44
45 // Navigate away.
46 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
47
48 // Check UKM.
49 std::vector<const ukm::mojom::UkmEntry*> entries =
50 ukm_recorder().GetEntriesByName(PageLoad::kEntryName);
51 auto name_filter = [](const ukm::mojom::UkmEntry* entry) {
52 return !ukm::TestUkmRecorder::EntryHasMetric(
53 entry, PageLoad::kInteractiveTiming_FirstScrollDelayName);
54 };
55 // There could be other metrics recorded for PageLoad; filter them out.
56 entries.erase(std::remove_if(entries.begin(), entries.end(), name_filter),
57 entries.end());
58 EXPECT_EQ(1ul, entries.size());
59 }
60