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/chrome_extensions_client.h"
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 class ChromeExtensionsClientTest
: public testing::Test
{
21 void SetUp() override
{
22 extensions_client_
.reset(new ChromeExtensionsClient());
23 ExtensionsClient::Set(extensions_client_
.get());
27 scoped_ptr
<ChromeExtensionsClient
> extensions_client_
;
30 // Test that a browser action extension returns a path to an icon.
31 TEST_F(ChromeExtensionsClientTest
, GetBrowserImagePaths
) {
32 base::FilePath install_dir
;
33 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA
, &install_dir
));
34 install_dir
= install_dir
.AppendASCII("extensions")
35 .AppendASCII("api_test")
36 .AppendASCII("browser_action")
37 .AppendASCII("basics");
40 scoped_refptr
<Extension
> extension(file_util::LoadExtension(
41 install_dir
, Manifest::UNPACKED
, Extension::NO_FLAGS
, &error
));
42 ASSERT_TRUE(extension
.get());
44 // The extension contains one icon.
45 std::set
<base::FilePath
> paths
=
46 ExtensionsClient::Get()->GetBrowserImagePaths(extension
.get());
47 ASSERT_EQ(1u, paths
.size());
48 EXPECT_EQ("icon.png", paths
.begin()->BaseName().AsUTF8Unsafe());
51 // Test that extensions with zero-length action icons will not load.
52 TEST_F(ChromeExtensionsClientTest
, CheckZeroLengthActionIconFiles
) {
53 base::FilePath install_dir
;
54 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA
, &install_dir
));
56 // Try to install an extension with a zero-length browser action icon file.
57 base::FilePath ext_dir
= install_dir
.AppendASCII("extensions")
59 .AppendASCII("Extensions")
60 .AppendASCII("gggggggggggggggggggggggggggggggg");
63 scoped_refptr
<Extension
> extension2(file_util::LoadExtension(
64 ext_dir
, Manifest::UNPACKED
, Extension::NO_FLAGS
, &error
));
65 EXPECT_FALSE(extension2
.get());
66 EXPECT_STREQ("Could not load icon 'icon.png' for browser action.",
69 // Try to install an extension with a zero-length page action icon file.
70 ext_dir
= install_dir
.AppendASCII("extensions")
72 .AppendASCII("Extensions")
73 .AppendASCII("hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh");
75 scoped_refptr
<Extension
> extension3(file_util::LoadExtension(
76 ext_dir
, Manifest::UNPACKED
, Extension::NO_FLAGS
, &error
));
77 EXPECT_FALSE(extension3
.get());
78 EXPECT_STREQ("Could not load icon 'icon.png' for page action.",
82 } // namespace extensions