summaryrefslogtreecommitdiffstats
path: root/webkit/tools/test_shell
diff options
context:
space:
mode:
authordarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-13 21:12:03 +0000
committerdarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-13 21:12:03 +0000
commitf6e59a6f478826a9a1d75b18f10f285487f18fac (patch)
tree0336e7be11b059b8e3cec7a2eef273fa0ef0994d /webkit/tools/test_shell
parent7502d0224e51f54f1d65fbfce6d100e99dc819dc (diff)
downloadchromium_src-f6e59a6f478826a9a1d75b18f10f285487f18fac.zip
chromium_src-f6e59a6f478826a9a1d75b18f10f285487f18fac.tar.gz
chromium_src-f6e59a6f478826a9a1d75b18f10f285487f18fac.tar.bz2
Re-do r15244 again.
Originally reviewed at http://codereview.chromium.org/100353 Eliminate webkit/glue/webhistoryitem* in favor of adding a NavigateBackForwardSoon method WebViewDelegate. This moves all of the hacky details of how we intercept "history.{back, forward,go}" into the webkit layer. My eventual plan is to teach WebCore how to make this not hacky. In this version of the CL, TestWebViewDelegate performs the back/forward navigation directly in NavigateBackForwardSoon instead of using PostTask to delay it. I'm doing this to minimize regressions so that I can hopefully get the rest of this CL landed. I also already made the changes to WebKit to force history. {back,forward,go} to be processed asynchronously. Finally, it was necessary to move DumpBackForwardList out of webkit_glue.cc since it was using itemAtIndex to generate those results, and now that we return synthetic URLs for that function, the results were very wrong. The fix is to move DumpBackForwardList into TestShell so that it can more directly inspect the TestNavigationController. Now, it is necessary for webkit_glue.h to expose a function to dump a content state string (aka a WebCore::HistoryItem). BUG=11423 R=mpcomplete Review URL: http://codereview.chromium.org/113328 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15997 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/tools/test_shell')
-rw-r--r--webkit/tools/test_shell/test_navigation_controller.cc18
-rw-r--r--webkit/tools/test_shell/test_navigation_controller.h10
-rw-r--r--webkit/tools/test_shell/test_shell.cc59
-rw-r--r--webkit/tools/test_shell/test_shell.h9
-rw-r--r--webkit/tools/test_shell/test_shell_gtk.cc10
-rw-r--r--webkit/tools/test_shell/test_shell_mac.mm4
-rw-r--r--webkit/tools/test_shell/test_shell_win.cc4
-rw-r--r--webkit/tools/test_shell/test_webview_delegate.cc35
-rw-r--r--webkit/tools/test_shell/test_webview_delegate.h2
9 files changed, 81 insertions, 70 deletions
diff --git a/webkit/tools/test_shell/test_navigation_controller.cc b/webkit/tools/test_shell/test_navigation_controller.cc
index ff4a753..1142839 100644
--- a/webkit/tools/test_shell/test_navigation_controller.cc
+++ b/webkit/tools/test_shell/test_navigation_controller.cc
@@ -5,7 +5,6 @@
#include "webkit/tools/test_shell/test_navigation_controller.h"
#include "base/logging.h"
-#include "webkit/glue/webhistoryitem.h"
#include "webkit/tools/test_shell/test_shell.h"
// ----------------------------------------------------------------------------
@@ -29,21 +28,9 @@ TestNavigationEntry::~TestNavigationEntry() {
}
void TestNavigationEntry::SetContentState(const std::string& state) {
- cached_history_item_ = NULL; // invalidate our cached item
state_ = state;
}
-WebHistoryItem* TestNavigationEntry::GetHistoryItem() const {
- if (!cached_history_item_) {
- TestShellExtraRequestData* extra_data =
- new TestShellExtraRequestData(GetPageID());
- cached_history_item_ =
- WebHistoryItem::Create(GetURL(), GetTitle(), GetContentState(),
- extra_data);
- }
- return cached_history_item_;
-}
-
// ----------------------------------------------------------------------------
// TestNavigationController
@@ -129,9 +116,8 @@ int TestNavigationController::GetCurrentEntryIndex() const {
}
-TestNavigationEntry* TestNavigationController::GetEntryAtOffset(
- int offset) const {
- int index = last_committed_entry_index_ + offset;
+TestNavigationEntry* TestNavigationController::GetEntryAtIndex(
+ int index) const {
if (index < 0 || index >= GetEntryCount())
return NULL;
diff --git a/webkit/tools/test_shell/test_navigation_controller.h b/webkit/tools/test_shell/test_navigation_controller.h
index 07f42f8..d26e994 100644
--- a/webkit/tools/test_shell/test_navigation_controller.h
+++ b/webkit/tools/test_shell/test_navigation_controller.h
@@ -16,7 +16,6 @@
class GURL;
class TestShell;
-class WebHistoryItem;
// Associated with browser-initated navigations to hold tracking data.
class TestShellExtraRequestData : public WebRequest::ExtraData {
@@ -67,7 +66,6 @@ class TestNavigationEntry {
void SetPageID(int page_id) { page_id_ = page_id; }
int32 GetPageID() const { return page_id_; }
- WebHistoryItem* GetHistoryItem() const;
const std::wstring& GetTargetFrame() const { return target_frame_; }
private:
@@ -79,8 +77,6 @@ class TestNavigationEntry {
std::wstring title_;
std::string state_;
- mutable scoped_refptr<WebHistoryItem> cached_history_item_;
-
std::wstring target_frame_;
DISALLOW_COPY_AND_ASSIGN(TestNavigationEntry);
@@ -132,9 +128,9 @@ class TestNavigationController {
// it is the pending_entry_index_.
int GetCurrentEntryIndex() const;
- // Returns the entry at the specified offset from current. Returns NULL
- // if out of bounds.
- TestNavigationEntry* GetEntryAtOffset(int offset) const;
+ // Returns the entry at the specified index. Returns NULL if out of
+ // bounds.
+ TestNavigationEntry* GetEntryAtIndex(int index) const;
// Return the entry with the corresponding type and page_id, or NULL if
// not found.
diff --git a/webkit/tools/test_shell/test_shell.cc b/webkit/tools/test_shell/test_shell.cc
index 7150807..0dd4c40 100644
--- a/webkit/tools/test_shell/test_shell.cc
+++ b/webkit/tools/test_shell/test_shell.cc
@@ -217,7 +217,7 @@ void TestShell::Dump(TestShell* shell) {
if (shell->layout_test_controller_->ShouldDumpBackForwardList()) {
std::wstring bfDump;
- DumpBackForwardList(&bfDump);
+ DumpAllBackForwardLists(&bfDump);
printf("%s", WideToUTF8(bfDump).c_str());
}
}
@@ -418,35 +418,52 @@ void TestShell::Show(WebView* webview, WindowOpenDisposition disposition) {
}
void TestShell::BindJSObjectsToWindow(WebFrame* frame) {
- // Only bind the test classes if we're running tests.
- if (layout_test_mode_) {
- layout_test_controller_->BindToJavascript(frame,
- L"layoutTestController");
- event_sending_controller_->BindToJavascript(frame,
- L"eventSender");
- text_input_controller_->BindToJavascript(frame,
- L"textInputController");
- }
+ // Only bind the test classes if we're running tests.
+ if (layout_test_mode_) {
+ layout_test_controller_->BindToJavascript(frame, L"layoutTestController");
+ event_sending_controller_->BindToJavascript(frame, L"eventSender");
+ text_input_controller_->BindToJavascript(frame, L"textInputController");
+ }
}
+void TestShell::DumpBackForwardEntry(int index, std::wstring* result) {
+ int current_index = navigation_controller_->GetLastCommittedEntryIndex();
-void TestShell::CallJSGC() {
- WebFrame* frame = webView()->GetMainFrame();
- frame->CallJSGC();
+ std::string content_state =
+ navigation_controller_->GetEntryAtIndex(index)->GetContentState();
+ if (content_state.empty()) {
+ content_state = webkit_glue::CreateHistoryStateForURL(
+ navigation_controller_->GetEntryAtIndex(index)->GetURL());
+ }
+
+ result->append(
+ webkit_glue::DumpHistoryState(content_state, 8, index == current_index));
}
+void TestShell::DumpBackForwardList(std::wstring* result) {
+ result->append(L"\n============== Back Forward List ==============\n");
+
+ for (int i = 0; i < navigation_controller_->GetEntryCount(); ++i)
+ DumpBackForwardEntry(i, result);
+
+ result->append(L"===============================================\n");
+}
+
+void TestShell::CallJSGC() {
+ webView()->GetMainFrame()->CallJSGC();
+}
WebView* TestShell::CreateWebView(WebView* webview) {
- // If we're running layout tests, only open a new window if the test has
- // called layoutTestController.setCanOpenWindows()
- if (layout_test_mode_ && !layout_test_controller_->CanOpenWindows())
- return NULL;
+ // If we're running layout tests, only open a new window if the test has
+ // called layoutTestController.setCanOpenWindows()
+ if (layout_test_mode_ && !layout_test_controller_->CanOpenWindows())
+ return NULL;
- TestShell* new_win;
- if (!CreateNewWindow(std::wstring(), &new_win))
- return NULL;
+ TestShell* new_win;
+ if (!CreateNewWindow(std::wstring(), &new_win))
+ return NULL;
- return new_win->webView();
+ return new_win->webView();
}
void TestShell::SizeToSVG() {
diff --git a/webkit/tools/test_shell/test_shell.h b/webkit/tools/test_shell/test_shell.h
index c5806c3..d6ac049 100644
--- a/webkit/tools/test_shell/test_shell.h
+++ b/webkit/tools/test_shell/test_shell.h
@@ -194,7 +194,14 @@ public:
static bool RunFileTest(const TestParams& params);
// Writes the back-forward list data for every open window into result.
- static void DumpBackForwardList(std::wstring* result);
+ // Should call DumpBackForwardListOfWindow on each TestShell window.
+ static void DumpAllBackForwardLists(std::wstring* result);
+
+ // Writes the single back-forward entry into result.
+ void DumpBackForwardEntry(int index, std::wstring* result);
+
+ // Writes the back-forward list data for this test shell into result.
+ void DumpBackForwardList(std::wstring* result);
// Dumps the output from given test as text and/or image depending on
// the flags set.
diff --git a/webkit/tools/test_shell/test_shell_gtk.cc b/webkit/tools/test_shell/test_shell_gtk.cc
index 40cd1c1..6971a57 100644
--- a/webkit/tools/test_shell/test_shell_gtk.cc
+++ b/webkit/tools/test_shell/test_shell_gtk.cc
@@ -482,14 +482,14 @@ void TestShell::ResizeSubViews() {
// GTK manages layout for us so we do nothing.
}
-/* static */ void TestShell::DumpBackForwardList(std::wstring* result) {
+/* static */ void TestShell::DumpAllBackForwardLists(std::wstring* result) {
result->clear();
for (WindowList::iterator iter = TestShell::windowList()->begin();
iter != TestShell::windowList()->end(); iter++) {
- GtkWindow* window = *iter;
- TestShell* shell =
- static_cast<TestShell*>(g_object_get_data(G_OBJECT(window), "test-shell"));
- webkit_glue::DumpBackForwardList(shell->webView(), NULL, result);
+ GtkWindow* window = *iter;
+ TestShell* shell =
+ static_cast<TestShell*>(g_object_get_data(G_OBJECT(window), "test-shell"));
+ shell->DumpBackForwardList(result);
}
}
diff --git a/webkit/tools/test_shell/test_shell_mac.mm b/webkit/tools/test_shell/test_shell_mac.mm
index 1fd92f1..5be826d 100644
--- a/webkit/tools/test_shell/test_shell_mac.mm
+++ b/webkit/tools/test_shell/test_shell_mac.mm
@@ -484,14 +484,14 @@ void TestShell::ResizeSubViews() {
// handled by Cocoa for us
}
-/* static */ void TestShell::DumpBackForwardList(std::wstring* result) {
+/* static */ void TestShell::DumpAllBackForwardLists(std::wstring* result) {
result->clear();
for (WindowList::iterator iter = TestShell::windowList()->begin();
iter != TestShell::windowList()->end(); iter++) {
NSWindow* window = *iter;
WindowMap::iterator it = window_map_.Get().find(window);
if (it != window_map_.Get().end())
- webkit_glue::DumpBackForwardList(it->second->webView(), NULL, result);
+ it->second->DumpBackForwardList(result);
else
LOG(ERROR) << "Failed to find shell for window during dump";
}
diff --git a/webkit/tools/test_shell/test_shell_win.cc b/webkit/tools/test_shell/test_shell_win.cc
index c118ceb..4cba4ad 100644
--- a/webkit/tools/test_shell/test_shell_win.cc
+++ b/webkit/tools/test_shell/test_shell_win.cc
@@ -208,14 +208,14 @@ ATOM TestShell::RegisterWindowClass() {
return RegisterClassEx(&wcex);
}
-void TestShell::DumpBackForwardList(std::wstring* result) {
+void TestShell::DumpAllBackForwardLists(std::wstring* result) {
result->clear();
for (WindowList::iterator iter = TestShell::windowList()->begin();
iter != TestShell::windowList()->end(); iter++) {
HWND hwnd = *iter;
TestShell* shell =
static_cast<TestShell*>(win_util::GetWindowUserData(hwnd));
- webkit_glue::DumpBackForwardList(shell->webView(), NULL, result);
+ shell->DumpBackForwardList(result);
}
}
diff --git a/webkit/tools/test_shell/test_webview_delegate.cc b/webkit/tools/test_shell/test_webview_delegate.cc
index 092b2a56..d886f4d 100644
--- a/webkit/tools/test_shell/test_webview_delegate.cc
+++ b/webkit/tools/test_shell/test_webview_delegate.cc
@@ -115,6 +115,14 @@ WebWidget* TestWebViewDelegate::CreatePopupWidget(WebView* webview,
return shell_->CreatePopupWidget(webview);
}
+WebWorker* TestWebViewDelegate::CreateWebWorker(WebWorkerClient* client) {
+#if ENABLE(WORKERS)
+ return TestWebWorkerHelper::CreateWebWorker(client);
+#else
+ return NULL;
+#endif
+}
+
void TestWebViewDelegate::OpenURL(WebView* webview, const GURL& url,
const GURL& referrer,
WindowOpenDisposition disposition) {
@@ -661,13 +669,8 @@ void TestWebViewDelegate::DidEndEditing() {
}
}
-WebHistoryItem* TestWebViewDelegate::GetHistoryEntryAtOffset(int offset) {
- TestNavigationEntry* entry = static_cast<TestNavigationEntry*>(
- shell_->navigation_controller()->GetEntryAtOffset(offset));
- if (!entry)
- return NULL;
-
- return entry->GetHistoryItem();
+void TestWebViewDelegate::NavigateBackForwardSoon(int offset) {
+ shell_->navigation_controller()->GoToOffset(offset);
}
int TestWebViewDelegate::GetHistoryBackListCount() {
@@ -791,6 +794,16 @@ void TestWebViewDelegate::LocationChangeDone(WebFrame* frame) {
if (frame == top_loading_frame_) {
top_loading_frame_ = NULL;
+ // It is important to update the content state for the current navigation
+ // entry in case we are done with the test and need to dump the back/
+ // forward list.
+ std::string state;
+ if (shell_->webView()->GetMainFrame()->GetCurrentHistoryState(&state)) {
+ TestNavigationEntry* entry =
+ shell_->navigation_controller()->GetLastCommittedEntry();
+ entry->SetContentState(state);
+ }
+
if (shell_->layout_test_mode())
shell_->layout_test_controller()->LocationChangeDone();
}
@@ -888,11 +901,3 @@ std::wstring TestWebViewDelegate::GetFrameDescription(WebFrame* webframe) {
return L"frame (anonymous)";
}
}
-
-WebWorker* TestWebViewDelegate::CreateWebWorker(WebWorkerClient* client) {
-#if ENABLE(WORKERS)
- return TestWebWorkerHelper::CreateWebWorker(client);
-#else
- return NULL;
-#endif
-}
diff --git a/webkit/tools/test_shell/test_webview_delegate.h b/webkit/tools/test_shell/test_webview_delegate.h
index 0c5ef3b..16db870 100644
--- a/webkit/tools/test_shell/test_webview_delegate.h
+++ b/webkit/tools/test_shell/test_webview_delegate.h
@@ -207,7 +207,7 @@ class TestWebViewDelegate : public base::RefCounted<TestWebViewDelegate>,
WebNavigationType type,
WindowOpenDisposition disposition,
bool is_redirect);
- virtual WebHistoryItem* GetHistoryEntryAtOffset(int offset);
+ virtual void NavigateBackForwardSoon(int offset);
virtual int GetHistoryBackListCount();
virtual int GetHistoryForwardListCount();