summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions/manifest_tests/extension_manifests_chromepermission_unittest.cc
blob: c87b3c7eb17c9d95547a049a3732c0d2cd94df4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (c) 2012 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 "base/command_line.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/manifest_tests/extension_manifest_test.h"
#include "chrome/common/extensions/permissions/permissions_data.h"
#include "chrome/common/url_constants.h"
#include "extensions/common/error_utils.h"
#include "extensions/common/manifest.h"
#include "extensions/common/manifest_constants.h"
#include "extensions/common/switches.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace extensions {

namespace errors = manifest_errors;

TEST_F(ExtensionManifestTest, ChromeURLPermissionInvalid) {
  LoadAndExpectWarning("permission_chrome_url_invalid.json",
                       ErrorUtils::FormatErrorMessage(
                           errors::kInvalidPermissionScheme,
                           chrome::kChromeUINewTabURL));
}

TEST_F(ExtensionManifestTest, ChromeURLPermissionAllowedWithFlag) {
  // Ignore the policy delegate for this test.
  PermissionsData::SetPolicyDelegate(NULL);
  CommandLine::ForCurrentProcess()->AppendSwitch(
      switches::kExtensionsOnChromeURLs);
  std::string error;
  scoped_refptr<Extension> extension =
    LoadAndExpectSuccess("permission_chrome_url_invalid.json");
  EXPECT_EQ("", error);
  const GURL newtab_url(chrome::kChromeUINewTabURL);
  EXPECT_TRUE(PermissionsData::CanExecuteScriptOnPage(
      extension.get(), newtab_url, newtab_url, 0, NULL, -1, &error)) << error;
}

TEST_F(ExtensionManifestTest, ChromeResourcesPermissionValidOnlyForComponents) {
  LoadAndExpectWarning("permission_chrome_resources_url.json",
                       ErrorUtils::FormatErrorMessage(
                           errors::kInvalidPermissionScheme,
                           "chrome://resources/"));
  std::string error;
  LoadExtension(Manifest("permission_chrome_resources_url.json"),
                &error,
                extensions::Manifest::COMPONENT,
                Extension::NO_FLAGS);
  EXPECT_EQ("", error);
}

}  // namespace extensions