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

Side by Side Diff: extensions/common/features/base_feature_provider_unittest.cc

Issue 1739183003: Make extensions::DictionaryBuilder and extensions::ListValue unmovable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/common/features/base_feature_provider.h" 5 #include "extensions/common/features/base_feature_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 28 matching lines...) Expand all
39 EXPECT_EQ(1, STLCount(*(extension_types), Manifest::TYPE_SHARED_MODULE)); 39 EXPECT_EQ(1, STLCount(*(extension_types), Manifest::TYPE_SHARED_MODULE));
40 } 40 }
41 41
42 // Tests that real manifest features have the correct availability for an 42 // Tests that real manifest features have the correct availability for an
43 // extension. 43 // extension.
44 TEST(BaseFeatureProviderTest, ManifestFeatureAvailability) { 44 TEST(BaseFeatureProviderTest, ManifestFeatureAvailability) {
45 const FeatureProvider* provider = BaseFeatureProvider::GetByName("manifest"); 45 const FeatureProvider* provider = BaseFeatureProvider::GetByName("manifest");
46 46
47 scoped_refptr<const Extension> extension = 47 scoped_refptr<const Extension> extension =
48 ExtensionBuilder() 48 ExtensionBuilder()
49 .SetManifest(std::move(DictionaryBuilder() 49 .SetManifest(DictionaryBuilder()
50 .Set("name", "test extension") 50 .Set("name", "test extension")
51 .Set("version", "1") 51 .Set("version", "1")
52 .Set("description", "hello there"))) 52 .Set("description", "hello there")
53 .Build())
53 .Build(); 54 .Build();
54 ASSERT_TRUE(extension.get()); 55 ASSERT_TRUE(extension.get());
55 56
56 Feature* feature = provider->GetFeature("description"); 57 Feature* feature = provider->GetFeature("description");
57 EXPECT_EQ(Feature::IS_AVAILABLE, 58 EXPECT_EQ(Feature::IS_AVAILABLE,
58 feature->IsAvailableToContext(extension.get(), 59 feature->IsAvailableToContext(extension.get(),
59 Feature::UNSPECIFIED_CONTEXT, 60 Feature::UNSPECIFIED_CONTEXT,
60 GURL()).result()); 61 GURL()).result());
61 62
62 // This is a generic extension, so an app-only feature isn't allowed. 63 // This is a generic extension, so an app-only feature isn't allowed.
(...skipping 30 matching lines...) Expand all
93 EXPECT_EQ(1, STLCount(*(extension_types), Manifest::TYPE_PLATFORM_APP)); 94 EXPECT_EQ(1, STLCount(*(extension_types), Manifest::TYPE_PLATFORM_APP));
94 } 95 }
95 96
96 // Tests that real permission features have the correct availability for an app. 97 // Tests that real permission features have the correct availability for an app.
97 TEST(BaseFeatureProviderTest, PermissionFeatureAvailability) { 98 TEST(BaseFeatureProviderTest, PermissionFeatureAvailability) {
98 const FeatureProvider* provider = 99 const FeatureProvider* provider =
99 BaseFeatureProvider::GetByName("permission"); 100 BaseFeatureProvider::GetByName("permission");
100 101
101 scoped_refptr<const Extension> app = 102 scoped_refptr<const Extension> app =
102 ExtensionBuilder() 103 ExtensionBuilder()
103 .SetManifest(std::move( 104 .SetManifest(
104 DictionaryBuilder() 105 DictionaryBuilder()
105 .Set("name", "test app") 106 .Set("name", "test app")
106 .Set("version", "1") 107 .Set("version", "1")
107 .Set("app", std::move(DictionaryBuilder().Set( 108 .Set("app",
108 "background", 109 DictionaryBuilder()
109 std::move(DictionaryBuilder().Set( 110 .Set("background",
110 "scripts", std::move(ListBuilder().Append( 111 DictionaryBuilder()
111 "background.js"))))))) 112 .Set("scripts", ListBuilder()
112 .Set("permissions", 113 .Append("background.js")
113 std::move(ListBuilder().Append("power"))))) 114 .Build())
115 .Build())
116 .Build())
117 .Set("permissions", ListBuilder().Append("power").Build())
118 .Build())
114 .Build(); 119 .Build();
115 ASSERT_TRUE(app.get()); 120 ASSERT_TRUE(app.get());
116 ASSERT_TRUE(app->is_platform_app()); 121 ASSERT_TRUE(app->is_platform_app());
117 122
118 // A permission requested in the manifest is available. 123 // A permission requested in the manifest is available.
119 Feature* feature = provider->GetFeature("power"); 124 Feature* feature = provider->GetFeature("power");
120 EXPECT_EQ( 125 EXPECT_EQ(
121 Feature::IS_AVAILABLE, 126 Feature::IS_AVAILABLE,
122 feature->IsAvailableToContext( 127 feature->IsAvailableToContext(
123 app.get(), Feature::UNSPECIFIED_CONTEXT, GURL()).result()); 128 app.get(), Feature::UNSPECIFIED_CONTEXT, GURL()).result());
(...skipping 10 matching lines...) Expand all
134 // A permission that isn't part of the manifest returns NOT_PRESENT. 139 // A permission that isn't part of the manifest returns NOT_PRESENT.
135 feature = provider->GetFeature("serial"); 140 feature = provider->GetFeature("serial");
136 ASSERT_TRUE(feature); 141 ASSERT_TRUE(feature);
137 EXPECT_EQ( 142 EXPECT_EQ(
138 Feature::NOT_PRESENT, 143 Feature::NOT_PRESENT,
139 feature->IsAvailableToContext( 144 feature->IsAvailableToContext(
140 app.get(), Feature::UNSPECIFIED_CONTEXT, GURL()).result()); 145 app.get(), Feature::UNSPECIFIED_CONTEXT, GURL()).result());
141 } 146 }
142 147
143 } // namespace extensions 148 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698