summaryrefslogtreecommitdiffstats
path: root/webkit/tools/test_shell
diff options
context:
space:
mode:
authorkuchhal@chromium.org <kuchhal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-16 19:30:42 +0000
committerkuchhal@chromium.org <kuchhal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-16 19:30:42 +0000
commit9be0aff3b6e0d6cb7ee6e24245ba34626c913d6b (patch)
tree751d2af19919f9d731a674d3758c227cd41433e6 /webkit/tools/test_shell
parentcefd753bec867863c7902680cf4c85d28d82d0f6 (diff)
downloadchromium_src-9be0aff3b6e0d6cb7ee6e24245ba34626c913d6b.zip
chromium_src-9be0aff3b6e0d6cb7ee6e24245ba34626c913d6b.tar.gz
chromium_src-9be0aff3b6e0d6cb7ee6e24245ba34626c913d6b.tar.bz2
* Dump text/image on notifyDone.
BUG=945322 Review URL: http://codereview.chromium.org/17459 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8198 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/tools/test_shell')
-rw-r--r--webkit/tools/test_shell/mac/main.mm6
-rw-r--r--webkit/tools/test_shell/test_shell.cc79
-rw-r--r--webkit/tools/test_shell/test_shell.h26
-rw-r--r--webkit/tools/test_shell/test_shell_gtk.cc73
-rw-r--r--webkit/tools/test_shell/test_shell_mac.mm84
-rw-r--r--webkit/tools/test_shell/test_shell_main.cc7
-rwxr-xr-x[-rw-r--r--]webkit/tools/test_shell/test_shell_win.cc73
7 files changed, 139 insertions, 209 deletions
diff --git a/webkit/tools/test_shell/mac/main.mm b/webkit/tools/test_shell/mac/main.mm
index 0bb6c70..91b33f3 100644
--- a/webkit/tools/test_shell/mac/main.mm
+++ b/webkit/tools/test_shell/mac/main.mm
@@ -321,11 +321,13 @@ int main(const int argc, const char *argv[]) {
continue;
SetCurrentTestName(filenameBuffer);
- if (!TestShell::RunFileTest(filenameBuffer, params))
+ params.test_url = filenameBuffer;
+ if (!TestShell::RunFileTest(params))
break;
}
} else {
- TestShell::RunFileTest(WideToUTF8(uri).c_str(), params);
+ params.test_url = WideToUTF8(uri).c_str();
+ TestShell::RunFileTest(params);
}
} else {
main_message_loop.Run();
diff --git a/webkit/tools/test_shell/test_shell.cc b/webkit/tools/test_shell/test_shell.cc
index fac10d6..41bfd4ea 100644
--- a/webkit/tools/test_shell/test_shell.cc
+++ b/webkit/tools/test_shell/test_shell.cc
@@ -123,6 +123,7 @@ TestShell::TestShell()
#if defined(OS_WIN)
default_edit_wnd_proc_(0),
#endif
+ test_params_(NULL),
test_is_preparing_(false),
test_is_pending_(false),
is_modal_(false),
@@ -183,6 +184,71 @@ static void UnitTestAssertHandler(const std::string& str) {
}
// static
+void TestShell::Dump(TestShell* shell) {
+ const TestParams* params = NULL;
+ if ((shell == NULL) || ((params = shell->test_params()) == NULL))
+ return;
+
+ // Echo the url in the output so we know we're not getting out of sync.
+ printf("#URL:%s\n", params->test_url.c_str());
+
+ // Dump the requested representation.
+ WebFrame* webFrame = shell->webView()->GetMainFrame();
+ if (webFrame) {
+ bool should_dump_as_text =
+ shell->layout_test_controller_->ShouldDumpAsText();
+ bool dumped_anything = false;
+ if (params->dump_tree) {
+ dumped_anything = true;
+ // Text output: the test page can request different types of output
+ // which we handle here.
+ if (!should_dump_as_text) {
+ // Plain text pages should be dumped as text
+ std::wstring mime_type =
+ webFrame->GetDataSource()->GetResponseMimeType();
+ should_dump_as_text = (mime_type == L"text/plain");
+ }
+ if (should_dump_as_text) {
+ bool recursive = shell->layout_test_controller_->
+ ShouldDumpChildFramesAsText();
+ std::string data_utf8 = WideToUTF8(
+ webkit_glue::DumpFramesAsText(webFrame, recursive));
+ if (fwrite(data_utf8.c_str(), 1, data_utf8.size(), stdout) !=
+ data_utf8.size()) {
+ LOG(FATAL) << "Short write to stdout, disk full?";
+ }
+ } else {
+ printf("%s", WideToUTF8(
+ webkit_glue::DumpRenderer(webFrame)).c_str());
+
+ bool recursive = shell->layout_test_controller_->
+ ShouldDumpChildFrameScrollPositions();
+ printf("%s", WideToUTF8(
+ webkit_glue::DumpFrameScrollPosition(webFrame, recursive)).c_str());
+ }
+
+ if (shell->layout_test_controller_->ShouldDumpBackForwardList()) {
+ std::wstring bfDump;
+ DumpBackForwardList(&bfDump);
+ printf("%s", WideToUTF8(bfDump).c_str());
+ }
+ }
+
+ if (params->dump_pixels && !should_dump_as_text) {
+ // Image output: we write the image data to the file given on the
+ // command line (for the dump pixels argument), and the MD5 sum to
+ // stdout.
+ dumped_anything = true;
+ std::string md5sum = DumpImage(webFrame, params->pixel_file_name);
+ printf("#MD5:%s\n", md5sum.c_str());
+ }
+ if (dumped_anything)
+ printf("#EOF\n");
+ fflush(stdout);
+ }
+}
+
+// static
std::string TestShell::DumpImage(WebFrame* web_frame,
const std::wstring& file_name) {
scoped_ptr<skia::BitmapPlatformDevice> device;
@@ -284,19 +350,12 @@ void TestShell::SetAllowScriptsToCloseWindows() {
void TestShell::ResetWebPreferences() {
DCHECK(web_prefs_);
- // Match the settings used by Mac DumpRenderTree, with the exception of
- // fonts.
+ // Match the settings used by Mac DumpRenderTree.
if (web_prefs_) {
*web_prefs_ = WebPreferences();
-#if defined(OS_MACOSX)
- web_prefs_->serif_font_family = L"Times";
-#else
- // NOTE: case matters here, this must be 'times new roman', else some
- // layout tests fail.
- web_prefs_->serif_font_family = L"times new roman";
-#endif
- web_prefs_->standard_font_family = web_prefs_->serif_font_family;
+ web_prefs_->standard_font_family = L"Times";
web_prefs_->fixed_font_family = L"Courier";
+ web_prefs_->serif_font_family = L"Times";
web_prefs_->sans_serif_font_family = L"Helvetica";
// These two fonts are picked from the intersection of
// Win XP font list and Vista font list :
diff --git a/webkit/tools/test_shell/test_shell.h b/webkit/tools/test_shell/test_shell.h
index 79ab497..699106f 100644
--- a/webkit/tools/test_shell/test_shell.h
+++ b/webkit/tools/test_shell/test_shell.h
@@ -64,6 +64,8 @@ public:
// Filename we dump pixels to (when pixel testing is enabled).
std::wstring pixel_file_name;
+ // URL of the test.
+ std::string test_url;
};
TestShell();
@@ -194,14 +196,19 @@ public:
// window JavaScript objects so they can be accessed by layout tests.
virtual void BindJSObjectsToWindow(WebFrame* frame);
- // Runs a layout test. Loads a single file into the first available
- // window, then dumps the requested text representation to stdout.
- // Returns false if the test cannot be run because no windows are open.
- static bool RunFileTest(const char* filename, const TestParams& params);
+ // Runs a layout test. Loads a single file (specified in params.test_url)
+ // into the first available window, then dumps the requested text
+ // representation to stdout. Returns false if the test cannot be run
+ // because no windows are open.
+ static bool RunFileTest(const TestParams& params);
// Writes the back-forward list data for every open window into result.
static void DumpBackForwardList(std::wstring* result);
+ // Dumps the output from given test as text and/or image depending on
+ // the flags set.
+ static void Dump(TestShell* shell);
+
// Writes the image captured from the given web frame to the given file.
// The returned string is the ASCII-ized MD5 sum of the image.
static std::string DumpImage(WebFrame* web_frame,
@@ -244,6 +251,11 @@ public:
void set_is_modal(bool value) { is_modal_ = value; }
bool is_modal() const { return is_modal_; }
+ const TestParams* test_params() { return test_params_; }
+ void set_test_params(const TestParams* test_params) {
+ test_params_ = test_params;
+ }
+
#if defined(OS_MACOSX)
// handle cleaning up a shell given the associated window
static void DestroyAssociatedShell(gfx::NativeWindow handle);
@@ -287,8 +299,8 @@ private:
// A set of all our windows.
static WindowList* window_list_;
#if defined(OS_MACOSX)
- static base::LazyInstance<std::map<gfx::NativeWindow, TestShell *> >
- window_map_;
+ typedef std::map<gfx::NativeWindow, TestShell *> WindowMap;
+ static base::LazyInstance<WindowMap> window_map_;
#endif
#if defined(OS_WIN)
@@ -311,6 +323,8 @@ private:
scoped_refptr<TestWebViewDelegate> delegate_;
+ const TestParams* test_params_;
+
// True while a test is preparing to run
bool test_is_preparing_;
diff --git a/webkit/tools/test_shell/test_shell_gtk.cc b/webkit/tools/test_shell/test_shell_gtk.cc
index 72f2f82..b5d42eb 100644
--- a/webkit/tools/test_shell/test_shell_gtk.cc
+++ b/webkit/tools/test_shell/test_shell_gtk.cc
@@ -115,6 +115,7 @@ void TestShell::InitializeTestShell(bool layout_test_mode) {
"/usr/share/fonts/truetype/ttf-lucida/LucidaSansRegular.ttf",
"/usr/share/fonts/truetype/kochi/kochi-gothic.ttf",
"/usr/share/fonts/truetype/kochi/kochi-mincho.ttf",
+ "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf",
};
for (size_t i = 0; i < arraysize(optional_fonts); ++i) {
const char* font = optional_fonts[i];
@@ -339,6 +340,10 @@ void TestShell::TestFinished() {
return;
test_is_pending_ = false;
+ GtkWidget* window = *(TestShell::windowList()->begin());
+ TestShell* shell = static_cast<TestShell*>(g_object_get_data(G_OBJECT(window),
+ "test-shell"));
+ TestShell::Dump(shell);
MessageLoop::current()->Quit();
}
@@ -435,8 +440,7 @@ void TestShell::ResizeSubViews() {
}
}
-/* static */ bool TestShell::RunFileTest(const char *filename,
- const TestParams& params) {
+/* static */ bool TestShell::RunFileTest(const TestParams& params) {
// Load the test file into the first available window.
if (TestShell::windowList()->empty()) {
LOG(ERROR) << "No windows open.";
@@ -472,74 +476,19 @@ void TestShell::ResizeSubViews() {
shell->ResizeSubViews();
- if (strstr(filename, "loading/") || strstr(filename, "loading\\"))
+ if (strstr(params.test_url.c_str(), "loading/") ||
+ strstr(params.test_url.c_str(), "loading\\"))
shell->layout_test_controller()->SetShouldDumpFrameLoadCallbacks(true);
shell->test_is_preparing_ = true;
- const std::wstring wstr = UTF8ToWide(filename);
+ shell->set_test_params(&params);
+ std::wstring wstr = UTF8ToWide(params.test_url.c_str());
shell->LoadURL(wstr.c_str());
shell->test_is_preparing_ = false;
shell->WaitTestFinished();
-
- // Echo the url in the output so we know we're not getting out of sync.
- printf("#URL:%s\n", filename);
-
- // Dump the requested representation.
- WebFrame* webFrame = shell->webView()->GetMainFrame();
- if (webFrame) {
- bool should_dump_as_text =
- shell->layout_test_controller_->ShouldDumpAsText();
- bool dumped_anything = false;
- if (params.dump_tree) {
- dumped_anything = true;
- // Text output: the test page can request different types of output
- // which we handle here.
- if (!should_dump_as_text) {
- // Plain text pages should be dumped as text
- std::wstring mime_type = webFrame->GetDataSource()->GetResponseMimeType();
- should_dump_as_text = (mime_type == L"text/plain");
- }
- if (should_dump_as_text) {
- bool recursive = shell->layout_test_controller_->
- ShouldDumpChildFramesAsText();
- std::string data_utf8 = WideToUTF8(
- webkit_glue::DumpFramesAsText(webFrame, recursive));
- if (fwrite(data_utf8.c_str(), 1, data_utf8.size(), stdout) !=
- data_utf8.size()) {
- LOG(FATAL) << "Short write to stdout, disk full?";
- }
- } else {
- printf("%s", WideToUTF8(
- webkit_glue::DumpRenderer(webFrame)).c_str());
-
- bool recursive = shell->layout_test_controller_->
- ShouldDumpChildFrameScrollPositions();
- printf("%s", WideToUTF8(
- webkit_glue::DumpFrameScrollPosition(webFrame, recursive)).
- c_str());
- }
-
- if (shell->layout_test_controller_->ShouldDumpBackForwardList()) {
- std::wstring bfDump;
- DumpBackForwardList(&bfDump);
- printf("%s", WideToUTF8(bfDump).c_str());
- }
- }
-
- if (params.dump_pixels && !should_dump_as_text) {
- // Image output: we write the image data to the file given on the
- // command line (for the dump pixels argument), and the MD5 sum to
- // stdout.
- dumped_anything = true;
- std::string md5sum = DumpImage(webFrame, params.pixel_file_name);
- printf("#MD5:%s\n", md5sum.c_str());
- }
- if (dumped_anything)
- printf("#EOF\n");
- fflush(stdout);
- }
+ shell->set_test_params(NULL);
return true;
}
diff --git a/webkit/tools/test_shell/test_shell_mac.mm b/webkit/tools/test_shell/test_shell_mac.mm
index 47fd8a3..4e6cf75 100644
--- a/webkit/tools/test_shell/test_shell_mac.mm
+++ b/webkit/tools/test_shell/test_shell_mac.mm
@@ -110,10 +110,11 @@ void TestShell::PlatformCleanUp() {
// static
void TestShell::DestroyAssociatedShell(gfx::NativeWindow handle) {
- TestShell* shell = window_map_.Get()[handle];
- if (shell)
+ WindowMap::iterator it = window_map_.Get().find(handle);
+ if (it != window_map_.Get().end()) {
+ delete it->second;
window_map_.Get().erase(handle);
- delete shell;
+ }
}
// static
@@ -513,6 +514,10 @@ void TestShell::TestFinished() {
return; // reached when running under test_shell_tests
test_is_pending_ = false;
+ NSWindow* window = *(TestShell::windowList()->begin());
+ WindowMap::iterator it = window_map_.Get().find(window);
+ if (it != window_map_.Get().end())
+ TestShell::Dump(it->second);
MessageLoop::current()->Quit();
}
@@ -632,6 +637,7 @@ bool TestShell::CreateNewWindow(const std::wstring& startingURL,
// static
void TestShell::DestroyWindow(gfx::NativeWindow windowHandle) {
TestShell::RemoveWindowFromList(windowHandle);
+ TestShell::DestroyAssociatedShell(windowHandle);
[windowHandle close];
}
@@ -667,14 +673,13 @@ void TestShell::ResizeSubViews() {
for (WindowList::iterator iter = TestShell::windowList()->begin();
iter != TestShell::windowList()->end(); iter++) {
NSWindow* window = *iter;
- TestShell* shell = window_map_.Get()[window];
- if (shell)
- webkit_glue::DumpBackForwardList(shell->webView(), NULL, result);
+ WindowMap::iterator it = window_map_.Get().find(window);
+ if (it != window_map_.Get().end())
+ webkit_glue::DumpBackForwardList(it->second->webView(), NULL, result);
}
}
-/* static */ bool TestShell::RunFileTest(const char* filename,
- const TestParams& params) {
+/* static */ bool TestShell::RunFileTest(const TestParams& params) {
// Load the test file into the first available window.
if (TestShell::windowList()->empty()) {
LOG(ERROR) << "No windows open.";
@@ -709,71 +714,18 @@ void TestShell::ResizeSubViews() {
[shell->m_mainWnd orderOut:nil];
shell->ResizeSubViews();
- if (strstr(filename, "loading/"))
+ if (strstr(params.test_url.c_str(), "loading/"))
shell->layout_test_controller()->SetShouldDumpFrameLoadCallbacks(true);
shell->test_is_preparing_ = true;
- shell->LoadURL(UTF8ToWide(filename).c_str());
+ shell->set_test_params(&params);
+ std::wstring wstr = UTF8ToWide(params.test_url.c_str());
+ shell->LoadURL(wstr.c_str());
shell->test_is_preparing_ = false;
shell->WaitTestFinished();
-
- // Echo the url in the output so we know we're not getting out of sync.
- printf("#URL:%s\n", filename);
-
- // Dump the requested representation.
- WebFrame* webFrame = shell->webView()->GetMainFrame();
- if (webFrame) {
- bool should_dump_as_text =
- shell->layout_test_controller_->ShouldDumpAsText();
- bool dumped_anything = false;
- if (params.dump_tree) {
- dumped_anything = true;
- // Text output: the test page can request different types of output
- // which we handle here.
- if (!should_dump_as_text) {
- // Plain text pages should be dumped as text
- std::string mime_type =
- WideToUTF8(webFrame->GetDataSource()->GetResponseMimeType());
- should_dump_as_text = (mime_type == "text/plain");
- }
- if (should_dump_as_text) {
- bool recursive = shell->layout_test_controller_->
- ShouldDumpChildFramesAsText();
- printf("%s", WideToUTF8(
- webkit_glue::DumpFramesAsText(webFrame, recursive)).
- c_str());
- } else {
- printf("%s", WideToUTF8(
- webkit_glue::DumpRenderer(webFrame)).c_str());
-
- bool recursive = shell->layout_test_controller_->
- ShouldDumpChildFrameScrollPositions();
- printf("%s", WideToUTF8(
- webkit_glue::DumpFrameScrollPosition(webFrame, recursive)).
- c_str());
- }
-
- if (shell->layout_test_controller_->ShouldDumpBackForwardList()) {
- std::wstring bfDump;
- DumpBackForwardList(&bfDump);
- printf("%s", WideToUTF8(bfDump).c_str());
- }
- }
-
- if (params.dump_pixels && !should_dump_as_text) {
- // Image output: we write the image data to the file given on the
- // command line (for the dump pixels argument), and the MD5 sum to
- // stdout.
- dumped_anything = true;
- std::string md5sum = DumpImage(webFrame, params.pixel_file_name);
- printf("#MD5:%s\n", md5sum.c_str());
- }
- if (dumped_anything)
- printf("#EOF\n");
- fflush(stdout);
- }
+ shell->set_test_params(NULL);
return true;
}
diff --git a/webkit/tools/test_shell/test_shell_main.cc b/webkit/tools/test_shell/test_shell_main.cc
index b2f9830..19199e0 100644
--- a/webkit/tools/test_shell/test_shell_main.cc
+++ b/webkit/tools/test_shell/test_shell_main.cc
@@ -370,12 +370,13 @@ int main(int argc, char* argv[]) {
if (!*filenameBuffer)
continue;
-
- if (!TestShell::RunFileTest(filenameBuffer, params))
+ params.test_url = filenameBuffer;
+ if (!TestShell::RunFileTest(params))
break;
}
} else {
- TestShell::RunFileTest(WideToUTF8(uri).c_str(), params);
+ params.test_url = WideToUTF8(uri).c_str();
+ TestShell::RunFileTest(params);
}
shell->CallJSGC();
diff --git a/webkit/tools/test_shell/test_shell_win.cc b/webkit/tools/test_shell/test_shell_win.cc
index 1dec4db..72ad7f2 100644..100755
--- a/webkit/tools/test_shell/test_shell_win.cc
+++ b/webkit/tools/test_shell/test_shell_win.cc
@@ -204,8 +204,8 @@ void TestShell::DumpBackForwardList(std::wstring* result) {
}
}
-bool TestShell::RunFileTest(const char *filename, const TestParams& params) {
- SetCurrentTestName(filename);
+bool TestShell::RunFileTest(const TestParams& params) {
+ SetCurrentTestName(params.test_url.c_str());
// Load the test file into the first available window.
if (TestShell::windowList()->empty()) {
@@ -241,71 +241,19 @@ bool TestShell::RunFileTest(const char *filename, const TestParams& params) {
SWP_NOSIZE | SWP_NOZORDER);
shell->ResizeSubViews();
- if (strstr(filename, "loading/") || strstr(filename, "loading\\"))
+ if (strstr(params.test_url.c_str(), "loading/") ||
+ strstr(params.test_url.c_str(), "loading\\"))
shell->layout_test_controller()->SetShouldDumpFrameLoadCallbacks(true);
shell->test_is_preparing_ = true;
-
- std::wstring wstr = UTF8ToWide(filename);
+ shell->set_test_params(&params);
+ std::wstring wstr = UTF8ToWide(params.test_url.c_str());
shell->LoadURL(wstr.c_str());
shell->test_is_preparing_ = false;
shell->WaitTestFinished();
+ shell->set_test_params(NULL);
- // Echo the url in the output so we know we're not getting out of sync.
- printf("#URL:%s\n", filename);
-
- // Dump the requested representation.
- WebFrame* webFrame = shell->webView()->GetMainFrame();
- if (webFrame) {
- bool should_dump_as_text =
- shell->layout_test_controller_->ShouldDumpAsText();
- bool dumped_anything = false;
- if (params.dump_tree) {
- dumped_anything = true;
- // Text output: the test page can request different types of output
- // which we handle here.
- if (!should_dump_as_text) {
- // Plain text pages should be dumped as text
- std::wstring mime_type =
- webFrame->GetDataSource()->GetResponseMimeType();
- should_dump_as_text = (mime_type == L"text/plain");
- }
- if (should_dump_as_text) {
- bool recursive = shell->layout_test_controller_->
- ShouldDumpChildFramesAsText();
- std::string data_utf8 = WideToUTF8(
- webkit_glue::DumpFramesAsText(webFrame, recursive));
- fwrite(data_utf8.c_str(), 1, data_utf8.size(), stdout);
- } else {
- printf("%s", WideToUTF8(
- webkit_glue::DumpRenderer(webFrame)).c_str());
-
- bool recursive = shell->layout_test_controller_->
- ShouldDumpChildFrameScrollPositions();
- printf("%s", WideToUTF8(
- webkit_glue::DumpFrameScrollPosition(webFrame, recursive)).c_str());
- }
-
- if (shell->layout_test_controller_->ShouldDumpBackForwardList()) {
- std::wstring bfDump;
- DumpBackForwardList(&bfDump);
- printf("%s", WideToUTF8(bfDump).c_str());
- }
- }
-
- if (params.dump_pixels && !should_dump_as_text) {
- // Image output: we write the image data to the file given on the
- // command line (for the dump pixels argument), and the MD5 sum to
- // stdout.
- dumped_anything = true;
- std::string md5sum = DumpImage(webFrame, params.pixel_file_name);
- printf("#MD5:%s\n", md5sum.c_str());
- }
- if (dumped_anything)
- printf("#EOF\n");
- fflush(stdout);
- }
return true;
}
@@ -416,10 +364,15 @@ void TestShell::TestFinished() {
if (!test_is_pending_)
return; // reached when running under test_shell_tests
+ test_is_pending_ = false;
+ HWND hwnd = *(TestShell::windowList()->begin());
+ TestShell* shell =
+ static_cast<TestShell*>(win_util::GetWindowUserData(hwnd));
+ TestShell::Dump(shell);
+
UINT_PTR timer_id = reinterpret_cast<UINT_PTR>(this);
KillTimer(mainWnd(), timer_id);
- test_is_pending_ = false;
MessageLoop::current()->Quit();
}