Skip to content

Commit aa5329f

Browse files
[WTR] Pixel tests generate the snapshots twice in Web and UI processes
https://bugs.webkit.org/show_bug.cgi?id=149595 Reviewed by Tim Horton. All ports except IOS implement PlatformWebView::windowSnapshotImage() to generate the snapshot for the pixel tests in the UI process. But we are still generating a snapshot for pixel tests in the Web process too, that is passed to the UI process but ignored. Whether a pixel result is needed or not, is only known by the web process depending on whether the test called dumpAsText with dumpPixels == true or not. Since the pixels are now dump in the UI process, we need to pass that information to the UI process when the test is done. For that we set a PixelResultIsPending bool parameter to the Done message, and we only add the PixelResult when UI process doesn't need to generate the pixels dump. * WebKitTestRunner/InjectedBundle/InjectedBundle.cpp: (WTR::InjectedBundle::didReceiveMessageToPage): Set m_pixelResultIsPending to false on reset. (WTR::InjectedBundle::done): Add PixelResultIsPending parameter to the Done message, and set the PixelResult if m_pixelResultIsPending is false. * WebKitTestRunner/InjectedBundle/InjectedBundle.h: (WTR::InjectedBundle::setPixelResult): Set m_pixelResultIsPending to false. (WTR::InjectedBundle::setNeedsPixelResult): Set m_pixelResultIsPending. * WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp: (WTR::InjectedBundlePage::dump): Only create a snapshot for IOS port. * WebKitTestRunner/TestInvocation.cpp: (WTR::TestInvocation::dumpResults): Use either the pixel result from the web process or generate a pixel result from the web view if need it. (WTR::TestInvocation::didReceiveMessageFromInjectedBundle): * WebKitTestRunner/TestInvocation.h: Add SnapshotResultType enum parameter to dumpPixelsAndCompareWithExpected, since the snapshot is created by the caller now, but the CG implementation needs to know if it's a Web or UI process snapshot. * WebKitTestRunner/cairo/TestInvocationCairo.cpp: (WTR::TestInvocation::dumpPixelsAndCompareWithExpected): Create a cairo surface for the given image. * WebKitTestRunner/cg/TestInvocationCG.cpp: (WTR::TestInvocation::dumpPixelsAndCompareWithExpected): Create a CGContext for the given image. git-svn-id: http://svn.webkit.org/repository/webkit/trunk@190304 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 2f977a9 commit aa5329f

File tree

8 files changed

+95
-27
lines changed

8 files changed

+95
-27
lines changed

Tools/ChangeLog

+47
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,50 @@
1+
2015-09-28 Carlos Garcia Campos <[email protected]>
2+
3+
[WTR] Pixel tests generate the snapshots twice in Web and UI processes
4+
https://bugs.webkit.org/show_bug.cgi?id=149595
5+
6+
Reviewed by Tim Horton.
7+
8+
All ports except IOS implement
9+
PlatformWebView::windowSnapshotImage() to generate the snapshot
10+
for the pixel tests in the UI process. But we are still generating
11+
a snapshot for pixel tests in the Web process too, that is passed
12+
to the UI process but ignored.
13+
Whether a pixel result is needed or not, is only known by the web
14+
process depending on whether the test called dumpAsText with
15+
dumpPixels == true or not. Since the pixels are now dump in the UI
16+
process, we need to pass that information to the UI process when
17+
the test is done. For that we set a PixelResultIsPending bool
18+
parameter to the Done message, and we only add the PixelResult
19+
when UI process doesn't need to generate the pixels dump.
20+
21+
* WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
22+
(WTR::InjectedBundle::didReceiveMessageToPage): Set
23+
m_pixelResultIsPending to false on reset.
24+
(WTR::InjectedBundle::done): Add PixelResultIsPending parameter to the
25+
Done message, and set the PixelResult if m_pixelResultIsPending is false.
26+
* WebKitTestRunner/InjectedBundle/InjectedBundle.h:
27+
(WTR::InjectedBundle::setPixelResult): Set m_pixelResultIsPending to false.
28+
(WTR::InjectedBundle::setNeedsPixelResult): Set m_pixelResultIsPending.
29+
* WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp:
30+
(WTR::InjectedBundlePage::dump): Only create a snapshot for IOS
31+
port.
32+
* WebKitTestRunner/TestInvocation.cpp:
33+
(WTR::TestInvocation::dumpResults): Use either the pixel result
34+
from the web process or generate a pixel result from the web view
35+
if need it.
36+
(WTR::TestInvocation::didReceiveMessageFromInjectedBundle):
37+
* WebKitTestRunner/TestInvocation.h: Add SnapshotResultType enum
38+
parameter to dumpPixelsAndCompareWithExpected, since the snapshot
39+
is created by the caller now, but the CG implementation needs to
40+
know if it's a Web or UI process snapshot.
41+
* WebKitTestRunner/cairo/TestInvocationCairo.cpp:
42+
(WTR::TestInvocation::dumpPixelsAndCompareWithExpected): Create a
43+
cairo surface for the given image.
44+
* WebKitTestRunner/cg/TestInvocationCG.cpp:
45+
(WTR::TestInvocation::dumpPixelsAndCompareWithExpected): Create a
46+
CGContext for the given image.
47+
148
2015-09-28 Dean Johnson <[email protected]>
249

