Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 { | |
|
jam
2014/04/24 16:23:26
nit: brace bracket on previous line. also below
Nate Chapin
2014/04/24 18:56:47
Done.
| |
| 176 base::string16 target1 = item1.target(); | |
| 177 base::string16 target2 = item2.target(); | |
| 178 std::transform(target1.begin(), target1.end(), target1.begin(), ToLower()); | |
| 179 std::transform(target2.begin(), target2.end(), target2.begin(), ToLower()); | |
| 180 return target1 < target2; | |
| 181 } | |
| 182 | |
| 183 std::string DumpHistoryItem(const blink::WebHistoryItem& item, | |
| 184 int indent, | |
| 185 bool is_current_index) | |
| 186 { | |
| 187 std::string result; | |
| 188 | |
| 189 if (is_current_index) { | |
| 190 result.append("curr->"); | |
| 191 result.append(indent - 6, ' '); // 6 == "curr->".length() | |
| 192 } else { | |
| 193 result.append(indent, ' '); | |
| 194 } | |
| 195 | |
| 196 std::string url = | |
| 197 WebTestRunner::normalizeLayoutTestURL(item.urlString().utf8()); | |
| 198 result.append(url); | |
| 199 if (!item.target().isEmpty()) { | |
| 200 result.append(" (in frame \""); | |
| 201 result.append(item.target().utf8()); | |
| 202 result.append("\")"); | |
| 203 } | |
| 204 result.append("\n"); | |
| 205 | |
| 206 const blink::WebVector<blink::WebHistoryItem>& children = item.children(); | |
| 207 if (!children.isEmpty()) { | |
| 208 // Must sort to eliminate arbitrary result ordering which defeats | |
| 209 // reproducible testing. | |
| 210 // FIXME: WebVector should probably just be a std::vector!! | |
| 211 std::vector<blink::WebHistoryItem> sortedChildren; | |
| 212 for (size_t i = 0; i < children.size(); ++i) | |
| 213 sortedChildren.push_back(children[i]); | |
| 214 std::sort(sortedChildren.begin(), | |
| 215 sortedChildren.end(), | |
| 216 HistoryItemCompareLess); | |
| 217 for (size_t i = 0; i < sortedChildren.size(); ++i) | |
| 218 result += DumpHistoryItem(sortedChildren[i], indent + 4, false); | |
| 219 } | |
| 220 | |
| 221 return result; | |
| 222 } | |
| 223 | |
| 224 std::string DumpBackForwardList(std::vector<PageState>& page_state, | |
| 225 size_t current_index) | |
| 226 { | |
| 227 std::string result; | |
| 228 result.append("\n============== Back Forward List ==============\n"); | |
| 229 for (size_t index = 0; index < page_state.size(); ++index) { | |
| 230 result.append(DumpHistoryItem( | |
| 231 PageStateToHistoryItem(page_state[index]), 8, index == current_index)); | |
| 232 } | |
| 233 result.append("===============================================\n"); | |
| 234 return result; | |
| 235 } | |
| 236 | |
| 164 } // namespace content | 237 } // namespace content |
| OLD | NEW |