| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "webkit/tools/test_shell/test_shell.h" | 5 #include "webkit/tools/test_shell/test_shell.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <fontconfig/fontconfig.h> | 9 #include <fontconfig/fontconfig.h> |
| 10 #include <gtk/gtk.h> | 10 #include <gtk/gtk.h> |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 } | 90 } |
| 91 | 91 |
| 92 // Callback for when you click the reload button. | 92 // Callback for when you click the reload button. |
| 93 void ReloadButtonClicked(GtkButton* button, TestShell* shell) { | 93 void ReloadButtonClicked(GtkButton* button, TestShell* shell) { |
| 94 shell->Reload(); | 94 shell->Reload(); |
| 95 } | 95 } |
| 96 | 96 |
| 97 // Callback for when you press enter in the URL box. | 97 // Callback for when you press enter in the URL box. |
| 98 void URLEntryActivate(GtkEntry* entry, TestShell* shell) { | 98 void URLEntryActivate(GtkEntry* entry, TestShell* shell) { |
| 99 const gchar* url = gtk_entry_get_text(entry); | 99 const gchar* url = gtk_entry_get_text(entry); |
| 100 shell->LoadURL(UTF8ToWide(url).c_str()); | 100 shell->LoadURL(GURL(url)); |
| 101 } | 101 } |
| 102 | 102 |
| 103 // Callback for Debug > Dump body text... menu item. | 103 // Callback for Debug > Dump body text... menu item. |
| 104 gboolean DumpBodyTextActivated(GtkWidget* widget, TestShell* shell) { | 104 gboolean DumpBodyTextActivated(GtkWidget* widget, TestShell* shell) { |
| 105 shell->DumpDocumentText(); | 105 shell->DumpDocumentText(); |
| 106 return FALSE; // Don't stop this message. | 106 return FALSE; // Don't stop this message. |
| 107 } | 107 } |
| 108 | 108 |
| 109 // Callback for Debug > Dump render tree... menu item. | 109 // Callback for Debug > Dump render tree... menu item. |
| 110 gboolean DumpRenderTreeActivated(GtkWidget* widget, TestShell* shell) { | 110 gboolean DumpRenderTreeActivated(GtkWidget* widget, TestShell* shell) { |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 void TestShell::PlatformCleanUp() { | 306 void TestShell::PlatformCleanUp() { |
| 307 if (m_mainWnd) { | 307 if (m_mainWnd) { |
| 308 // Disconnect our MainWindowDestroyed handler so that we don't go through | 308 // Disconnect our MainWindowDestroyed handler so that we don't go through |
| 309 // the shutdown process more than once. | 309 // the shutdown process more than once. |
| 310 g_signal_handlers_disconnect_by_func(m_mainWnd, | 310 g_signal_handlers_disconnect_by_func(m_mainWnd, |
| 311 reinterpret_cast<gpointer>(MainWindowDestroyed), this); | 311 reinterpret_cast<gpointer>(MainWindowDestroyed), this); |
| 312 gtk_widget_destroy(GTK_WIDGET(m_mainWnd)); | 312 gtk_widget_destroy(GTK_WIDGET(m_mainWnd)); |
| 313 } | 313 } |
| 314 } | 314 } |
| 315 | 315 |
| 316 bool TestShell::Initialize(const std::wstring& startingURL) { | 316 bool TestShell::Initialize(const GURL& starting_url) { |
| 317 m_mainWnd = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); | 317 m_mainWnd = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); |
| 318 gtk_window_set_title(m_mainWnd, "Test Shell"); | 318 gtk_window_set_title(m_mainWnd, "Test Shell"); |
| 319 // Null out m_mainWnd when it is destroyed so we don't destroy it twice. | 319 // Null out m_mainWnd when it is destroyed so we don't destroy it twice. |
| 320 g_signal_connect(G_OBJECT(m_mainWnd), "destroy", | 320 g_signal_connect(G_OBJECT(m_mainWnd), "destroy", |
| 321 G_CALLBACK(gtk_widget_destroyed), &m_mainWnd); | 321 G_CALLBACK(gtk_widget_destroyed), &m_mainWnd); |
| 322 g_signal_connect(G_OBJECT(m_mainWnd), "destroy", | 322 g_signal_connect(G_OBJECT(m_mainWnd), "destroy", |
| 323 G_CALLBACK(MainWindowDestroyed), this); | 323 G_CALLBACK(MainWindowDestroyed), this); |
| 324 g_signal_connect(G_OBJECT(m_mainWnd), "focus-out-event", | 324 g_signal_connect(G_OBJECT(m_mainWnd), "focus-out-event", |
| 325 G_CALLBACK(MainWindowLostFocus), this); | 325 G_CALLBACK(MainWindowLostFocus), this); |
| 326 g_object_set_data(G_OBJECT(m_mainWnd), "test-shell", this); | 326 g_object_set_data(G_OBJECT(m_mainWnd), "test-shell", this); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 351 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), reload, -1 /* append */); | 351 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), reload, -1 /* append */); |
| 352 | 352 |
| 353 GtkToolItem* stop = gtk_tool_button_new_from_stock(GTK_STOCK_STOP); | 353 GtkToolItem* stop = gtk_tool_button_new_from_stock(GTK_STOCK_STOP); |
| 354 g_signal_connect(G_OBJECT(stop), "clicked", | 354 g_signal_connect(G_OBJECT(stop), "clicked", |
| 355 G_CALLBACK(StopButtonClicked), this); | 355 G_CALLBACK(StopButtonClicked), this); |
| 356 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), stop, -1 /* append */); | 356 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), stop, -1 /* append */); |
| 357 | 357 |
| 358 m_editWnd = gtk_entry_new(); | 358 m_editWnd = gtk_entry_new(); |
| 359 g_signal_connect(G_OBJECT(m_editWnd), "activate", | 359 g_signal_connect(G_OBJECT(m_editWnd), "activate", |
| 360 G_CALLBACK(URLEntryActivate), this); | 360 G_CALLBACK(URLEntryActivate), this); |
| 361 gtk_entry_set_text(GTK_ENTRY(m_editWnd), WideToUTF8(startingURL).c_str()); | 361 gtk_entry_set_text(GTK_ENTRY(m_editWnd), starting_url.spec().c_str()); |
| 362 | 362 |
| 363 GtkToolItem* tool_item = gtk_tool_item_new(); | 363 GtkToolItem* tool_item = gtk_tool_item_new(); |
| 364 gtk_container_add(GTK_CONTAINER(tool_item), m_editWnd); | 364 gtk_container_add(GTK_CONTAINER(tool_item), m_editWnd); |
| 365 gtk_tool_item_set_expand(tool_item, TRUE); | 365 gtk_tool_item_set_expand(tool_item, TRUE); |
| 366 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), tool_item, -1 /* append */); | 366 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), tool_item, -1 /* append */); |
| 367 | 367 |
| 368 gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0); | 368 gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0); |
| 369 m_webViewHost.reset( | 369 m_webViewHost.reset( |
| 370 WebViewHost::Create(vbox, delegate_.get(), *TestShell::web_prefs_)); | 370 WebViewHost::Create(vbox, delegate_.get(), *TestShell::web_prefs_)); |
| 371 | 371 |
| 372 gtk_container_add(GTK_CONTAINER(m_mainWnd), vbox); | 372 gtk_container_add(GTK_CONTAINER(m_mainWnd), vbox); |
| 373 gtk_widget_show_all(GTK_WIDGET(m_mainWnd)); | 373 gtk_widget_show_all(GTK_WIDGET(m_mainWnd)); |
| 374 | 374 |
| 375 // LoadURL will do a resize, so make sure we don't call LoadURL | 375 // LoadURL will do a resize, so make sure we don't call LoadURL |
| 376 // until we've completed all of our GTK setup. | 376 // until we've completed all of our GTK setup. |
| 377 if (!startingURL.empty()) | 377 if (starting_url.is_valid()) |
| 378 LoadURL(startingURL.c_str()); | 378 LoadURL(starting_url); |
| 379 | 379 |
| 380 bool bIsSVGTest = startingURL.find(L"W3C-SVG-1.1") != std::wstring::npos; | 380 if (IsSVGTestURL(starting_url)) |
| 381 if (bIsSVGTest) | |
| 382 SizeToSVG(); | 381 SizeToSVG(); |
| 383 else | 382 else |
| 384 SizeToDefault(); | 383 SizeToDefault(); |
| 385 | 384 |
| 386 return true; | 385 return true; |
| 387 } | 386 } |
| 388 | 387 |
| 389 void TestShell::TestFinished() { | 388 void TestShell::TestFinished() { |
| 390 if(!test_is_pending_) | 389 if(!test_is_pending_) |
| 391 return; | 390 return; |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 | 546 |
| 548 shell->ResizeSubViews(); | 547 shell->ResizeSubViews(); |
| 549 | 548 |
| 550 if (strstr(params.test_url.c_str(), "loading/") || | 549 if (strstr(params.test_url.c_str(), "loading/") || |
| 551 strstr(params.test_url.c_str(), "loading\\")) | 550 strstr(params.test_url.c_str(), "loading\\")) |
| 552 shell->layout_test_controller()->SetShouldDumpFrameLoadCallbacks(true); | 551 shell->layout_test_controller()->SetShouldDumpFrameLoadCallbacks(true); |
| 553 | 552 |
| 554 shell->test_is_preparing_ = true; | 553 shell->test_is_preparing_ = true; |
| 555 | 554 |
| 556 shell->set_test_params(¶ms); | 555 shell->set_test_params(¶ms); |
| 557 std::wstring wstr = UTF8ToWide(params.test_url.c_str()); | 556 shell->LoadURL(GURL(params.test_url)); |
| 558 shell->LoadURL(wstr.c_str()); | |
| 559 | 557 |
| 560 shell->test_is_preparing_ = false; | 558 shell->test_is_preparing_ = false; |
| 561 shell->WaitTestFinished(); | 559 shell->WaitTestFinished(); |
| 562 shell->set_test_params(NULL); | 560 shell->set_test_params(NULL); |
| 563 | 561 |
| 564 return true; | 562 return true; |
| 565 } | 563 } |
| 566 | 564 |
| 567 void TestShell::LoadURLForFrame(const wchar_t* url, | 565 void TestShell::LoadURLForFrame(const GURL& url, |
| 568 const wchar_t* frame_name) { | 566 const std::wstring& frame_name) { |
| 569 if (!url) | 567 if (!url.is_valid()) |
| 570 return; | 568 return; |
| 571 | 569 |
| 572 bool bIsSVGTest = wcsstr(url, L"W3C-SVG-1.1") > 0; | 570 if (IsSVGTestURL(url)) { |
| 573 | |
| 574 if (bIsSVGTest) | |
| 575 SizeToSVG(); | 571 SizeToSVG(); |
| 576 else { | 572 } else { |
| 577 // only resize back to the default when running tests | 573 // only resize back to the default when running tests |
| 578 if (layout_test_mode()) | 574 if (layout_test_mode()) |
| 579 SizeToDefault(); | 575 SizeToDefault(); |
| 580 } | 576 } |
| 581 | 577 |
| 582 std::wstring frame_string; | 578 navigation_controller_->LoadEntry( |
| 583 if (frame_name) | 579 new TestNavigationEntry(-1, url, std::wstring(), frame_name)); |
| 584 frame_string = frame_name; | |
| 585 | |
| 586 std::wstring path(url); | |
| 587 GURL gurl; | |
| 588 // PathExists will reject any string with no leading '/' | |
| 589 // as well as empty strings. | |
| 590 if (file_util::AbsolutePath(&path)) | |
| 591 gurl = net::FilePathToFileURL(FilePath::FromWStringHack(path)); | |
| 592 else | |
| 593 gurl = GURL(WideToUTF8(url)); | |
| 594 | |
| 595 navigation_controller_->LoadEntry(new TestNavigationEntry( | |
| 596 -1, gurl, std::wstring(), frame_string)); | |
| 597 } | 580 } |
| 598 | 581 |
| 599 // TODO(agl): PromptForSaveFile should use FilePath | 582 // TODO(agl): PromptForSaveFile should use FilePath |
| 600 bool TestShell::PromptForSaveFile(const wchar_t* prompt_title, | 583 bool TestShell::PromptForSaveFile(const wchar_t* prompt_title, |
| 601 std::wstring* result) { | 584 std::wstring* result) { |
| 602 GtkWidget* dialog; | 585 GtkWidget* dialog; |
| 603 dialog = gtk_file_chooser_dialog_new(WideToUTF8(prompt_title).c_str(), | 586 dialog = gtk_file_chooser_dialog_new(WideToUTF8(prompt_title).c_str(), |
| 604 GTK_WINDOW(m_mainWnd), | 587 GTK_WINDOW(m_mainWnd), |
| 605 GTK_FILE_CHOOSER_ACTION_SAVE, | 588 GTK_FILE_CHOOSER_ACTION_SAVE, |
| 606 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, | 589 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 break; | 669 break; |
| 687 } | 670 } |
| 688 return TestShell::NetResourceProvider(resource_id); | 671 return TestShell::NetResourceProvider(resource_id); |
| 689 } | 672 } |
| 690 | 673 |
| 691 void GetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins) { | 674 void GetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins) { |
| 692 NPAPI::PluginList::Singleton()->GetPlugins(refresh, plugins); | 675 NPAPI::PluginList::Singleton()->GetPlugins(refresh, plugins); |
| 693 } | 676 } |
| 694 | 677 |
| 695 } // namespace webkit_glue | 678 } // namespace webkit_glue |
| OLD | NEW |