diff options
author | tc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-21 19:19:16 +0000 |
---|---|---|
committer | tc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-21 19:19:16 +0000 |
commit | 989a9adc283220f30bed65f5254ef63684df3732 (patch) | |
tree | b9d1ceb54771120144ef8d150e04c01c7b3ce0f8 /webkit | |
parent | 70cbae67f090da022412d43f86684a6a026847cf (diff) | |
download | chromium_src-989a9adc283220f30bed65f5254ef63684df3732.zip chromium_src-989a9adc283220f30bed65f5254ef63684df3732.tar.gz chromium_src-989a9adc283220f30bed65f5254ef63684df3732.tar.bz2 |
Add test shell resources into the linux .pak file.
Add a new test_shell_resources.grd that is only used on linux
and add it into test_shell.pak.
Move the data pack initialization into the global init and cleanup methods.
Move the old code for loading from disk into the platform specific files.
Review URL: http://codereview.chromium.org/18385
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8378 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/tools/test_shell/SConscript | 13 | ||||
-rw-r--r-- | webkit/tools/test_shell/resources/feed.html | 1 | ||||
-rwxr-xr-x | webkit/tools/test_shell/test_shell.cc | 81 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell.h | 2 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell_gtk.cc | 54 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell_mac.mm | 67 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell_resources.grd | 16 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell_win.cc | 58 |
8 files changed, 196 insertions, 96 deletions
diff --git a/webkit/tools/test_shell/SConscript b/webkit/tools/test_shell/SConscript index 4c0d8cd1..f42160b 100644 --- a/webkit/tools/test_shell/SConscript +++ b/webkit/tools/test_shell/SConscript @@ -195,7 +195,17 @@ if env.Bit('windows'): env.Depends(test_shell, '$V8_DIR/vc80.pdb') if env.Bit('linux'): - # Build the linux resource file. + # Build the linux resource files. + import sys + sys.path.append(env.Dir('$CHROME_SRC_DIR/tools/grit').abspath) + env_grd = env.Clone() + env_grd.Tool('scons', toolpath=[env_grd.Dir('$CHROME_SRC_DIR/tools/grit/grit')]) + # This dummy target is used to tell the emitter where to put the target + # files. + generated = env_grd.GRIT( + '$TARGET_ROOT/grit_derived_sources/fake_test_shell_resources', + '$CHROME_SRC_DIR/webkit/tools/test_shell/test_shell_resources.grd') + env.Append(BUILDERS = { 'Repack' : Builder( action = 'python $CHROME_SRC_DIR/tools/data_pack/repack.py $TARGET $SOURCES', )}) @@ -203,6 +213,7 @@ if env.Bit('linux'): '$TARGET_ROOT/test_shell.pak', ['$TARGET_ROOT/grit_derived_sources/net_resources.pak', '$TARGET_ROOT/grit_derived_sources/webkit_resources.pak', + '$TARGET_ROOT/grit_derived_sources/test_shell_resources.pak', ] ) env.Depends(test_shell, test_shell_data) diff --git a/webkit/tools/test_shell/resources/feed.html b/webkit/tools/test_shell/resources/feed.html new file mode 100644 index 0000000..3d66b023 --- /dev/null +++ b/webkit/tools/test_shell/resources/feed.html @@ -0,0 +1 @@ +Feed preview for {{URL}}
\ No newline at end of file diff --git a/webkit/tools/test_shell/test_shell.cc b/webkit/tools/test_shell/test_shell.cc index ced93a5..e76b288 100755 --- a/webkit/tools/test_shell/test_shell.cc +++ b/webkit/tools/test_shell/test_shell.cc @@ -40,9 +40,6 @@ #include "SkBitmap.h" -// Generated by GRIT -#include "webkit_resources.h" - namespace { // Default timeout in ms for file page loads when in layout test mode. @@ -57,31 +54,6 @@ const int kTestWindowHeight = 600; const int kSVGTestWindowWidth = 480; const int kSVGTestWindowHeight = 360; -// Helper method for getting the path to the test shell resources directory. -FilePath GetResourcesFilePath() { - FilePath path; -#if defined(OS_MACOSX) - // we need to know if we're bundled or not to know which path to use - if (mac_util::AmIBundled()) { - PathService::Get(base::DIR_EXE, &path); - path = path.Append(FILE_PATH_LITERAL(FilePath::kParentDirectory)); - return path.Append(FILE_PATH_LITERAL("Resources")); - } else { - PathService::Get(base::DIR_SOURCE_ROOT, &path); - path = path.Append(FILE_PATH_LITERAL("webkit")); - path = path.Append(FILE_PATH_LITERAL("tools")); - path = path.Append(FILE_PATH_LITERAL("test_shell")); - return path.Append(FILE_PATH_LITERAL("resources")); - } -#else - PathService::Get(base::DIR_SOURCE_ROOT, &path); - path = path.Append(FILE_PATH_LITERAL("webkit")); - path = path.Append(FILE_PATH_LITERAL("tools")); - path = path.Append(FILE_PATH_LITERAL("test_shell")); - return path.Append(FILE_PATH_LITERAL("resources")); -#endif -} - // URLRequestTestShellFileJob is used to serve the inspector class URLRequestTestShellFileJob : public URLRequestFileJob { public: @@ -181,9 +153,7 @@ bool TestShell::CreateNewWindow(const std::wstring& startingURL, } void TestShell::ShutdownTestShell() { -#if defined(OS_WIN) || defined(OS_MACOSX) PlatformShutdown(); -#endif SimpleResourceLoaderBridge::Shutdown(); delete window_list_; delete TestShell::web_prefs_; @@ -526,57 +496,6 @@ bool GetPreferredExtensionForMimeType(const std::string& mime_type, return net::GetPreferredExtensionForMimeType(mime_type, ext); } -std::string GetDataResource(int resource_id) { - switch (resource_id) { - case IDR_BROKENIMAGE: { - // Use webkit's broken image icon (16x16) - static std::string broken_image_data; - if (broken_image_data.empty()) { - FilePath path = GetResourcesFilePath(); -#if defined(OS_WIN) || defined(OS_LINUX) - path = path.Append(FILE_PATH_LITERAL("missingImage.gif")); -#elif defined(OS_MACOSX) - // In order to match WebKit's colors for the missing image, we have to - // use a PNG. The GIF doesn't have the color range needed to correctly - // match the TIFF they use in Safari. - path = path.Append(FILE_PATH_LITERAL("missingImage.png")); -#endif - bool success = file_util::ReadFileToString(path.ToWStringHack(), - &broken_image_data); - if (!success) { - LOG(FATAL) << "Failed reading: " << path.value(); - } - } - return broken_image_data; - } - case IDR_FEED_PREVIEW: - // It is necessary to return a feed preview template that contains - // a {{URL}} substring where the feed URL should go; see the code - // that computes feed previews in feed_preview.cc:MakeFeedPreview. - // This fixes issue #932714. - return std::string("Feed preview for {{URL}}"); - case IDR_TEXTAREA_RESIZER: { - // Use webkit's text area resizer image. - static std::string resize_corner_data; - if (resize_corner_data.empty()) { - FilePath path = GetResourcesFilePath(); - path = path.Append(FILE_PATH_LITERAL("textAreaResizeCorner.png")); - bool success = file_util::ReadFileToString(path.ToWStringHack(), - &resize_corner_data); - if (!success) { - LOG(FATAL) << "Failed reading: " << path.value(); - } - } - return resize_corner_data; - } - - default: - break; - } - - return std::string(); -} - GlueBitmap GetBitmapResource(int resource_id) { return NULL; } diff --git a/webkit/tools/test_shell/test_shell.h b/webkit/tools/test_shell/test_shell.h index ce25eb9..3da7b8a 100644 --- a/webkit/tools/test_shell/test_shell.h +++ b/webkit/tools/test_shell/test_shell.h @@ -271,9 +271,7 @@ protected: static LRESULT CALLBACK EditWndProc(HWND, UINT, WPARAM, LPARAM); #endif -#if defined(OS_WIN) || defined(OS_MACOSX) static void PlatformShutdown(); -#endif protected: gfx::NativeWindow m_mainWnd; diff --git a/webkit/tools/test_shell/test_shell_gtk.cc b/webkit/tools/test_shell/test_shell_gtk.cc index aef75d4..3cac690 100644 --- a/webkit/tools/test_shell/test_shell_gtk.cc +++ b/webkit/tools/test_shell/test_shell_gtk.cc @@ -30,6 +30,9 @@ #include "webkit/tools/test_shell/test_navigation_controller.h" #include "webkit/tools/test_shell/test_webview_delegate.h" +// Generated by GRIT +#include "webkit_resources.h" +#include "test_shell_resources.h" // TODO(deanm): Needed for the localized string shim. #include "webkit_strings.h" @@ -41,6 +44,9 @@ const FcChar8* FilePathAsFcChar(const FilePath& path) { return reinterpret_cast<const FcChar8*>(path.value().c_str()); } +// Data resources on linux. This is a pointer to the mmapped resources file. +static base::DataPack* g_resource_data_pack; + } // static @@ -50,6 +56,13 @@ void TestShell::InitializeTestShell(bool layout_test_mode) { web_prefs_ = new WebPreferences; + g_resource_data_pack = new base::DataPack; + FilePath data_path; + PathService::Get(base::DIR_EXE, &data_path); + data_path = data_path.Append("test_shell.pak"); + bool success = g_resource_data_pack->Load(data_path); + CHECK(success) << "failed to load test_shell.pak"; + ResetWebPreferences(); // We wish to make the layout tests reproducable with respect to fonts. Skia @@ -142,6 +155,11 @@ void TestShell::InitializeTestShell(bool layout_test_mode) { LOG(FATAL) << "Failed to set the default font configuration"; } +void TestShell::PlatformShutdown() { + delete g_resource_data_pack; + g_resource_data_pack = NULL; +} + void TestShell::PlatformCleanUp() { // The GTK widgets will be destroyed, which will free the associated // objects. So we don't need the scoped_ptr to free the webViewHost. @@ -621,19 +639,8 @@ void TestShell::ShowStartupDebuggingDialog() { // static StringPiece TestShell::NetResourceProvider(int key) { - static scoped_ptr<base::DataPack> resource_data_pack; - - if (!resource_data_pack.get()) { - resource_data_pack.reset(new base::DataPack); - FilePath data_path; - PathService::Get(base::DIR_EXE, &data_path); - data_path = data_path.Append("test_shell.pak"); - bool success = resource_data_pack->Load(data_path); - CHECK(success) << "failed to load test_shell.pak"; - } - StringPiece res; - resource_data_pack->Get(key, &res); + g_resource_data_pack->Get(key, &res); return res; } @@ -776,6 +783,29 @@ std::wstring GetLocalizedString(int message_id) { return UTF8ToWide(str); } +std::string GetDataResource(int resource_id) { + switch (resource_id) { + case IDR_FEED_PREVIEW: + // It is necessary to return a feed preview template that contains + // a {{URL}} substring where the feed URL should go; see the code + // that computes feed previews in feed_preview.cc:MakeFeedPreview. + // This fixes issue #932714. + resource_id = IDR_FEED_PREVIEW_TESTSHELL; + break; + case IDR_BROKENIMAGE: + resource_id = IDR_BROKENIMAGE_TESTSHELL; + break; + case IDR_TEXTAREA_RESIZER: + resource_id = IDR_TEXTAREA_RESIZER_TESTSHELL; + break; + default: + NOTREACHED(); + } + StringPiece res; + g_resource_data_pack->Get(resource_id, &res); + return res.as_string(); +} + bool GetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins) { // TODO(port): Implement plugins someday. Don't let the error message // of NOTIMPLEMENTED into our layout test diffs. diff --git a/webkit/tools/test_shell/test_shell_mac.mm b/webkit/tools/test_shell/test_shell_mac.mm index 40a6fd2..4e8c22e 100644 --- a/webkit/tools/test_shell/test_shell_mac.mm +++ b/webkit/tools/test_shell/test_shell_mac.mm @@ -38,6 +38,9 @@ #include "webkit/tools/test_shell/simple_resource_loader_bridge.h" #include "webkit/tools/test_shell/test_navigation_controller.h" +// Generated by GRIT +#include "webkit_resources.h" + #import "skia/include/SkBitmap.h" #import "mac/DumpRenderTreePasteboard.h" @@ -66,6 +69,23 @@ const int kTestWindowYLocation = -14000; base::LazyInstance <std::map<gfx::NativeWindow, TestShell *> > TestShell::window_map_(base::LINKER_INITIALIZED); +// Helper method for getting the path to the test shell resources directory. +FilePath GetResourcesFilePath() { + FilePath path; + // We need to know if we're bundled or not to know which path to use. + if (mac_util::AmIBundled()) { + PathService::Get(base::DIR_EXE, &path); + path = path.Append(FILE_PATH_LITERAL(FilePath::kParentDirectory)); + return path.Append(FILE_PATH_LITERAL("Resources")); + } else { + PathService::Get(base::DIR_SOURCE_ROOT, &path); + path = path.Append(FILE_PATH_LITERAL("webkit")); + path = path.Append(FILE_PATH_LITERAL("tools")); + path = path.Append(FILE_PATH_LITERAL("test_shell")); + return path.Append(FILE_PATH_LITERAL("resources")); + } +} + // Receives notification that the window is closing so that it can start the // tear-down process. Is responsible for deleting itself when done. @interface WindowCloseDelegate : NSObject @@ -878,6 +898,53 @@ std::wstring GetLocalizedString(int message_id) { return UTF8ToWide([localString UTF8String]); } +std::string GetDataResource(int resource_id) { + switch (resource_id) { + case IDR_BROKENIMAGE: { + // Use webkit's broken image icon (16x16) + static std::string broken_image_data; + if (broken_image_data.empty()) { + FilePath path = GetResourcesFilePath(); + // In order to match WebKit's colors for the missing image, we have to + // use a PNG. The GIF doesn't have the color range needed to correctly + // match the TIFF they use in Safari. + path = path.Append(FILE_PATH_LITERAL("missingImage.png")); + bool success = file_util::ReadFileToString(path.ToWStringHack(), + &broken_image_data); + if (!success) { + LOG(FATAL) << "Failed reading: " << path.value(); + } + } + return broken_image_data; + } + case IDR_FEED_PREVIEW: + // It is necessary to return a feed preview template that contains + // a {{URL}} substring where the feed URL should go; see the code + // that computes feed previews in feed_preview.cc:MakeFeedPreview. + // This fixes issue #932714. + return std::string("Feed preview for {{URL}}"); + case IDR_TEXTAREA_RESIZER: { + // Use webkit's text area resizer image. + static std::string resize_corner_data; + if (resize_corner_data.empty()) { + FilePath path = GetResourcesFilePath(); + path = path.Append(FILE_PATH_LITERAL("textAreaResizeCorner.png")); + bool success = file_util::ReadFileToString(path.ToWStringHack(), + &resize_corner_data); + if (!success) { + LOG(FATAL) << "Failed reading: " << path.value(); + } + } + return resize_corner_data; + } + + default: + break; + } + + return std::string(); +} + NSCursor* LoadCursor(int cursor_id) { // TODO(port): add some more options here return [NSCursor arrowCursor]; diff --git a/webkit/tools/test_shell/test_shell_resources.grd b/webkit/tools/test_shell/test_shell_resources.grd new file mode 100644 index 0000000..7978b60 --- /dev/null +++ b/webkit/tools/test_shell/test_shell_resources.grd @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8"?> +<grit latest_public_release="0" current_release="1"> + <outputs> + <output filename="test_shell_resources.h" type="rc_header"> + <emit emit_type='prepend'></emit> + </output> + <output filename="test_shell_resources.pak" type="data_package" /> + </outputs> + <release seq="1"> + <includes> + <include name="IDR_BROKENIMAGE_TESTSHELL" file="resources\missingImage.gif" type="BINDATA" /> + <include name="IDR_FEED_PREVIEW_TESTSHELL" file="resources\feed.html" type="BINDATA" /> + <include name="IDR_TEXTAREA_RESIZER_TESTSHELL" file="resources\textAreaResizeCorner.png" type="BINDATA" /> + </includes> + </release> +</grit> diff --git a/webkit/tools/test_shell/test_shell_win.cc b/webkit/tools/test_shell/test_shell_win.cc index 81baf04..e217314 100644 --- a/webkit/tools/test_shell/test_shell_win.cc +++ b/webkit/tools/test_shell/test_shell_win.cc @@ -34,6 +34,9 @@ #include "webkit/tools/test_shell/test_navigation_controller.h" #include "webkit/tools/test_shell/test_shell_switches.h" +// Generated by GRIT +#include "webkit_resources.h" + #define MAX_LOADSTRING 100 #define BUTTON_WIDTH 72 @@ -112,6 +115,16 @@ bool MinidumpCallback(const wchar_t *dumpPath, return false; } +// Helper method for getting the path to the test shell resources directory. +FilePath GetResourcesFilePath() { + FilePath path; + PathService::Get(base::DIR_SOURCE_ROOT, &path); + path = path.Append(FILE_PATH_LITERAL("webkit")); + path = path.Append(FILE_PATH_LITERAL("tools")); + path = path.Append(FILE_PATH_LITERAL("test_shell")); + return path.Append(FILE_PATH_LITERAL("resources")); +} + StringPiece GetRawDataResource(HMODULE module, int resource_id) { void* data_ptr; size_t data_size; @@ -721,6 +734,51 @@ std::wstring GetLocalizedString(int message_id) { return std::wstring(image->achString, image->nLength); } +// TODO(tc): Convert this to using resources from test_shell.rc. +std::string GetDataResource(int resource_id) { + switch (resource_id) { + case IDR_BROKENIMAGE: { + // Use webkit's broken image icon (16x16) + static std::string broken_image_data; + if (broken_image_data.empty()) { + FilePath path = GetResourcesFilePath(); + path = path.Append(FILE_PATH_LITERAL("missingImage.gif")); + bool success = file_util::ReadFileToString(path.ToWStringHack(), + &broken_image_data); + if (!success) { + LOG(FATAL) << "Failed reading: " << path.value(); + } + } + return broken_image_data; + } + case IDR_FEED_PREVIEW: + // It is necessary to return a feed preview template that contains + // a {{URL}} substring where the feed URL should go; see the code + // that computes feed previews in feed_preview.cc:MakeFeedPreview. + // This fixes issue #932714. + return std::string("Feed preview for {{URL}}"); + case IDR_TEXTAREA_RESIZER: { + // Use webkit's text area resizer image. + static std::string resize_corner_data; + if (resize_corner_data.empty()) { + FilePath path = GetResourcesFilePath(); + path = path.Append(FILE_PATH_LITERAL("textAreaResizeCorner.png")); + bool success = file_util::ReadFileToString(path.ToWStringHack(), + &resize_corner_data); + if (!success) { + LOG(FATAL) << "Failed reading: " << path.value(); + } + } + return resize_corner_data; + } + + default: + break; + } + + return std::string(); +} + HCURSOR LoadCursor(int cursor_id) { return NULL; } |