Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(591)

Side by Side Diff: chrome/common/extensions/manifest_handlers/content_scripts_manifest_unittest.cc

Issue 11724002: Move ContentScripts out of Extension (Closed) Base URL: http://git.chromium.org/chromium/src.git@dc_unref_browser_action
Patch Set: Latest master for CQ Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/strings/string_number_conversions.h" 6 #include "base/strings/string_number_conversions.h"
7 #include "chrome/common/chrome_switches.h" 7 #include "chrome/common/chrome_switches.h"
8 #include "chrome/common/extensions/extension.h" 8 #include "chrome/common/extensions/extension.h"
9 #include "chrome/common/extensions/extension_manifest_constants.h" 9 #include "chrome/common/extensions/extension_manifest_constants.h"
10 #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h"
10 #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h" 11 #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h"
11 #include "extensions/common/error_utils.h" 12 #include "extensions/common/error_utils.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 14
14 namespace errors = extension_manifest_errors; 15 namespace errors = extension_manifest_errors;
15 16
16 TEST_F(ExtensionManifestTest, ContentScriptMatchPattern) { 17 namespace extensions {
18
19 class ContentScriptsManifestTest : public ExtensionManifestTest {
20 protected:
21 virtual void SetUp() OVERRIDE {
22 ExtensionManifestTest::SetUp();
23 (new ContentScriptsHandler)->Register();
24 }
25 };
26
27 TEST_F(ContentScriptsManifestTest, ContentScriptMatchPattern) {
17 Testcase testcases[] = { 28 Testcase testcases[] = {
18 // chrome:// urls are not allowed. 29 // chrome:// urls are not allowed.
19 Testcase("content_script_chrome_url_invalid.json", 30 Testcase("content_script_chrome_url_invalid.json",
20 extensions::ErrorUtils::FormatErrorMessage( 31 ErrorUtils::FormatErrorMessage(
21 errors::kInvalidMatch, 32 errors::kInvalidMatch,
22 base::IntToString(0), 33 base::IntToString(0),
23 base::IntToString(0), 34 base::IntToString(0),
24 URLPattern::GetParseResultString( 35 URLPattern::GetParseResultString(
25 URLPattern::PARSE_ERROR_INVALID_SCHEME))), 36 URLPattern::PARSE_ERROR_INVALID_SCHEME))),
26 37
27 // Match paterns must be strings. 38 // Match paterns must be strings.
28 Testcase("content_script_match_pattern_not_string.json", 39 Testcase("content_script_match_pattern_not_string.json",
29 extensions::ErrorUtils::FormatErrorMessage(errors::kInvalidMatch, 40 ErrorUtils::FormatErrorMessage(errors::kInvalidMatch,
30 base::IntToString(0), 41 base::IntToString(0),
31 base::IntToString(0), 42 base::IntToString(0),
32 errors::kExpectString)) 43 errors::kExpectString))
33 }; 44 };
34 RunTestcases(testcases, arraysize(testcases), 45 RunTestcases(testcases, arraysize(testcases),
35 EXPECT_TYPE_ERROR); 46 EXPECT_TYPE_ERROR);
36 47
37 LoadAndExpectSuccess("ports_in_content_scripts.json"); 48 LoadAndExpectSuccess("ports_in_content_scripts.json");
38 } 49 }
39 50
40 TEST_F(ExtensionManifestTest, ContentScriptsOnChromeUrlsWithFlag) { 51 TEST_F(ContentScriptsManifestTest, ContentScriptsOnChromeUrlsWithFlag) {
41 CommandLine::ForCurrentProcess()->AppendSwitch( 52 CommandLine::ForCurrentProcess()->AppendSwitch(
42 switches::kExtensionsOnChromeURLs); 53 switches::kExtensionsOnChromeURLs);
43 std::string error; 54 std::string error;
44 scoped_refptr<extensions::Extension> extension = 55 scoped_refptr<extensions::Extension> extension =
45 LoadAndExpectSuccess("content_script_chrome_url_invalid.json"); 56 LoadAndExpectSuccess("content_script_chrome_url_invalid.json");
46 EXPECT_EQ("", error); 57 EXPECT_EQ("", error);
47 const GURL newtab_url("chrome://newtab/"); 58 const GURL newtab_url("chrome://newtab/");
48 EXPECT_TRUE(extension->HasContentScriptAtURL(newtab_url)); 59 EXPECT_TRUE(ContentScriptsInfo::ExtensionHasScriptAtURL(extension,
60 newtab_url));
49 } 61 }
62
63 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698