summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-14 19:06:30 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-14 19:06:30 +0000
commit98af9aca7168f061bfaae5cd4f4eb3f7de4e70e7 (patch)
treeb2a1eafeb6863d2ca93615034b7dab005fd2e72b
parentc70d067f569f4d927e7be8f221f856812af396d7 (diff)
downloadchromium_src-98af9aca7168f061bfaae5cd4f4eb3f7de4e70e7.zip
chromium_src-98af9aca7168f061bfaae5cd4f4eb3f7de4e70e7.tar.gz
chromium_src-98af9aca7168f061bfaae5cd4f4eb3f7de4e70e7.tar.bz2
Create a path provider for gfx, allowing the removal of the temporary app dependency.
TBR=darin BUG=none TEST=none git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41552 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--app/test_suite.h1
-rw-r--r--gfx/DEPS1
-rw-r--r--gfx/gfx.gyp4
-rw-r--r--gfx/gfx_paths.cc51
-rw-r--r--gfx/gfx_paths.h27
-rw-r--r--gfx/icon_util.cc16
-rw-r--r--gfx/icon_util_unittest.cc6
-rw-r--r--gfx/run_all_unittests.cc4
-rw-r--r--gfx/test/data/icon_util/128_X_128_icon.ico (renamed from app/test/data/icon_util/128_X_128_icon.ico)bin67646 -> 67646 bytes
-rw-r--r--gfx/test/data/icon_util/16_X_16_icon.ico (renamed from app/test/data/icon_util/16_X_16_icon.ico)bin1150 -> 1150 bytes
-rw-r--r--gfx/test_suite.h60
11 files changed, 154 insertions, 16 deletions
diff --git a/app/test_suite.h b/app/test_suite.h
index 4826b4f..061dc9c 100644
--- a/app/test_suite.h
+++ b/app/test_suite.h
@@ -31,7 +31,6 @@ class AppTestSuite : public TestSuite {
TestSuite::Initialize();
app::RegisterPathProvider();
-
#if defined(OS_MACOSX)
// Look in the framework bundle for resources.
// TODO(port): make a resource bundle for non-app exes. What's done here
diff --git a/gfx/DEPS b/gfx/DEPS
index e0624e5..568a137 100644
--- a/gfx/DEPS
+++ b/gfx/DEPS
@@ -1,5 +1,4 @@
include_rules = [
- "+app", # TEMPORARY
"+base",
"+skia",
]
diff --git a/gfx/gfx.gyp b/gfx/gfx.gyp
index e8f9272..6b88ab6 100644
--- a/gfx/gfx.gyp
+++ b/gfx/gfx.gyp
@@ -18,6 +18,7 @@
],
'sources': [
'run_all_unittests.cc',
+ 'test_suite.h',
],
'include_dirs': [
'..',
@@ -51,7 +52,8 @@
'../third_party/zlib/zlib.gyp:zlib',
],
'sources': [
- 'empty.cc',
+ 'gfx_paths.cc',
+ 'gfx_paths.h',
],
'conditions': [
['OS=="win"', {
diff --git a/gfx/gfx_paths.cc b/gfx/gfx_paths.cc
new file mode 100644
index 0000000..bcb82ab
--- /dev/null
+++ b/gfx/gfx_paths.cc
@@ -0,0 +1,51 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "gfx/gfx_paths.h"
+
+#include "base/command_line.h"
+#include "base/file_path.h"
+#include "base/file_util.h"
+#include "base/path_service.h"
+
+namespace gfx {
+
+bool PathProvider(int key, FilePath* result) {
+ // Assume that we will not need to create the directory if it does not exist.
+ // This flag can be set to true for the cases where we want to create it.
+ bool create_dir = false;
+
+ FilePath cur;
+ switch (key) {
+ // The following are only valid in the development environment, and
+ // will fail if executed from an installed executable (because the
+ // generated path won't exist).
+ case DIR_TEST_DATA:
+ if (!PathService::Get(base::DIR_SOURCE_ROOT, &cur))
+ return false;
+ cur = cur.Append(FILE_PATH_LITERAL("gfx"));
+ cur = cur.Append(FILE_PATH_LITERAL("test"));
+ cur = cur.Append(FILE_PATH_LITERAL("data"));
+ if (!file_util::PathExists(cur)) // we don't want to create this
+ return false;
+ break;
+ default:
+ return false;
+ }
+
+ if (create_dir && !file_util::PathExists(cur) &&
+ !file_util::CreateDirectory(cur))
+ return false;
+
+ *result = cur;
+ return true;
+}
+
+// This cannot be done as a static initializer sadly since Visual Studio will
+// eliminate this object file if there is no direct entry point into it.
+void RegisterPathProvider() {
+ PathService::RegisterProvider(PathProvider, PATH_START, PATH_END);
+}
+
+} // namespace gfx
diff --git a/gfx/gfx_paths.h b/gfx/gfx_paths.h
new file mode 100644
index 0000000..7da1acc
--- /dev/null
+++ b/gfx/gfx_paths.h
@@ -0,0 +1,27 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef GFX_GFX_PATHS_H_
+#define GFX_GFX_PATHS_H_
+
+// This file declares path keys for the app module. These can be used with
+// the PathService to access various special directories and files.
+
+namespace gfx {
+
+enum {
+ PATH_START = 2000,
+
+ // Valid only in development environment; TODO(darin): move these
+ DIR_TEST_DATA, // Directory where unit test data resides.
+
+ PATH_END
+};
+
+// Call once to register the provider for the path keys defined above.
+void RegisterPathProvider();
+
+} // namespace gfx
+
+#endif // GFX_GFX_PATHS_H_
diff --git a/gfx/icon_util.cc b/gfx/icon_util.cc
index 243ed17..f26ab95 100644
--- a/gfx/icon_util.cc
+++ b/gfx/icon_util.cc
@@ -4,10 +4,10 @@
#include "gfx/icon_util.h"
-#include "app/win_util.h"
#include "base/file_util.h"
#include "base/gfx/size.h"
#include "base/logging.h"
+#include "base/scoped_handle.h"
#include "base/scoped_ptr.h"
#include "skia/ext/image_operations.h"
#include "third_party/skia/include/core/SkBitmap.h"
@@ -204,13 +204,13 @@ bool IconUtil::CreateIconFileFromSkBitmap(const SkBitmap& bitmap,
}
// We start by creating the file.
- win_util::ScopedHandle icon_file(::CreateFile(icon_file_name.c_str(),
- GENERIC_WRITE,
- 0,
- NULL,
- CREATE_ALWAYS,
- FILE_ATTRIBUTE_NORMAL,
- NULL));
+ ScopedHandle icon_file(::CreateFile(icon_file_name.c_str(),
+ GENERIC_WRITE,
+ 0,
+ NULL,
+ CREATE_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL));
if (icon_file.Get() == INVALID_HANDLE_VALUE) {
return false;
diff --git a/gfx/icon_util_unittest.cc b/gfx/icon_util_unittest.cc
index 967a547..f7f9786 100644
--- a/gfx/icon_util_unittest.cc
+++ b/gfx/icon_util_unittest.cc
@@ -1,12 +1,12 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "app/app_paths.h"
#include "base/gfx/size.h"
#include "base/scoped_ptr.h"
#include "base/file_util.h"
#include "base/path_service.h"
+#include "gfx/gfx_paths.h"
#include "gfx/icon_util.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -20,7 +20,7 @@ namespace {
class IconUtilTest : public testing::Test {
public:
IconUtilTest() {
- PathService::Get(app::DIR_TEST_DATA, &test_data_directory_);
+ PathService::Get(gfx::DIR_TEST_DATA, &test_data_directory_);
}
~IconUtilTest() {}
diff --git a/gfx/run_all_unittests.cc b/gfx/run_all_unittests.cc
index f008d3e..834d7c8 100644
--- a/gfx/run_all_unittests.cc
+++ b/gfx/run_all_unittests.cc
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "base/test/test_suite.h"
+#include "gfx/test_suite.h"
int main(int argc, char** argv) {
- return TestSuite(argc, argv).Run();
+ return GfxTestSuite(argc, argv).Run();
}
diff --git a/app/test/data/icon_util/128_X_128_icon.ico b/gfx/test/data/icon_util/128_X_128_icon.ico
index a5d72fe..a5d72fe 100644
--- a/app/test/data/icon_util/128_X_128_icon.ico
+++ b/gfx/test/data/icon_util/128_X_128_icon.ico
Binary files differ
diff --git a/app/test/data/icon_util/16_X_16_icon.ico b/gfx/test/data/icon_util/16_X_16_icon.ico
index 0e524f1..0e524f1 100644
--- a/app/test/data/icon_util/16_X_16_icon.ico
+++ b/gfx/test/data/icon_util/16_X_16_icon.ico
Binary files differ
diff --git a/gfx/test_suite.h b/gfx/test_suite.h
new file mode 100644
index 0000000..3f60d21
--- /dev/null
+++ b/gfx/test_suite.h
@@ -0,0 +1,60 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef GFX_TEST_SUITE_H_
+#define GFX_TEST_SUITE_H_
+
+#include "build/build_config.h"
+
+#include <string>
+
+#include "gfx/gfx_paths.h"
+#include "base/path_service.h"
+#if defined(OS_MACOSX)
+#include "base/mac_util.h"
+#endif
+#include "base/scoped_nsautorelease_pool.h"
+#include "base/test/test_suite.h"
+
+class GfxTestSuite : public TestSuite {
+ public:
+ GfxTestSuite(int argc, char** argv) : TestSuite(argc, argv) {
+ }
+
+ protected:
+
+ virtual void Initialize() {
+ base::ScopedNSAutoreleasePool autorelease_pool;
+
+ TestSuite::Initialize();
+
+ gfx::RegisterPathProvider();
+
+#if defined(OS_MACOSX)
+ // Look in the framework bundle for resources.
+ // TODO(port): make a resource bundle for non-app exes. What's done here
+ // isn't really right because this code needs to depend on chrome_dll
+ // being built. This is inappropriate in app.
+ FilePath path;
+ PathService::Get(base::DIR_EXE, &path);
+#if defined(GOOGLE_CHROME_BUILD)
+ path = path.AppendASCII("Google Chrome Framework.framework");
+#elif defined(CHROMIUM_BUILD)
+ path = path.AppendASCII("Chromium Framework.framework");
+#else
+#error Unknown branding
+#endif
+ mac_util::SetOverrideAppBundlePath(path);
+#endif // OS_MACOSX
+ }
+
+ virtual void Shutdown() {
+#if defined(OS_MACOSX)
+ mac_util::SetOverrideAppBundle(NULL);
+#endif
+ TestSuite::Shutdown();
+ }
+};
+
+#endif // GFX_TEST_SUITE_H_