OLD | NEW |
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/api/declarative/rules_registry.h" | 5 #include "extensions/browser/api/declarative/rules_registry.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/run_loop.h" |
11 #include "base/values.h" | 12 #include "base/values.h" |
12 #include "content/public/test/test_browser_thread.h" | 13 #include "content/public/test/test_browser_thread.h" |
13 #include "extensions/browser/api/declarative/rules_registry_service.h" | 14 #include "extensions/browser/api/declarative/rules_registry_service.h" |
14 #include "extensions/browser/api/declarative/test_rules_registry.h" | 15 #include "extensions/browser/api/declarative/test_rules_registry.h" |
15 #include "extensions/browser/api_test_utils.h" | 16 #include "extensions/browser/api_test_utils.h" |
16 #include "extensions/common/extension.h" | 17 #include "extensions/common/extension.h" |
17 #include "extensions/common/extension_builder.h" | 18 #include "extensions/common/extension_builder.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
19 | 20 |
20 namespace { | 21 namespace { |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 scoped_refptr<Extension> extension = ExtensionBuilder() | 137 scoped_refptr<Extension> extension = ExtensionBuilder() |
137 .SetManifest(std::move(manifest)) | 138 .SetManifest(std::move(manifest)) |
138 .SetID(kExtensionId) | 139 .SetID(kExtensionId) |
139 .Build(); | 140 .Build(); |
140 registry->OnExtensionUninstalled(extension.get()); | 141 registry->OnExtensionUninstalled(extension.get()); |
141 EXPECT_EQ(0u /*extensions*/ + 0u /*rules*/, | 142 EXPECT_EQ(0u /*extensions*/ + 0u /*rules*/, |
142 registry->GetNumberOfUsedRuleIdentifiersForTesting()); | 143 registry->GetNumberOfUsedRuleIdentifiersForTesting()); |
143 | 144 |
144 // Make sure that deletion traits of registry are executed. | 145 // Make sure that deletion traits of registry are executed. |
145 registry = NULL; | 146 registry = NULL; |
146 message_loop.RunUntilIdle(); | 147 base::RunLoop().RunUntilIdle(); |
147 } | 148 } |
148 | 149 |
149 TEST(RulesRegistryTest, FillOptionalPriority) { | 150 TEST(RulesRegistryTest, FillOptionalPriority) { |
150 base::MessageLoopForUI message_loop; | 151 base::MessageLoopForUI message_loop; |
151 content::TestBrowserThread thread(content::BrowserThread::UI, &message_loop); | 152 content::TestBrowserThread thread(content::BrowserThread::UI, &message_loop); |
152 | 153 |
153 std::string error; | 154 std::string error; |
154 scoped_refptr<RulesRegistry> registry = | 155 scoped_refptr<RulesRegistry> registry = |
155 new TestRulesRegistry(content::BrowserThread::UI, "" /*event_name*/, key); | 156 new TestRulesRegistry(content::BrowserThread::UI, "" /*event_name*/, key); |
156 | 157 |
(...skipping 15 matching lines...) Expand all Loading... |
172 ASSERT_TRUE(get_rules[1]->priority.get()); | 173 ASSERT_TRUE(get_rules[1]->priority.get()); |
173 | 174 |
174 // Verify the precondition so that the following EXPECT_EQ statements work. | 175 // Verify the precondition so that the following EXPECT_EQ statements work. |
175 EXPECT_GT(RulesRegistry::DEFAULT_PRIORITY, 2); | 176 EXPECT_GT(RulesRegistry::DEFAULT_PRIORITY, 2); |
176 EXPECT_EQ(2, std::min(*get_rules[0]->priority, *get_rules[1]->priority)); | 177 EXPECT_EQ(2, std::min(*get_rules[0]->priority, *get_rules[1]->priority)); |
177 EXPECT_EQ(RulesRegistry::DEFAULT_PRIORITY, | 178 EXPECT_EQ(RulesRegistry::DEFAULT_PRIORITY, |
178 std::max(*get_rules[0]->priority, *get_rules[1]->priority)); | 179 std::max(*get_rules[0]->priority, *get_rules[1]->priority)); |
179 | 180 |
180 // Make sure that deletion traits of registry are executed. | 181 // Make sure that deletion traits of registry are executed. |
181 registry = NULL; | 182 registry = NULL; |
182 message_loop.RunUntilIdle(); | 183 base::RunLoop().RunUntilIdle(); |
183 } | 184 } |
184 | 185 |
185 // Test verifies 2 rules defined in the manifest appear in the registry. | 186 // Test verifies 2 rules defined in the manifest appear in the registry. |
186 TEST(RulesRegistryTest, TwoRulesInManifest) { | 187 TEST(RulesRegistryTest, TwoRulesInManifest) { |
187 base::MessageLoopForUI message_loop; | 188 base::MessageLoopForUI message_loop; |
188 content::TestBrowserThread thread(content::BrowserThread::UI, &message_loop); | 189 content::TestBrowserThread thread(content::BrowserThread::UI, &message_loop); |
189 | 190 |
190 // Create extension | 191 // Create extension |
191 std::unique_ptr<base::DictionaryValue> manifest = ParseDictionary( | 192 std::unique_ptr<base::DictionaryValue> manifest = ParseDictionary( |
192 "{" | 193 "{" |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 | 334 |
334 // Remove all rules. | 335 // Remove all rules. |
335 registry->RemoveAllRules(kExtensionId); | 336 registry->RemoveAllRules(kExtensionId); |
336 get_rules.clear(); | 337 get_rules.clear(); |
337 registry->GetAllRules(kExtensionId, &get_rules); | 338 registry->GetAllRules(kExtensionId, &get_rules); |
338 ASSERT_EQ(1u, get_rules.size()); | 339 ASSERT_EQ(1u, get_rules.size()); |
339 EXPECT_EQ("manifest_rule_0", *(get_rules[0]->id)); | 340 EXPECT_EQ("manifest_rule_0", *(get_rules[0]->id)); |
340 } | 341 } |
341 | 342 |
342 } // namespace extensions | 343 } // namespace extensions |
OLD | NEW |