| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 23 matching lines...) Expand all Loading... |
| 34 #include "webkit/plugins/npapi/plugin_list.h" | 34 #include "webkit/plugins/npapi/plugin_list.h" |
| 35 #include "webkit/tools/test_shell/test_navigation_controller.h" | 35 #include "webkit/tools/test_shell/test_navigation_controller.h" |
| 36 #include "webkit/tools/test_shell/test_shell_webkit_init.h" | 36 #include "webkit/tools/test_shell/test_shell_webkit_init.h" |
| 37 #include "webkit/tools/test_shell/test_webview_delegate.h" | 37 #include "webkit/tools/test_shell/test_webview_delegate.h" |
| 38 | 38 |
| 39 using WebKit::WebPoint; | 39 using WebKit::WebPoint; |
| 40 using WebKit::WebWidget; | 40 using WebKit::WebWidget; |
| 41 | 41 |
| 42 namespace { | 42 namespace { |
| 43 | 43 |
| 44 // Convert a FilePath into an FcChar* (used by fontconfig). | 44 // Convert a base::FilePath into an FcChar* (used by fontconfig). |
| 45 // The pointer only lives for the duration for the expression. | 45 // The pointer only lives for the duration for the expression. |
| 46 const FcChar8* FilePathAsFcChar(const FilePath& path) { | 46 const FcChar8* FilePathAsFcChar(const base::FilePath& path) { |
| 47 return reinterpret_cast<const FcChar8*>(path.value().c_str()); | 47 return reinterpret_cast<const FcChar8*>(path.value().c_str()); |
| 48 } | 48 } |
| 49 | 49 |
| 50 void TerminationSignalHandler(int signatl) { | 50 void TerminationSignalHandler(int signatl) { |
| 51 TestShell::ShutdownTestShell(); | 51 TestShell::ShutdownTestShell(); |
| 52 exit(0); | 52 exit(0); |
| 53 } | 53 } |
| 54 | 54 |
| 55 // GTK callbacks ------------------------------------------------------ | 55 // GTK callbacks ------------------------------------------------------ |
| 56 | 56 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 | 152 |
| 153 // static | 153 // static |
| 154 void TestShell::InitializeTestShell(bool layout_test_mode, | 154 void TestShell::InitializeTestShell(bool layout_test_mode, |
| 155 bool allow_external_pages) { | 155 bool allow_external_pages) { |
| 156 window_list_ = new WindowList; | 156 window_list_ = new WindowList; |
| 157 layout_test_mode_ = layout_test_mode; | 157 layout_test_mode_ = layout_test_mode; |
| 158 allow_external_pages_ = allow_external_pages; | 158 allow_external_pages_ = allow_external_pages; |
| 159 | 159 |
| 160 web_prefs_ = new webkit_glue::WebPreferences; | 160 web_prefs_ = new webkit_glue::WebPreferences; |
| 161 | 161 |
| 162 FilePath data_path; | 162 base::FilePath data_path; |
| 163 PathService::Get(base::DIR_EXE, &data_path); | 163 PathService::Get(base::DIR_EXE, &data_path); |
| 164 data_path = data_path.Append("test_shell.pak"); | 164 data_path = data_path.Append("test_shell.pak"); |
| 165 ResourceBundle::InitSharedInstanceWithPakPath(data_path); | 165 ResourceBundle::InitSharedInstanceWithPakPath(data_path); |
| 166 | 166 |
| 167 FilePath resources_dir; | 167 base::FilePath resources_dir; |
| 168 PathService::Get(base::DIR_SOURCE_ROOT, &resources_dir); | 168 PathService::Get(base::DIR_SOURCE_ROOT, &resources_dir); |
| 169 resources_dir = resources_dir.Append("webkit/tools/test_shell/resources"); | 169 resources_dir = resources_dir.Append("webkit/tools/test_shell/resources"); |
| 170 | 170 |
| 171 ResetWebPreferences(); | 171 ResetWebPreferences(); |
| 172 | 172 |
| 173 // We wish to make the layout tests reproducable with respect to fonts. Skia | 173 // We wish to make the layout tests reproducable with respect to fonts. Skia |
| 174 // uses fontconfig to resolve font family names from WebKit into actual font | 174 // uses fontconfig to resolve font family names from WebKit into actual font |
| 175 // files found on the current system. This means that fonts vary based on the | 175 // files found on the current system. This means that fonts vary based on the |
| 176 // system and also on the fontconfig configuration. | 176 // system and also on the fontconfig configuration. |
| 177 // | 177 // |
| 178 // To avoid this we initialise fontconfig here and install a configuration | 178 // To avoid this we initialise fontconfig here and install a configuration |
| 179 // which only knows about a few, select, fonts. | 179 // which only knows about a few, select, fonts. |
| 180 | 180 |
| 181 // We have fontconfig parse a config file from our resources file. This | 181 // We have fontconfig parse a config file from our resources file. This |
| 182 // sets a number of aliases ("sans"->"Arial" etc), but doesn't include any | 182 // sets a number of aliases ("sans"->"Arial" etc), but doesn't include any |
| 183 // font directories. | 183 // font directories. |
| 184 if (layout_test_mode) { | 184 if (layout_test_mode) { |
| 185 FcInit(); | 185 FcInit(); |
| 186 | 186 |
| 187 FcConfig* fontcfg = FcConfigCreate(); | 187 FcConfig* fontcfg = FcConfigCreate(); |
| 188 FilePath fontconfig_path = resources_dir.Append("fonts.conf"); | 188 base::FilePath fontconfig_path = resources_dir.Append("fonts.conf"); |
| 189 if (!FcConfigParseAndLoad(fontcfg, FilePathAsFcChar(fontconfig_path), | 189 if (!FcConfigParseAndLoad(fontcfg, FilePathAsFcChar(fontconfig_path), |
| 190 true)) { | 190 true)) { |
| 191 LOG(FATAL) << "Failed to parse fontconfig config file"; | 191 LOG(FATAL) << "Failed to parse fontconfig config file"; |
| 192 } | 192 } |
| 193 | 193 |
| 194 // This is the list of fonts that fontconfig will know about. It | 194 // This is the list of fonts that fontconfig will know about. It |
| 195 // will try its best to match based only on the fonts here in. The | 195 // will try its best to match based only on the fonts here in. The |
| 196 // paths are where these fonts are found on our Ubuntu boxes. | 196 // paths are where these fonts are found on our Ubuntu boxes. |
| 197 static const char *const fonts[] = { | 197 static const char *const fonts[] = { |
| 198 "/usr/share/fonts/truetype/kochi/kochi-gothic.ttf", | 198 "/usr/share/fonts/truetype/kochi/kochi-gothic.ttf", |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 << "Without this, some layout tests will fail. " | 256 << "Without this, some layout tests will fail. " |
| 257 << "See http://code.google.com/p/chromium/wiki/" | 257 << "See http://code.google.com/p/chromium/wiki/" |
| 258 << "LinuxBuildInstructionsPrerequisites for more."; | 258 << "LinuxBuildInstructionsPrerequisites for more."; |
| 259 } else { | 259 } else { |
| 260 if (!FcConfigAppFontAddFile(fontcfg, (FcChar8 *) font)) | 260 if (!FcConfigAppFontAddFile(fontcfg, (FcChar8 *) font)) |
| 261 LOG(FATAL) << "Failed to load font " << font; | 261 LOG(FATAL) << "Failed to load font " << font; |
| 262 } | 262 } |
| 263 } | 263 } |
| 264 | 264 |
| 265 // Also load the layout-test-specific "Ahem" font. | 265 // Also load the layout-test-specific "Ahem" font. |
| 266 FilePath ahem_path = resources_dir.Append("AHEM____.TTF"); | 266 base::FilePath ahem_path = resources_dir.Append("AHEM____.TTF"); |
| 267 if (!FcConfigAppFontAddFile(fontcfg, FilePathAsFcChar(ahem_path))) { | 267 if (!FcConfigAppFontAddFile(fontcfg, FilePathAsFcChar(ahem_path))) { |
| 268 LOG(FATAL) << "Failed to load font " << ahem_path.value().c_str(); | 268 LOG(FATAL) << "Failed to load font " << ahem_path.value().c_str(); |
| 269 } | 269 } |
| 270 | 270 |
| 271 if (!FcConfigSetCurrent(fontcfg)) | 271 if (!FcConfigSetCurrent(fontcfg)) |
| 272 LOG(FATAL) << "Failed to set the default font configuration"; | 272 LOG(FATAL) << "Failed to set the default font configuration"; |
| 273 } | 273 } |
| 274 | 274 |
| 275 // Install an signal handler so we clean up after ourselves. | 275 // Install an signal handler so we clean up after ourselves. |
| 276 signal(SIGINT, TerminationSignalHandler); | 276 signal(SIGINT, TerminationSignalHandler); |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 // only resize back to the default when running tests | 501 // only resize back to the default when running tests |
| 502 if (layout_test_mode()) | 502 if (layout_test_mode()) |
| 503 SizeToDefault(); | 503 SizeToDefault(); |
| 504 } | 504 } |
| 505 | 505 |
| 506 navigation_controller_->LoadEntry( | 506 navigation_controller_->LoadEntry( |
| 507 new TestNavigationEntry(-1, url, frame_name)); | 507 new TestNavigationEntry(-1, url, frame_name)); |
| 508 } | 508 } |
| 509 | 509 |
| 510 bool TestShell::PromptForSaveFile(const wchar_t* prompt_title, | 510 bool TestShell::PromptForSaveFile(const wchar_t* prompt_title, |
| 511 FilePath* result) { | 511 base::FilePath* result) { |
| 512 GtkWidget* dialog; | 512 GtkWidget* dialog; |
| 513 dialog = gtk_file_chooser_dialog_new(WideToUTF8(prompt_title).c_str(), | 513 dialog = gtk_file_chooser_dialog_new(WideToUTF8(prompt_title).c_str(), |
| 514 GTK_WINDOW(m_mainWnd), | 514 GTK_WINDOW(m_mainWnd), |
| 515 GTK_FILE_CHOOSER_ACTION_SAVE, | 515 GTK_FILE_CHOOSER_ACTION_SAVE, |
| 516 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, | 516 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, |
| 517 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, | 517 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, |
| 518 NULL); // Terminate (button, id) pairs. | 518 NULL); // Terminate (button, id) pairs. |
| 519 gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), | 519 gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), |
| 520 TRUE); | 520 TRUE); |
| 521 int dialog_result = gtk_dialog_run(GTK_DIALOG(dialog)); | 521 int dialog_result = gtk_dialog_run(GTK_DIALOG(dialog)); |
| 522 if (dialog_result != GTK_RESPONSE_ACCEPT) { | 522 if (dialog_result != GTK_RESPONSE_ACCEPT) { |
| 523 gtk_widget_destroy(dialog); | 523 gtk_widget_destroy(dialog); |
| 524 return false; | 524 return false; |
| 525 } | 525 } |
| 526 char* path = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); | 526 char* path = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); |
| 527 gtk_widget_destroy(dialog); | 527 gtk_widget_destroy(dialog); |
| 528 *result = FilePath(path); | 528 *result = base::FilePath(path); |
| 529 g_free(path); | 529 g_free(path); |
| 530 return true; | 530 return true; |
| 531 } | 531 } |
| 532 | 532 |
| 533 // static | 533 // static |
| 534 std::string TestShell::RewriteLocalUrl(const std::string& url) { | 534 std::string TestShell::RewriteLocalUrl(const std::string& url) { |
| 535 // Convert file:///tmp/LayoutTests urls to the actual location on disk. | 535 // Convert file:///tmp/LayoutTests urls to the actual location on disk. |
| 536 const char kPrefix[] = "file:///tmp/LayoutTests/"; | 536 const char kPrefix[] = "file:///tmp/LayoutTests/"; |
| 537 const int kPrefixLen = arraysize(kPrefix) - 1; | 537 const int kPrefixLen = arraysize(kPrefix) - 1; |
| 538 | 538 |
| 539 std::string new_url(url); | 539 std::string new_url(url); |
| 540 if (url.compare(0, kPrefixLen, kPrefix, kPrefixLen) == 0) { | 540 if (url.compare(0, kPrefixLen, kPrefix, kPrefixLen) == 0) { |
| 541 FilePath replace_path; | 541 base::FilePath replace_path; |
| 542 PathService::Get(base::DIR_SOURCE_ROOT, &replace_path); | 542 PathService::Get(base::DIR_SOURCE_ROOT, &replace_path); |
| 543 replace_path = replace_path.Append( | 543 replace_path = replace_path.Append( |
| 544 "third_party/WebKit/LayoutTests/"); | 544 "third_party/WebKit/LayoutTests/"); |
| 545 new_url = std::string("file://") + replace_path.value() + | 545 new_url = std::string("file://") + replace_path.value() + |
| 546 url.substr(kPrefixLen); | 546 url.substr(kPrefixLen); |
| 547 } | 547 } |
| 548 | 548 |
| 549 return new_url; | 549 return new_url; |
| 550 } | 550 } |
| 551 | 551 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 576 case IDR_BROKENIMAGE: | 576 case IDR_BROKENIMAGE: |
| 577 resource_id = IDR_BROKENIMAGE_TESTSHELL; | 577 resource_id = IDR_BROKENIMAGE_TESTSHELL; |
| 578 break; | 578 break; |
| 579 case IDR_TEXTAREA_RESIZER: | 579 case IDR_TEXTAREA_RESIZER: |
| 580 resource_id = IDR_TEXTAREA_RESIZER_TESTSHELL; | 580 resource_id = IDR_TEXTAREA_RESIZER_TESTSHELL; |
| 581 break; | 581 break; |
| 582 } | 582 } |
| 583 // TODO(flackr): Pass scale_factor. | 583 // TODO(flackr): Pass scale_factor. |
| 584 return TestShell::ResourceProvider(resource_id); | 584 return TestShell::ResourceProvider(resource_id); |
| 585 } | 585 } |
| OLD | NEW |