diff options
author | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-23 14:14:06 +0000 |
---|---|---|
committer | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-23 14:14:06 +0000 |
commit | 8f72269f2b1e3bfe229ba26612aef17c8f1a6f52 (patch) | |
tree | 8e7e75ad8789e9e8ee8c0e40d9cddfe7ff9aacbe /content/shell | |
parent | 911170301422eba9d74e6a55eaa2fb9e7d5b5ec5 (diff) | |
download | chromium_src-8f72269f2b1e3bfe229ba26612aef17c8f1a6f52.zip chromium_src-8f72269f2b1e3bfe229ba26612aef17c8f1a6f52.tar.gz chromium_src-8f72269f2b1e3bfe229ba26612aef17c8f1a6f52.tar.bz2 |
[content shell] implement WebTestDelegate::captureHistoryForWindow
BUG=111316
R=creis@chromium.org
TEST=most navigation and history tests pass
Review URL: https://chromiumcodereview.appspot.com/12320012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@184317 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/shell')
-rw-r--r-- | content/shell/shell_messages.h | 11 | ||||
-rw-r--r-- | content/shell/webkit_test_controller.cc | 48 | ||||
-rw-r--r-- | content/shell/webkit_test_controller.h | 1 | ||||
-rw-r--r-- | content/shell/webkit_test_runner.cc | 53 | ||||
-rw-r--r-- | content/shell/webkit_test_runner.h | 16 |
5 files changed, 118 insertions, 11 deletions
diff --git a/content/shell/shell_messages.h b/content/shell/shell_messages.h index 1eebc5d..e9f4cc3 100644 --- a/content/shell/shell_messages.h +++ b/content/shell/shell_messages.h @@ -46,6 +46,16 @@ IPC_MESSAGE_CONTROL1(ShellViewMsg_SetWebKitSourceDir, IPC_MESSAGE_ROUTED1(ShellViewMsg_SetTestConfiguration, ShellViewMsg_SetTestConfiguration_Params) +// Pushes a snapshot of the current session history from the browser process. +// This includes only information about those RenderViews that are in the +// same process as the main window of the layout test and that are the current +// active RenderView of their WebContents. +IPC_MESSAGE_ROUTED3( + ShellViewMsg_SessionHistory, + std::vector<int> /* routing_ids */, + std::vector<std::vector<std::string> > /* session_histories */, + std::vector<unsigned> /* current_entry_indexes */) + // Send a text dump of the WebContents to the render host. IPC_MESSAGE_ROUTED1(ShellViewHostMsg_TextDump, std::string /* dump */) @@ -96,3 +106,4 @@ IPC_MESSAGE_ROUTED1(ShellViewHostMsg_SetDeviceScaleFactor, float /* factor */) IPC_MESSAGE_ROUTED1(ShellViewHostMsg_SetFocus, bool /* focus */) +IPC_MESSAGE_ROUTED0(ShellViewHostMsg_CaptureSessionHistory) diff --git a/content/shell/webkit_test_controller.cc b/content/shell/webkit_test_controller.cc index bb3d47d..d2eed15 100644 --- a/content/shell/webkit_test_controller.cc +++ b/content/shell/webkit_test_controller.cc @@ -13,6 +13,7 @@ #include "base/string_number_conversions.h" #include "base/stringprintf.h" #include "content/public/browser/navigation_controller.h" +#include "content/public/browser/navigation_entry.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/notification_types.h" #include "content/public/browser/render_process_host.h" @@ -24,6 +25,7 @@ #include "content/shell/shell_messages.h" #include "content/shell/shell_switches.h" #include "content/shell/webkit_test_helpers.h" +#include "webkit/glue/glue_serialize.h" #include "webkit/support/webkit_support_gfx.h" namespace content { @@ -288,6 +290,8 @@ bool WebKitTestController::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(ShellViewHostMsg_SetClientWindowRect, OnSetClientWindowRect) IPC_MESSAGE_HANDLER(ShellViewHostMsg_SetFocus, OnSetFocus) + IPC_MESSAGE_HANDLER(ShellViewHostMsg_CaptureSessionHistory, + OnCaptureSessionHistory) IPC_MESSAGE_HANDLER(ShellViewHostMsg_NotImplemented, OnNotImplemented) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() @@ -477,6 +481,50 @@ void WebKitTestController::OnSetFocus(bool focus) { main_window_->web_contents()->GetRenderViewHost()->Blur(); } +void WebKitTestController::OnCaptureSessionHistory() { + std::vector<int> routing_ids; + std::vector<std::vector<std::string> > session_histories; + std::vector<unsigned> current_entry_indexes; + + RenderViewHost* render_view_host = + main_window_->web_contents()->GetRenderViewHost(); + + for (std::vector<Shell*>::iterator window = Shell::windows().begin(); + window != Shell::windows().end(); + ++window) { + WebContents* web_contents = (*window)->web_contents(); + // Only capture the history from windows in the same process as the main + // window. During layout tests, we only use two processes when an + // devtools window is open. This should not happen during history navigation + // tests. + if (render_view_host->GetProcess() != + web_contents->GetRenderViewHost()->GetProcess()) { + NOTREACHED(); + continue; + } + routing_ids.push_back(web_contents->GetRenderViewHost()->GetRoutingID()); + current_entry_indexes.push_back( + web_contents->GetController().GetCurrentEntryIndex()); + std::vector<std::string> history; + for (int entry = 0; entry < web_contents->GetController().GetEntryCount(); + ++entry) { + std::string state = web_contents->GetController().GetEntryAtIndex(entry) + ->GetContentState(); + if (state.empty()) { + state = webkit_glue::CreateHistoryStateForURL( + web_contents->GetController().GetEntryAtIndex(entry)->GetURL()); + } + history.push_back(state); + } + session_histories.push_back(history); + } + + Send(new ShellViewMsg_SessionHistory(render_view_host->GetRoutingID(), + routing_ids, + session_histories, + current_entry_indexes)); +} + void WebKitTestController::OnNotImplemented( const std::string& object_name, const std::string& property_name) { diff --git a/content/shell/webkit_test_controller.h b/content/shell/webkit_test_controller.h index 3b4693a..6ca620c 100644 --- a/content/shell/webkit_test_controller.h +++ b/content/shell/webkit_test_controller.h @@ -131,6 +131,7 @@ class WebKitTestController : public base::NonThreadSafe, void OnLoadURLForFrame(const GURL& url, const std::string& frame_name); void OnSetClientWindowRect(const gfx::Rect& rect); void OnSetFocus(bool focus); + void OnCaptureSessionHistory(); void OnNotImplemented(const std::string& object_name, const std::string& method_name); diff --git a/content/shell/webkit_test_runner.cc b/content/shell/webkit_test_runner.cc index fc70b61..a08015e 100644 --- a/content/shell/webkit_test_runner.cc +++ b/content/shell/webkit_test_runner.cc @@ -42,6 +42,7 @@ #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" #include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/WebTask.h" @@ -50,6 +51,7 @@ #include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/WebTestRunner.h" #include "ui/gfx/rect.h" #include "webkit/base/file_path_string_conversions.h" +#include "webkit/glue/glue_serialize.h" #include "webkit/glue/webkit_glue.h" #include "webkit/glue/webpreferences.h" @@ -61,6 +63,7 @@ using WebKit::WebDeviceOrientation; using WebKit::WebElement; using WebKit::WebFrame; using WebKit::WebGamepads; +using WebKit::WebHistoryItem; using WebKit::WebRect; using WebKit::WebSize; using WebKit::WebString; @@ -330,7 +333,11 @@ void WebKitTestRunner::testFinished() { WebTestInterfaces* interfaces = ShellRenderProcessObserver::GetInstance()->test_interfaces(); interfaces->setTestIsRunning(false); - CaptureDump(); + if (interfaces->testRunner()->shouldDumpBackForwardList()) { + Send(new ShellViewHostMsg_CaptureSessionHistory(routing_id())); + } else { + CaptureDump(); + } } void WebKitTestRunner::testTimedOut() { @@ -379,15 +386,33 @@ bool WebKitTestRunner::allowExternalPages() { } void WebKitTestRunner::captureHistoryForWindow( -#if defined(WEBTESTRUNNER_NEW_HISTORY_CAPTURE) WebTestProxyBase* proxy, -#else - size_t windowIndex, -#endif WebVector<WebKit::WebHistoryItem>* history, size_t* currentEntryIndex) { - Send(new ShellViewHostMsg_NotImplemented( - routing_id(), "WebKitTestRunner", "captureHistoryForWindow")); + size_t pos = 0; + std::vector<int>::iterator id; + for (id = routing_ids_.begin(); id != routing_ids_.end(); ++id, ++pos) { + RenderView* render_view = RenderView::FromRoutingID(*id); + if (!render_view) { + NOTREACHED(); + continue; + } + if (WebKitTestRunner::Get(render_view)->proxy() == proxy) + break; + } + + 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] = + webkit_glue::HistoryItemFromString(session_histories_[pos][entry]); + } + history->swap(result); } // RenderViewObserver -------------------------------------------------------- @@ -401,6 +426,7 @@ bool WebKitTestRunner::OnMessageReceived(const IPC::Message& message) { IPC_BEGIN_MESSAGE_MAP(WebKitTestRunner, message) IPC_MESSAGE_HANDLER(ShellViewMsg_SetTestConfiguration, OnSetTestConfiguration) + IPC_MESSAGE_HANDLER(ShellViewMsg_SessionHistory, OnSessionHistory) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() @@ -418,6 +444,9 @@ void WebKitTestRunner::Reset() { layout_test_timeout_ = 30 * 1000; allow_external_pages_ = false; expected_pixel_hash_ = std::string(); + routing_ids_.clear(); + session_histories_.clear(); + current_entry_indexes_.clear(); } // Private methods ----------------------------------------------------------- @@ -495,4 +524,14 @@ void WebKitTestRunner::OnSetTestConfiguration( interfaces->configureForTestWithURL(params.test_url, enable_pixel_dumping_); } +void WebKitTestRunner::OnSessionHistory( + const std::vector<int>& routing_ids, + const std::vector<std::vector<std::string> >& session_histories, + const std::vector<unsigned>& current_entry_indexes) { + routing_ids_ = routing_ids; + session_histories_ = session_histories; + current_entry_indexes_ = current_entry_indexes; + CaptureDump(); +} + } // namespace content diff --git a/content/shell/webkit_test_runner.h b/content/shell/webkit_test_runner.h index dad432c..07b5d09 100644 --- a/content/shell/webkit_test_runner.h +++ b/content/shell/webkit_test_runner.h @@ -5,6 +5,8 @@ #ifndef CONTENT_SHELL_WEBKIT_TEST_RUNNER_H_ #define CONTENT_SHELL_WEBKIT_TEST_RUNNER_H_ +#include <vector> + #include "base/file_path.h" #include "base/memory/scoped_ptr.h" #include "content/public/renderer/render_view_observer.h" @@ -80,11 +82,7 @@ class WebKitTestRunner : public RenderViewObserver, const std::string& frame_name); virtual bool allowExternalPages(); virtual void captureHistoryForWindow( -#if defined(WEBTESTRUNNER_NEW_HISTORY_CAPTURE) WebTestRunner::WebTestProxyBase* proxy, -#else - size_t windowIndex, -#endif WebKit::WebVector<WebKit::WebHistoryItem>* history, size_t* currentEntryIndex); @@ -97,7 +95,13 @@ class WebKitTestRunner : public RenderViewObserver, // Message handlers. void OnSetTestConfiguration( const ShellViewMsg_SetTestConfiguration_Params& params); + void OnSessionHistory( + const std::vector<int>& routing_ids, + const std::vector<std::vector<std::string> >& session_histories, + const std::vector<unsigned>& current_entry_indexes); + // After finishing the test, retrieves the audio, text, and pixel dumps from + // the TestRunner library and sends them to the browser process. void CaptureDump(); base::FilePath current_working_directory_; @@ -112,6 +116,10 @@ class WebKitTestRunner : public RenderViewObserver, bool allow_external_pages_; std::string expected_pixel_hash_; + std::vector<int> routing_ids_; + std::vector<std::vector<std::string> > session_histories_; + std::vector<unsigned> current_entry_indexes_; + bool is_main_window_; DISALLOW_COPY_AND_ASSIGN(WebKitTestRunner); |