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/extension.h"
7 #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h"
8 #include "chrome/common/extensions/permissions/permissions_data.h"
9 #include "chrome/common/url_constants.h"
10 #include "extensions/common/error_utils.h"
11 #include "extensions/common/manifest.h"
12 #include "extensions/common/manifest_constants.h"
13 #include "extensions/common/switches.h"
14 #include "testing/gtest/include/gtest/gtest.h"
16 namespace extensions {
18 namespace errors = manifest_errors;
20 TEST_F(ExtensionManifestTest, ChromeURLPermissionInvalid) {
21 LoadAndExpectWarning("permission_chrome_url_invalid.json",
22 ErrorUtils::FormatErrorMessage(
23 errors::kInvalidPermissionScheme,
24 chrome::kChromeUINewTabURL));
27 TEST_F(ExtensionManifestTest, ChromeURLPermissionAllowedWithFlag) {
28 // Ignore the policy delegate for this test.
29 PermissionsData::SetPolicyDelegate(NULL);
30 CommandLine::ForCurrentProcess()->AppendSwitch(
31 switches::kExtensionsOnChromeURLs);
33 scoped_refptr<Extension> extension =
34 LoadAndExpectSuccess("permission_chrome_url_invalid.json");
36 const GURL newtab_url(chrome::kChromeUINewTabURL);
37 EXPECT_TRUE(PermissionsData::CanExecuteScriptOnPage(
38 extension.get(), newtab_url, newtab_url, 0, NULL, -1, &error)) << error;
41 TEST_F(ExtensionManifestTest, ChromeResourcesPermissionValidOnlyForComponents) {
42 LoadAndExpectWarning("permission_chrome_resources_url.json",
43 ErrorUtils::FormatErrorMessage(
44 errors::kInvalidPermissionScheme,
45 "chrome://resources/"));
47 LoadExtension(Manifest("permission_chrome_resources_url.json"),
49 extensions::Manifest::COMPONENT,
54 } // namespace extensions