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

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
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 if (type == TypeToCreate::kExtension) {
Devlin 2017/06/01 22:17:58 prefer a switch
tbarzic 2017/06/02 00:49:05 Done.
28 manifest_builder.Set(
29 "background",
30 DictionaryBuilder()
31 .Set("scripts", ListBuilder().Append("background.js").Build())
32 .Build());
33 } else if (type == TypeToCreate::kHostedApp) {
34 manifest_builder.Set(
35 "app", DictionaryBuilder()
36 .Set("launch", DictionaryBuilder()
37 .Set("web_url", "https://www.foo.bar")
38 .Build())
39 .Build());
40 } else if (type == TypeToCreate::kPlatformApp) {
41 manifest_builder.Set(
42 "app", DictionaryBuilder()
43 .Set("background",
44 DictionaryBuilder()
45 .Set("scripts",
46 ListBuilder().Append("background.js").Build())
47 .Build())
48 .Build());
49 }
50
51 return ExtensionBuilder()
52 .SetID(id)
53 .SetManifest(manifest_builder.Build())
54 .Build();
55 }
56
57 } // namespace
58 } // namespace extensions
59
9 using extensions::ProcessMap; 60 using extensions::ProcessMap;
10 61
11 TEST(ExtensionProcessMapTest, Test) { 62 TEST(ExtensionProcessMapTest, Test) {
12 ProcessMap map; 63 ProcessMap map;
13 64
14 // Test behavior when empty. 65 // Test behavior when empty.
15 EXPECT_FALSE(map.Contains("a", 1)); 66 EXPECT_FALSE(map.Contains("a", 1));
16 EXPECT_FALSE(map.Remove("a", 1, 1)); 67 EXPECT_FALSE(map.Remove("a", 1, 1));
17 EXPECT_EQ(0u, map.size()); 68 EXPECT_EQ(0u, map.size());
18 69
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 107
57 EXPECT_TRUE(map.Remove("a", 1, 5)); 108 EXPECT_TRUE(map.Remove("a", 1, 5));
58 EXPECT_EQ(3u, map.size()); 109 EXPECT_EQ(3u, map.size());
59 EXPECT_FALSE(map.Contains("a", 1)); 110 EXPECT_FALSE(map.Contains("a", 1));
60 111
61 EXPECT_EQ(2, map.RemoveAllFromProcess(2)); 112 EXPECT_EQ(2, map.RemoveAllFromProcess(2));
62 EXPECT_EQ(1u, map.size()); 113 EXPECT_EQ(1u, map.size());
63 EXPECT_EQ(0, map.RemoveAllFromProcess(2)); 114 EXPECT_EQ(0, map.RemoveAllFromProcess(2));
64 EXPECT_EQ(1u, map.size()); 115 EXPECT_EQ(1u, map.size());
65 } 116 }
117
118 TEST(ExtensionProcessMapTest, GetMostLikelyContextType) {
119 ProcessMap map;
120
121 EXPECT_EQ(extensions::Feature::WEB_PAGE_CONTEXT,
122 map.GetMostLikelyContextType(nullptr, 1));
123
124 scoped_refptr<const extensions::Extension> extension =
125 CreateExtensionWithFlags(extensions::TypeToCreate::kExtension, "a");
126
127 EXPECT_EQ(extensions::Feature::CONTENT_SCRIPT_CONTEXT,
128 map.GetMostLikelyContextType(extension.get(), 2));
129
130 map.Insert("b", 3, 1);
131 extension =
132 CreateExtensionWithFlags(extensions::TypeToCreate::kExtension, "b");
133 EXPECT_EQ(extensions::Feature::BLESSED_EXTENSION_CONTEXT,
134 map.GetMostLikelyContextType(extension.get(), 3));
135
136 map.Insert("c", 4, 2);
137 extension =
138 CreateExtensionWithFlags(extensions::TypeToCreate::kPlatformApp, "c");
139 EXPECT_EQ(extensions::Feature::BLESSED_EXTENSION_CONTEXT,
140 map.GetMostLikelyContextType(extension.get(), 4));
141
142 map.set_is_lock_screen_context(true);
143
144 map.Insert("d", 5, 3);
145 extension =
146 CreateExtensionWithFlags(extensions::TypeToCreate::kPlatformApp, "d");
147 EXPECT_EQ(extensions::Feature::LOCK_SCREEN_EXTENSION_CONTEXT,
148 map.GetMostLikelyContextType(extension.get(), 5));
149
150 map.Insert("e", 6, 4);
151 extension =
152 CreateExtensionWithFlags(extensions::TypeToCreate::kExtension, "e");
153 EXPECT_EQ(extensions::Feature::LOCK_SCREEN_EXTENSION_CONTEXT,
154 map.GetMostLikelyContextType(extension.get(), 6));
155
156 map.Insert("f", 7, 5);
157 extension =
158 CreateExtensionWithFlags(extensions::TypeToCreate::kHostedApp, "f");
159 EXPECT_EQ(extensions::Feature::BLESSED_WEB_PAGE_CONTEXT,
160 map.GetMostLikelyContextType(extension.get(), 7));
161 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698