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

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, 6 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
« no previous file with comments | « extensions/browser/process_map.cc ('k') | extensions/browser/renderer_startup_helper.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 DictionaryBuilder manifest_builder;
23 manifest_builder.Set("name", "Test extension")
24 .Set("version", "1.0")
25 .Set("manifest_version", 2);
26
27 switch (type) {
28 case TypeToCreate::kExtension:
29 manifest_builder.Set(
30 "background",
31 DictionaryBuilder()
32 .Set("scripts", ListBuilder().Append("background.js").Build())
33 .Build());
34 break;
35 case TypeToCreate::kHostedApp:
36 manifest_builder.Set(
37 "app", DictionaryBuilder()
38 .Set("launch", DictionaryBuilder()
39 .Set("web_url", "https://www.foo.bar")
40 .Build())
41 .Build());
42 break;
43 case TypeToCreate::kPlatformApp:
44 manifest_builder.Set(
45 "app",
46 DictionaryBuilder()
47 .Set("background",
48 DictionaryBuilder()
49 .Set("scripts",
50 ListBuilder().Append("background.js").Build())
51 .Build())
52 .Build());
53 break;
54 }
55
56 return ExtensionBuilder()
57 .SetID(id)
58 .SetManifest(manifest_builder.Build())
59 .Build();
60 }
61
62 } // namespace
63 } // namespace extensions
64
9 using extensions::ProcessMap; 65 using extensions::ProcessMap;
10 66
11 TEST(ExtensionProcessMapTest, Test) { 67 TEST(ExtensionProcessMapTest, Test) {
12 ProcessMap map; 68 ProcessMap map;
13 69
14 // Test behavior when empty. 70 // Test behavior when empty.
15 EXPECT_FALSE(map.Contains("a", 1)); 71 EXPECT_FALSE(map.Contains("a", 1));
16 EXPECT_FALSE(map.Remove("a", 1, 1)); 72 EXPECT_FALSE(map.Remove("a", 1, 1));
17 EXPECT_EQ(0u, map.size()); 73 EXPECT_EQ(0u, map.size());
18 74
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 112
57 EXPECT_TRUE(map.Remove("a", 1, 5)); 113 EXPECT_TRUE(map.Remove("a", 1, 5));
58 EXPECT_EQ(3u, map.size()); 114 EXPECT_EQ(3u, map.size());
59 EXPECT_FALSE(map.Contains("a", 1)); 115 EXPECT_FALSE(map.Contains("a", 1));
60 116
61 EXPECT_EQ(2, map.RemoveAllFromProcess(2)); 117 EXPECT_EQ(2, map.RemoveAllFromProcess(2));
62 EXPECT_EQ(1u, map.size()); 118 EXPECT_EQ(1u, map.size());
63 EXPECT_EQ(0, map.RemoveAllFromProcess(2)); 119 EXPECT_EQ(0, map.RemoveAllFromProcess(2));
64 EXPECT_EQ(1u, map.size()); 120 EXPECT_EQ(1u, map.size());
65 } 121 }
122
123 TEST(ExtensionProcessMapTest, GetMostLikelyContextType) {
124 ProcessMap map;
125
126 EXPECT_EQ(extensions::Feature::WEB_PAGE_CONTEXT,
127 map.GetMostLikelyContextType(nullptr, 1));
128
129 scoped_refptr<const extensions::Extension> extension =
130 CreateExtensionWithFlags(extensions::TypeToCreate::kExtension, "a");
131
132 EXPECT_EQ(extensions::Feature::CONTENT_SCRIPT_CONTEXT,
133 map.GetMostLikelyContextType(extension.get(), 2));
134
135 map.Insert("b", 3, 1);
136 extension =
137 CreateExtensionWithFlags(extensions::TypeToCreate::kExtension, "b");
138 EXPECT_EQ(extensions::Feature::BLESSED_EXTENSION_CONTEXT,
139 map.GetMostLikelyContextType(extension.get(), 3));
140
141 map.Insert("c", 4, 2);
142 extension =
143 CreateExtensionWithFlags(extensions::TypeToCreate::kPlatformApp, "c");
144 EXPECT_EQ(extensions::Feature::BLESSED_EXTENSION_CONTEXT,
145 map.GetMostLikelyContextType(extension.get(), 4));
146
147 map.set_is_lock_screen_context(true);
148
149 map.Insert("d", 5, 3);
150 extension =
151 CreateExtensionWithFlags(extensions::TypeToCreate::kPlatformApp, "d");
152 EXPECT_EQ(extensions::Feature::LOCK_SCREEN_EXTENSION_CONTEXT,
153 map.GetMostLikelyContextType(extension.get(), 5));
154
155 map.Insert("e", 6, 4);
156 extension =
157 CreateExtensionWithFlags(extensions::TypeToCreate::kExtension, "e");
158 EXPECT_EQ(extensions::Feature::LOCK_SCREEN_EXTENSION_CONTEXT,
159 map.GetMostLikelyContextType(extension.get(), 6));
160
161 map.Insert("f", 7, 5);
162 extension =
163 CreateExtensionWithFlags(extensions::TypeToCreate::kHostedApp, "f");
164 EXPECT_EQ(extensions::Feature::BLESSED_WEB_PAGE_CONTEXT,
165 map.GetMostLikelyContextType(extension.get(), 7));
166 }
OLDNEW
« no previous file with comments | « extensions/browser/process_map.cc ('k') | extensions/browser/renderer_startup_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698