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

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

Issue 28273006: <webview>: Implement declarativeWebRequest API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed nits Created 7 years, 1 month 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 "chrome/browser/extensions/api/declarative/rules_registry.h" 5 #include "chrome/browser/extensions/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 "chrome/browser/extensions/api/declarative/test_rules_registry.h" 10 #include "chrome/browser/extensions/api/declarative/test_rules_registry.h"
11 #include "content/public/test/test_browser_thread.h" 11 #include "content/public/test/test_browser_thread.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 namespace { 14 namespace {
15 const char kExtensionId[] = "foobar"; 15 const char kExtensionId[] = "foobar";
16 const char kRuleId[] = "foo"; 16 const char kRuleId[] = "foo";
17 } // namespace 17 } // namespace
18 18
19 namespace extensions { 19 namespace extensions {
20 20
21 TEST(InitializingRulesRegistryTest, FillOptionalIdentifiers) { 21 TEST(InitializingRulesRegistryTest, FillOptionalIdentifiers) {
22 base::MessageLoopForUI message_loop; 22 base::MessageLoopForUI message_loop;
23 content::TestBrowserThread thread(content::BrowserThread::UI, &message_loop); 23 content::TestBrowserThread thread(content::BrowserThread::UI, &message_loop);
24 24
25 const RulesRegistry::WebViewKey key(0, 0);
25 std::string error; 26 std::string error;
26 scoped_refptr<RulesRegistry> registry = 27 scoped_refptr<RulesRegistry> registry =
27 new TestRulesRegistry(content::BrowserThread::UI, "" /*event_name*/); 28 new TestRulesRegistry(content::BrowserThread::UI, "" /*event_name*/, key);
28 29
29 // Add rules and check that their identifiers are filled and unique. 30 // Add rules and check that their identifiers are filled and unique.
30 31
31 std::vector<linked_ptr<RulesRegistry::Rule> > add_rules; 32 std::vector<linked_ptr<RulesRegistry::Rule> > add_rules;
32 add_rules.push_back(make_linked_ptr(new RulesRegistry::Rule)); 33 add_rules.push_back(make_linked_ptr(new RulesRegistry::Rule));
33 add_rules.push_back(make_linked_ptr(new RulesRegistry::Rule)); 34 add_rules.push_back(make_linked_ptr(new RulesRegistry::Rule));
34 error = registry->AddRules(kExtensionId, add_rules); 35 error = registry->AddRules(kExtensionId, add_rules);
35 EXPECT_TRUE(error.empty()); 36 EXPECT_TRUE(error.empty());
36 37
37 std::vector<linked_ptr<RulesRegistry::Rule> > get_rules; 38 std::vector<linked_ptr<RulesRegistry::Rule> > get_rules;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 131
131 // Make sure that deletion traits of registry are executed. 132 // Make sure that deletion traits of registry are executed.
132 registry = NULL; 133 registry = NULL;
133 message_loop.RunUntilIdle(); 134 message_loop.RunUntilIdle();
134 } 135 }
135 136
136 TEST(InitializingRulesRegistryTest, FillOptionalPriority) { 137 TEST(InitializingRulesRegistryTest, FillOptionalPriority) {
137 base::MessageLoopForUI message_loop; 138 base::MessageLoopForUI message_loop;
138 content::TestBrowserThread thread(content::BrowserThread::UI, &message_loop); 139 content::TestBrowserThread thread(content::BrowserThread::UI, &message_loop);
139 140
141 const RulesRegistry::WebViewKey key(0, 0);
140 std::string error; 142 std::string error;
141 scoped_refptr<RulesRegistry> registry = 143 scoped_refptr<RulesRegistry> registry =
142 new TestRulesRegistry(content::BrowserThread::UI, "" /*event_name*/); 144 new TestRulesRegistry(content::BrowserThread::UI, "" /*event_name*/, key);
143 145
144 // Add rules and check that their priorities are filled if they are empty. 146 // Add rules and check that their priorities are filled if they are empty.
145 147
146 std::vector<linked_ptr<RulesRegistry::Rule> > add_rules; 148 std::vector<linked_ptr<RulesRegistry::Rule> > add_rules;
147 add_rules.push_back(make_linked_ptr(new RulesRegistry::Rule)); 149 add_rules.push_back(make_linked_ptr(new RulesRegistry::Rule));
148 add_rules[0]->priority.reset(new int(2)); 150 add_rules[0]->priority.reset(new int(2));
149 add_rules.push_back(make_linked_ptr(new RulesRegistry::Rule)); 151 add_rules.push_back(make_linked_ptr(new RulesRegistry::Rule));
150 error = registry->AddRules(kExtensionId, add_rules); 152 error = registry->AddRules(kExtensionId, add_rules);
151 EXPECT_TRUE(error.empty()); 153 EXPECT_TRUE(error.empty());
152 154
(...skipping 11 matching lines...) Expand all
164 EXPECT_EQ(2, std::min(*get_rules[0]->priority, *get_rules[1]->priority)); 166 EXPECT_EQ(2, std::min(*get_rules[0]->priority, *get_rules[1]->priority));
165 EXPECT_EQ(RulesRegistry::DEFAULT_PRIORITY, 167 EXPECT_EQ(RulesRegistry::DEFAULT_PRIORITY,
166 std::max(*get_rules[0]->priority, *get_rules[1]->priority)); 168 std::max(*get_rules[0]->priority, *get_rules[1]->priority));
167 169
168 // Make sure that deletion traits of registry are executed. 170 // Make sure that deletion traits of registry are executed.
169 registry = NULL; 171 registry = NULL;
170 message_loop.RunUntilIdle(); 172 message_loop.RunUntilIdle();
171 } 173 }
172 174
173 } // namespace extensions 175 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698