Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(567)

Side by Side Diff: content/test/layouttest_support.cc

Issue 246163006: Move history serialization from contet/public/renderer/ to content/renderer/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix braces Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/shell/renderer/webkit_test_runner.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/public/test/layouttest_support.h" 5 #include "content/public/test/layouttest_support.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "content/browser/renderer_host/render_widget_host_impl.h" 9 #include "content/browser/renderer_host/render_widget_host_impl.h"
10 #include "content/common/gpu/image_transport_surface.h" 10 #include "content/common/gpu/image_transport_surface.h"
11 #include "content/public/common/page_state.h"
12 #include "content/renderer/history_serialization.h"
11 #include "content/renderer/render_thread_impl.h" 13 #include "content/renderer/render_thread_impl.h"
12 #include "content/renderer/render_view_impl.h" 14 #include "content/renderer/render_view_impl.h"
13 #include "content/renderer/renderer_webkitplatformsupport_impl.h" 15 #include "content/renderer/renderer_webkitplatformsupport_impl.h"
16 #include "content/shell/renderer/test_runner/TestCommon.h"
14 #include "content/shell/renderer/test_runner/WebFrameTestProxy.h" 17 #include "content/shell/renderer/test_runner/WebFrameTestProxy.h"
15 #include "content/shell/renderer/test_runner/WebTestProxy.h" 18 #include "content/shell/renderer/test_runner/WebTestProxy.h"
16 #include "content/test/test_media_stream_client.h" 19 #include "content/test/test_media_stream_client.h"
17 #include "third_party/WebKit/public/platform/WebDeviceMotionData.h" 20 #include "third_party/WebKit/public/platform/WebDeviceMotionData.h"
18 #include "third_party/WebKit/public/platform/WebDeviceOrientationData.h" 21 #include "third_party/WebKit/public/platform/WebDeviceOrientationData.h"
19 #include "third_party/WebKit/public/platform/WebGamepads.h" 22 #include "third_party/WebKit/public/platform/WebGamepads.h"
23 #include "third_party/WebKit/public/web/WebHistoryItem.h"
20 24
21 #if defined(OS_MACOSX) 25 #if defined(OS_MACOSX)
22 #include "content/browser/renderer_host/popup_menu_helper_mac.h" 26 #include "content/browser/renderer_host/popup_menu_helper_mac.h"
23 #endif 27 #endif
24 28
25 using blink::WebDeviceMotionData; 29 using blink::WebDeviceMotionData;
26 using blink::WebDeviceOrientationData; 30 using blink::WebDeviceOrientationData;
27 using blink::WebGamepad; 31 using blink::WebGamepad;
28 using blink::WebGamepads; 32 using blink::WebGamepads;
29 using blink::WebRect; 33 using blink::WebRect;
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 static_cast<RenderViewImpl*>(render_view)-> 158 static_cast<RenderViewImpl*>(render_view)->
155 DisableAutoResizeForTesting(new_size); 159 DisableAutoResizeForTesting(new_size);
156 } 160 }
157 161
158 void UseMockMediaStreams(RenderView* render_view) { 162 void UseMockMediaStreams(RenderView* render_view) {
159 RenderViewImpl* render_view_impl = static_cast<RenderViewImpl*>(render_view); 163 RenderViewImpl* render_view_impl = static_cast<RenderViewImpl*>(render_view);
160 render_view_impl->SetMediaStreamClientForTesting( 164 render_view_impl->SetMediaStreamClientForTesting(
161 new TestMediaStreamClient(render_view_impl)); 165 new TestMediaStreamClient(render_view_impl));
162 } 166 }
163 167
168 struct ToLower {
169 base::char16 operator()(base::char16 c) { return tolower(c); }
170 };
171
172 // Returns True if item1 < item2.
173 bool HistoryItemCompareLess(const blink::WebHistoryItem& item1,
174 const blink::WebHistoryItem& item2) {
175 base::string16 target1 = item1.target();
176 base::string16 target2 = item2.target();
177 std::transform(target1.begin(), target1.end(), target1.begin(), ToLower());
178 std::transform(target2.begin(), target2.end(), target2.begin(), ToLower());
179 return target1 < target2;
180 }
181
182 std::string DumpHistoryItem(const blink::WebHistoryItem& item,
183 int indent,
184 bool is_current_index) {
185 std::string result;
186
187 if (is_current_index) {
188 result.append("curr->");
189 result.append(indent - 6, ' '); // 6 == "curr->".length()
190 } else {
191 result.append(indent, ' ');
192 }
193
194 std::string url =
195 WebTestRunner::normalizeLayoutTestURL(item.urlString().utf8());
196 result.append(url);
197 if (!item.target().isEmpty()) {
198 result.append(" (in frame \"");
199 result.append(item.target().utf8());
200 result.append("\")");
201 }
202 result.append("\n");
203
204 const blink::WebVector<blink::WebHistoryItem>& children = item.children();
205 if (!children.isEmpty()) {
206 // Must sort to eliminate arbitrary result ordering which defeats
207 // reproducible testing.
208 // FIXME: WebVector should probably just be a std::vector!!
209 std::vector<blink::WebHistoryItem> sortedChildren;
210 for (size_t i = 0; i < children.size(); ++i)
211 sortedChildren.push_back(children[i]);
212 std::sort(sortedChildren.begin(),
213 sortedChildren.end(),
214 HistoryItemCompareLess);
215 for (size_t i = 0; i < sortedChildren.size(); ++i)
216 result += DumpHistoryItem(sortedChildren[i], indent + 4, false);
217 }
218
219 return result;
220 }
221
222 std::string DumpBackForwardList(std::vector<PageState>& page_state,
223 size_t current_index) {
224 std::string result;
225 result.append("\n============== Back Forward List ==============\n");
226 for (size_t index = 0; index < page_state.size(); ++index) {
227 result.append(DumpHistoryItem(
228 PageStateToHistoryItem(page_state[index]), 8, index == current_index));
229 }
230 result.append("===============================================\n");
231 return result;
232 }
233
164 } // namespace content 234 } // namespace content
OLDNEW
« no previous file with comments | « content/shell/renderer/webkit_test_runner.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698