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

Side by Side Diff: extensions/browser/process_map_unittest.cc

Issue 2892403002: Introduce lock screen app context to extension features (Closed)
Patch Set: . Created 3 years, 7 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 "extensions/browser/process_map.h" 5 #include "extensions/browser/process_map.h"
6 6
7 #include "base/memory/ref_counted.h"
8 #include "base/values.h"
9 #include "extensions/common/extension.h"
10 #include "extensions/common/extension_builder.h"
11 #include "extensions/common/features/feature.h"
12 #include "extensions/common/value_builder.h"
7 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
8 14
15 namespace extensions {
16 namespace {
17
18 enum class TypeToCreate { kExtension, kHostedApp, kPlatformApp };
19
20 scoped_refptr<const Extension> CreateExtensionWithFlags(TypeToCreate type,
21 const std::string& id,
22 int flags) {
23 DictionaryBuilder manifest_builder;
24 manifest_builder.Set("name", "Test extension")
25 .Set("version", "1.0")
26 .Set("manifest_version", 2);
27
28 if (type == TypeToCreate::kExtension) {
29 manifest_builder.Set(
30 "background",
31 DictionaryBuilder()
32 .Set("scripts", ListBuilder().Append("background.js").Build())
33 .Build());
34 } else if (type == TypeToCreate::kHostedApp) {
35 manifest_builder.Set(
36 "app", DictionaryBuilder()
37 .Set("launch", DictionaryBuilder()
38 .Set("web_url", "https://www.foo.bar")
39 .Build())
40 .Build());
41 } else if (type == TypeToCreate::kPlatformApp) {
42 manifest_builder.Set(
43 "app", DictionaryBuilder()
44 .Set("background",
45 DictionaryBuilder()
46 .Set("scripts",
47 ListBuilder().Append("background.js").Build())
48 .Build())
49 .Build());
50 }
51
52 return ExtensionBuilder()
53 .SetID(id)
54 .AddFlags(flags)
55 .SetManifest(manifest_builder.Build())
56 .Build();
57 }
58
59 } // namespace
60 } // namespace extensions
61
9 using extensions::ProcessMap; 62 using extensions::ProcessMap;
10 63
11 TEST(ExtensionProcessMapTest, Test) { 64 TEST(ExtensionProcessMapTest, Test) {
12 ProcessMap map; 65 ProcessMap map;
13 66
14 // Test behavior when empty. 67 // Test behavior when empty.
15 EXPECT_FALSE(map.Contains("a", 1)); 68 EXPECT_FALSE(map.Contains("a", 1));
16 EXPECT_FALSE(map.Remove("a", 1, 1)); 69 EXPECT_FALSE(map.Remove("a", 1, 1));
17 EXPECT_EQ(0u, map.size()); 70 EXPECT_EQ(0u, map.size());
18 71
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 109
57 EXPECT_TRUE(map.Remove("a", 1, 5)); 110 EXPECT_TRUE(map.Remove("a", 1, 5));
58 EXPECT_EQ(3u, map.size()); 111 EXPECT_EQ(3u, map.size());
59 EXPECT_FALSE(map.Contains("a", 1)); 112 EXPECT_FALSE(map.Contains("a", 1));
60 113
61 EXPECT_EQ(2, map.RemoveAllFromProcess(2)); 114 EXPECT_EQ(2, map.RemoveAllFromProcess(2));
62 EXPECT_EQ(1u, map.size()); 115 EXPECT_EQ(1u, map.size());
63 EXPECT_EQ(0, map.RemoveAllFromProcess(2)); 116 EXPECT_EQ(0, map.RemoveAllFromProcess(2));
64 EXPECT_EQ(1u, map.size()); 117 EXPECT_EQ(1u, map.size());
65 } 118 }
119
120 TEST(ExtensionProcessMapTest, GetMostLikelyContextType) {
121 ProcessMap map;
122
123 EXPECT_EQ(extensions::Feature::WEB_PAGE_CONTEXT,
124 map.GetMostLikelyContextType(nullptr, 1));
125
126 scoped_refptr<const extensions::Extension> extension =
127 CreateExtensionWithFlags(extensions::TypeToCreate::kExtension, "a",
128 extensions::Extension::NO_FLAGS);
129
130 EXPECT_EQ(extensions::Feature::CONTENT_SCRIPT_CONTEXT,
131 map.GetMostLikelyContextType(extension.get(), 2));
132
133 map.Insert("b", 3, 1);
134 extension = CreateExtensionWithFlags(extensions::TypeToCreate::kExtension,
135 "b", extensions::Extension::NO_FLAGS);
136 EXPECT_EQ(extensions::Feature::BLESSED_EXTENSION_CONTEXT,
137 map.GetMostLikelyContextType(extension.get(), 3));
138
139 map.Insert("c", 4, 2);
140 extension = CreateExtensionWithFlags(extensions::TypeToCreate::kPlatformApp,
141 "c", extensions::Extension::NO_FLAGS);
142 EXPECT_EQ(extensions::Feature::BLESSED_EXTENSION_CONTEXT,
143 map.GetMostLikelyContextType(extension.get(), 4));
144
145 map.Insert("d", 5, 3);
146 extension =
147 CreateExtensionWithFlags(extensions::TypeToCreate::kPlatformApp, "d",
148 extensions::Extension::RUNS_ON_LOCK_SCREEN);
149 EXPECT_EQ(extensions::Feature::LOCK_SCREEN_EXTENSION_CONTEXT,
150 map.GetMostLikelyContextType(extension.get(), 5));
151
152 map.Insert("e", 6, 4);
153 extension =
154 CreateExtensionWithFlags(extensions::TypeToCreate::kExtension, "e",
155 extensions::Extension::RUNS_ON_LOCK_SCREEN);
156 EXPECT_EQ(extensions::Feature::LOCK_SCREEN_EXTENSION_CONTEXT,
157 map.GetMostLikelyContextType(extension.get(), 6));
158
159 map.Insert("f", 7, 5);
160 extension =
161 CreateExtensionWithFlags(extensions::TypeToCreate::kHostedApp, "f",
162 extensions::Extension::RUNS_ON_LOCK_SCREEN);
163 EXPECT_EQ(extensions::Feature::BLESSED_WEB_PAGE_CONTEXT,
164 map.GetMostLikelyContextType(extension.get(), 7));
165 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698