1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696
|
/*
* Copyright (C) 2010, 2011, 2012 Apple Inc. All rights reserved.
* Copyright (C) 2012 Intel Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "TestInvocation.h"
#include "PlatformWebView.h"
#include "StringFunctions.h"
#include "TestController.h"
#include <climits>
#include <cstdio>
#include <WebKit2/WKContextPrivate.h>
#include <WebKit2/WKData.h>
#include <WebKit2/WKDictionary.h>
#include <WebKit2/WKInspector.h>
#include <WebKit2/WKRetainPtr.h>
#include <wtf/OwnArrayPtr.h>
#include <wtf/PassOwnArrayPtr.h>
#include <wtf/PassOwnPtr.h>
#include <wtf/text/CString.h>
#if PLATFORM(MAC)
#include <Carbon/Carbon.h>
#include <WebKit2/WKPagePrivateMac.h>
#endif
#if OS(WINDOWS)
#include <direct.h> // For _getcwd.
#define getcwd _getcwd // MSDN says getcwd is deprecated.
#define PATH_MAX _MAX_PATH
#else
#include <unistd.h> // For getcwd.
#endif
using namespace WebKit;
using namespace std;
namespace WTR {
static WKURLRef createWKURL(const char* pathOrURL)
{
if (strstr(pathOrURL, "http://") || strstr(pathOrURL, "https://") || strstr(pathOrURL, "file://"))
return WKURLCreateWithUTF8CString(pathOrURL);
// Creating from filesytem path.
size_t length = strlen(pathOrURL);
if (!length)
return 0;
#if OS(WINDOWS)
const char separator = '\\';
bool isAbsolutePath = length >= 3 && pathOrURL[1] == ':' && pathOrURL[2] == separator;
// FIXME: Remove the "localhost/" suffix once <http://webkit.org/b/55683> is fixed.
const char* filePrefix = "file://localhost/";
#else
const char separator = '/';
bool isAbsolutePath = pathOrURL[0] == separator;
const char* filePrefix = "file://";
#endif
static const size_t prefixLength = strlen(filePrefix);
OwnArrayPtr<char> buffer;
if (isAbsolutePath) {
buffer = adoptArrayPtr(new char[prefixLength + length + 1]);
strcpy(buffer.get(), filePrefix);
strcpy(buffer.get() + prefixLength, pathOrURL);
} else {
buffer = adoptArrayPtr(new char[prefixLength + PATH_MAX + length + 2]); // 1 for the separator
strcpy(buffer.get(), filePrefix);
if (!getcwd(buffer.get() + prefixLength, PATH_MAX))
return 0;
size_t numCharacters = strlen(buffer.get());
buffer[numCharacters] = separator;
strcpy(buffer.get() + numCharacters + 1, pathOrURL);
}
return WKURLCreateWithUTF8CString(buffer.get());
}
TestInvocation::TestInvocation(const std::string& pathOrURL)
: m_url(AdoptWK, createWKURL(pathOrURL.c_str()))
, m_pathOrURL(pathOrURL)
, m_dumpPixels(false)
, m_timeout(0)
, m_gotInitialResponse(false)
, m_gotFinalMessage(false)
, m_gotRepaint(false)
, m_error(false)
, m_webProcessIsUnresponsive(false)
{
}
TestInvocation::~TestInvocation()
{
}
void TestInvocation::setIsPixelTest(const std::string& expectedPixelHash)
{
m_dumpPixels = true;
m_expectedPixelHash = expectedPixelHash;
}
void TestInvocation::setCustomTimeout(int timeout)
{
m_timeout = timeout;
}
static void sizeWebViewForCurrentTest(const char* pathOrURL)
{
bool isSVGW3CTest = strstr(pathOrURL, "svg/W3C-SVG-1.1") || strstr(pathOrURL, "svg\\W3C-SVG-1.1");
if (isSVGW3CTest)
TestController::shared().mainWebView()->resizeTo(TestController::w3cSVGViewWidth, TestController::w3cSVGViewHeight);
else
TestController::shared().mainWebView()->resizeTo(TestController::viewWidth, TestController::viewHeight);
}
static bool shouldLogFrameLoadDelegates(const char* pathOrURL)
{
return strstr(pathOrURL, "loading/");
}
#if ENABLE(INSPECTOR)
static bool shouldOpenWebInspector(const char* pathOrURL)
{
return strstr(pathOrURL, "inspector/") || strstr(pathOrURL, "inspector\\");
}
#endif
#if PLATFORM(MAC)
static bool shouldUseTiledDrawing(const char* pathOrURL)
{
return strstr(pathOrURL, "tiled-drawing/") || strstr(pathOrURL, "tiled-drawing\\");
}
#endif
static void updateTiledDrawingForCurrentTest(const char* pathOrURL)
{
#if PLATFORM(MAC)
WKRetainPtr<WKMutableDictionaryRef> viewOptions = adoptWK(WKMutableDictionaryCreate());
WKRetainPtr<WKStringRef> useTiledDrawingKey = adoptWK(WKStringCreateWithUTF8CString("TiledDrawing"));
WKRetainPtr<WKBooleanRef> useTiledDrawingValue = adoptWK(WKBooleanCreate(shouldUseTiledDrawing(pathOrURL)));
WKDictionaryAddItem(viewOptions.get(), useTiledDrawingKey.get(), useTiledDrawingValue.get());
TestController::shared().ensureViewSupportsOptions(viewOptions.get());
#else
UNUSED_PARAM(pathOrURL);
#endif
}
static bool shouldUseFixedLayout(const char* pathOrURL)
{
#if ENABLE(CSS_DEVICE_ADAPTATION)
if (strstr(pathOrURL, "device-adapt/") || strstr(pathOrURL, "device-adapt\\"))
return true;
#endif
#if USE(TILED_BACKING_STORE) && PLATFORM(EFL)
if (strstr(pathOrURL, "sticky/") || strstr(pathOrURL, "sticky\\"))
return true;
#endif
return false;
UNUSED_PARAM(pathOrURL);
}
static void updateLayoutType(const char* pathOrURL)
{
WKRetainPtr<WKMutableDictionaryRef> viewOptions = adoptWK(WKMutableDictionaryCreate());
WKRetainPtr<WKStringRef> useFixedLayoutKey = adoptWK(WKStringCreateWithUTF8CString("UseFixedLayout"));
WKRetainPtr<WKBooleanRef> useFixedLayoutValue = adoptWK(WKBooleanCreate(shouldUseFixedLayout(pathOrURL)));
WKDictionaryAddItem(viewOptions.get(), useFixedLayoutKey.get(), useFixedLayoutValue.get());
TestController::shared().ensureViewSupportsOptions(viewOptions.get());
}
void TestInvocation::invoke()
{
TestController::TimeoutDuration timeoutToUse = TestController::LongTimeout;
sizeWebViewForCurrentTest(m_pathOrURL.c_str());
updateLayoutType(m_pathOrURL.c_str());
updateTiledDrawingForCurrentTest(m_pathOrURL.c_str());
m_textOutput.clear();
WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("BeginTest"));
WKRetainPtr<WKMutableDictionaryRef> beginTestMessageBody = adoptWK(WKMutableDictionaryCreate());
WKRetainPtr<WKStringRef> dumpFrameLoadDelegatesKey = adoptWK(WKStringCreateWithUTF8CString("DumpFrameLoadDelegates"));
WKRetainPtr<WKBooleanRef> dumpFrameLoadDelegatesValue = adoptWK(WKBooleanCreate(shouldLogFrameLoadDelegates(m_pathOrURL.c_str())));
WKDictionaryAddItem(beginTestMessageBody.get(), dumpFrameLoadDelegatesKey.get(), dumpFrameLoadDelegatesValue.get());
WKRetainPtr<WKStringRef> dumpPixelsKey = adoptWK(WKStringCreateWithUTF8CString("DumpPixels"));
WKRetainPtr<WKBooleanRef> dumpPixelsValue = adoptWK(WKBooleanCreate(m_dumpPixels));
WKDictionaryAddItem(beginTestMessageBody.get(), dumpPixelsKey.get(), dumpPixelsValue.get());
WKRetainPtr<WKStringRef> useWaitToDumpWatchdogTimerKey = adoptWK(WKStringCreateWithUTF8CString("UseWaitToDumpWatchdogTimer"));
WKRetainPtr<WKBooleanRef> useWaitToDumpWatchdogTimerValue = adoptWK(WKBooleanCreate(TestController::shared().useWaitToDumpWatchdogTimer()));
WKDictionaryAddItem(beginTestMessageBody.get(), useWaitToDumpWatchdogTimerKey.get(), useWaitToDumpWatchdogTimerValue.get());
WKRetainPtr<WKStringRef> timeoutKey = adoptWK(WKStringCreateWithUTF8CString("Timeout"));
WKRetainPtr<WKUInt64Ref> timeoutValue = adoptWK(WKUInt64Create(m_timeout));
WKDictionaryAddItem(beginTestMessageBody.get(), timeoutKey.get(), timeoutValue.get());
WKContextPostMessageToInjectedBundle(TestController::shared().context(), messageName.get(), beginTestMessageBody.get());
TestController::shared().runUntil(m_gotInitialResponse, TestController::ShortTimeout);
if (!m_gotInitialResponse) {
m_errorMessage = "Timed out waiting for initial response from web process\n";
m_webProcessIsUnresponsive = true;
goto end;
}
if (m_error)
goto end;
#if ENABLE(INSPECTOR)
if (shouldOpenWebInspector(m_pathOrURL.c_str()))
WKInspectorShow(WKPageGetInspector(TestController::shared().mainWebView()->page()));
#endif // ENABLE(INSPECTOR)
WKPageLoadURL(TestController::shared().mainWebView()->page(), m_url.get());
if (TestController::shared().useWaitToDumpWatchdogTimer()) {
if (m_timeout > 0)
timeoutToUse = TestController::CustomTimeout;
} else
timeoutToUse = TestController::NoTimeout;
TestController::shared().runUntil(m_gotFinalMessage, timeoutToUse);
if (!m_gotFinalMessage) {
m_errorMessage = "Timed out waiting for final message from web process\n";
m_webProcessIsUnresponsive = true;
goto end;
}
if (m_error)
goto end;
dumpResults();
end:
#if ENABLE(INSPECTOR)
if (m_gotInitialResponse)
WKInspectorClose(WKPageGetInspector(TestController::shared().mainWebView()->page()));
#endif // ENABLE(INSPECTOR)
if (m_webProcessIsUnresponsive)
dumpWebProcessUnresponsiveness();
else if (!TestController::shared().resetStateToConsistentValues()) {
m_errorMessage = "Timed out loading about:blank before the next test";
dumpWebProcessUnresponsiveness();
}
}
void TestInvocation::dumpWebProcessUnresponsiveness()
{
dumpWebProcessUnresponsiveness(m_errorMessage.c_str());
}
void TestInvocation::dumpWebProcessUnresponsiveness(const char* errorMessage)
{
const char* errorMessageToStderr = 0;
#if PLATFORM(MAC)
char buffer[64];
pid_t pid = WKPageGetProcessIdentifier(TestController::shared().mainWebView()->page());
sprintf(buffer, "#PROCESS UNRESPONSIVE - WebProcess (pid %ld)\n", static_cast<long>(pid));
errorMessageToStderr = buffer;
#else
errorMessageToStderr = "#PROCESS UNRESPONSIVE - WebProcess";
#endif
dump(errorMessage, errorMessageToStderr, true);
}
void TestInvocation::dump(const char* textToStdout, const char* textToStderr, bool seenError)
{
printf("Content-Type: text/plain\n");
if (textToStdout)
fputs(textToStdout, stdout);
if (textToStderr)
fputs(textToStderr, stderr);
fputs("#EOF\n", stdout);
fputs("#EOF\n", stderr);
if (seenError)
fputs("#EOF\n", stdout);
fflush(stdout);
fflush(stderr);
}
void TestInvocation::dumpResults()
{
if (m_textOutput.length() || !m_audioResult)
dump(m_textOutput.toString().utf8().data());
else
dumpAudio(m_audioResult.get());
if (m_dumpPixels && m_pixelResult)
dumpPixelsAndCompareWithExpected(m_pixelResult.get(), m_repaintRects.get());
fputs("#EOF\n", stdout);
fflush(stdout);
fflush(stderr);
}
void TestInvocation::dumpAudio(WKDataRef audioData)
{
size_t length = WKDataGetSize(audioData);
if (!length)
return;
const unsigned char* data = WKDataGetBytes(audioData);
printf("Content-Type: audio/wav\n");
printf("Content-Length: %lu\n", static_cast<unsigned long>(length));
const size_t bytesToWriteInOneChunk = 1 << 15;
size_t dataRemainingToWrite = length;
while (dataRemainingToWrite) {
size_t bytesToWriteInThisChunk = std::min(dataRemainingToWrite, bytesToWriteInOneChunk);
size_t bytesWritten = fwrite(data, 1, bytesToWriteInThisChunk, stdout);
if (bytesWritten != bytesToWriteInThisChunk)
break;
dataRemainingToWrite -= bytesWritten;
data += bytesWritten;
}
printf("#EOF\n");
fprintf(stderr, "#EOF\n");
}
bool TestInvocation::compareActualHashToExpectedAndDumpResults(const char actualHash[33])
{
// Compute the hash of the bitmap context pixels
fprintf(stdout, "\nActualHash: %s\n", actualHash);
if (!m_expectedPixelHash.length())
return false;
ASSERT(m_expectedPixelHash.length() == 32);
fprintf(stdout, "\nExpectedHash: %s\n", m_expectedPixelHash.c_str());
// FIXME: Do case insensitive compare.
return m_expectedPixelHash == actualHash;
}
void TestInvocation::didReceiveMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody)
{
if (WKStringIsEqualToUTF8CString(messageName, "Error")) {
// Set all states to true to stop spinning the runloop.
m_gotInitialResponse = true;
m_gotFinalMessage = true;
m_error = true;
m_errorMessage = "FAIL\n";
TestController::shared().notifyDone();
return;
}
if (WKStringIsEqualToUTF8CString(messageName, "Ack")) {
ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
WKStringRef messageBodyString = static_cast<WKStringRef>(messageBody);
if (WKStringIsEqualToUTF8CString(messageBodyString, "BeginTest")) {
m_gotInitialResponse = true;
TestController::shared().notifyDone();
return;
}
ASSERT_NOT_REACHED();
}
if (WKStringIsEqualToUTF8CString(messageName, "Done")) {
ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
WKRetainPtr<WKStringRef> pixelResultKey = adoptWK(WKStringCreateWithUTF8CString("PixelResult"));
m_pixelResult = static_cast<WKImageRef>(WKDictionaryGetItemForKey(messageBodyDictionary, pixelResultKey.get()));
ASSERT(!m_pixelResult || m_dumpPixels);
WKRetainPtr<WKStringRef> repaintRectsKey = adoptWK(WKStringCreateWithUTF8CString("RepaintRects"));
m_repaintRects = static_cast<WKArrayRef>(WKDictionaryGetItemForKey(messageBodyDictionary, repaintRectsKey.get()));
WKRetainPtr<WKStringRef> audioResultKey = adoptWK(WKStringCreateWithUTF8CString("AudioResult"));
m_audioResult = static_cast<WKDataRef>(WKDictionaryGetItemForKey(messageBodyDictionary, audioResultKey.get()));
m_gotFinalMessage = true;
TestController::shared().notifyDone();
return;
}
if (WKStringIsEqualToUTF8CString(messageName, "TextOutput")) {
ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
WKStringRef textOutput = static_cast<WKStringRef>(messageBody);
m_textOutput.append(toWTFString(textOutput));
return;
}
if (WKStringIsEqualToUTF8CString(messageName, "BeforeUnloadReturnValue")) {
ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
WKBooleanRef beforeUnloadReturnValue = static_cast<WKBooleanRef>(messageBody);
TestController::shared().setBeforeUnloadReturnValue(WKBooleanGetValue(beforeUnloadReturnValue));
return;
}
if (WKStringIsEqualToUTF8CString(messageName, "AddChromeInputField")) {
TestController::shared().mainWebView()->addChromeInputField();
WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallAddChromeInputFieldCallback"));
WKContextPostMessageToInjectedBundle(TestController::shared().context(), messageName.get(), 0);
return;
}
if (WKStringIsEqualToUTF8CString(messageName, "RemoveChromeInputField")) {
TestController::shared().mainWebView()->removeChromeInputField();
WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallRemoveChromeInputFieldCallback"));
WKContextPostMessageToInjectedBundle(TestController::shared().context(), messageName.get(), 0);
return;
}
if (WKStringIsEqualToUTF8CString(messageName, "FocusWebView")) {
TestController::shared().mainWebView()->makeWebViewFirstResponder();
WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallFocusWebViewCallback"));
WKContextPostMessageToInjectedBundle(TestController::shared().context(), messageName.get(), 0);
return;
}
if (WKStringIsEqualToUTF8CString(messageName, "SetBackingScaleFactor")) {
ASSERT(WKGetTypeID(messageBody) == WKDoubleGetTypeID());
double backingScaleFactor = WKDoubleGetValue(static_cast<WKDoubleRef>(messageBody));
WKPageSetCustomBackingScaleFactor(TestController::shared().mainWebView()->page(), backingScaleFactor);
WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallSetBackingScaleFactorCallback"));
WKContextPostMessageToInjectedBundle(TestController::shared().context(), messageName.get(), 0);
return;
}
if (WKStringIsEqualToUTF8CString(messageName, "SimulateWebNotificationClick")) {
ASSERT(WKGetTypeID(messageBody) == WKUInt64GetTypeID());
uint64_t notificationID = WKUInt64GetValue(static_cast<WKUInt64Ref>(messageBody));
TestController::shared().simulateWebNotificationClick(notificationID);
return;
}
if (WKStringIsEqualToUTF8CString(messageName, "SetGeolocationPermission")) {
ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
WKBooleanRef enabledWK = static_cast<WKBooleanRef>(messageBody);
TestController::shared().setGeolocationPermission(WKBooleanGetValue(enabledWK));
return;
}
if (WKStringIsEqualToUTF8CString(messageName, "SetMockGeolocationPosition")) {
ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
WKRetainPtr<WKStringRef> latitudeKeyWK(AdoptWK, WKStringCreateWithUTF8CString("latitude"));
WKDoubleRef latitudeWK = static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, latitudeKeyWK.get()));
double latitude = WKDoubleGetValue(latitudeWK);
WKRetainPtr<WKStringRef> longitudeKeyWK(AdoptWK, WKStringCreateWithUTF8CString("longitude"));
WKDoubleRef longitudeWK = static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, longitudeKeyWK.get()));
double longitude = WKDoubleGetValue(longitudeWK);
WKRetainPtr<WKStringRef> accuracyKeyWK(AdoptWK, WKStringCreateWithUTF8CString("accuracy"));
WKDoubleRef accuracyWK = static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, accuracyKeyWK.get()));
double accuracy = WKDoubleGetValue(accuracyWK);
WKRetainPtr<WKStringRef> providesAltitudeKeyWK(AdoptWK, WKStringCreateWithUTF8CString("providesAltitude"));
WKBooleanRef providesAltitudeWK = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, providesAltitudeKeyWK.get()));
bool providesAltitude = WKBooleanGetValue(providesAltitudeWK);
WKRetainPtr<WKStringRef> altitudeKeyWK(AdoptWK, WKStringCreateWithUTF8CString("altitude"));
WKDoubleRef altitudeWK = static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, altitudeKeyWK.get()));
double altitude = WKDoubleGetValue(altitudeWK);
WKRetainPtr<WKStringRef> providesAltitudeAccuracyKeyWK(AdoptWK, WKStringCreateWithUTF8CString("providesAltitudeAccuracy"));
WKBooleanRef providesAltitudeAccuracyWK = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, providesAltitudeAccuracyKeyWK.get()));
bool providesAltitudeAccuracy = WKBooleanGetValue(providesAltitudeAccuracyWK);
WKRetainPtr<WKStringRef> altitudeAccuracyKeyWK(AdoptWK, WKStringCreateWithUTF8CString("altitudeAccuracy"));
WKDoubleRef altitudeAccuracyWK = static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, altitudeAccuracyKeyWK.get()));
double altitudeAccuracy = WKDoubleGetValue(altitudeAccuracyWK);
WKRetainPtr<WKStringRef> providesHeadingKeyWK(AdoptWK, WKStringCreateWithUTF8CString("providesHeading"));
WKBooleanRef providesHeadingWK = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, providesHeadingKeyWK.get()));
bool providesHeading = WKBooleanGetValue(providesHeadingWK);
WKRetainPtr<WKStringRef> headingKeyWK(AdoptWK, WKStringCreateWithUTF8CString("heading"));
WKDoubleRef headingWK = static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, headingKeyWK.get()));
double heading = WKDoubleGetValue(headingWK);
WKRetainPtr<WKStringRef> providesSpeedKeyWK(AdoptWK, WKStringCreateWithUTF8CString("providesSpeed"));
WKBooleanRef providesSpeedWK = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, providesSpeedKeyWK.get()));
bool providesSpeed = WKBooleanGetValue(providesSpeedWK);
WKRetainPtr<WKStringRef> speedKeyWK(AdoptWK, WKStringCreateWithUTF8CString("speed"));
WKDoubleRef speedWK = static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, speedKeyWK.get()));
double speed = WKDoubleGetValue(speedWK);
TestController::shared().setMockGeolocationPosition(latitude, longitude, accuracy, providesAltitude, altitude, providesAltitudeAccuracy, altitudeAccuracy, providesHeading, heading, providesSpeed, speed);
return;
}
if (WKStringIsEqualToUTF8CString(messageName, "SetMockGeolocationPositionUnavailableError")) {
ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
WKStringRef errorMessage = static_cast<WKStringRef>(messageBody);
TestController::shared().setMockGeolocationPositionUnavailableError(errorMessage);
return;
}
if (WKStringIsEqualToUTF8CString(messageName, "SetCustomPolicyDelegate")) {
ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
WKRetainPtr<WKStringRef> enabledKeyWK(AdoptWK, WKStringCreateWithUTF8CString("enabled"));
WKBooleanRef enabledWK = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, enabledKeyWK.get()));
bool enabled = WKBooleanGetValue(enabledWK);
WKRetainPtr<WKStringRef> permissiveKeyWK(AdoptWK, WKStringCreateWithUTF8CString("permissive"));
WKBooleanRef permissiveWK = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, permissiveKeyWK.get()));
bool permissive = WKBooleanGetValue(permissiveWK);
TestController::shared().setCustomPolicyDelegate(enabled, permissive);
return;
}
if (WKStringIsEqualToUTF8CString(messageName, "SetVisibilityState")) {
ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
WKRetainPtr<WKStringRef> visibilityStateKeyWK(AdoptWK, WKStringCreateWithUTF8CString("visibilityState"));
WKUInt64Ref visibilityStateWK = static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, visibilityStateKeyWK.get()));
WKPageVisibilityState visibilityState = static_cast<WKPageVisibilityState>(WKUInt64GetValue(visibilityStateWK));
WKRetainPtr<WKStringRef> isInitialKeyWK(AdoptWK, WKStringCreateWithUTF8CString("isInitialState"));
WKBooleanRef isInitialWK = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, isInitialKeyWK.get()));
bool isInitialState = WKBooleanGetValue(isInitialWK);
TestController::shared().setVisibilityState(visibilityState, isInitialState);
return;
}
if (WKStringIsEqualToUTF8CString(messageName, "ProcessWorkQueue")) {
if (TestController::shared().workQueueManager().processWorkQueue()) {
WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("WorkQueueProcessedCallback"));
WKContextPostMessageToInjectedBundle(TestController::shared().context(), messageName.get(), 0);
}
return;
}
if (WKStringIsEqualToUTF8CString(messageName, "QueueBackNavigation")) {
ASSERT(WKGetTypeID(messageBody) == WKUInt64GetTypeID());
uint64_t stepCount = WKUInt64GetValue(static_cast<WKUInt64Ref>(messageBody));
TestController::shared().workQueueManager().queueBackNavigation(stepCount);
return;
}
if (WKStringIsEqualToUTF8CString(messageName, "QueueForwardNavigation")) {
ASSERT(WKGetTypeID(messageBody) == WKUInt64GetTypeID());
uint64_t stepCount = WKUInt64GetValue(static_cast<WKUInt64Ref>(messageBody));
TestController::shared().workQueueManager().queueForwardNavigation(stepCount);
return;
}
if (WKStringIsEqualToUTF8CString(messageName, "QueueLoad")) {
ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
WKDictionaryRef loadDataDictionary = static_cast<WKDictionaryRef>(messageBody);
WKRetainPtr<WKStringRef> urlKey(AdoptWK, WKStringCreateWithUTF8CString("url"));
WKStringRef urlWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(loadDataDictionary, urlKey.get()));
WKRetainPtr<WKStringRef> targetKey(AdoptWK, WKStringCreateWithUTF8CString("target"));
WKStringRef targetWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(loadDataDictionary, targetKey.get()));
TestController::shared().workQueueManager().queueLoad(toWTFString(urlWK), toWTFString(targetWK));
return;
}
if (WKStringIsEqualToUTF8CString(messageName, "QueueLoadHTMLString")) {
ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
WKDictionaryRef loadDataDictionary = static_cast<WKDictionaryRef>(messageBody);
WKRetainPtr<WKStringRef> contentKey(AdoptWK, WKStringCreateWithUTF8CString("content"));
WKStringRef contentWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(loadDataDictionary, contentKey.get()));
WKRetainPtr<WKStringRef> baseURLKey(AdoptWK, WKStringCreateWithUTF8CString("baseURL"));
WKStringRef baseURLWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(loadDataDictionary, baseURLKey.get()));
WKRetainPtr<WKStringRef> unreachableURLKey(AdoptWK, WKStringCreateWithUTF8CString("unreachableURL"));
WKStringRef unreachableURLWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(loadDataDictionary, unreachableURLKey.get()));
TestController::shared().workQueueManager().queueLoadHTMLString(toWTFString(contentWK), baseURLWK ? toWTFString(baseURLWK) : String(), unreachableURLWK ? toWTFString(unreachableURLWK) : String());
return;
}
if (WKStringIsEqualToUTF8CString(messageName, "QueueReload")) {
TestController::shared().workQueueManager().queueReload();
return;
}
if (WKStringIsEqualToUTF8CString(messageName, "QueueLoadingScript")) {
ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
WKStringRef script = static_cast<WKStringRef>(messageBody);
TestController::shared().workQueueManager().queueLoadingScript(toWTFString(script));
return;
}
if (WKStringIsEqualToUTF8CString(messageName, "QueueNonLoadingScript")) {
ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
WKStringRef script = static_cast<WKStringRef>(messageBody);
TestController::shared().workQueueManager().queueNonLoadingScript(toWTFString(script));
return;
}
if (WKStringIsEqualToUTF8CString(messageName, "SetHandlesAuthenticationChallenge")) {
ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
WKBooleanRef value = static_cast<WKBooleanRef>(messageBody);
TestController::shared().setHandlesAuthenticationChallenges(WKBooleanGetValue(value));
return;
}
if (WKStringIsEqualToUTF8CString(messageName, "SetAuthenticationUsername")) {
ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
WKStringRef username = static_cast<WKStringRef>(messageBody);
TestController::shared().setAuthenticationUsername(toWTFString(username));
return;
}
if (WKStringIsEqualToUTF8CString(messageName, "SetAuthenticationPassword")) {
ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
WKStringRef password = static_cast<WKStringRef>(messageBody);
TestController::shared().setAuthenticationPassword(toWTFString(password));
return;
}
if (WKStringIsEqualToUTF8CString(messageName, "SetBlockAllPlugins")) {
ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
WKBooleanRef shouldBlock = static_cast<WKBooleanRef>(messageBody);
TestController::shared().setBlockAllPlugins(WKBooleanGetValue(shouldBlock));
return;
}
ASSERT_NOT_REACHED();
}
WKRetainPtr<WKTypeRef> TestInvocation::didReceiveSynchronousMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody)
{
if (WKStringIsEqualToUTF8CString(messageName, "SetWindowIsKey")) {
ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
WKBooleanRef isKeyValue = static_cast<WKBooleanRef>(messageBody);
TestController::shared().mainWebView()->setWindowIsKey(WKBooleanGetValue(isKeyValue));
return 0;
}
if (WKStringIsEqualToUTF8CString(messageName, "IsWorkQueueEmpty")) {
bool isEmpty = TestController::shared().workQueueManager().isWorkQueueEmpty();
WKRetainPtr<WKTypeRef> result(AdoptWK, WKBooleanCreate(isEmpty));
return result;
}
if (WKStringIsEqualToUTF8CString(messageName, "SecureEventInputIsEnabled")) {
#if PLATFORM(MAC)
WKRetainPtr<WKBooleanRef> result(AdoptWK, WKBooleanCreate(IsSecureEventInputEnabled()));
#else
WKRetainPtr<WKBooleanRef> result(AdoptWK, WKBooleanCreate(false));
#endif
return result;
}
ASSERT_NOT_REACHED();
return 0;
}
void TestInvocation::outputText(const WTF::String& text)
{
m_textOutput.append(text);
}
} // namespace WTR
|