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

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

Issue 9422003: Migrate Declarative API bindings to new JSON objects generated by JSON compiler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix memory leaks Created 8 years, 9 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/api/declarative/rules_registry_service.h"
6
7 #include "base/bind.h"
8 #include "base/message_loop.h"
9 #include "chrome/browser/extensions/api/declarative/test_rules_registry.h"
10 #include "content/test/test_browser_thread.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace {
14 const char kExtensionId[] = "foo";
15
16 void InsertRule(scoped_refptr<extensions::RulesRegistry> registry,
17 const std::string id) {
18 std::vector<linked_ptr<extensions::RulesRegistry::Rule> > add_rules;
19 add_rules.push_back(make_linked_ptr(new extensions::RulesRegistry::Rule));
20 add_rules[0]->id.reset(new std::string(id));
21 std::string error = registry->AddRules(kExtensionId, add_rules);
22 EXPECT_TRUE(error.empty());
23 }
24
25 void VerifyNumberOfRules(scoped_refptr<extensions::RulesRegistry> registry,
26 size_t expected_number_of_rules) {
27 std::vector<linked_ptr<extensions::RulesRegistry::Rule> > get_rules;
28 std::string error = registry->GetAllRules(kExtensionId, &get_rules);
29 EXPECT_EQ(expected_number_of_rules, get_rules.size());
30 }
31
32 } // namespace
33
34 namespace extensions {
35
36 class RulesRegistryServiceTest : public testing::Test {
37 public:
38 RulesRegistryServiceTest()
39 : ui(content::BrowserThread::UI, &message_loop),
40 io(content::BrowserThread::IO, &message_loop) {}
41
42 virtual ~RulesRegistryServiceTest() {}
43
44 virtual void TearDown() OVERRIDE {
45 // Make sure that deletion traits of all registries are executed.
46 message_loop.RunAllPending();
47 }
48
49 protected:
50 MessageLoop message_loop;
51 content::TestBrowserThread ui;
52 content::TestBrowserThread io;
53 };
54
55 TEST_F(RulesRegistryServiceTest, TestConstructionAndMultiThreading) {
56 TestRulesRegistry* ui_registry = new TestRulesRegistry;
57 ui_registry->SetOwnerThread(content::BrowserThread::UI);
58
59 TestRulesRegistry* io_registry = new TestRulesRegistry;
60 io_registry->SetOwnerThread(content::BrowserThread::IO);
61
62 // Test registration.
63
64 RulesRegistryService registry_service(NULL);
65 registry_service.RegisterRulesRegistry("ui", make_scoped_refptr(ui_registry));
66 registry_service.RegisterRulesRegistry("io", make_scoped_refptr(io_registry));
67
68 EXPECT_TRUE(registry_service.GetRulesRegistry("ui").get());
69 EXPECT_TRUE(registry_service.GetRulesRegistry("io").get());
70 EXPECT_FALSE(registry_service.GetRulesRegistry("foo").get());
71
72 content::BrowserThread::PostTask(
73 content::BrowserThread::UI, FROM_HERE,
74 base::Bind(&InsertRule, registry_service.GetRulesRegistry("ui"),
75 "ui_task"));
76
77 content::BrowserThread::PostTask(
78 content::BrowserThread::IO, FROM_HERE,
79 base::Bind(&InsertRule, registry_service.GetRulesRegistry("io"),
80 "io_task"));
81
82 content::BrowserThread::PostTask(
83 content::BrowserThread::UI, FROM_HERE,
84 base::Bind(&VerifyNumberOfRules,
85 registry_service.GetRulesRegistry("ui"), 1));
86
87 content::BrowserThread::PostTask(
88 content::BrowserThread::IO, FROM_HERE,
89 base::Bind(&VerifyNumberOfRules,
90 registry_service.GetRulesRegistry("io"), 1));
91
92 message_loop.RunAllPending();
93
94 // Test extension unloading.
95
96 registry_service.SimulateExtensionUnloaded(kExtensionId);
97
98 content::BrowserThread::PostTask(
99 content::BrowserThread::UI, FROM_HERE,
100 base::Bind(&VerifyNumberOfRules,
101 registry_service.GetRulesRegistry("ui"), 0));
102
103 content::BrowserThread::PostTask(
104 content::BrowserThread::IO, FROM_HERE,
105 base::Bind(&VerifyNumberOfRules,
106 registry_service.GetRulesRegistry("io"), 0));
107
108 message_loop.RunAllPending();
109 }
110
111 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698