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

Side by Side Diff: chrome/browser/extensions/api/declarative/rules_registry_with_cache_unittest.cc

Issue 1226353004: Generate all extension schema namespaces as "api" and instead vary the generated bundle names. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 5 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // Here we test the TestRulesRegistry which is the simplest possible 7 // Here we test the TestRulesRegistry which is the simplest possible
8 // implementation of RulesRegistryWithCache as a proxy for 8 // implementation of RulesRegistryWithCache as a proxy for
9 // RulesRegistryWithCache. 9 // RulesRegistryWithCache.
10 10
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 extension2_ = env_.MakeExtension(manifest_extra); 64 extension2_ = env_.MakeExtension(manifest_extra);
65 CHECK(extension2_.get()); 65 CHECK(extension2_.get());
66 CHECK_NE(extension2_->id(), extension1_->id()); 66 CHECK_NE(extension2_->id(), extension1_->id());
67 } 67 }
68 68
69 ~RulesRegistryWithCacheTest() override {} 69 ~RulesRegistryWithCacheTest() override {}
70 70
71 std::string AddRule(const std::string& extension_id, 71 std::string AddRule(const std::string& extension_id,
72 const std::string& rule_id, 72 const std::string& rule_id,
73 TestRulesRegistry* registry) { 73 TestRulesRegistry* registry) {
74 std::vector<linked_ptr<core_api::events::Rule>> add_rules; 74 std::vector<linked_ptr<api::events::Rule>> add_rules;
75 add_rules.push_back(make_linked_ptr(new core_api::events::Rule)); 75 add_rules.push_back(make_linked_ptr(new api::events::Rule));
76 add_rules[0]->id.reset(new std::string(rule_id)); 76 add_rules[0]->id.reset(new std::string(rule_id));
77 return registry->AddRules(extension_id, add_rules); 77 return registry->AddRules(extension_id, add_rules);
78 } 78 }
79 79
80 std::string AddRule(const std::string& extension_id, 80 std::string AddRule(const std::string& extension_id,
81 const std::string& rule_id) { 81 const std::string& rule_id) {
82 return AddRule(extension_id, rule_id, registry_.get()); 82 return AddRule(extension_id, rule_id, registry_.get());
83 } 83 }
84 84
85 std::string RemoveRule(const std::string& extension_id, 85 std::string RemoveRule(const std::string& extension_id,
86 const std::string& rule_id) { 86 const std::string& rule_id) {
87 std::vector<std::string> remove_rules; 87 std::vector<std::string> remove_rules;
88 remove_rules.push_back(rule_id); 88 remove_rules.push_back(rule_id);
89 return registry_->RemoveRules(extension_id, remove_rules); 89 return registry_->RemoveRules(extension_id, remove_rules);
90 } 90 }
91 91
92 int GetNumberOfRules(const std::string& extension_id, 92 int GetNumberOfRules(const std::string& extension_id,
93 TestRulesRegistry* registry) { 93 TestRulesRegistry* registry) {
94 std::vector<linked_ptr<core_api::events::Rule>> get_rules; 94 std::vector<linked_ptr<api::events::Rule>> get_rules;
95 registry->GetAllRules(extension_id, &get_rules); 95 registry->GetAllRules(extension_id, &get_rules);
96 return get_rules.size(); 96 return get_rules.size();
97 } 97 }
98 98
99 int GetNumberOfRules(const std::string& extension_id) { 99 int GetNumberOfRules(const std::string& extension_id) {
100 return GetNumberOfRules(extension_id, registry_.get()); 100 return GetNumberOfRules(extension_id, registry_.get());
101 } 101 }
102 102
103 TestingProfile* profile() const { return env_.profile(); } 103 TestingProfile* profile() const { return env_.profile(); }
104 104
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 TEST_F(RulesRegistryWithCacheTest, GetRules) { 180 TEST_F(RulesRegistryWithCacheTest, GetRules) {
181 // Prime registry. 181 // Prime registry.
182 EXPECT_EQ("", AddRule(extension1_->id(), kRuleId)); 182 EXPECT_EQ("", AddRule(extension1_->id(), kRuleId));
183 EXPECT_EQ("", AddRule(extension1_->id(), kRule2Id)); 183 EXPECT_EQ("", AddRule(extension1_->id(), kRule2Id));
184 EXPECT_EQ("", AddRule(extension2_->id(), kRuleId)); 184 EXPECT_EQ("", AddRule(extension2_->id(), kRuleId));
185 185
186 // Check that we get the correct rule and unknown rules are ignored. 186 // Check that we get the correct rule and unknown rules are ignored.
187 std::vector<std::string> rules_to_get; 187 std::vector<std::string> rules_to_get;
188 rules_to_get.push_back(kRuleId); 188 rules_to_get.push_back(kRuleId);
189 rules_to_get.push_back("unknown_rule"); 189 rules_to_get.push_back("unknown_rule");
190 std::vector<linked_ptr<core_api::events::Rule>> gotten_rules; 190 std::vector<linked_ptr<api::events::Rule>> gotten_rules;
191 registry_->GetRules(extension1_->id(), rules_to_get, &gotten_rules); 191 registry_->GetRules(extension1_->id(), rules_to_get, &gotten_rules);
192 ASSERT_EQ(1u, gotten_rules.size()); 192 ASSERT_EQ(1u, gotten_rules.size());
193 ASSERT_TRUE(gotten_rules[0]->id.get()); 193 ASSERT_TRUE(gotten_rules[0]->id.get());
194 EXPECT_EQ(kRuleId, *(gotten_rules[0]->id)); 194 EXPECT_EQ(kRuleId, *(gotten_rules[0]->id));
195 } 195 }
196 196
197 TEST_F(RulesRegistryWithCacheTest, GetAllRules) { 197 TEST_F(RulesRegistryWithCacheTest, GetAllRules) {
198 // Prime registry. 198 // Prime registry.
199 EXPECT_EQ("", AddRule(extension1_->id(), kRuleId)); 199 EXPECT_EQ("", AddRule(extension1_->id(), kRuleId));
200 EXPECT_EQ("", AddRule(extension1_->id(), kRule2Id)); 200 EXPECT_EQ("", AddRule(extension1_->id(), kRule2Id));
201 EXPECT_EQ("", AddRule(extension2_->id(), kRuleId)); 201 EXPECT_EQ("", AddRule(extension2_->id(), kRuleId));
202 202
203 // Check that we get the correct rules. 203 // Check that we get the correct rules.
204 std::vector<linked_ptr<core_api::events::Rule>> gotten_rules; 204 std::vector<linked_ptr<api::events::Rule>> gotten_rules;
205 registry_->GetAllRules(extension1_->id(), &gotten_rules); 205 registry_->GetAllRules(extension1_->id(), &gotten_rules);
206 EXPECT_EQ(2u, gotten_rules.size()); 206 EXPECT_EQ(2u, gotten_rules.size());
207 ASSERT_TRUE(gotten_rules[0]->id.get()); 207 ASSERT_TRUE(gotten_rules[0]->id.get());
208 ASSERT_TRUE(gotten_rules[1]->id.get()); 208 ASSERT_TRUE(gotten_rules[1]->id.get());
209 EXPECT_TRUE( (kRuleId == *(gotten_rules[0]->id) && 209 EXPECT_TRUE( (kRuleId == *(gotten_rules[0]->id) &&
210 kRule2Id == *(gotten_rules[1]->id)) || 210 kRule2Id == *(gotten_rules[1]->id)) ||
211 (kRuleId == *(gotten_rules[1]->id) && 211 (kRuleId == *(gotten_rules[1]->id) &&
212 kRule2Id == *(gotten_rules[0]->id)) ); 212 kRule2Id == *(gotten_rules[0]->id)) );
213 } 213 }
214 214
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 381
382 int write_count = store->write_count(); 382 int write_count = store->write_count();
383 EXPECT_EQ("", AddRule(extension1_->id(), kRuleId)); 383 EXPECT_EQ("", AddRule(extension1_->id(), kRuleId));
384 EXPECT_EQ("", AddRule(extension2_->id(), kRule2Id)); 384 EXPECT_EQ("", AddRule(extension2_->id(), kRule2Id));
385 env_.GetExtensionSystem()->SetReady(); 385 env_.GetExtensionSystem()->SetReady();
386 base::RunLoop().RunUntilIdle(); 386 base::RunLoop().RunUntilIdle();
387 EXPECT_EQ(write_count + 2, store->write_count()); 387 EXPECT_EQ(write_count + 2, store->write_count());
388 } 388 }
389 389
390 } // namespace extensions 390 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698