Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: Source/web/tests/WebViewTest.cpp

Issue 908453003: Blink changes to record interest rects for http://w3c.github.io/frame-timing/ (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Update LayoutTests for new properties Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/web/WebViewImpl.cpp ('k') | Source/web/tests/data/frame_timing_1.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 27 matching lines...) Expand all
38 #include "core/frame/FrameHost.h" 38 #include "core/frame/FrameHost.h"
39 #include "core/frame/FrameView.h" 39 #include "core/frame/FrameView.h"
40 #include "core/frame/LocalFrame.h" 40 #include "core/frame/LocalFrame.h"
41 #include "core/frame/PinchViewport.h" 41 #include "core/frame/PinchViewport.h"
42 #include "core/frame/Settings.h" 42 #include "core/frame/Settings.h"
43 #include "core/html/HTMLDocument.h" 43 #include "core/html/HTMLDocument.h"
44 #include "core/html/HTMLIFrameElement.h" 44 #include "core/html/HTMLIFrameElement.h"
45 #include "core/html/HTMLInputElement.h" 45 #include "core/html/HTMLInputElement.h"
46 #include "core/html/HTMLTextAreaElement.h" 46 #include "core/html/HTMLTextAreaElement.h"
47 #include "core/layout/LayoutView.h" 47 #include "core/layout/LayoutView.h"
48 #include "core/loader/DocumentLoader.h"
48 #include "core/loader/FrameLoadRequest.h" 49 #include "core/loader/FrameLoadRequest.h"
49 #include "core/page/Chrome.h" 50 #include "core/page/Chrome.h"
50 #include "core/page/Page.h" 51 #include "core/page/Page.h"
51 #include "core/paint/DeprecatedPaintLayer.h" 52 #include "core/paint/DeprecatedPaintLayer.h"
52 #include "core/paint/DeprecatedPaintLayerPainter.h" 53 #include "core/paint/DeprecatedPaintLayerPainter.h"
54 #include "core/timing/DOMWindowPerformance.h"
55 #include "core/timing/Performance.h"
56 #include "core/timing/PerformanceCompositeTiming.h"
53 #include "platform/KeyboardCodes.h" 57 #include "platform/KeyboardCodes.h"
54 #include "platform/UserGestureIndicator.h" 58 #include "platform/UserGestureIndicator.h"
55 #include "platform/geometry/IntSize.h" 59 #include "platform/geometry/IntSize.h"
56 #include "platform/graphics/Color.h" 60 #include "platform/graphics/Color.h"
57 #include "platform/graphics/GraphicsContext.h" 61 #include "platform/graphics/GraphicsContext.h"
58 #include "platform/testing/URLTestHelpers.h" 62 #include "platform/testing/URLTestHelpers.h"
59 #include "platform/testing/UnitTestHelpers.h" 63 #include "platform/testing/UnitTestHelpers.h"
60 #include "public/platform/Platform.h" 64 #include "public/platform/Platform.h"
61 #include "public/platform/WebClipboard.h" 65 #include "public/platform/WebClipboard.h"
62 #include "public/platform/WebDisplayMode.h" 66 #include "public/platform/WebDisplayMode.h"
(...skipping 21 matching lines...) Expand all
84 #include "third_party/skia/include/core/SkCanvas.h" 88 #include "third_party/skia/include/core/SkCanvas.h"
85 #include "web/WebLocalFrameImpl.h" 89 #include "web/WebLocalFrameImpl.h"
86 #include "web/WebSettingsImpl.h" 90 #include "web/WebSettingsImpl.h"
87 #include "web/WebViewImpl.h" 91 #include "web/WebViewImpl.h"
88 #include "web/tests/FrameTestHelpers.h" 92 #include "web/tests/FrameTestHelpers.h"
89 #include <gtest/gtest.h> 93 #include <gtest/gtest.h>
90 94
91 using namespace blink; 95 using namespace blink;
92 using blink::FrameTestHelpers::loadFrame; 96 using blink::FrameTestHelpers::loadFrame;
93 using blink::URLTestHelpers::toKURL; 97 using blink::URLTestHelpers::toKURL;
98 using blink::URLTestHelpers::registerMockedURLLoad;
94 using blink::testing::runPendingTasks; 99 using blink::testing::runPendingTasks;
95 100
96 namespace { 101 namespace {
97 102
98 enum HorizontalScrollbarState { 103 enum HorizontalScrollbarState {
99 NoHorizontalScrollbar, 104 NoHorizontalScrollbar,
100 VisibleHorizontalScrollbar, 105 VisibleHorizontalScrollbar,
101 }; 106 };
102 107
103 enum VerticalScrollbarState { 108 enum VerticalScrollbarState {
(...skipping 2639 matching lines...) Expand 10 before | Expand all | Expand 10 after
2743 2748
2744 // Test without any preventDefault. 2749 // Test without any preventDefault.
2745 client.reset(); 2750 client.reset();
2746 frame->executeScript(WebScriptSource("setTest('none');")); 2751 frame->executeScript(WebScriptSource("setTest('none');"));
2747 EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureTap, WebString::fr omUTF8("target"))); 2752 EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureTap, WebString::fr omUTF8("target")));
2748 EXPECT_TRUE(client.getWasCalled()); 2753 EXPECT_TRUE(client.getWasCalled());
2749 2754
2750 m_webViewHelper.reset(); // Remove dependency on locally scoped client. 2755 m_webViewHelper.reset(); // Remove dependency on locally scoped client.
2751 } 2756 }
2752 2757
2758 // Test 3 frames, all on the same layer (i.e. [1 2 3])
2759 TEST_F(WebViewTest, TestPushFrameTimingRequestRectsToGraphicsLayer1)
2760 {
2761 std::string url = m_baseURL + "frame_timing_inner.html?100px:100px";
2762 registerMockedURLLoad(toKURL(url), "frame_timing_inner.html");
2763 url = m_baseURL + "frame_timing_inner.html?200px:200px";
2764 registerMockedURLLoad(toKURL(url), "frame_timing_inner.html");
2765 url = m_baseURL + "frame_timing_inner.html?300px:300px";
2766 registerMockedURLLoad(toKURL(url), "frame_timing_inner.html");
2767 url = m_baseURL + "frame_timing_1.html";
2768 registerMockedURLLoad(toKURL(url), "frame_timing_1.html");
2769
2770 WebView* webView = m_webViewHelper.initialize(true);
2771 loadFrame(webView->mainFrame(), url);
2772
2773 webView->resize(WebSize(800, 600));
2774 webView->layout();
2775
2776 WebViewImpl* webViewImpl = toWebViewImpl(webView);
2777
2778 Frame* frame = webViewImpl->page()->mainFrame();
2779 int64_t id = frame->frameID();
2780
2781 EXPECT_EQ(3u, frame->tree().childCount());
2782
2783 WebVector<std::pair<int64_t, WebRect>> frameTimingRequests =
2784 toLocalFrame(frame)->document()
2785 ->layoutView()->enclosingLayer()
2786 ->enclosingLayerForPaintInvalidationCrossingFrameBoundaries()
2787 ->graphicsLayerBacking()->platformLayer()->frameTimingRequests();
2788
2789 EXPECT_EQ(4u, frameTimingRequests.size());
2790 EXPECT_EQ(id + 0, frameTimingRequests[0].first);
2791 EXPECT_EQ(WebRect(0, 0, 800, 600), frameTimingRequests[0].second);
2792 EXPECT_EQ(id + 1, frameTimingRequests[1].first);
2793 EXPECT_EQ(WebRect(2, 2, 100, 100), frameTimingRequests[1].second);
2794 EXPECT_EQ(id + 2, frameTimingRequests[2].first);
2795 EXPECT_EQ(WebRect(106, 2, 200, 200), frameTimingRequests[2].second);
2796 EXPECT_EQ(id + 3, frameTimingRequests[3].first);
2797 EXPECT_EQ(WebRect(310, 2, 300, 300), frameTimingRequests[3].second);
2798 }
2799
2800 // Test 3 frames, where frame 2 is on a different GraphicsLayer (i.e. [1 2' 3])
2801 TEST_F(WebViewTest, TestPushFrameTimingRequestRectsToGraphicsLayer2)
2802 {
2803 std::string url = m_baseURL + "frame_timing_inner.html?100px:100px";
2804 registerMockedURLLoad(toKURL(url), "frame_timing_inner.html");
2805 url = m_baseURL + "frame_timing_inner.html?200px:200px";
2806 registerMockedURLLoad(toKURL(url), "frame_timing_inner.html");
2807 url = m_baseURL + "frame_timing_inner.html?300px:300px";
2808 registerMockedURLLoad(toKURL(url), "frame_timing_inner.html");
2809 url = m_baseURL + "frame_timing_2.html";
2810 registerMockedURLLoad(toKURL(url), "frame_timing_2.html");
2811
2812 WebView* webView = m_webViewHelper.initialize(true);
2813 loadFrame(webView->mainFrame(), url);
2814
2815 webView->resize(WebSize(800, 600));
2816 webView->layout();
2817
2818 WebViewImpl* webViewImpl = toWebViewImpl(webView);
2819
2820 Frame* frame = webViewImpl->page()->mainFrame();
2821 int64_t id = frame->frameID();
2822
2823 EXPECT_EQ(3u, frame->tree().childCount());
2824
2825 const WebLayer* graphicsLayer1 =
2826 toLocalFrame(webViewImpl->page()->mainFrame())->document()
2827 ->layoutView()->enclosingLayer()
2828 ->enclosingLayerForPaintInvalidationCrossingFrameBoundaries()
2829 ->graphicsLayerBacking()->platformLayer();
2830 WebVector<std::pair<int64_t, WebRect>> frameTimingRequests1 =
2831 graphicsLayer1->frameTimingRequests();
2832
2833 EXPECT_EQ(3u, frameTimingRequests1.size());
2834 EXPECT_EQ(id + 0, frameTimingRequests1[0].first);
2835 EXPECT_EQ(WebRect(0, 0, 800, 600), frameTimingRequests1[0].second);
2836 EXPECT_EQ(id + 1, frameTimingRequests1[1].first);
2837 EXPECT_EQ(WebRect(2, 2, 100, 100), frameTimingRequests1[1].second);
2838 EXPECT_EQ(id + 3, frameTimingRequests1[2].first);
2839 EXPECT_EQ(WebRect(310, 2, 300, 300), frameTimingRequests1[2].second);
2840
2841 const WebLayer* graphicsLayer2 = nullptr;
2842 for (Frame* frame = webViewImpl->page()->mainFrame(); frame;
2843 frame = frame->tree().traverseNext()) {
2844 graphicsLayer2 = toLocalFrame(frame)->document()->layoutView()
2845 ->enclosingLayer()
2846 ->enclosingLayerForPaintInvalidationCrossingFrameBoundaries()
2847 ->graphicsLayerBacking()->platformLayer();
2848 if (graphicsLayer2 != graphicsLayer1)
2849 break;
2850 }
2851 WebVector<std::pair<int64_t, WebRect>> frameTimingRequests2 =
2852 graphicsLayer2->frameTimingRequests();
2853 EXPECT_EQ(1u, frameTimingRequests2.size());
2854 EXPECT_EQ(id + 2, frameTimingRequests2[0].first);
2855 EXPECT_EQ(WebRect(2, 2, 200, 200), frameTimingRequests2[0].second);
2856 }
2857
2858
2859 // Test nested frames (i.e. [1 2'[4 5'] 3])
2860 TEST_F(WebViewTest, TestPushFrameTimingRequestRectsToGraphicsLayer3)
2861 {
2862 std::string url = m_baseURL + "frame_timing_inner.html?100px:100px";
2863 registerMockedURLLoad(toKURL(url), "frame_timing_inner.html");
2864 url = m_baseURL + "frame_timing_inner.html?200px:200px";
2865 registerMockedURLLoad(toKURL(url), "frame_timing_inner.html");
2866 url = m_baseURL + "frame_timing_inner.html?300px:300px";
2867 registerMockedURLLoad(toKURL(url), "frame_timing_inner.html");
2868 url = m_baseURL + "frame_timing_b.html";
2869 registerMockedURLLoad(toKURL(url), "frame_timing_b.html");
2870 url = m_baseURL + "frame_timing_3.html";
2871 registerMockedURLLoad(toKURL(url), "frame_timing_3.html");
2872
2873 WebView* webView = m_webViewHelper.initialize(true);
2874 loadFrame(webView->mainFrame(), url);
2875
2876 webView->resize(WebSize(800, 600));
2877 webView->layout();
2878
2879 WebViewImpl* webViewImpl = toWebViewImpl(webView);
2880
2881 Frame* frame = webViewImpl->page()->mainFrame();
2882 int64_t id = frame->frameID();
2883
2884 EXPECT_EQ(3u, frame->tree().childCount());
2885
2886 const WebLayer* graphicsLayer1 =
2887 toLocalFrame(webViewImpl->page()->mainFrame())->document()
2888 ->layoutView()->enclosingLayer()
2889 ->enclosingLayerForPaintInvalidationCrossingFrameBoundaries()
2890 ->graphicsLayerBacking()->platformLayer();
2891 WebVector<std::pair<int64_t, WebRect>> frameTimingRequests1 =
2892 graphicsLayer1->frameTimingRequests();
2893
2894 EXPECT_EQ(3u, frameTimingRequests1.size());
2895 EXPECT_EQ(id + 0, frameTimingRequests1[0].first);
2896 EXPECT_EQ(WebRect(0, 0, 800, 600), frameTimingRequests1[0].second);
2897 EXPECT_EQ(WebRect(2, 2, 100, 100), frameTimingRequests1[1].second);
2898 EXPECT_EQ(WebRect(410, 2, 200, 200), frameTimingRequests1[2].second);
2899
2900 const WebLayer* graphicsLayer2 = nullptr;
2901 for (Frame* frame = webViewImpl->page()->mainFrame(); frame;
2902 frame = frame->tree().traverseNext()) {
2903 graphicsLayer2 = toLocalFrame(frame)->document()->layoutView()
2904 ->enclosingLayer()
2905 ->enclosingLayerForPaintInvalidationCrossingFrameBoundaries()
2906 ->graphicsLayerBacking()->platformLayer();
2907 if (graphicsLayer2 != graphicsLayer1)
2908 break;
2909 }
2910 WebVector<std::pair<int64_t, WebRect>> frameTimingRequests2 =
2911 graphicsLayer2->frameTimingRequests();
2912 EXPECT_EQ(2u, frameTimingRequests2.size());
2913 EXPECT_EQ(WebRect(0, 0, 300, 300), frameTimingRequests2[0].second);
2914 EXPECT_EQ(WebRect(2, 2, 100, 100), frameTimingRequests2[1].second);
2915
2916 const WebLayer* graphicsLayer3 = nullptr;
2917 for (Frame* frame = webViewImpl->page()->mainFrame(); frame;
2918 frame = frame->tree().traverseNext()) {
2919 graphicsLayer3 = toLocalFrame(frame)->document()->layoutView()
2920 ->enclosingLayer()
2921 ->enclosingLayerForPaintInvalidationCrossingFrameBoundaries()
2922 ->graphicsLayerBacking()->platformLayer();
2923 if (graphicsLayer3 != graphicsLayer1 && graphicsLayer3 != graphicsLayer2 )
2924 break;
2925 }
2926 WebVector<std::pair<int64_t, WebRect>> frameTimingRequests3 =
2927 graphicsLayer3->frameTimingRequests();
2928 EXPECT_EQ(1u, frameTimingRequests3.size());
2929 EXPECT_EQ(WebRect(2, 2, 100, 100), frameTimingRequests3[0].second);
2930 }
2931
2932 // Test 3 frames, all on the same layer (i.e. [1 2 3])
2933 TEST_F(WebViewTest, TestRecordFrameTimingEvents)
2934 {
2935 std::string url = m_baseURL + "frame_timing_inner.html?100px:100px";
2936 registerMockedURLLoad(toKURL(url), "frame_timing_inner.html");
2937 url = m_baseURL + "frame_timing_inner.html?200px:200px";
2938 registerMockedURLLoad(toKURL(url), "frame_timing_inner.html");
2939 url = m_baseURL + "frame_timing_inner.html?300px:300px";
2940 registerMockedURLLoad(toKURL(url), "frame_timing_inner.html");
2941 url = m_baseURL + "frame_timing_1.html";
2942 registerMockedURLLoad(toKURL(url), "frame_timing_1.html");
2943
2944 WebView* webView = m_webViewHelper.initialize(true);
2945 loadFrame(webView->mainFrame(), url);
2946
2947 webView->resize(WebSize(800, 600));
2948 webView->layout();
2949
2950 WebViewImpl* webViewImpl = toWebViewImpl(webView);
2951
2952 Frame* frame = webViewImpl->page()->mainFrame();
2953 int64_t id = frame->frameID();
2954
2955 std::vector<WebFrameTimingEvent> compositePairs(3);
2956 compositePairs[0] = WebFrameTimingEvent(1, 2.0);
2957 compositePairs[1] = WebFrameTimingEvent(2, 3.0);
2958 compositePairs[2] = WebFrameTimingEvent(3, 4.0);
2959 WebVector<WebFrameTimingEvent> compositeEvents(compositePairs);
2960 webViewImpl->recordFrameTimingEvent(WebView::CompositeEvent, id, compositeEv ents);
2961 PerformanceEntryVector composites = DOMWindowPerformance::performance(*frame ->domWindow())->getEntriesByType("composite");
2962 PerformanceEntryVector renders = DOMWindowPerformance::performance(*frame->d omWindow())->getEntriesByType("render");
2963 ASSERT_EQ(3ul, composites.size());
2964 ASSERT_EQ(0ul, renders.size());
2965 for (size_t i = 0; i < composites.size(); ++i) {
2966 double docTime = frame->domWindow()->document()->loader()->timing().mono tonicTimeToZeroBasedDocumentTime(compositePairs[i].startTime) * 1000.0;
2967 ASSERT_EQ(docTime, composites[i]->startTime());
2968 }
2969
2970 // Skip ahead to subframe 2.
2971 frame = frame->tree().traverseNext();
2972 frame = frame->tree().traverseNext();
2973 id += 2;
2974
2975 std::vector<WebFrameTimingEvent> renderPairs(4);
2976 renderPairs[0] = WebFrameTimingEvent(4, 5.0, 6.0);
2977 renderPairs[1] =WebFrameTimingEvent(5, 6.0, 7.0);
2978 renderPairs[2] =WebFrameTimingEvent(6, 7.0, 8.0);
2979 renderPairs[3] =WebFrameTimingEvent(7, 8.0, 9.0);
2980 WebVector<WebFrameTimingEvent> renderEvents(renderPairs);
2981 webViewImpl->recordFrameTimingEvent(WebView::RenderEvent, id, renderEvents);
2982 composites = DOMWindowPerformance::performance(*frame->domWindow())->getEntr iesByType("composite");
2983 renders = DOMWindowPerformance::performance(*frame->domWindow())->getEntries ByType("render");
2984 ASSERT_EQ(0ul, composites.size());
2985 ASSERT_EQ(4ul, renders.size());
2986 for (size_t i = 0; i < renders.size(); ++i) {
2987 double docStartTime = frame->domWindow()->document()->loader()->timing() .monotonicTimeToZeroBasedDocumentTime(renderPairs[i].startTime) * 1000.0;
2988 ASSERT_DOUBLE_EQ(docStartTime, renders[i]->startTime());
2989 double docFinishTime = frame->domWindow()->document()->loader()->timing( ).monotonicTimeToZeroBasedDocumentTime(renderPairs[i].finishTime) * 1000.0;
2990 double docDuration = docFinishTime - docStartTime;
2991 ASSERT_DOUBLE_EQ(docDuration, renders[i]->duration());
2992 }
2993 }
2994
2753 } // namespace 2995 } // namespace
OLDNEW
« no previous file with comments | « Source/web/WebViewImpl.cpp ('k') | Source/web/tests/data/frame_timing_1.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698