OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/test_runner/web_view_test_client.h" | 5 #include "components/test_runner/web_view_test_client.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "components/test_runner/event_sender.h" | 13 #include "components/test_runner/event_sender.h" |
14 #include "components/test_runner/mock_web_speech_recognizer.h" | 14 #include "components/test_runner/mock_web_speech_recognizer.h" |
15 #include "components/test_runner/test_common.h" | 15 #include "components/test_runner/test_common.h" |
| 16 #include "components/test_runner/test_interfaces.h" |
16 #include "components/test_runner/test_runner.h" | 17 #include "components/test_runner/test_runner.h" |
17 #include "components/test_runner/test_runner_for_specific_view.h" | 18 #include "components/test_runner/test_runner_for_specific_view.h" |
18 #include "components/test_runner/web_test_delegate.h" | 19 #include "components/test_runner/web_test_delegate.h" |
19 #include "components/test_runner/web_view_test_proxy.h" | 20 #include "components/test_runner/web_view_test_proxy.h" |
20 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 21 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
21 #include "third_party/WebKit/public/web/WebFrame.h" | 22 #include "third_party/WebKit/public/web/WebFrame.h" |
22 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 23 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
23 #include "third_party/WebKit/public/web/WebPagePopup.h" | 24 #include "third_party/WebKit/public/web/WebPagePopup.h" |
24 #include "third_party/WebKit/public/web/WebPrintParams.h" | 25 #include "third_party/WebKit/public/web/WebPrintParams.h" |
25 #include "third_party/WebKit/public/web/WebView.h" | 26 #include "third_party/WebKit/public/web/WebView.h" |
26 #include "third_party/WebKit/public/web/WebWidget.h" | 27 #include "third_party/WebKit/public/web/WebWidget.h" |
27 | 28 |
28 namespace test_runner { | 29 namespace test_runner { |
29 | 30 |
30 WebViewTestClient::WebViewTestClient( | 31 WebViewTestClient::WebViewTestClient( |
31 TestRunner* test_runner, | |
32 WebViewTestProxyBase* web_view_test_proxy_base) | 32 WebViewTestProxyBase* web_view_test_proxy_base) |
33 : test_runner_(test_runner), | 33 : web_view_test_proxy_base_(web_view_test_proxy_base) { |
34 web_view_test_proxy_base_(web_view_test_proxy_base) { | |
35 DCHECK(test_runner); | |
36 DCHECK(web_view_test_proxy_base); | 34 DCHECK(web_view_test_proxy_base); |
37 } | 35 } |
38 | 36 |
39 WebViewTestClient::~WebViewTestClient() {} | 37 WebViewTestClient::~WebViewTestClient() {} |
40 | 38 |
41 void WebViewTestClient::startDragging(blink::WebLocalFrame* frame, | 39 void WebViewTestClient::startDragging(blink::WebLocalFrame* frame, |
42 const blink::WebDragData& data, | 40 const blink::WebDragData& data, |
43 blink::WebDragOperationsMask mask, | 41 blink::WebDragOperationsMask mask, |
44 const blink::WebImage& image, | 42 const blink::WebImage& image, |
45 const blink::WebPoint& point) { | 43 const blink::WebPoint& point) { |
46 test_runner_->setDragImage(image); | 44 test_runner()->setDragImage(image); |
47 | 45 |
48 // When running a test, we need to fake a drag drop operation otherwise | 46 // When running a test, we need to fake a drag drop operation otherwise |
49 // Windows waits for real mouse events to know when the drag is over. | 47 // Windows waits for real mouse events to know when the drag is over. |
50 web_view_test_proxy_base_->event_sender()->DoDragDrop(data, mask); | 48 web_view_test_proxy_base_->event_sender()->DoDragDrop(data, mask); |
51 } | 49 } |
52 | 50 |
53 // The output from these methods in layout test mode should match that | 51 // The output from these methods in layout test mode should match that |
54 // expected by the layout tests. See EditingDelegate.m in DumpRenderTree. | 52 // expected by the layout tests. See EditingDelegate.m in DumpRenderTree. |
55 | 53 |
56 void WebViewTestClient::didChangeContents() { | 54 void WebViewTestClient::didChangeContents() { |
57 if (test_runner_->shouldDumpEditingCallbacks()) | 55 if (test_runner()->shouldDumpEditingCallbacks()) |
58 delegate()->PrintMessage( | 56 delegate()->PrintMessage( |
59 "EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification\n"); | 57 "EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification\n"); |
60 } | 58 } |
61 | 59 |
62 blink::WebView* WebViewTestClient::createView( | 60 blink::WebView* WebViewTestClient::createView( |
63 blink::WebLocalFrame* frame, | 61 blink::WebLocalFrame* frame, |
64 const blink::WebURLRequest& request, | 62 const blink::WebURLRequest& request, |
65 const blink::WebWindowFeatures& features, | 63 const blink::WebWindowFeatures& features, |
66 const blink::WebString& frame_name, | 64 const blink::WebString& frame_name, |
67 blink::WebNavigationPolicy policy, | 65 blink::WebNavigationPolicy policy, |
68 bool suppress_opener) { | 66 bool suppress_opener) { |
69 if (test_runner_->shouldDumpNavigationPolicy()) { | 67 if (test_runner()->shouldDumpNavigationPolicy()) { |
70 delegate()->PrintMessage("Default policy for createView for '" + | 68 delegate()->PrintMessage("Default policy for createView for '" + |
71 URLDescription(request.url()) + "' is '" + | 69 URLDescription(request.url()) + "' is '" + |
72 WebNavigationPolicyToString(policy) + "'\n"); | 70 WebNavigationPolicyToString(policy) + "'\n"); |
73 } | 71 } |
74 | 72 |
75 if (!test_runner_->canOpenWindows()) | 73 if (!test_runner()->canOpenWindows()) |
76 return nullptr; | 74 return nullptr; |
77 if (test_runner_->shouldDumpCreateView()) | 75 if (test_runner()->shouldDumpCreateView()) |
78 delegate()->PrintMessage(std::string("createView(") + | 76 delegate()->PrintMessage(std::string("createView(") + |
79 URLDescription(request.url()) + ")\n"); | 77 URLDescription(request.url()) + ")\n"); |
80 | 78 |
81 // The return value below is used to communicate to WebViewTestProxy whether | 79 // The return value below is used to communicate to WebViewTestProxy whether |
82 // it should forward the createView request to RenderViewImpl or not. The | 80 // it should forward the createView request to RenderViewImpl or not. The |
83 // somewhat ugly cast is used to do this while fitting into the existing | 81 // somewhat ugly cast is used to do this while fitting into the existing |
84 // WebViewClient interface. | 82 // WebViewClient interface. |
85 return reinterpret_cast<blink::WebView*>(0xdeadbeef); | 83 return reinterpret_cast<blink::WebView*>(0xdeadbeef); |
86 } | 84 } |
87 | 85 |
88 void WebViewTestClient::setStatusText(const blink::WebString& text) { | 86 void WebViewTestClient::setStatusText(const blink::WebString& text) { |
89 if (!test_runner_->shouldDumpStatusCallbacks()) | 87 if (!test_runner()->shouldDumpStatusCallbacks()) |
90 return; | 88 return; |
91 delegate()->PrintMessage( | 89 delegate()->PrintMessage( |
92 std::string("UI DELEGATE STATUS CALLBACK: setStatusText:") + | 90 std::string("UI DELEGATE STATUS CALLBACK: setStatusText:") + |
93 text.utf8().data() + "\n"); | 91 text.utf8().data() + "\n"); |
94 } | 92 } |
95 | 93 |
96 // Simulate a print by going into print mode and then exit straight away. | 94 // Simulate a print by going into print mode and then exit straight away. |
97 void WebViewTestClient::printPage(blink::WebLocalFrame* frame) { | 95 void WebViewTestClient::printPage(blink::WebLocalFrame* frame) { |
98 blink::WebSize page_size_in_pixels = frame->view()->size(); | 96 blink::WebSize page_size_in_pixels = frame->view()->size(); |
99 if (page_size_in_pixels.isEmpty()) | 97 if (page_size_in_pixels.isEmpty()) |
100 return; | 98 return; |
101 blink::WebPrintParams printParams(page_size_in_pixels); | 99 blink::WebPrintParams printParams(page_size_in_pixels); |
102 frame->printBegin(printParams); | 100 frame->printBegin(printParams); |
103 frame->printEnd(); | 101 frame->printEnd(); |
104 } | 102 } |
105 | 103 |
106 void WebViewTestClient::showValidationMessage( | 104 void WebViewTestClient::showValidationMessage( |
107 const blink::WebRect& anchor_in_root_view, | 105 const blink::WebRect& anchor_in_root_view, |
108 const blink::WebString& main_message, | 106 const blink::WebString& main_message, |
109 blink::WebTextDirection main_message_hint, | 107 blink::WebTextDirection main_message_hint, |
110 const blink::WebString& sub_message, | 108 const blink::WebString& sub_message, |
111 blink::WebTextDirection sub_message_hint) { | 109 blink::WebTextDirection sub_message_hint) { |
112 if (test_runner_->is_web_platform_tests_mode()) | 110 if (test_runner()->is_web_platform_tests_mode()) |
113 return; | 111 return; |
114 | 112 |
115 base::string16 wrapped_main_text = main_message; | 113 base::string16 wrapped_main_text = main_message; |
116 base::string16 wrapped_sub_text = sub_message; | 114 base::string16 wrapped_sub_text = sub_message; |
117 | 115 |
118 if (main_message_hint == blink::WebTextDirectionLeftToRight) { | 116 if (main_message_hint == blink::WebTextDirectionLeftToRight) { |
119 wrapped_main_text = | 117 wrapped_main_text = |
120 base::i18n::GetDisplayStringInLTRDirectionality(wrapped_main_text); | 118 base::i18n::GetDisplayStringInLTRDirectionality(wrapped_main_text); |
121 } else if (main_message_hint == blink::WebTextDirectionRightToLeft && | 119 } else if (main_message_hint == blink::WebTextDirectionRightToLeft && |
122 !base::i18n::IsRTL()) { | 120 !base::i18n::IsRTL()) { |
123 base::i18n::WrapStringWithRTLFormatting(&wrapped_main_text); | 121 base::i18n::WrapStringWithRTLFormatting(&wrapped_main_text); |
124 } | 122 } |
125 | 123 |
126 if (!wrapped_sub_text.empty()) { | 124 if (!wrapped_sub_text.empty()) { |
127 if (sub_message_hint == blink::WebTextDirectionLeftToRight) { | 125 if (sub_message_hint == blink::WebTextDirectionLeftToRight) { |
128 wrapped_sub_text = | 126 wrapped_sub_text = |
129 base::i18n::GetDisplayStringInLTRDirectionality(wrapped_sub_text); | 127 base::i18n::GetDisplayStringInLTRDirectionality(wrapped_sub_text); |
130 } else if (sub_message_hint == blink::WebTextDirectionRightToLeft) { | 128 } else if (sub_message_hint == blink::WebTextDirectionRightToLeft) { |
131 base::i18n::WrapStringWithRTLFormatting(&wrapped_sub_text); | 129 base::i18n::WrapStringWithRTLFormatting(&wrapped_sub_text); |
132 } | 130 } |
133 } | 131 } |
134 delegate()->PrintMessage("ValidationMessageClient: main-message=" + | 132 delegate()->PrintMessage("ValidationMessageClient: main-message=" + |
135 base::UTF16ToUTF8(wrapped_main_text) + | 133 base::UTF16ToUTF8(wrapped_main_text) + |
136 " sub-message=" + | 134 " sub-message=" + |
137 base::UTF16ToUTF8(wrapped_sub_text) + "\n"); | 135 base::UTF16ToUTF8(wrapped_sub_text) + "\n"); |
138 } | 136 } |
139 | 137 |
140 blink::WebSpeechRecognizer* WebViewTestClient::speechRecognizer() { | 138 blink::WebSpeechRecognizer* WebViewTestClient::speechRecognizer() { |
141 return test_runner_->getMockWebSpeechRecognizer(); | 139 return test_runner()->getMockWebSpeechRecognizer(); |
142 } | 140 } |
143 | 141 |
144 blink::WebString WebViewTestClient::acceptLanguages() { | 142 blink::WebString WebViewTestClient::acceptLanguages() { |
145 return blink::WebString::fromUTF8(test_runner_->GetAcceptLanguages()); | 143 return blink::WebString::fromUTF8(test_runner()->GetAcceptLanguages()); |
146 } | 144 } |
147 | 145 |
148 WebTestDelegate* WebViewTestClient::delegate() { | 146 WebTestDelegate* WebViewTestClient::delegate() { |
149 return web_view_test_proxy_base_->delegate(); | 147 return web_view_test_proxy_base_->delegate(); |
150 } | 148 } |
151 | 149 |
152 void WebViewTestClient::didFocus() { | 150 void WebViewTestClient::didFocus() { |
153 test_runner_->SetFocus(web_view_test_proxy_base_->web_view(), true); | 151 test_runner()->SetFocus(web_view_test_proxy_base_->web_view(), true); |
| 152 } |
| 153 |
| 154 TestRunner* WebViewTestClient::test_runner() { |
| 155 return web_view_test_proxy_base_->test_interfaces()->GetTestRunner(); |
154 } | 156 } |
155 | 157 |
156 } // namespace test_runner | 158 } // namespace test_runner |
OLD | NEW |