Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(474)

Side by Side Diff: webkit/tools/test_shell/test_shell_mac.mm

Issue 12163003: Add FilePath to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/tools/test_shell/test_shell_gtk.cc ('k') | webkit/tools/test_shell/test_shell_main.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <ApplicationServices/ApplicationServices.h> 5 #include <ApplicationServices/ApplicationServices.h>
6 #import <Cocoa/Cocoa.h> 6 #import <Cocoa/Cocoa.h>
7 #import <objc/objc-runtime.h> 7 #import <objc/objc-runtime.h>
8 #include <sys/stat.h> 8 #include <sys/stat.h>
9 9
10 #include "webkit/tools/test_shell/test_shell.h" 10 #include "webkit/tools/test_shell/test_shell.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 const int kTestWindowYLocation = -14000; 71 const int kTestWindowYLocation = -14000;
72 72
73 // Data pack resource. This is a pointer to the mmapped resources file. 73 // Data pack resource. This is a pointer to the mmapped resources file.
74 static ui::DataPack* g_resource_data_pack = NULL; 74 static ui::DataPack* g_resource_data_pack = NULL;
75 75
76 // Define static member variables 76 // Define static member variables
77 base::LazyInstance <std::map<gfx::NativeWindow, TestShell *> > 77 base::LazyInstance <std::map<gfx::NativeWindow, TestShell *> >
78 TestShell::window_map_ = LAZY_INSTANCE_INITIALIZER; 78 TestShell::window_map_ = LAZY_INSTANCE_INITIALIZER;
79 79
80 // Helper method for getting the path to the test shell resources directory. 80 // Helper method for getting the path to the test shell resources directory.
81 FilePath GetResourcesFilePath() { 81 base::FilePath GetResourcesFilePath() {
82 FilePath path; 82 base::FilePath path;
83 // We need to know if we're bundled or not to know which path to use. 83 // We need to know if we're bundled or not to know which path to use.
84 if (base::mac::AmIBundled()) { 84 if (base::mac::AmIBundled()) {
85 PathService::Get(base::DIR_EXE, &path); 85 PathService::Get(base::DIR_EXE, &path);
86 path = path.Append(FilePath::kParentDirectory); 86 path = path.Append(base::FilePath::kParentDirectory);
87 return path.AppendASCII("Resources"); 87 return path.AppendASCII("Resources");
88 } else { 88 } else {
89 PathService::Get(base::DIR_SOURCE_ROOT, &path); 89 PathService::Get(base::DIR_SOURCE_ROOT, &path);
90 path = path.AppendASCII("webkit"); 90 path = path.AppendASCII("webkit");
91 path = path.AppendASCII("tools"); 91 path = path.AppendASCII("tools");
92 path = path.AppendASCII("test_shell"); 92 path = path.AppendASCII("test_shell");
93 return path.AppendASCII("resources"); 93 return path.AppendASCII("resources");
94 } 94 }
95 } 95 }
96 96
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 208
209 web_prefs_ = new webkit_glue::WebPreferences; 209 web_prefs_ = new webkit_glue::WebPreferences;
210 210
211 // mmap the data pack which holds strings used by WebCore. This is only 211 // mmap the data pack which holds strings used by WebCore. This is only
212 // a fatal error if we're bundled, which means we might be running layout 212 // a fatal error if we're bundled, which means we might be running layout
213 // tests. This is a harmless failure for test_shell_tests. 213 // tests. This is a harmless failure for test_shell_tests.
214 g_resource_data_pack = new ui::DataPack(ui::SCALE_FACTOR_100P); 214 g_resource_data_pack = new ui::DataPack(ui::SCALE_FACTOR_100P);
215 NSString *resource_path = 215 NSString *resource_path =
216 [base::mac::FrameworkBundle() pathForResource:@"test_shell" 216 [base::mac::FrameworkBundle() pathForResource:@"test_shell"
217 ofType:@"pak"]; 217 ofType:@"pak"];
218 FilePath resources_pak_path([resource_path fileSystemRepresentation]); 218 base::FilePath resources_pak_path([resource_path fileSystemRepresentation]);
219 if (!g_resource_data_pack->LoadFromPath(resources_pak_path)) { 219 if (!g_resource_data_pack->LoadFromPath(resources_pak_path)) {
220 LOG(FATAL) << "failed to load test_shell.pak"; 220 LOG(FATAL) << "failed to load test_shell.pak";
221 } 221 }
222 222
223 ResetWebPreferences(); 223 ResetWebPreferences();
224 224
225 // Load the Ahem font, which is used by layout tests. 225 // Load the Ahem font, which is used by layout tests.
226 NSString* ahem_path = [[base::mac::FrameworkBundle() resourcePath] 226 NSString* ahem_path = [[base::mac::FrameworkBundle() resourcePath]
227 stringByAppendingPathComponent:@"AHEM____.TTF"]; 227 stringByAppendingPathComponent:@"AHEM____.TTF"];
228 NSURL* ahem_path_url = [NSURL fileURLWithPath:ahem_path]; 228 NSURL* ahem_path_url = [NSURL fileURLWithPath:ahem_path];
229 CFErrorRef error; 229 CFErrorRef error;
230 if (!CTFontManagerRegisterFontsForURL((CFURLRef)ahem_path_url, 230 if (!CTFontManagerRegisterFontsForURL((CFURLRef)ahem_path_url,
231 kCTFontManagerScopeProcess, &error)) { 231 kCTFontManagerScopeProcess, &error)) {
232 DLOG(FATAL) << "CTFontManagerRegisterFontsForURL " 232 DLOG(FATAL) << "CTFontManagerRegisterFontsForURL "
233 << [ahem_path fileSystemRepresentation] 233 << [ahem_path fileSystemRepresentation]
234 << [[(NSError*)error description] UTF8String]; 234 << [[(NSError*)error description] UTF8String];
235 } 235 }
236 236
237 // Add <app bundle's parent dir>/plugins to the plugin path so we can load 237 // Add <app bundle's parent dir>/plugins to the plugin path so we can load
238 // test plugins. 238 // test plugins.
239 FilePath plugins_dir; 239 base::FilePath plugins_dir;
240 PathService::Get(base::DIR_EXE, &plugins_dir); 240 PathService::Get(base::DIR_EXE, &plugins_dir);
241 if (base::mac::AmIBundled()) { 241 if (base::mac::AmIBundled()) {
242 plugins_dir = plugins_dir.AppendASCII("../../../plugins"); 242 plugins_dir = plugins_dir.AppendASCII("../../../plugins");
243 } else { 243 } else {
244 plugins_dir = plugins_dir.AppendASCII("plugins"); 244 plugins_dir = plugins_dir.AppendASCII("plugins");
245 } 245 }
246 webkit::npapi::PluginList::Singleton()->AddExtraPluginDir(plugins_dir); 246 webkit::npapi::PluginList::Singleton()->AddExtraPluginDir(plugins_dir);
247 } 247 }
248 248
249 NSButton* MakeTestButton(NSRect* rect, NSString* title, NSView* parent) { 249 NSButton* MakeTestButton(NSRect* rect, NSString* title, NSView* parent) {
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 // only resize back to the default when running tests 532 // only resize back to the default when running tests
533 if (layout_test_mode()) 533 if (layout_test_mode())
534 SizeToDefault(); 534 SizeToDefault();
535 } 535 }
536 536
537 navigation_controller_->LoadEntry( 537 navigation_controller_->LoadEntry(
538 new TestNavigationEntry(-1, url, frame_name)); 538 new TestNavigationEntry(-1, url, frame_name));
539 } 539 }
540 540
541 bool TestShell::PromptForSaveFile(const wchar_t* prompt_title, 541 bool TestShell::PromptForSaveFile(const wchar_t* prompt_title,
542 FilePath* result) 542 base::FilePath* result)
543 { 543 {
544 NSSavePanel* save_panel = [NSSavePanel savePanel]; 544 NSSavePanel* save_panel = [NSSavePanel savePanel];
545 545
546 /* set up new attributes */ 546 /* set up new attributes */
547 [save_panel setAllowedFileTypes:@[@"txt"]]; 547 [save_panel setAllowedFileTypes:@[@"txt"]];
548 [save_panel setMessage: 548 [save_panel setMessage:
549 [NSString stringWithUTF8String:WideToUTF8(prompt_title).c_str()]]; 549 [NSString stringWithUTF8String:WideToUTF8(prompt_title).c_str()]];
550 550
551 /* display the NSSavePanel */ 551 /* display the NSSavePanel */
552 [save_panel setDirectoryURL:[NSURL fileURLWithPath:NSHomeDirectory()]]; 552 [save_panel setDirectoryURL:[NSURL fileURLWithPath:NSHomeDirectory()]];
553 [save_panel setNameFieldStringValue:@""]; 553 [save_panel setNameFieldStringValue:@""];
554 if ([save_panel runModal] == NSFileHandlingPanelOKButton) { 554 if ([save_panel runModal] == NSFileHandlingPanelOKButton) {
555 *result = FilePath([[[save_panel URL] path] fileSystemRepresentation]); 555 *result = base::FilePath([[[save_panel URL] path] fileSystemRepresentation]) ;
556 return true; 556 return true;
557 } 557 }
558 return false; 558 return false;
559 } 559 }
560 560
561 // static 561 // static
562 std::string TestShell::RewriteLocalUrl(const std::string& url) { 562 std::string TestShell::RewriteLocalUrl(const std::string& url) {
563 // Convert file:///tmp/LayoutTests urls to the actual location on disk. 563 // Convert file:///tmp/LayoutTests urls to the actual location on disk.
564 const char kPrefix[] = "file:///tmp/LayoutTests/"; 564 const char kPrefix[] = "file:///tmp/LayoutTests/";
565 const int kPrefixLen = arraysize(kPrefix) - 1; 565 const int kPrefixLen = arraysize(kPrefix) - 1;
566 566
567 std::string new_url(url); 567 std::string new_url(url);
568 if (url.compare(0, kPrefixLen, kPrefix, kPrefixLen) == 0) { 568 if (url.compare(0, kPrefixLen, kPrefix, kPrefixLen) == 0) {
569 FilePath replace_path; 569 base::FilePath replace_path;
570 PathService::Get(base::DIR_SOURCE_ROOT, &replace_path); 570 PathService::Get(base::DIR_SOURCE_ROOT, &replace_path);
571 replace_path = replace_path.Append( 571 replace_path = replace_path.Append(
572 "third_party/WebKit/LayoutTests/"); 572 "third_party/WebKit/LayoutTests/");
573 new_url = std::string("file://") + replace_path.value() + 573 new_url = std::string("file://") + replace_path.value() +
574 url.substr(kPrefixLen); 574 url.substr(kPrefixLen);
575 } 575 }
576 576
577 return new_url; 577 return new_url;
578 } 578 }
579 579
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 } 621 }
622 622
623 base::StringPiece TestShellWebKitInit::GetDataResource( 623 base::StringPiece TestShellWebKitInit::GetDataResource(
624 int resource_id, 624 int resource_id,
625 ui::ScaleFactor scale_factor) { 625 ui::ScaleFactor scale_factor) {
626 switch (resource_id) { 626 switch (resource_id) {
627 case IDR_BROKENIMAGE: { 627 case IDR_BROKENIMAGE: {
628 // Use webkit's broken image icon (16x16) 628 // Use webkit's broken image icon (16x16)
629 static std::string broken_image_data; 629 static std::string broken_image_data;
630 if (broken_image_data.empty()) { 630 if (broken_image_data.empty()) {
631 FilePath path = GetResourcesFilePath(); 631 base::FilePath path = GetResourcesFilePath();
632 // In order to match WebKit's colors for the missing image, we have to 632 // In order to match WebKit's colors for the missing image, we have to
633 // use a PNG. The GIF doesn't have the color range needed to correctly 633 // use a PNG. The GIF doesn't have the color range needed to correctly
634 // match the TIFF they use in Safari. 634 // match the TIFF they use in Safari.
635 path = path.AppendASCII("missingImage.png"); 635 path = path.AppendASCII("missingImage.png");
636 bool success = file_util::ReadFileToString(path, &broken_image_data); 636 bool success = file_util::ReadFileToString(path, &broken_image_data);
637 if (!success) { 637 if (!success) {
638 LOG(FATAL) << "Failed reading: " << path.value(); 638 LOG(FATAL) << "Failed reading: " << path.value();
639 } 639 }
640 } 640 }
641 return broken_image_data; 641 return broken_image_data;
642 } 642 }
643 case IDR_TEXTAREA_RESIZER: { 643 case IDR_TEXTAREA_RESIZER: {
644 // Use webkit's text area resizer image. 644 // Use webkit's text area resizer image.
645 static std::string resize_corner_data; 645 static std::string resize_corner_data;
646 if (resize_corner_data.empty()) { 646 if (resize_corner_data.empty()) {
647 FilePath path = GetResourcesFilePath(); 647 base::FilePath path = GetResourcesFilePath();
648 path = path.AppendASCII("textAreaResizeCorner.png"); 648 path = path.AppendASCII("textAreaResizeCorner.png");
649 bool success = file_util::ReadFileToString(path, &resize_corner_data); 649 bool success = file_util::ReadFileToString(path, &resize_corner_data);
650 if (!success) { 650 if (!success) {
651 LOG(FATAL) << "Failed reading: " << path.value(); 651 LOG(FATAL) << "Failed reading: " << path.value();
652 } 652 }
653 } 653 }
654 return resize_corner_data; 654 return resize_corner_data;
655 } 655 }
656 656
657 case IDR_SEARCH_CANCEL: 657 case IDR_SEARCH_CANCEL:
(...skipping 27 matching lines...) Expand all
685 return false; 685 return false;
686 } 686 }
687 687
688 void DidLoadPlugin(const std::string& filename) { 688 void DidLoadPlugin(const std::string& filename) {
689 } 689 }
690 690
691 void DidUnloadPlugin(const std::string& filename) { 691 void DidUnloadPlugin(const std::string& filename) {
692 } 692 }
693 693
694 } // namespace webkit_glue 694 } // namespace webkit_glue
OLDNEW
« no previous file with comments | « webkit/tools/test_shell/test_shell_gtk.cc ('k') | webkit/tools/test_shell/test_shell_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698