Adding instrumentation to locate the source of jankiness
[chromium-blink-merge.git] / chrome / common / extensions / extension_file_util_unittest.cc
blob64b8bc71fe1c6d947c3f6b5351297bce5dde9bda
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
3 // found in the LICENSE file.
5 #include "chrome/common/extensions/extension_file_util.h"
7 #include <set>
8 #include <string>
10 #include "base/path_service.h"
11 #include "chrome/common/chrome_paths.h"
12 #include "extensions/common/extension.h"
13 #include "extensions/common/file_util.h"
14 #include "extensions/common/manifest.h"
15 #include "testing/gtest/include/gtest/gtest.h"
17 namespace extensions {
19 typedef testing::Test ExtensionFileUtilTest;
21 // Test that a browser action extension returns a path to an icon.
22 TEST_F(ExtensionFileUtilTest, GetBrowserImagePaths) {
23 base::FilePath install_dir;
24 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir));
25 install_dir = install_dir.AppendASCII("extensions")
26 .AppendASCII("api_test")
27 .AppendASCII("browser_action")
28 .AppendASCII("basics");
30 std::string error;
31 scoped_refptr<Extension> extension(file_util::LoadExtension(
32 install_dir, Manifest::UNPACKED, Extension::NO_FLAGS, &error));
33 ASSERT_TRUE(extension.get());
35 // The extension contains one icon.
36 std::set<base::FilePath> paths =
37 extension_file_util::GetBrowserImagePaths(extension.get());
38 ASSERT_EQ(1u, paths.size());
39 EXPECT_EQ("icon.png", paths.begin()->BaseName().AsUTF8Unsafe());
42 // Test that extensions with zero-length action icons will not load.
43 TEST_F(ExtensionFileUtilTest, CheckZeroLengthActionIconFiles) {
44 base::FilePath install_dir;
45 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir));
47 // Try to install an extension with a zero-length browser action icon file.
48 base::FilePath ext_dir = install_dir.AppendASCII("extensions")
49 .AppendASCII("bad")
50 .AppendASCII("Extensions")
51 .AppendASCII("gggggggggggggggggggggggggggggggg");
53 std::string error;
54 scoped_refptr<Extension> extension2(file_util::LoadExtension(
55 ext_dir, Manifest::UNPACKED, Extension::NO_FLAGS, &error));
56 EXPECT_FALSE(extension2.get());
57 EXPECT_STREQ("Could not load icon 'icon.png' for browser action.",
58 error.c_str());
60 // Try to install an extension with a zero-length page action icon file.
61 ext_dir = install_dir.AppendASCII("extensions")
62 .AppendASCII("bad")
63 .AppendASCII("Extensions")
64 .AppendASCII("hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh");
66 scoped_refptr<Extension> extension3(file_util::LoadExtension(
67 ext_dir, Manifest::UNPACKED, Extension::NO_FLAGS, &error));
68 EXPECT_FALSE(extension3.get());
69 EXPECT_STREQ("Could not load icon 'icon.png' for page action.",
70 error.c_str());
73 } // namespace extensions