| 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 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 // This function is used on Windows to re-layout the window on a resize. | 484 // This function is used on Windows to re-layout the window on a resize. |
| 485 // GTK manages layout for us so we do nothing. | 485 // GTK manages layout for us so we do nothing. |
| 486 } | 486 } |
| 487 | 487 |
| 488 /* static */ void TestShell::DumpAllBackForwardLists(std::wstring* result) { | 488 /* static */ void TestShell::DumpAllBackForwardLists(std::wstring* result) { |
| 489 result->clear(); | 489 result->clear(); |
| 490 for (WindowList::iterator iter = TestShell::windowList()->begin(); | 490 for (WindowList::iterator iter = TestShell::windowList()->begin(); |
| 491 iter != TestShell::windowList()->end(); iter++) { | 491 iter != TestShell::windowList()->end(); iter++) { |
| 492 GtkWindow* window = *iter; | 492 GtkWindow* window = *iter; |
| 493 TestShell* shell = | 493 TestShell* shell = |
| 494 static_cast<TestShell*>(g_object_get_data(G_OBJECT(window), "test-shell"
)); | 494 static_cast<TestShell*>(g_object_get_data(G_OBJECT(window), |
| 495 "test-shell")); |
| 495 shell->DumpBackForwardList(result); | 496 shell->DumpBackForwardList(result); |
| 496 } | 497 } |
| 497 } | 498 } |
| 498 | 499 |
| 499 /* static */ bool TestShell::RunFileTest(const TestParams& params) { | 500 /* static */ bool TestShell::RunFileTest(const TestParams& params) { |
| 500 // Load the test file into the first available window. | 501 // Load the test file into the first available window. |
| 501 if (TestShell::windowList()->empty()) { | 502 if (TestShell::windowList()->empty()) { |
| 502 LOG(ERROR) << "No windows open."; | 503 LOG(ERROR) << "No windows open."; |
| 503 return false; | 504 return false; |
| 504 } | 505 } |
| 505 | 506 |
| 506 GtkWindow* window = *(TestShell::windowList()->begin()); | 507 GtkWindow* window = *(TestShell::windowList()->begin()); |
| 507 TestShell* shell = | 508 TestShell* shell = |
| 508 static_cast<TestShell*>(g_object_get_data(G_OBJECT(window), "test-shell"))
; | 509 static_cast<TestShell*>(g_object_get_data(G_OBJECT(window), |
| 510 "test-shell")); |
| 509 | 511 |
| 510 // Clear focus between tests. | 512 // Clear focus between tests. |
| 511 shell->m_focusedWidgetHost = NULL; | 513 shell->m_focusedWidgetHost = NULL; |
| 512 | 514 |
| 513 // Make sure the previous load is stopped. | 515 // Make sure the previous load is stopped. |
| 514 shell->webView()->mainFrame()->stopLoading(); | 516 shell->webView()->mainFrame()->stopLoading(); |
| 515 shell->navigation_controller()->Reset(); | 517 shell->navigation_controller()->Reset(); |
| 516 | 518 |
| 517 // StopLoading may update state maintained in the test controller (for | 519 // StopLoading may update state maintained in the test controller (for |
| 518 // example, whether the WorkQueue is frozen) as such, we need to reset it | 520 // example, whether the WorkQueue is frozen) as such, we need to reset it |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 } else { | 565 } else { |
| 564 // only resize back to the default when running tests | 566 // only resize back to the default when running tests |
| 565 if (layout_test_mode()) | 567 if (layout_test_mode()) |
| 566 SizeToDefault(); | 568 SizeToDefault(); |
| 567 } | 569 } |
| 568 | 570 |
| 569 navigation_controller_->LoadEntry( | 571 navigation_controller_->LoadEntry( |
| 570 new TestNavigationEntry(-1, url, std::wstring(), frame_name)); | 572 new TestNavigationEntry(-1, url, std::wstring(), frame_name)); |
| 571 } | 573 } |
| 572 | 574 |
| 573 // TODO(agl): PromptForSaveFile should use FilePath | |
| 574 bool TestShell::PromptForSaveFile(const wchar_t* prompt_title, | 575 bool TestShell::PromptForSaveFile(const wchar_t* prompt_title, |
| 575 std::wstring* result) { | 576 FilePath* result) { |
| 576 GtkWidget* dialog; | 577 GtkWidget* dialog; |
| 577 dialog = gtk_file_chooser_dialog_new(WideToUTF8(prompt_title).c_str(), | 578 dialog = gtk_file_chooser_dialog_new(WideToUTF8(prompt_title).c_str(), |
| 578 GTK_WINDOW(m_mainWnd), | 579 GTK_WINDOW(m_mainWnd), |
| 579 GTK_FILE_CHOOSER_ACTION_SAVE, | 580 GTK_FILE_CHOOSER_ACTION_SAVE, |
| 580 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, | 581 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, |
| 581 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, | 582 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, |
| 582 NULL); // Terminate (button, id) pairs. | 583 NULL); // Terminate (button, id) pairs. |
| 583 gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), | 584 gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), |
| 584 TRUE); | 585 TRUE); |
| 585 int dialog_result = gtk_dialog_run(GTK_DIALOG(dialog)); | 586 int dialog_result = gtk_dialog_run(GTK_DIALOG(dialog)); |
| 586 if (dialog_result != GTK_RESPONSE_ACCEPT) { | 587 if (dialog_result != GTK_RESPONSE_ACCEPT) { |
| 587 gtk_widget_destroy(dialog); | 588 gtk_widget_destroy(dialog); |
| 588 return false; | 589 return false; |
| 589 } | 590 } |
| 590 char* path = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); | 591 char* path = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); |
| 591 gtk_widget_destroy(dialog); | 592 gtk_widget_destroy(dialog); |
| 592 *result = UTF8ToWide(path); | 593 *result = FilePath(path); |
| 593 g_free(path); | 594 g_free(path); |
| 594 return true; | 595 return true; |
| 595 } | 596 } |
| 596 | 597 |
| 597 // static | 598 // static |
| 598 std::string TestShell::RewriteLocalUrl(const std::string& url) { | 599 std::string TestShell::RewriteLocalUrl(const std::string& url) { |
| 599 // Convert file:///tmp/LayoutTests urls to the actual location on disk. | 600 // Convert file:///tmp/LayoutTests urls to the actual location on disk. |
| 600 const char kPrefix[] = "file:///tmp/LayoutTests/"; | 601 const char kPrefix[] = "file:///tmp/LayoutTests/"; |
| 601 const int kPrefixLen = arraysize(kPrefix) - 1; | 602 const int kPrefixLen = arraysize(kPrefix) - 1; |
| 602 | 603 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 break; | 654 break; |
| 654 } | 655 } |
| 655 return TestShell::NetResourceProvider(resource_id); | 656 return TestShell::NetResourceProvider(resource_id); |
| 656 } | 657 } |
| 657 | 658 |
| 658 void GetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins) { | 659 void GetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins) { |
| 659 NPAPI::PluginList::Singleton()->GetPlugins(refresh, plugins); | 660 NPAPI::PluginList::Singleton()->GetPlugins(refresh, plugins); |
| 660 } | 661 } |
| 661 | 662 |
| 662 } // namespace webkit_glue | 663 } // namespace webkit_glue |
| OLD | NEW |