Chromium Code Reviews| 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 | 8 |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "content/public/test/test_browser_thread.h" | 10 #include "content/public/test/test_browser_thread.h" |
| 11 #include "extensions/browser/api/declarative/rules_registry_service.h" | |
| 11 #include "extensions/browser/api/declarative/test_rules_registry.h" | 12 #include "extensions/browser/api/declarative/test_rules_registry.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 const char kExtensionId[] = "foobar"; | 16 const char kExtensionId[] = "foobar"; |
| 16 const char kRuleId[] = "foo"; | 17 const char kRuleId[] = "foo"; |
| 18 const int key = extensions::RulesRegistryService::kDefultRulesRegistryID; | |
|
Fady Samuel
2014/11/26 23:39:41
kDefaultRulesRegistryID
| |
| 17 } // namespace | 19 } // namespace |
| 18 | 20 |
| 19 namespace extensions { | 21 namespace extensions { |
| 20 | 22 |
| 21 TEST(RulesRegistryTest, FillOptionalIdentifiers) { | 23 TEST(RulesRegistryTest, FillOptionalIdentifiers) { |
| 22 base::MessageLoopForUI message_loop; | 24 base::MessageLoopForUI message_loop; |
| 23 content::TestBrowserThread thread(content::BrowserThread::UI, &message_loop); | 25 content::TestBrowserThread thread(content::BrowserThread::UI, &message_loop); |
| 24 | 26 |
| 25 const RulesRegistry::WebViewKey key(0, 0); | |
| 26 std::string error; | 27 std::string error; |
| 27 scoped_refptr<RulesRegistry> registry = | 28 scoped_refptr<RulesRegistry> registry = |
| 28 new TestRulesRegistry(content::BrowserThread::UI, "" /*event_name*/, key); | 29 new TestRulesRegistry(content::BrowserThread::UI, "" /*event_name*/, key); |
| 29 | 30 |
| 30 // Add rules and check that their identifiers are filled and unique. | 31 // Add rules and check that their identifiers are filled and unique. |
| 31 | 32 |
| 32 std::vector<linked_ptr<RulesRegistry::Rule> > add_rules; | 33 std::vector<linked_ptr<RulesRegistry::Rule> > add_rules; |
| 33 add_rules.push_back(make_linked_ptr(new RulesRegistry::Rule)); | 34 add_rules.push_back(make_linked_ptr(new RulesRegistry::Rule)); |
| 34 add_rules.push_back(make_linked_ptr(new RulesRegistry::Rule)); | 35 add_rules.push_back(make_linked_ptr(new RulesRegistry::Rule)); |
| 35 error = registry->AddRules(kExtensionId, add_rules); | 36 error = registry->AddRules(kExtensionId, add_rules); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 | 126 |
| 126 // Make sure that deletion traits of registry are executed. | 127 // Make sure that deletion traits of registry are executed. |
| 127 registry = NULL; | 128 registry = NULL; |
| 128 message_loop.RunUntilIdle(); | 129 message_loop.RunUntilIdle(); |
| 129 } | 130 } |
| 130 | 131 |
| 131 TEST(RulesRegistryTest, FillOptionalPriority) { | 132 TEST(RulesRegistryTest, FillOptionalPriority) { |
| 132 base::MessageLoopForUI message_loop; | 133 base::MessageLoopForUI message_loop; |
| 133 content::TestBrowserThread thread(content::BrowserThread::UI, &message_loop); | 134 content::TestBrowserThread thread(content::BrowserThread::UI, &message_loop); |
| 134 | 135 |
| 135 const RulesRegistry::WebViewKey key(0, 0); | |
| 136 std::string error; | 136 std::string error; |
| 137 scoped_refptr<RulesRegistry> registry = | 137 scoped_refptr<RulesRegistry> registry = |
| 138 new TestRulesRegistry(content::BrowserThread::UI, "" /*event_name*/, key); | 138 new TestRulesRegistry(content::BrowserThread::UI, "" /*event_name*/, key); |
| 139 | 139 |
| 140 // Add rules and check that their priorities are filled if they are empty. | 140 // Add rules and check that their priorities are filled if they are empty. |
| 141 | 141 |
| 142 std::vector<linked_ptr<RulesRegistry::Rule> > add_rules; | 142 std::vector<linked_ptr<RulesRegistry::Rule> > add_rules; |
| 143 add_rules.push_back(make_linked_ptr(new RulesRegistry::Rule)); | 143 add_rules.push_back(make_linked_ptr(new RulesRegistry::Rule)); |
| 144 add_rules[0]->priority.reset(new int(2)); | 144 add_rules[0]->priority.reset(new int(2)); |
| 145 add_rules.push_back(make_linked_ptr(new RulesRegistry::Rule)); | 145 add_rules.push_back(make_linked_ptr(new RulesRegistry::Rule)); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 159 EXPECT_EQ(2, std::min(*get_rules[0]->priority, *get_rules[1]->priority)); | 159 EXPECT_EQ(2, std::min(*get_rules[0]->priority, *get_rules[1]->priority)); |
| 160 EXPECT_EQ(RulesRegistry::DEFAULT_PRIORITY, | 160 EXPECT_EQ(RulesRegistry::DEFAULT_PRIORITY, |
| 161 std::max(*get_rules[0]->priority, *get_rules[1]->priority)); | 161 std::max(*get_rules[0]->priority, *get_rules[1]->priority)); |
| 162 | 162 |
| 163 // Make sure that deletion traits of registry are executed. | 163 // Make sure that deletion traits of registry are executed. |
| 164 registry = NULL; | 164 registry = NULL; |
| 165 message_loop.RunUntilIdle(); | 165 message_loop.RunUntilIdle(); |
| 166 } | 166 } |
| 167 | 167 |
| 168 } // namespace extensions | 168 } // namespace extensions |
| OLD | NEW |