| 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" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 | 121 |
| 122 std::vector<linked_ptr<api::events::Rule>> get_rules_4b; | 122 std::vector<linked_ptr<api::events::Rule>> get_rules_4b; |
| 123 registry->GetAllRules(kExtensionId, &get_rules_4b); | 123 registry->GetAllRules(kExtensionId, &get_rules_4b); |
| 124 | 124 |
| 125 ASSERT_EQ(1u, get_rules_4b.size()); | 125 ASSERT_EQ(1u, get_rules_4b.size()); |
| 126 | 126 |
| 127 ASSERT_TRUE(get_rules_4b[0]->id.get()); | 127 ASSERT_TRUE(get_rules_4b[0]->id.get()); |
| 128 EXPECT_EQ(kRuleId, *get_rules_4b[0]->id); | 128 EXPECT_EQ(kRuleId, *get_rules_4b[0]->id); |
| 129 | 129 |
| 130 // Create extension | 130 // Create extension |
| 131 scoped_ptr<base::DictionaryValue> manifest = ParseDictionary( | 131 std::unique_ptr<base::DictionaryValue> manifest = ParseDictionary( |
| 132 "{" | 132 "{" |
| 133 " \"name\": \"Test\"," | 133 " \"name\": \"Test\"," |
| 134 " \"version\": \"1\"" | 134 " \"version\": \"1\"" |
| 135 "}"); | 135 "}"); |
| 136 scoped_refptr<Extension> extension = ExtensionBuilder() | 136 scoped_refptr<Extension> extension = ExtensionBuilder() |
| 137 .SetManifest(std::move(manifest)) | 137 .SetManifest(std::move(manifest)) |
| 138 .SetID(kExtensionId) | 138 .SetID(kExtensionId) |
| 139 .Build(); | 139 .Build(); |
| 140 registry->OnExtensionUninstalled(extension.get()); | 140 registry->OnExtensionUninstalled(extension.get()); |
| 141 EXPECT_EQ(0u /*extensions*/ + 0u /*rules*/, | 141 EXPECT_EQ(0u /*extensions*/ + 0u /*rules*/, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 registry = NULL; | 181 registry = NULL; |
| 182 message_loop.RunUntilIdle(); | 182 message_loop.RunUntilIdle(); |
| 183 } | 183 } |
| 184 | 184 |
| 185 // Test verifies 2 rules defined in the manifest appear in the registry. | 185 // Test verifies 2 rules defined in the manifest appear in the registry. |
| 186 TEST(RulesRegistryTest, TwoRulesInManifest) { | 186 TEST(RulesRegistryTest, TwoRulesInManifest) { |
| 187 base::MessageLoopForUI message_loop; | 187 base::MessageLoopForUI message_loop; |
| 188 content::TestBrowserThread thread(content::BrowserThread::UI, &message_loop); | 188 content::TestBrowserThread thread(content::BrowserThread::UI, &message_loop); |
| 189 | 189 |
| 190 // Create extension | 190 // Create extension |
| 191 scoped_ptr<base::DictionaryValue> manifest = ParseDictionary( | 191 std::unique_ptr<base::DictionaryValue> manifest = ParseDictionary( |
| 192 "{" | 192 "{" |
| 193 " \"name\": \"Test\"," | 193 " \"name\": \"Test\"," |
| 194 " \"version\": \"1\"," | 194 " \"version\": \"1\"," |
| 195 " \"event_rules\": [" | 195 " \"event_rules\": [" |
| 196 " {" | 196 " {" |
| 197 " \"id\": \"000\"," | 197 " \"id\": \"000\"," |
| 198 " \"priority\": 200," | 198 " \"priority\": 200," |
| 199 " \"tags\": [\"tagged\"]," | 199 " \"tags\": [\"tagged\"]," |
| 200 " \"event\": \"declarativeContent.onPageChanged\"," | 200 " \"event\": \"declarativeContent.onPageChanged\"," |
| 201 " \"actions\": [{" | 201 " \"actions\": [{" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 225 | 225 |
| 226 scoped_refptr<RulesRegistry> registry = new TestRulesRegistry( | 226 scoped_refptr<RulesRegistry> registry = new TestRulesRegistry( |
| 227 content::BrowserThread::UI, "declarativeContent.onPageChanged", key); | 227 content::BrowserThread::UI, "declarativeContent.onPageChanged", key); |
| 228 // Simulate what RulesRegistryService would do on extension load. | 228 // Simulate what RulesRegistryService would do on extension load. |
| 229 registry->OnExtensionLoaded(extension.get()); | 229 registry->OnExtensionLoaded(extension.get()); |
| 230 | 230 |
| 231 std::vector<linked_ptr<api::events::Rule>> get_rules; | 231 std::vector<linked_ptr<api::events::Rule>> get_rules; |
| 232 registry->GetAllRules(kExtensionId, &get_rules); | 232 registry->GetAllRules(kExtensionId, &get_rules); |
| 233 | 233 |
| 234 ASSERT_EQ(2u, get_rules.size()); | 234 ASSERT_EQ(2u, get_rules.size()); |
| 235 scoped_ptr<base::DictionaryValue> expected_rule_0 = ParseDictionary( | 235 std::unique_ptr<base::DictionaryValue> expected_rule_0 = ParseDictionary( |
| 236 "{" | 236 "{" |
| 237 " \"id\": \"000\"," | 237 " \"id\": \"000\"," |
| 238 " \"priority\": 200," | 238 " \"priority\": 200," |
| 239 " \"tags\": [\"tagged\"]," | 239 " \"tags\": [\"tagged\"]," |
| 240 " \"actions\": [{" | 240 " \"actions\": [{" |
| 241 " \"instanceType\": \"declarativeContent.ShowPageAction\"" | 241 " \"instanceType\": \"declarativeContent.ShowPageAction\"" |
| 242 " }]," | 242 " }]," |
| 243 " \"conditions\" : [{" | 243 " \"conditions\" : [{" |
| 244 " \"css\": [\"video\"]," | 244 " \"css\": [\"video\"]," |
| 245 " \"instanceType\" : \"declarativeContent.PageStateMatcher\"" | 245 " \"instanceType\" : \"declarativeContent.PageStateMatcher\"" |
| 246 " }]" | 246 " }]" |
| 247 "}"); | 247 "}"); |
| 248 EXPECT_TRUE(expected_rule_0->Equals(get_rules[0]->ToValue().get())); | 248 EXPECT_TRUE(expected_rule_0->Equals(get_rules[0]->ToValue().get())); |
| 249 | 249 |
| 250 scoped_ptr<base::DictionaryValue> expected_rule_1 = ParseDictionary( | 250 std::unique_ptr<base::DictionaryValue> expected_rule_1 = ParseDictionary( |
| 251 "{" | 251 "{" |
| 252 " \"id\": \"_0_\"," | 252 " \"id\": \"_0_\"," |
| 253 " \"priority\": 100," | 253 " \"priority\": 100," |
| 254 " \"actions\": [{" | 254 " \"actions\": [{" |
| 255 " \"instanceType\": \"declarativeContent.ShowPageAction\"" | 255 " \"instanceType\": \"declarativeContent.ShowPageAction\"" |
| 256 " }]," | 256 " }]," |
| 257 " \"conditions\" : [{" | 257 " \"conditions\" : [{" |
| 258 " \"css\": [\"input[type='password']\"]," | 258 " \"css\": [\"input[type='password']\"]," |
| 259 " \"instanceType\" : \"declarativeContent.PageStateMatcher\"" | 259 " \"instanceType\" : \"declarativeContent.PageStateMatcher\"" |
| 260 " }]" | 260 " }]" |
| 261 "}"); | 261 "}"); |
| 262 EXPECT_TRUE(expected_rule_1->Equals(get_rules[1]->ToValue().get())); | 262 EXPECT_TRUE(expected_rule_1->Equals(get_rules[1]->ToValue().get())); |
| 263 } | 263 } |
| 264 | 264 |
| 265 // Tests verifies that rules defined in the manifest cannot be deleted but | 265 // Tests verifies that rules defined in the manifest cannot be deleted but |
| 266 // programmatically added rules still can be deleted. | 266 // programmatically added rules still can be deleted. |
| 267 TEST(RulesRegistryTest, DeleteRuleInManifest) { | 267 TEST(RulesRegistryTest, DeleteRuleInManifest) { |
| 268 base::MessageLoopForUI message_loop; | 268 base::MessageLoopForUI message_loop; |
| 269 content::TestBrowserThread thread(content::BrowserThread::UI, &message_loop); | 269 content::TestBrowserThread thread(content::BrowserThread::UI, &message_loop); |
| 270 | 270 |
| 271 // Create extension | 271 // Create extension |
| 272 scoped_ptr<base::DictionaryValue> manifest = ParseDictionary( | 272 std::unique_ptr<base::DictionaryValue> manifest = ParseDictionary( |
| 273 "{" | 273 "{" |
| 274 " \"name\": \"Test\"," | 274 " \"name\": \"Test\"," |
| 275 " \"version\": \"1\"," | 275 " \"version\": \"1\"," |
| 276 " \"event_rules\": [{" | 276 " \"event_rules\": [{" |
| 277 " \"id\": \"manifest_rule_0\"," | 277 " \"id\": \"manifest_rule_0\"," |
| 278 " \"event\": \"declarativeContent.onPageChanged\"," | 278 " \"event\": \"declarativeContent.onPageChanged\"," |
| 279 " \"actions\": [{" | 279 " \"actions\": [{" |
| 280 " \"type\": \"declarativeContent.ShowPageAction\"" | 280 " \"type\": \"declarativeContent.ShowPageAction\"" |
| 281 " }]," | 281 " }]," |
| 282 " \"conditions\" : [{" | 282 " \"conditions\" : [{" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 | 333 |
| 334 // Remove all rules. | 334 // Remove all rules. |
| 335 registry->RemoveAllRules(kExtensionId); | 335 registry->RemoveAllRules(kExtensionId); |
| 336 get_rules.clear(); | 336 get_rules.clear(); |
| 337 registry->GetAllRules(kExtensionId, &get_rules); | 337 registry->GetAllRules(kExtensionId, &get_rules); |
| 338 ASSERT_EQ(1u, get_rules.size()); | 338 ASSERT_EQ(1u, get_rules.size()); |
| 339 EXPECT_EQ("manifest_rule_0", *(get_rules[0]->id)); | 339 EXPECT_EQ("manifest_rule_0", *(get_rules[0]->id)); |
| 340 } | 340 } |
| 341 | 341 |
| 342 } // namespace extensions | 342 } // namespace extensions |
| OLD | NEW |