diff options
author | japhet@chromium.org <japhet@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-25 08:36:38 +0000 |
---|---|---|
committer | japhet@chromium.org <japhet@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-25 08:36:38 +0000 |
commit | dc064357f798deeb025e96ad1e082c38efccfe35 (patch) | |
tree | 2327d1e9addda415be53fda5566e50622f2cb01e /content | |
parent | d5a255bcddcacfe147c02c5f3d4baee29f1e4235 (diff) | |
download | chromium_src-dc064357f798deeb025e96ad1e082c38efccfe35.zip chromium_src-dc064357f798deeb025e96ad1e082c38efccfe35.tar.gz chromium_src-dc064357f798deeb025e96ad1e082c38efccfe35.tar.bz2 |
Move history serialization from contet/public/renderer/ to content/renderer/
The only reason it is in content/public/ is so that content/shell can dump
history state for testing. Move back/forward list dumping to content/test/.
BUG=
Review URL: https://codereview.chromium.org/246163006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266158 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r-- | content/content_renderer.gypi | 4 | ||||
-rw-r--r-- | content/public/test/layouttest_support.h | 8 | ||||
-rw-r--r-- | content/public/test/render_view_test.cc | 2 | ||||
-rw-r--r-- | content/renderer/context_menu_params_builder.cc | 2 | ||||
-rw-r--r-- | content/renderer/history_serialization.cc (renamed from content/public/renderer/history_item_serialization.cc) | 4 | ||||
-rw-r--r-- | content/renderer/history_serialization.h (renamed from content/public/renderer/history_item_serialization.h) | 8 | ||||
-rw-r--r-- | content/renderer/render_frame_impl.cc | 2 | ||||
-rw-r--r-- | content/renderer/render_view_browsertest.cc | 2 | ||||
-rw-r--r-- | content/renderer/render_view_impl.cc | 2 | ||||
-rw-r--r-- | content/shell/renderer/test_runner/WebTestDelegate.h | 6 | ||||
-rw-r--r-- | content/shell/renderer/test_runner/WebTestProxy.cpp | 65 | ||||
-rw-r--r-- | content/shell/renderer/webkit_test_runner.cc | 18 | ||||
-rw-r--r-- | content/shell/renderer/webkit_test_runner.h | 5 | ||||
-rw-r--r-- | content/test/layouttest_support.cc | 70 |
14 files changed, 101 insertions, 97 deletions
diff --git a/content/content_renderer.gypi b/content/content_renderer.gypi index f45e51b..45b0cd1 100644 --- a/content/content_renderer.gypi +++ b/content/content_renderer.gypi @@ -43,8 +43,6 @@ 'public/renderer/context_menu_client.h', 'public/renderer/document_state.cc', 'public/renderer/document_state.h', - 'public/renderer/history_item_serialization.cc', - 'public/renderer/history_item_serialization.h', 'public/renderer/key_system_info.cc', 'public/renderer/key_system_info.h', 'public/renderer/navigation_state.cc', @@ -169,6 +167,8 @@ 'renderer/history_controller.h', 'renderer/history_entry.cc', 'renderer/history_entry.h', + 'renderer/history_serialization.cc', + 'renderer/history_serialization.h', 'renderer/idle_user_detector.cc', 'renderer/idle_user_detector.h', 'renderer/image_loading_helper.cc', diff --git a/content/public/test/layouttest_support.h b/content/public/test/layouttest_support.h index 3b3ab3b..a96b0a7 100644 --- a/content/public/test/layouttest_support.h +++ b/content/public/test/layouttest_support.h @@ -5,6 +5,9 @@ #ifndef CONTENT_PUBLIC_TEST_LAYOUTTEST_SUPPORT_H_ #define CONTENT_PUBLIC_TEST_LAYOUTTEST_SUPPORT_H_ +#include <string> +#include <vector> + #include "base/callback_forward.h" #include "third_party/WebKit/public/platform/WebScreenOrientationType.h" @@ -18,6 +21,7 @@ struct WebSize; namespace content { +class PageState; class RenderView; class WebTestProxyBase; @@ -93,6 +97,10 @@ void DisableAutoResizeMode(RenderView* render_view, // Forces the |render_view| to use mock media streams. void UseMockMediaStreams(RenderView* render_view); +// Provides a text dump of the contents of the given page state. +std::string DumpBackForwardList(std::vector<PageState>& page_state, + size_t current_index); + } // namespace content #endif // CONTENT_PUBLIC_TEST_LAYOUTTEST_SUPPORT_H_ diff --git a/content/public/test/render_view_test.cc b/content/public/test/render_view_test.cc index 94d7b63..33c0fdb 100644 --- a/content/public/test/render_view_test.cc +++ b/content/public/test/render_view_test.cc @@ -14,8 +14,8 @@ #include "content/public/common/content_client.h" #include "content/public/common/renderer_preferences.h" #include "content/public/renderer/content_renderer_client.h" -#include "content/public/renderer/history_item_serialization.h" #include "content/renderer/history_controller.h" +#include "content/renderer/history_serialization.h" #include "content/renderer/render_thread_impl.h" #include "content/renderer/render_view_impl.h" #include "content/renderer/renderer_main_platform_delegate.h" diff --git a/content/renderer/context_menu_params_builder.cc b/content/renderer/context_menu_params_builder.cc index 2f22745..0b3af2b 100644 --- a/content/renderer/context_menu_params_builder.cc +++ b/content/renderer/context_menu_params_builder.cc @@ -7,7 +7,7 @@ #include "base/logging.h" #include "content/common/ssl_status_serialization.h" #include "content/public/common/context_menu_params.h" -#include "content/public/renderer/history_item_serialization.h" +#include "content/renderer/history_serialization.h" #include "content/renderer/menu_item_builder.h" #include "third_party/WebKit/public/web/WebElement.h" #include "third_party/WebKit/public/web/WebNode.h" diff --git a/content/public/renderer/history_item_serialization.cc b/content/renderer/history_serialization.cc index ef1c2a2d..f6a4987 100644 --- a/content/public/renderer/history_item_serialization.cc +++ b/content/renderer/history_serialization.cc @@ -1,8 +1,8 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Copyright 2014 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 "content/public/renderer/history_item_serialization.h" +#include "content/renderer/history_serialization.h" #include "content/common/page_state_serialization.h" #include "content/public/common/page_state.h" diff --git a/content/public/renderer/history_item_serialization.h b/content/renderer/history_serialization.h index dda1cf4..6160fd3 100644 --- a/content/public/renderer/history_item_serialization.h +++ b/content/renderer/history_serialization.h @@ -1,9 +1,9 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Copyright 2014 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. -#ifndef CONTENT_RENDERER_HISTORY_ITEM_SERIALIZATION_H_ -#define CONTENT_RENDERER_HISTORY_ITEM_SERIALIZATION_H_ +#ifndef CONTENT_RENDERER_HISTORY_SERIALIZATION_H_ +#define CONTENT_RENDERER_HISTORY_SERIALIZATION_H_ #include <string> @@ -23,4 +23,4 @@ CONTENT_EXPORT blink::WebHistoryItem PageStateToHistoryItem( } // namespace content -#endif // CONTENT_RENDERER_HISTORY_ITEM_SERIALIZATION_H_ +#endif // CONTENT_RENDERER_HISTORY_SERIALIZATION_H_ diff --git a/content/renderer/render_frame_impl.cc b/content/renderer/render_frame_impl.cc index c6526dd..31db214 100644 --- a/content/renderer/render_frame_impl.cc +++ b/content/renderer/render_frame_impl.cc @@ -41,7 +41,6 @@ #include "content/public/renderer/content_renderer_client.h" #include "content/public/renderer/context_menu_client.h" #include "content/public/renderer/document_state.h" -#include "content/public/renderer/history_item_serialization.h" #include "content/public/renderer/navigation_state.h" #include "content/public/renderer/render_frame_observer.h" #include "content/renderer/accessibility/renderer_accessibility.h" @@ -51,6 +50,7 @@ #include "content/renderer/context_menu_params_builder.h" #include "content/renderer/dom_automation_controller.h" #include "content/renderer/history_controller.h" +#include "content/renderer/history_serialization.h" #include "content/renderer/image_loading_helper.h" #include "content/renderer/ime_event_guard.h" #include "content/renderer/internal_document_state_data.h" diff --git a/content/renderer/render_view_browsertest.cc b/content/renderer/render_view_browsertest.cc index bb24dfd..1f8ce67 100644 --- a/content/renderer/render_view_browsertest.cc +++ b/content/renderer/render_view_browsertest.cc @@ -23,7 +23,6 @@ #include "content/public/common/url_utils.h" #include "content/public/renderer/content_renderer_client.h" #include "content/public/renderer/document_state.h" -#include "content/public/renderer/history_item_serialization.h" #include "content/public/renderer/navigation_state.h" #include "content/public/test/browser_test_utils.h" #include "content/public/test/render_view_test.h" @@ -32,6 +31,7 @@ #include "content/renderer/accessibility/renderer_accessibility_complete.h" #include "content/renderer/accessibility/renderer_accessibility_focus_only.h" #include "content/renderer/history_controller.h" +#include "content/renderer/history_serialization.h" #include "content/renderer/render_view_impl.h" #include "content/shell/browser/shell.h" #include "content/shell/browser/shell_browser_context.h" diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc index cf16222..96775e1 100644 --- a/content/renderer/render_view_impl.cc +++ b/content/renderer/render_view_impl.cc @@ -63,7 +63,6 @@ #include "content/public/common/url_utils.h" #include "content/public/renderer/content_renderer_client.h" #include "content/public/renderer/document_state.h" -#include "content/public/renderer/history_item_serialization.h" #include "content/public/renderer/navigation_state.h" #include "content/public/renderer/render_view_observer.h" #include "content/public/renderer/render_view_visitor.h" @@ -82,6 +81,7 @@ #include "content/renderer/geolocation_dispatcher.h" #include "content/renderer/gpu/render_widget_compositor.h" #include "content/renderer/history_controller.h" +#include "content/renderer/history_serialization.h" #include "content/renderer/idle_user_detector.h" #include "content/renderer/ime_event_guard.h" #include "content/renderer/input/input_handler_manager.h" diff --git a/content/shell/renderer/test_runner/WebTestDelegate.h b/content/shell/renderer/test_runner/WebTestDelegate.h index 8dbea51..fa4ef33 100644 --- a/content/shell/renderer/test_runner/WebTestDelegate.h +++ b/content/shell/renderer/test_runner/WebTestDelegate.h @@ -150,9 +150,9 @@ public: // Returns true if resource requests to external URLs should be permitted. virtual bool allowExternalPages() = 0; - // Returns the back/forward history for the WebView associated with the - // given WebTestProxyBase as well as the index of the current entry. - virtual void captureHistoryForWindow(content::WebTestProxyBase*, blink::WebVector<blink::WebHistoryItem>*, size_t* currentEntryIndex) = 0; + // Returns a text dump the back/forward history for the WebView associated + // with the given WebTestProxyBase. + virtual std::string dumpHistoryForWindow(content::WebTestProxyBase*) = 0; }; } diff --git a/content/shell/renderer/test_runner/WebTestProxy.cpp b/content/shell/renderer/test_runner/WebTestProxy.cpp index 1c4f1b1..97f78217 100644 --- a/content/shell/renderer/test_runner/WebTestProxy.cpp +++ b/content/shell/renderer/test_runner/WebTestProxy.cpp @@ -304,73 +304,12 @@ string dumpFrameScrollPosition(WebFrame* frame, bool recursive) return result; } -struct ToLower { - base::char16 operator()(base::char16 c) { return tolower(c); } -}; - -// Returns True if item1 < item2. -bool HistoryItemCompareLess(const WebHistoryItem& item1, const WebHistoryItem& item2) -{ - base::string16 target1 = item1.target(); - base::string16 target2 = item2.target(); - std::transform(target1.begin(), target1.end(), target1.begin(), ToLower()); - std::transform(target2.begin(), target2.end(), target2.begin(), ToLower()); - return target1 < target2; -} - -string dumpHistoryItem(const WebHistoryItem& item, int indent, bool isCurrent) -{ - string result; - - if (isCurrent) { - result.append("curr->"); - result.append(indent - 6, ' '); // 6 == "curr->".length() - } else - result.append(indent, ' '); - - string url = normalizeLayoutTestURL(item.urlString().utf8()); - result.append(url); - if (!item.target().isEmpty()) { - result.append(" (in frame \""); - result.append(item.target().utf8()); - result.append("\")"); - } - result.append("\n"); - - const WebVector<WebHistoryItem>& children = item.children(); - if (!children.isEmpty()) { - // Must sort to eliminate arbitrary result ordering which defeats - // reproducible testing. - // FIXME: WebVector should probably just be a std::vector!! - std::vector<WebHistoryItem> sortedChildren; - for (size_t i = 0; i < children.size(); ++i) - sortedChildren.push_back(children[i]); - std::sort(sortedChildren.begin(), sortedChildren.end(), HistoryItemCompareLess); - for (size_t i = 0; i < sortedChildren.size(); ++i) - result += dumpHistoryItem(sortedChildren[i], indent + 4, false); - } - - return result; -} - -void dumpBackForwardList(const WebVector<WebHistoryItem>& history, size_t currentEntryIndex, string& result) -{ - result.append("\n============== Back Forward List ==============\n"); - for (size_t index = 0; index < history.size(); ++index) - result.append(dumpHistoryItem(history[index], 8, index == currentEntryIndex)); - result.append("===============================================\n"); -} - string dumpAllBackForwardLists(TestInterfaces* interfaces, WebTestDelegate* delegate) { string result; const vector<WebTestProxyBase*>& windowList = interfaces->windowList(); - for (unsigned i = 0; i < windowList.size(); ++i) { - size_t currentEntryIndex = 0; - WebVector<WebHistoryItem> history; - delegate->captureHistoryForWindow(windowList.at(i), &history, ¤tEntryIndex); - dumpBackForwardList(history, currentEntryIndex, result); - } + for (unsigned i = 0; i < windowList.size(); ++i) + result.append(delegate->dumpHistoryForWindow(windowList.at(i))); return result; } diff --git a/content/shell/renderer/webkit_test_runner.cc b/content/shell/renderer/webkit_test_runner.cc index 5e96587..f0454e1 100644 --- a/content/shell/renderer/webkit_test_runner.cc +++ b/content/shell/renderer/webkit_test_runner.cc @@ -22,7 +22,6 @@ #include "base/time/time.h" #include "content/public/common/content_switches.h" #include "content/public/common/url_constants.h" -#include "content/public/renderer/history_item_serialization.h" #include "content/public/renderer/render_view.h" #include "content/public/renderer/render_view_visitor.h" #include "content/public/test/layouttest_support.h" @@ -540,10 +539,7 @@ bool WebKitTestRunner::allowExternalPages() { return test_config_.allow_external_pages; } -void WebKitTestRunner::captureHistoryForWindow( - WebTestProxyBase* proxy, - WebVector<blink::WebHistoryItem>* history, - size_t* currentEntryIndex) { +std::string WebKitTestRunner::dumpHistoryForWindow(WebTestProxyBase* proxy) { size_t pos = 0; std::vector<int>::iterator id; for (id = routing_ids_.begin(); id != routing_ids_.end(); ++id, ++pos) { @@ -558,16 +554,10 @@ void WebKitTestRunner::captureHistoryForWindow( if (id == routing_ids_.end()) { NOTREACHED(); - return; - } - size_t num_entries = session_histories_[pos].size(); - *currentEntryIndex = current_entry_indexes_[pos]; - WebVector<WebHistoryItem> result(num_entries); - for (size_t entry = 0; entry < num_entries; ++entry) { - result[entry] = - PageStateToHistoryItem(session_histories_[pos][entry]); + return std::string(); } - history->swap(result); + return DumpBackForwardList(session_histories_[pos], + current_entry_indexes_[pos]); } // RenderViewObserver -------------------------------------------------------- diff --git a/content/shell/renderer/webkit_test_runner.h b/content/shell/renderer/webkit_test_runner.h index aceb56b..a5ef240 100644 --- a/content/shell/renderer/webkit_test_runner.h +++ b/content/shell/renderer/webkit_test_runner.h @@ -107,10 +107,7 @@ class WebKitTestRunner : public RenderViewObserver, virtual void loadURLForFrame(const blink::WebURL& url, const std::string& frame_name) OVERRIDE; virtual bool allowExternalPages() OVERRIDE; - virtual void captureHistoryForWindow( - WebTestProxyBase* proxy, - blink::WebVector<blink::WebHistoryItem>* history, - size_t* currentEntryIndex) OVERRIDE; + virtual std::string dumpHistoryForWindow(WebTestProxyBase* proxy) OVERRIDE; void Reset(); diff --git a/content/test/layouttest_support.cc b/content/test/layouttest_support.cc index 64832d7..387d75a 100644 --- a/content/test/layouttest_support.cc +++ b/content/test/layouttest_support.cc @@ -8,15 +8,19 @@ #include "base/lazy_instance.h" #include "content/browser/renderer_host/render_widget_host_impl.h" #include "content/common/gpu/image_transport_surface.h" +#include "content/public/common/page_state.h" +#include "content/renderer/history_serialization.h" #include "content/renderer/render_thread_impl.h" #include "content/renderer/render_view_impl.h" #include "content/renderer/renderer_webkitplatformsupport_impl.h" +#include "content/shell/renderer/test_runner/TestCommon.h" #include "content/shell/renderer/test_runner/WebFrameTestProxy.h" #include "content/shell/renderer/test_runner/WebTestProxy.h" #include "content/test/test_media_stream_client.h" #include "third_party/WebKit/public/platform/WebDeviceMotionData.h" #include "third_party/WebKit/public/platform/WebDeviceOrientationData.h" #include "third_party/WebKit/public/platform/WebGamepads.h" +#include "third_party/WebKit/public/web/WebHistoryItem.h" #if defined(OS_MACOSX) #include "content/browser/renderer_host/popup_menu_helper_mac.h" @@ -161,4 +165,70 @@ void UseMockMediaStreams(RenderView* render_view) { new TestMediaStreamClient(render_view_impl)); } +struct ToLower { + base::char16 operator()(base::char16 c) { return tolower(c); } +}; + +// Returns True if item1 < item2. +bool HistoryItemCompareLess(const blink::WebHistoryItem& item1, + const blink::WebHistoryItem& item2) { + base::string16 target1 = item1.target(); + base::string16 target2 = item2.target(); + std::transform(target1.begin(), target1.end(), target1.begin(), ToLower()); + std::transform(target2.begin(), target2.end(), target2.begin(), ToLower()); + return target1 < target2; +} + +std::string DumpHistoryItem(const blink::WebHistoryItem& item, + int indent, + bool is_current_index) { + std::string result; + + if (is_current_index) { + result.append("curr->"); + result.append(indent - 6, ' '); // 6 == "curr->".length() + } else { + result.append(indent, ' '); + } + + std::string url = + WebTestRunner::normalizeLayoutTestURL(item.urlString().utf8()); + result.append(url); + if (!item.target().isEmpty()) { + result.append(" (in frame \""); + result.append(item.target().utf8()); + result.append("\")"); + } + result.append("\n"); + + const blink::WebVector<blink::WebHistoryItem>& children = item.children(); + if (!children.isEmpty()) { + // Must sort to eliminate arbitrary result ordering which defeats + // reproducible testing. + // FIXME: WebVector should probably just be a std::vector!! + std::vector<blink::WebHistoryItem> sortedChildren; + for (size_t i = 0; i < children.size(); ++i) + sortedChildren.push_back(children[i]); + std::sort(sortedChildren.begin(), + sortedChildren.end(), + HistoryItemCompareLess); + for (size_t i = 0; i < sortedChildren.size(); ++i) + result += DumpHistoryItem(sortedChildren[i], indent + 4, false); + } + + return result; +} + +std::string DumpBackForwardList(std::vector<PageState>& page_state, + size_t current_index) { + std::string result; + result.append("\n============== Back Forward List ==============\n"); + for (size_t index = 0; index < page_state.size(); ++index) { + result.append(DumpHistoryItem( + PageStateToHistoryItem(page_state[index]), 8, index == current_index)); + } + result.append("===============================================\n"); + return result; +} + } // namespace content |