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
|
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/test_runner/web_view_test_client.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/i18n/rtl.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "components/test_runner/event_sender.h"
#include "components/test_runner/mock_web_speech_recognizer.h"
#include "components/test_runner/test_common.h"
#include "components/test_runner/test_interfaces.h"
#include "components/test_runner/test_runner.h"
#include "components/test_runner/test_runner_for_specific_view.h"
#include "components/test_runner/web_test_delegate.h"
#include "components/test_runner/web_view_test_proxy.h"
#include "components/test_runner/web_widget_test_proxy.h"
#include "third_party/WebKit/public/platform/WebURLRequest.h"
#include "third_party/WebKit/public/web/WebFrame.h"
#include "third_party/WebKit/public/web/WebLocalFrame.h"
#include "third_party/WebKit/public/web/WebPagePopup.h"
#include "third_party/WebKit/public/web/WebPrintParams.h"
#include "third_party/WebKit/public/web/WebView.h"
#include "third_party/WebKit/public/web/WebWidget.h"
namespace test_runner {
WebViewTestClient::WebViewTestClient(
WebViewTestProxyBase* web_view_test_proxy_base)
: web_view_test_proxy_base_(web_view_test_proxy_base) {
DCHECK(web_view_test_proxy_base);
}
WebViewTestClient::~WebViewTestClient() {}
// The output from these methods in layout test mode should match that
// expected by the layout tests. See EditingDelegate.m in DumpRenderTree.
void WebViewTestClient::didChangeContents() {
if (test_runner()->shouldDumpEditingCallbacks())
delegate()->PrintMessage(
"EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification\n");
}
blink::WebView* WebViewTestClient::createView(
blink::WebLocalFrame* frame,
const blink::WebURLRequest& request,
const blink::WebWindowFeatures& features,
const blink::WebString& frame_name,
blink::WebNavigationPolicy policy,
bool suppress_opener) {
if (test_runner()->shouldDumpNavigationPolicy()) {
delegate()->PrintMessage("Default policy for createView for '" +
URLDescription(request.url()) + "' is '" +
WebNavigationPolicyToString(policy) + "'\n");
}
if (!test_runner()->canOpenWindows())
return nullptr;
if (test_runner()->shouldDumpCreateView())
delegate()->PrintMessage(std::string("createView(") +
URLDescription(request.url()) + ")\n");
// The return value below is used to communicate to WebViewTestProxy whether
// it should forward the createView request to RenderViewImpl or not. The
// somewhat ugly cast is used to do this while fitting into the existing
// WebViewClient interface.
return reinterpret_cast<blink::WebView*>(0xdeadbeef);
}
void WebViewTestClient::setStatusText(const blink::WebString& text) {
if (!test_runner()->shouldDumpStatusCallbacks())
return;
delegate()->PrintMessage(
std::string("UI DELEGATE STATUS CALLBACK: setStatusText:") +
text.utf8().data() + "\n");
}
// Simulate a print by going into print mode and then exit straight away.
void WebViewTestClient::printPage(blink::WebLocalFrame* frame) {
blink::WebSize page_size_in_pixels = frame->view()->size();
if (page_size_in_pixels.isEmpty())
return;
blink::WebPrintParams printParams(page_size_in_pixels);
frame->printBegin(printParams);
frame->printEnd();
}
void WebViewTestClient::showValidationMessage(
const blink::WebRect& anchor_in_root_view,
const blink::WebString& main_message,
blink::WebTextDirection main_message_hint,
const blink::WebString& sub_message,
blink::WebTextDirection sub_message_hint) {
if (test_runner()->is_web_platform_tests_mode())
return;
base::string16 wrapped_main_text = main_message;
base::string16 wrapped_sub_text = sub_message;
if (main_message_hint == blink::WebTextDirectionLeftToRight) {
wrapped_main_text =
base::i18n::GetDisplayStringInLTRDirectionality(wrapped_main_text);
} else if (main_message_hint == blink::WebTextDirectionRightToLeft &&
!base::i18n::IsRTL()) {
base::i18n::WrapStringWithRTLFormatting(&wrapped_main_text);
}
if (!wrapped_sub_text.empty()) {
if (sub_message_hint == blink::WebTextDirectionLeftToRight) {
wrapped_sub_text =
base::i18n::GetDisplayStringInLTRDirectionality(wrapped_sub_text);
} else if (sub_message_hint == blink::WebTextDirectionRightToLeft) {
base::i18n::WrapStringWithRTLFormatting(&wrapped_sub_text);
}
}
delegate()->PrintMessage("ValidationMessageClient: main-message=" +
base::UTF16ToUTF8(wrapped_main_text) +
" sub-message=" +
base::UTF16ToUTF8(wrapped_sub_text) + "\n");
}
blink::WebSpeechRecognizer* WebViewTestClient::speechRecognizer() {
return test_runner()->getMockWebSpeechRecognizer();
}
blink::WebString WebViewTestClient::acceptLanguages() {
return blink::WebString::fromUTF8(test_runner()->GetAcceptLanguages());
}
WebTestDelegate* WebViewTestClient::delegate() {
return web_view_test_proxy_base_->delegate();
}
void WebViewTestClient::didFocus() {
test_runner()->SetFocus(web_view_test_proxy_base_->web_view(), true);
}
TestRunner* WebViewTestClient::test_runner() {
return web_view_test_proxy_base_->test_interfaces()->GetTestRunner();
}
} // namespace test_runner
|