// The output from all these methods matches what DumpRenderTree produces. bool NotificationPresenter::show(const WebNotification& notification) { WebString identifier = identifierForNotification(notification); if (!notification.replaceId().isEmpty()) { string replaceId(notification.replaceId().utf8()); if (m_replacements.find(replaceId) != m_replacements.end()) m_delegate->printMessage(string("REPLACING NOTIFICATION ") + m_replacements.find(replaceId)->second + "\n"); m_replacements[replaceId] = identifier.utf8(); } if (notification.isHTML()) m_delegate->printMessage(string("DESKTOP NOTIFICATION: contents at ") + string(notification.url().spec()) + "\n"); else { m_delegate->printMessage("DESKTOP NOTIFICATION:"); m_delegate->printMessage(notification.direction() == WebTextDirectionRightToLeft ? "(RTL)" : ""); m_delegate->printMessage(" icon "); m_delegate->printMessage(notification.iconURL().isEmpty() ? "" : notification.iconURL().spec().data()); m_delegate->printMessage(", title "); m_delegate->printMessage(notification.title().isEmpty() ? "" : notification.title().utf8().data()); m_delegate->printMessage(", text "); m_delegate->printMessage(notification.body().isEmpty() ? "" : notification.body().utf8().data()); m_delegate->printMessage("\n"); } string id(identifier.utf8()); m_activeNotifications[id] = notification; Platform::current()->callOnMainThread(deferredDisplayDispatch, new WebNotification(notification)); return true; }
TEST_F(FrameThrottlingTest, DumpThrottledFrame) { webView().settings()->setJavaScriptEnabled(true); // Create a frame which is throttled. SimRequest mainResource("https://example.com/", "text/html"); SimRequest frameResource("https://example.com/iframe.html", "text/html"); loadURL("https://example.com/"); mainResource.complete( "main <iframe id=frame sandbox=allow-scripts src=iframe.html></iframe>"); frameResource.complete(""); auto* frameElement = toHTMLIFrameElement(document().getElementById("frame")); frameElement->setAttribute(styleAttr, "transform: translateY(480px)"); compositeFrame(); EXPECT_TRUE(frameElement->contentDocument()->view()->canThrottleRendering()); LocalFrame* localFrame = toLocalFrame(frameElement->contentFrame()); localFrame->script().executeScriptInMainWorld( "document.body.innerHTML = 'throttled'"); EXPECT_FALSE(compositor().needsBeginFrame()); // The dumped contents should not include the throttled frame. DocumentLifecycle::AllowThrottlingScope throttlingScope( document().lifecycle()); WebString result = WebFrameContentDumper::deprecatedDumpFrameTreeAsText( webView().mainFrameImpl(), 1024); EXPECT_NE(std::string::npos, result.utf8().find("main")); EXPECT_EQ(std::string::npos, result.utf8().find("throttled")); }
void NotificationPresenter::cancel(const WebNotification& notification) { WebString identifier = identifierForNotification(notification); m_delegate->printMessage(string("DESKTOP NOTIFICATION CLOSED: ") + string(identifier.utf8()) + "\n"); WebNotification eventTarget(notification); eventTarget.dispatchCloseEvent(false); string id(identifier.utf8()); m_activeNotifications.erase(id); }
void registerMockedURLLoad(const WebURL& fullURL, const WebString& fileName, const WebString& relativeBaseDirectory, const WebString& mimeType) { WebURLResponse response(fullURL); response.setMIMEType(mimeType); response.setHTTPStatusCode(200); // Physical file path for the mock = <webkitRootDir> + relativeBaseDirectory + fileName. std::string filePath = std::string(Platform::current()->unitTestSupport()->webKitRootDir().utf8().data()); filePath.append("/engine/web/tests/data/"); filePath.append(std::string(relativeBaseDirectory.utf8().data())); filePath.append(std::string(fileName.utf8().data())); Platform::current()->unitTestSupport()->registerMockedURL(fullURL, response, WebString::fromUTF8(filePath.c_str())); }
void WebViewHost::setStatusText(const WebString& text) { if (!layoutTestController()->shouldDumpStatusCallbacks()) return; // When running tests, write to stdout. printf("UI DELEGATE STATUS CALLBACK: setStatusText:%s\n", text.utf8().data()); }
WebNotificationPresenter::Permission NotificationPresenter::checkPermission(const WebSecurityOrigin& origin) { // Check with the layout test controller WebString originString = origin.toString(); bool allowed = m_allowedOrigins.find(string(originString.utf8())) != m_allowedOrigins.end(); return allowed ? WebNotificationPresenter::PermissionAllowed : WebNotificationPresenter::PermissionDenied; }
bool WebViewHost::shouldApplyStyle(const WebString& style, const WebRange& range) { if (layoutTestController()->shouldDumpEditingCallbacks()) { printf("EDITING DELEGATE: shouldApplyStyle:%s toElementsInDOMRange:", style.utf8().data()); printRangeDescription(range); fputs("\n", stdout); } return layoutTestController()->acceptsEditing(); }
bool WebViewHost::shouldInsertText(const WebString& text, const WebRange& range, WebEditingAction action) { if (layoutTestController()->shouldDumpEditingCallbacks()) { printf("EDITING DELEGATE: shouldInsertText:%s replacingDOMRange:", text.utf8().data()); printRangeDescription(range); printf(" givenAction:%s\n", editingActionDescription(action).c_str()); } return layoutTestController()->acceptsEditing(); }
void NotificationPresenter::cancel(const WebNotification& notification) { WebString identifier = identifierForNotification(notification); printf("DESKTOP NOTIFICATION CLOSED: %s\n", identifier.utf8().data()); WebNotification eventTarget(notification); eventTarget.dispatchCloseEvent(false); WTF::String id(identifier.data(), identifier.length()); m_activeNotifications.remove(id); }
bool NotificationPresenter::simulateClick(const WebString& title) { string id(title.utf8()); if (m_activeNotifications.find(id) == m_activeNotifications.end()) return false; const WebNotification& notification = m_activeNotifications.find(id)->second; WebNotification eventTarget(notification); eventTarget.dispatchClickEvent(); return true; }
void EventSender::dumpFilenameBeingDragged(const CppArgumentList&, CppVariant*) { WebString filename; WebVector<WebDragData::Item> items = currentDragData.items(); for (size_t i = 0; i < items.size(); ++i) { if (items[i].storageType == WebDragData::Item::StorageTypeBinaryData) { filename = items[i].title; break; } } printf("Filename being dragged: %s\n", filename.utf8().data()); }
void LayoutTestController::counterValueForElementById(const CppArgumentList& arguments, CppVariant* result) { result->setNull(); if (arguments.size() < 1 || !arguments[0].isString()) return; WebFrame* frame = m_shell->webView()->mainFrame(); if (!frame) return; WebString counterValue = frame->counterValueForElementById(cppVariantToWebString(arguments[0])); if (counterValue.isNull()) return; result->set(counterValue.utf8()); }
void MockWebSpeechInputController::addMockRecognitionResult(const WebString& result, double confidence, const WebString& language) { WebSpeechInputResult res; res.assign(result, confidence); if (language.isEmpty()) m_resultsForEmptyLanguage.push_back(res); else { string langString = language.utf8(); if (m_recognitionResults.find(langString) == m_recognitionResults.end()) m_recognitionResults[langString] = vector<WebSpeechInputResult>(); m_recognitionResults[langString].push_back(res); } }
void WebViewHost::didReceiveTitle(WebFrame* frame, const WebString& title) { WebCString title8 = title.utf8(); if (m_shell->shouldDumpFrameLoadCallbacks()) { printFrameDescription(frame); printf(" - didReceiveTitle: %s\n", title8.data()); } if (layoutTestController()->shouldDumpTitleChanges()) printf("TITLE CHANGED: %s\n", title8.data()); setPageTitle(title); }
bool MockWebSpeechInputController::startRecognition(int requestId, const WebRect& elementRect, const WebString& language, const WebString& grammar, const WebSecurityOrigin& origin) { if (m_speechTask) return false; m_requestId = requestId; m_requestRect = elementRect; m_recording = true; m_language = language.utf8(); m_speechTask = new SpeechTask(this); m_delegate->postTask(m_speechTask); return true; }
bool WebSocketImpl::sendText(const WebString& message) { size_t size = message.utf8().length(); m_bufferedAmount += size; if (m_isClosingOrClosed) m_bufferedAmountAfterClose += size; // FIXME: Deprecate this call. m_client->didUpdateBufferedAmount(m_bufferedAmount); if (m_isClosingOrClosed) return true; m_private->send(message); return true; }
void WebViewHost::didReceiveResponse(WebFrame*, unsigned identifier, const WebURLResponse& response) { if (m_shell->shouldDumpResourceLoadCallbacks()) { printResourceDescription(identifier); fputs(" - didReceiveResponse ", stdout); printResponseDescription(response); fputs("\n", stdout); } if (m_shell->shouldDumpResourceResponseMIMETypes()) { GURL url = response.url(); WebString mimeType = response.mimeType(); printf("%s has MIME type %s\n", url.ExtractFileName().c_str(), // Simulate NSURLResponse's mapping of empty/unknown MIME types to application/octet-stream mimeType.isEmpty() ? "application/octet-stream" : mimeType.utf8().data()); } }
void PlainTextController::plainText(const CppArgumentList& arguments, CppVariant* result) { result->setNull(); if (arguments.size() < 1 || !arguments[0].isObject()) return; // Check that passed-in object is, in fact, a range. NPObject* npobject = NPVARIANT_TO_OBJECT(arguments[0]); if (!npobject) return; WebRange range; if (!WebBindings::getRange(npobject, &range)) return; // Extract the text using the Range's text() method WebString text = range.toPlainText(); result->set(text.utf8()); }
float TestPlugin::parseOpacity(const WebString& string) { return static_cast<float>(atof(string.utf8().data())); }
void registerMockedURLFromBaseURL(const WebString& baseURL, const WebString& fileName, const WebString& mimeType) { // fullURL = baseURL + fileName. std::string fullString = std::string(baseURL.utf8().data()) + std::string(fileName.utf8().data()); registerMockedURLLoad(toKURL(fullString.c_str()), fileName, WebString::fromUTF8(""), mimeType); }
void HTMLMediaElementEncryptedMedia::keyError(const WebString& keySystem, const WebString& sessionId, WebMediaPlayerEncryptedMediaClient::MediaKeyErrorCode errorCode, unsigned short systemCode) { WTF_LOG(Media, "HTMLMediaElementEncryptedMedia::mediaPlayerKeyError: sessionID=%s, errorCode=%d, systemCode=%d", sessionId.utf8().data(), errorCode, systemCode); MediaKeyError::Code mediaKeyErrorCode = MediaKeyError::MEDIA_KEYERR_UNKNOWN; switch (errorCode) { case WebMediaPlayerEncryptedMediaClient::MediaKeyErrorCodeUnknown: mediaKeyErrorCode = MediaKeyError::MEDIA_KEYERR_UNKNOWN; break; case WebMediaPlayerEncryptedMediaClient::MediaKeyErrorCodeClient: mediaKeyErrorCode = MediaKeyError::MEDIA_KEYERR_CLIENT; break; case WebMediaPlayerEncryptedMediaClient::MediaKeyErrorCodeService: mediaKeyErrorCode = MediaKeyError::MEDIA_KEYERR_SERVICE; break; case WebMediaPlayerEncryptedMediaClient::MediaKeyErrorCodeOutput: mediaKeyErrorCode = MediaKeyError::MEDIA_KEYERR_OUTPUT; break; case WebMediaPlayerEncryptedMediaClient::MediaKeyErrorCodeHardwareChange: mediaKeyErrorCode = MediaKeyError::MEDIA_KEYERR_HARDWARECHANGE; break; case WebMediaPlayerEncryptedMediaClient::MediaKeyErrorCodeDomain: mediaKeyErrorCode = MediaKeyError::MEDIA_KEYERR_DOMAIN; break; } MediaKeyEventInit initializer; initializer.setKeySystem(keySystem); initializer.setSessionId(sessionId); initializer.setErrorCode(MediaKeyError::create(mediaKeyErrorCode)); initializer.setSystemCode(systemCode); RefPtrWillBeRawPtr<Event> event = MediaKeyEvent::create(EventTypeNames::webkitkeyerror, initializer); event->setTarget(m_mediaElement); m_mediaElement->scheduleEvent(event.release()); }
void MockWebValidationMessageClient::showValidationMessage(const WebRect&, const WebString& message, const WebString& subMessage, WebTextDirection) { m_delegate->printMessage(std::string("ValidationMessageClient: main-message=") + std::string(message.utf8()) + " sub-message=" + std::string(subMessage.utf8()) + "\n"); }
void HTMLMediaElementEncryptedMedia::keyMessage(const WebString& keySystem, const WebString& sessionId, const unsigned char* message, unsigned messageLength, const WebURL& defaultURL) { WTF_LOG(Media, "HTMLMediaElementEncryptedMedia::mediaPlayerKeyMessage: sessionID=%s", sessionId.utf8().data()); MediaKeyEventInit initializer; initializer.setKeySystem(keySystem); initializer.setSessionId(sessionId); initializer.setMessage(DOMUint8Array::create(message, messageLength)); initializer.setDefaultURL(KURL(defaultURL)); RefPtrWillBeRawPtr<Event> event = MediaKeyEvent::create(EventTypeNames::webkitkeymessage, initializer); event->setTarget(m_mediaElement); m_mediaElement->scheduleEvent(event.release()); }
void NotificationPresenter::grantPermission(const WebString& origin) { m_allowedOrigins.insert(origin.utf8()); }
void NotificationPresenter::objectDestroyed(const WebKit::WebNotification& notification) { WebString identifier = identifierForNotification(notification); string id(identifier.utf8()); m_activeNotifications.erase(id); }
void WebViewHost::runModalAlertDialog(WebFrame*, const WebString& message) { printf("ALERT: %s\n", message.utf8().data()); }
bool WebViewHost::runModalConfirmDialog(WebFrame*, const WebString& message) { printf("CONFIRM: %s\n", message.utf8().data()); return true; }
bool WebViewHost::runModalPromptDialog(WebFrame* frame, const WebString& message, const WebString& defaultValue, WebString*) { printf("PROMPT: %s, default text: %s\n", message.utf8().data(), defaultValue.utf8().data()); return true; }