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

Side by Side Diff: chrome/common/extensions/manifest_tests/extension_manifests_background_unittest.cc

Issue 578653005: Revert "Refactor ExtensionManifestTest to allow usage in src/extensions" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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) 2012 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 "chrome/common/extensions/manifest_tests/chrome_manifest_test.h" 5 #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/common/extensions/features/feature_channel.h" 10 #include "chrome/common/extensions/features/feature_channel.h"
11 #include "extensions/common/constants.h" 11 #include "extensions/common/constants.h"
12 #include "extensions/common/error_utils.h" 12 #include "extensions/common/error_utils.h"
13 #include "extensions/common/extension.h" 13 #include "extensions/common/extension.h"
14 #include "extensions/common/manifest_constants.h" 14 #include "extensions/common/manifest_constants.h"
15 #include "extensions/common/manifest_handlers/background_info.h" 15 #include "extensions/common/manifest_handlers/background_info.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 17
18 namespace extensions { 18 namespace extensions {
19 19
20 namespace errors = manifest_errors; 20 namespace errors = manifest_errors;
21 namespace keys = manifest_keys; 21 namespace keys = manifest_keys;
22 22
23 class ExtensionManifestBackgroundTest : public ChromeManifestTest { 23 class ExtensionManifestBackgroundTest : public ExtensionManifestTest {
24 }; 24 };
25 25
26 TEST_F(ExtensionManifestBackgroundTest, BackgroundPermission) { 26 TEST_F(ExtensionManifestBackgroundTest, BackgroundPermission) {
27 LoadAndExpectError("background_permission.json", 27 LoadAndExpectError("background_permission.json",
28 errors::kBackgroundPermissionNeeded); 28 errors::kBackgroundPermissionNeeded);
29 } 29 }
30 30
31 TEST_F(ExtensionManifestBackgroundTest, BackgroundScripts) { 31 TEST_F(ExtensionManifestBackgroundTest, BackgroundScripts) {
32 std::string error; 32 std::string error;
33 scoped_ptr<base::DictionaryValue> manifest( 33 scoped_ptr<base::DictionaryValue> manifest(
34 LoadManifest("background_scripts.json", &error)); 34 LoadManifest("background_scripts.json", &error));
35 ASSERT_TRUE(manifest.get()); 35 ASSERT_TRUE(manifest.get());
36 36
37 scoped_refptr<Extension> extension( 37 scoped_refptr<Extension> extension(
38 LoadAndExpectSuccess(ManifestData(manifest.get(), ""))); 38 LoadAndExpectSuccess(Manifest(manifest.get(), "")));
39 ASSERT_TRUE(extension.get()); 39 ASSERT_TRUE(extension.get());
40 const std::vector<std::string>& background_scripts = 40 const std::vector<std::string>& background_scripts =
41 BackgroundInfo::GetBackgroundScripts(extension.get()); 41 BackgroundInfo::GetBackgroundScripts(extension.get());
42 ASSERT_EQ(2u, background_scripts.size()); 42 ASSERT_EQ(2u, background_scripts.size());
43 EXPECT_EQ("foo.js", background_scripts[0u]); 43 EXPECT_EQ("foo.js", background_scripts[0u]);
44 EXPECT_EQ("bar/baz.js", background_scripts[1u]); 44 EXPECT_EQ("bar/baz.js", background_scripts[1u]);
45 45
46 EXPECT_TRUE(BackgroundInfo::HasBackgroundPage(extension.get())); 46 EXPECT_TRUE(BackgroundInfo::HasBackgroundPage(extension.get()));
47 EXPECT_EQ( 47 EXPECT_EQ(
48 std::string("/") + kGeneratedBackgroundPageFilename, 48 std::string("/") + kGeneratedBackgroundPageFilename,
49 BackgroundInfo::GetBackgroundURL(extension.get()).path()); 49 BackgroundInfo::GetBackgroundURL(extension.get()).path());
50 50
51 manifest->SetString("background_page", "monkey.html"); 51 manifest->SetString("background_page", "monkey.html");
52 LoadAndExpectError(ManifestData(manifest.get(), ""), 52 LoadAndExpectError(Manifest(manifest.get(), ""),
53 errors::kInvalidBackgroundCombination); 53 errors::kInvalidBackgroundCombination);
54 } 54 }
55 55
56 TEST_F(ExtensionManifestBackgroundTest, BackgroundPage) { 56 TEST_F(ExtensionManifestBackgroundTest, BackgroundPage) {
57 scoped_refptr<Extension> extension( 57 scoped_refptr<Extension> extension(
58 LoadAndExpectSuccess("background_page.json")); 58 LoadAndExpectSuccess("background_page.json"));
59 ASSERT_TRUE(extension.get()); 59 ASSERT_TRUE(extension.get());
60 EXPECT_EQ("/foo.html", 60 EXPECT_EQ("/foo.html",
61 BackgroundInfo::GetBackgroundURL(extension.get()).path()); 61 BackgroundInfo::GetBackgroundURL(extension.get()).path());
62 EXPECT_TRUE(BackgroundInfo::AllowJSAccess(extension.get())); 62 EXPECT_TRUE(BackgroundInfo::AllowJSAccess(extension.get()));
63 63
64 std::string error; 64 std::string error;
65 scoped_ptr<base::DictionaryValue> manifest( 65 scoped_ptr<base::DictionaryValue> manifest(
66 LoadManifest("background_page_legacy.json", &error)); 66 LoadManifest("background_page_legacy.json", &error));
67 ASSERT_TRUE(manifest.get()); 67 ASSERT_TRUE(manifest.get());
68 extension = LoadAndExpectSuccess(ManifestData(manifest.get(), "")); 68 extension = LoadAndExpectSuccess(Manifest(manifest.get(), ""));
69 ASSERT_TRUE(extension.get()); 69 ASSERT_TRUE(extension.get());
70 EXPECT_EQ("/foo.html", 70 EXPECT_EQ("/foo.html",
71 BackgroundInfo::GetBackgroundURL(extension.get()).path()); 71 BackgroundInfo::GetBackgroundURL(extension.get()).path());
72 72
73 manifest->SetInteger(keys::kManifestVersion, 2); 73 manifest->SetInteger(keys::kManifestVersion, 2);
74 LoadAndExpectWarning( 74 LoadAndExpectWarning(
75 ManifestData(manifest.get(), ""), 75 Manifest(manifest.get(), ""),
76 "'background_page' requires manifest version of 1 or lower."); 76 "'background_page' requires manifest version of 1 or lower.");
77 } 77 }
78 78
79 TEST_F(ExtensionManifestBackgroundTest, BackgroundAllowNoJsAccess) { 79 TEST_F(ExtensionManifestBackgroundTest, BackgroundAllowNoJsAccess) {
80 scoped_refptr<Extension> extension; 80 scoped_refptr<Extension> extension;
81 extension = LoadAndExpectSuccess("background_allow_no_js_access.json"); 81 extension = LoadAndExpectSuccess("background_allow_no_js_access.json");
82 ASSERT_TRUE(extension.get()); 82 ASSERT_TRUE(extension.get());
83 EXPECT_FALSE(BackgroundInfo::AllowJSAccess(extension.get())); 83 EXPECT_FALSE(BackgroundInfo::AllowJSAccess(extension.get()));
84 84
85 extension = LoadAndExpectSuccess("background_allow_no_js_access2.json"); 85 extension = LoadAndExpectSuccess("background_allow_no_js_access2.json");
86 ASSERT_TRUE(extension.get()); 86 ASSERT_TRUE(extension.get());
87 EXPECT_FALSE(BackgroundInfo::AllowJSAccess(extension.get())); 87 EXPECT_FALSE(BackgroundInfo::AllowJSAccess(extension.get()));
88 } 88 }
89 89
90 TEST_F(ExtensionManifestBackgroundTest, BackgroundPageWebRequest) { 90 TEST_F(ExtensionManifestBackgroundTest, BackgroundPageWebRequest) {
91 ScopedCurrentChannel current_channel(chrome::VersionInfo::CHANNEL_DEV); 91 ScopedCurrentChannel current_channel(chrome::VersionInfo::CHANNEL_DEV);
92 92
93 std::string error; 93 std::string error;
94 scoped_ptr<base::DictionaryValue> manifest( 94 scoped_ptr<base::DictionaryValue> manifest(
95 LoadManifest("background_page.json", &error)); 95 LoadManifest("background_page.json", &error));
96 ASSERT_TRUE(manifest.get()); 96 ASSERT_TRUE(manifest.get());
97 manifest->SetBoolean(keys::kBackgroundPersistent, false); 97 manifest->SetBoolean(keys::kBackgroundPersistent, false);
98 manifest->SetInteger(keys::kManifestVersion, 2); 98 manifest->SetInteger(keys::kManifestVersion, 2);
99 scoped_refptr<Extension> extension( 99 scoped_refptr<Extension> extension(
100 LoadAndExpectSuccess(ManifestData(manifest.get(), ""))); 100 LoadAndExpectSuccess(Manifest(manifest.get(), "")));
101 ASSERT_TRUE(extension.get()); 101 ASSERT_TRUE(extension.get());
102 EXPECT_TRUE(BackgroundInfo::HasLazyBackgroundPage(extension.get())); 102 EXPECT_TRUE(BackgroundInfo::HasLazyBackgroundPage(extension.get()));
103 103
104 base::ListValue* permissions = new base::ListValue(); 104 base::ListValue* permissions = new base::ListValue();
105 permissions->Append(new base::StringValue("webRequest")); 105 permissions->Append(new base::StringValue("webRequest"));
106 manifest->Set(keys::kPermissions, permissions); 106 manifest->Set(keys::kPermissions, permissions);
107 LoadAndExpectError(ManifestData(manifest.get(), ""), 107 LoadAndExpectError(Manifest(manifest.get(), ""),
108 errors::kWebRequestConflictsWithLazyBackground); 108 errors::kWebRequestConflictsWithLazyBackground);
109 } 109 }
110 110
111 } // namespace extensions 111 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698