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 "base/command_line.h"
6 #include "chrome/common/extensions/manifest_tests/chrome_manifest_test.h"
7 #include "chrome/common/url_constants.h"
8 #include "extensions/common/error_utils.h"
9 #include "extensions/common/extension.h"
10 #include "extensions/common/manifest.h"
11 #include "extensions/common/manifest_constants.h"
12 #include "extensions/common/permissions/permissions_data.h"
13 #include "extensions/common/switches.h"
14 #include "testing/gtest/include/gtest/gtest.h"
16 namespace extensions
{
18 namespace errors
= manifest_errors
;
20 typedef ChromeManifestTest ChromePermissionManifestTest
;
22 TEST_F(ChromePermissionManifestTest
, ChromeURLPermissionInvalid
) {
23 LoadAndExpectWarning("permission_chrome_url_invalid.json",
24 ErrorUtils::FormatErrorMessage(
25 errors::kInvalidPermissionScheme
,
26 chrome::kChromeUINewTabURL
));
29 TEST_F(ChromePermissionManifestTest
, ChromeURLPermissionAllowedWithFlag
) {
30 // Ignore the policy delegate for this test.
31 PermissionsData::SetPolicyDelegate(NULL
);
32 base::CommandLine::ForCurrentProcess()->AppendSwitch(
33 switches::kExtensionsOnChromeURLs
);
35 scoped_refptr
<Extension
> extension
=
36 LoadAndExpectSuccess("permission_chrome_url_invalid.json");
38 const GURL
newtab_url(chrome::kChromeUINewTabURL
);
39 EXPECT_TRUE(extension
->permissions_data()->CanAccessPage(
40 extension
.get(), newtab_url
, 0, -1, &error
)) << error
;
43 TEST_F(ChromePermissionManifestTest
,
44 ChromeResourcesPermissionValidOnlyForComponents
) {
45 LoadAndExpectWarning("permission_chrome_resources_url.json",
46 ErrorUtils::FormatErrorMessage(
47 errors::kInvalidPermissionScheme
,
48 "chrome://resources/"));
50 LoadExtension(ManifestData("permission_chrome_resources_url.json"),
52 extensions::Manifest::COMPONENT
,
57 } // namespace extensions