350
Fix JS errors on dashboard metrics page

Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ void InjectedBundle::didReceiveMessageToPage(WKBundlePageRef page, WKStringRef m
186186

187187
m_state = Idle;
188188
m_dumpPixels = false;
189+
m_pixelResultIsPending = false;
189190

190191
resetLocalSettings();
191192
m_testRunner->removeAllWebNotificationPermissions();
@@ -338,8 +339,14 @@ void InjectedBundle::done()
338339
WKRetainPtr<WKStringRef> doneMessageName(AdoptWK, WKStringCreateWithUTF8CString("Done"));
339340
WKRetainPtr<WKMutableDictionaryRef> doneMessageBody(AdoptWK, WKMutableDictionaryCreate());
340341

341-
WKRetainPtr<WKStringRef> pixelResultKey = adoptWK(WKStringCreateWithUTF8CString("PixelResult"));
342-
WKDictionarySetItem(doneMessageBody.get(), pixelResultKey.get(), m_pixelResult.get());
342+
WKRetainPtr<WKStringRef> pixelResultIsPendingKey = adoptWK(WKStringCreateWithUTF8CString("PixelResultIsPending"));
343+
WKRetainPtr<WKBooleanRef> pixelResultIsPending(AdoptWK, WKBooleanCreate(m_pixelResultIsPending));
344+
WKDictionarySetItem(doneMessageBody.get(), pixelResultIsPendingKey.get(), pixelResultIsPending.get());
345+
346+
if (!m_pixelResultIsPending) {
347+
WKRetainPtr<WKStringRef> pixelResultKey = adoptWK(WKStringCreateWithUTF8CString("PixelResult"));
348+
WKDictionarySetItem(doneMessageBody.get(), pixelResultKey.get(), m_pixelResult.get());
349+
}
343350

344351
WKRetainPtr<WKStringRef> repaintRectsKey = adoptWK(WKStringCreateWithUTF8CString("RepaintRects"));
345352
WKDictionarySetItem(doneMessageBody.get(), repaintRectsKey.get(), m_repaintRects.get());

Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ class InjectedBundle {
6666

6767
void done();
6868
void setAudioResult(WKDataRef audioData) { m_audioResult = audioData; }
69-
void setPixelResult(WKImageRef image) { m_pixelResult = image; }
69+
void setPixelResult(WKImageRef image) { m_pixelResult = image; m_pixelResultIsPending = false; }
70+
void setPixelResultIsPending(bool isPending) { m_pixelResultIsPending = isPending; }
7071
void setRepaintRects(WKArrayRef rects) { m_repaintRects = rects; }
7172

7273
bool isTestRunning() { return m_state == Testing; }
@@ -164,6 +165,7 @@ class InjectedBundle {
164165
bool m_useWaitToDumpWatchdogTimer;
165166
bool m_useWorkQueue;
166167
int m_timeout;
168+
bool m_pixelResultIsPending { false };
167169

168170
WKRetainPtr<WKDataRef> m_audioResult;
169171
WKRetainPtr<WKImageRef> m_pixelResult;

Tools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -892,11 +892,16 @@ void InjectedBundlePage::dump()
892892
injectedBundle.dumpBackForwardListsForAllPages(stringBuilder);
893893

894894
if (injectedBundle.shouldDumpPixels() && injectedBundle.testRunner()->shouldDumpPixels()) {
895+
#if PLATFORM(IOS)
896+
// IOS doesn't implement PlatformWebView::windowSnapshotImage() yet, so we need to generate the snapshot in the web process.
895897
WKSnapshotOptions options = kWKSnapshotOptionsShareable | kWKSnapshotOptionsInViewCoordinates;
896898
if (injectedBundle.testRunner()->shouldDumpSelectionRect())
897899
options |= kWKSnapshotOptionsPaintSelectionRectangle;
898900

899901
injectedBundle.setPixelResult(adoptWK(WKBundlePageCreateSnapshotWithOptions(m_page, WKBundleFrameGetVisibleContentBounds(WKBundlePageGetMainFrame(m_page)), options)).get());
902+
#else
903+
injectedBundle.setPixelResultIsPending(true);
904+
#endif
900905
if (WKBundlePageIsTrackingRepaints(m_page))
901906
injectedBundle.setRepaintRects(adoptWK(WKBundlePageCopyTrackedRepaintRects(m_page)).get());
902907
}

Tools/WebKitTestRunner/TestInvocation.cpp

+24-12
Original file line numberDiff line numberDiff line change
@@ -288,16 +288,22 @@ void TestInvocation::dumpResults()
288288
else
289289
dumpAudio(m_audioResult.get());
290290

291-
if (m_dumpPixels && m_pixelResult) {
292-
m_gotRepaint = false;
293-
WKPageForceRepaint(TestController::singleton().mainWebView()->page(), this, TestInvocation::forceRepaintDoneCallback);
294-
TestController::singleton().runUntil(m_gotRepaint, TestController::shortTimeout);
295-
if (!m_gotRepaint) {
296-
m_errorMessage = "Timed out waiting for pre-pixel dump repaint\n";
297-
m_webProcessIsUnresponsive = true;
298-
return;
291+
if (m_dumpPixels) {
292+
if (m_pixelResult)
293+
dumpPixelsAndCompareWithExpected(m_pixelResult.get(), m_repaintRects.get(), TestInvocation::SnapshotResultType::WebContents);
294+
else if (m_pixelResultIsPending) {
295+
m_gotRepaint = false;
296+
WKPageForceRepaint(TestController::singleton().mainWebView()->page(), this, TestInvocation::forceRepaintDoneCallback);
297+
TestController::singleton().runUntil(m_gotRepaint, TestController::shortTimeout);
298+
if (!m_gotRepaint) {
299+
m_errorMessage = "Timed out waiting for pre-pixel dump repaint\n";
300+
m_webProcessIsUnresponsive = true;
301+
return;
302+
}
303+
WKRetainPtr<WKImageRef> windowSnapshot = TestController::singleton().mainWebView()->windowSnapshotImage();
304+
ASSERT(windowSnapshot);
305+
dumpPixelsAndCompareWithExpected(windowSnapshot.get(), m_repaintRects.get(), TestInvocation::SnapshotResultType::WebView);
299306
}
300-
dumpPixelsAndCompareWithExpected(m_pixelResult.get(), m_repaintRects.get());
301307
}
302308

303309
fputs("#EOF\n", stdout);
@@ -364,9 +370,15 @@ void TestInvocation::didReceiveMessageFromInjectedBundle(WKStringRef messageName
364370
ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
365371
WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
366372

367-
WKRetainPtr<WKStringRef> pixelResultKey = adoptWK(WKStringCreateWithUTF8CString("PixelResult"));
368-
m_pixelResult = static_cast<WKImageRef>(WKDictionaryGetItemForKey(messageBodyDictionary, pixelResultKey.get()));
369-
ASSERT(!m_pixelResult || m_dumpPixels);
373+
WKRetainPtr<WKStringRef> pixelResultIsPendingKey = adoptWK(WKStringCreateWithUTF8CString("PixelResultIsPending"));
374+
WKBooleanRef pixelResultIsPending = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, pixelResultIsPendingKey.get()));
375+
m_pixelResultIsPending = WKBooleanGetValue(pixelResultIsPending);
376+
377+
if (!m_pixelResultIsPending) {
378+
WKRetainPtr<WKStringRef> pixelResultKey = adoptWK(WKStringCreateWithUTF8CString("PixelResult"));
379+
m_pixelResult = static_cast<WKImageRef>(WKDictionaryGetItemForKey(messageBodyDictionary, pixelResultKey.get()));
380+
ASSERT(!m_pixelResult || m_dumpPixels);
381+
}
370382

371383
WKRetainPtr<WKStringRef> repaintRectsKey = adoptWK(WKStringCreateWithUTF8CString("RepaintRects"));
372384
m_repaintRects = static_cast<WKArrayRef>(WKDictionaryGetItemForKey(messageBodyDictionary, repaintRectsKey.get()));

Tools/WebKitTestRunner/TestInvocation.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ class TestInvocation : public UIScriptContextDelegate {
6969
private:
7070
void dumpResults();
7171
static void dump(const char* textToStdout, const char* textToStderr = 0, bool seenError = false);
72-
void dumpPixelsAndCompareWithExpected(WKImageRef, WKArrayRef repaintRects);
72+
enum class SnapshotResultType { WebView, WebContents };
73+
void dumpPixelsAndCompareWithExpected(WKImageRef, WKArrayRef repaintRects, SnapshotResultType);
7374
void dumpAudio(WKDataRef);
7475
bool compareActualHashToExpectedAndDumpResults(const char[33]);
7576

@@ -93,6 +94,7 @@ class TestInvocation : public UIScriptContextDelegate {
9394
WTF::String m_urlString;
9495

9596
bool m_dumpPixels;
97+
bool m_pixelResultIsPending { false };
9698
std::string m_expectedPixelHash;
9799

98100
int m_timeout;

Tools/WebKitTestRunner/cairo/TestInvocationCairo.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ static void paintRepaintRectOverlay(cairo_surface_t* surface, WKArrayRef repaint
106106
cairo_destroy(context);
107107
}
108108

109-
void TestInvocation::dumpPixelsAndCompareWithExpected(WKImageRef, WKArrayRef repaintRects)
109+
void TestInvocation::dumpPixelsAndCompareWithExpected(WKImageRef image, WKArrayRef repaintRects, SnapshotResultType)
110110
{
111-
cairo_surface_t* surface = WKImageCreateCairoSurface(TestController::singleton().mainWebView()->windowSnapshotImage().get());
111+
cairo_surface_t* surface = WKImageCreateCairoSurface(image);
112112

113113
if (repaintRects)
114114
paintRepaintRectOverlay(surface, repaintRects);

Tools/WebKitTestRunner/cg/TestInvocationCG.cpp

+2-9
Original file line numberDiff line numberDiff line change
@@ -154,16 +154,9 @@ static void paintRepaintRectOverlay(CGContextRef context, WKImageRef image, WKAr
154154
CGContextRestoreGState(context);
155155
}
156156

157-
void TestInvocation::dumpPixelsAndCompareWithExpected(WKImageRef image, WKArrayRef repaintRects)
157+
void TestInvocation::dumpPixelsAndCompareWithExpected(WKImageRef image, WKArrayRef repaintRects, SnapshotResultType snapshotType)
158158
{
159-
PlatformWebView* webView = TestController::singleton().mainWebView();
160-
WKRetainPtr<WKImageRef> windowSnapshot = webView->windowSnapshotImage();
161-
162-
RetainPtr<CGContextRef> context;
163-
if (windowSnapshot)
164-
context = adoptCF(createCGContextFromImage(windowSnapshot.get(), DontFlipGraphicsContext));
165-
else
166-
context = adoptCF(createCGContextFromImage(image));
159+
RetainPtr<CGContextRef> context = adoptCF(createCGContextFromImage(image, snapshotType == SnapshotResultType::WebView ? DontFlipGraphicsContext : FlipGraphicsContext));
167160

168161
// A non-null repaintRects array means we're doing a repaint test.
169162
if (repaintRects)

0 commit comments

Comments
 (0)