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

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

Issue 764643002: Remove WebViewKey in rules registry. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits. Created 6 years 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_service.h" 5 #include "extensions/browser/api/declarative/rules_registry_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "chrome/test/base/testing_profile.h" 9 #include "chrome/test/base/testing_profile.h"
10 #include "content/public/test/test_browser_thread.h" 10 #include "content/public/test/test_browser_thread.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 message_loop_.RunUntilIdle(); 48 message_loop_.RunUntilIdle();
49 } 49 }
50 50
51 protected: 51 protected:
52 base::MessageLoop message_loop_; 52 base::MessageLoop message_loop_;
53 content::TestBrowserThread ui_; 53 content::TestBrowserThread ui_;
54 content::TestBrowserThread io_; 54 content::TestBrowserThread io_;
55 }; 55 };
56 56
57 TEST_F(RulesRegistryServiceTest, TestConstructionAndMultiThreading) { 57 TEST_F(RulesRegistryServiceTest, TestConstructionAndMultiThreading) {
58 const RulesRegistry::WebViewKey key(0, 0); 58 RulesRegistryService registry_service(NULL);
59
60 int key = RulesRegistryService::kDefaultRulesRegistryID;
59 TestRulesRegistry* ui_registry = 61 TestRulesRegistry* ui_registry =
60 new TestRulesRegistry(content::BrowserThread::UI, "ui", key); 62 new TestRulesRegistry(content::BrowserThread::UI, "ui", key);
61 63
62 TestRulesRegistry* io_registry = 64 TestRulesRegistry* io_registry =
63 new TestRulesRegistry(content::BrowserThread::IO, "io", key); 65 new TestRulesRegistry(content::BrowserThread::IO, "io", key);
64 66
65 // Test registration. 67 // Test registration.
66 68
67 RulesRegistryService registry_service(NULL);
68 registry_service.RegisterRulesRegistry(make_scoped_refptr(ui_registry)); 69 registry_service.RegisterRulesRegistry(make_scoped_refptr(ui_registry));
69 registry_service.RegisterRulesRegistry(make_scoped_refptr(io_registry)); 70 registry_service.RegisterRulesRegistry(make_scoped_refptr(io_registry));
70 71
71 EXPECT_TRUE(registry_service.GetRulesRegistry(key, "ui").get()); 72 EXPECT_TRUE(registry_service.GetRulesRegistry(key, "ui").get());
72 EXPECT_TRUE(registry_service.GetRulesRegistry(key, "io").get()); 73 EXPECT_TRUE(registry_service.GetRulesRegistry(key, "io").get());
73 EXPECT_FALSE(registry_service.GetRulesRegistry(key, "foo").get()); 74 EXPECT_FALSE(registry_service.GetRulesRegistry(key, "foo").get());
74 75
75 content::BrowserThread::PostTask( 76 content::BrowserThread::PostTask(
76 content::BrowserThread::UI, FROM_HERE, 77 content::BrowserThread::UI, FROM_HERE,
77 base::Bind(&InsertRule, registry_service.GetRulesRegistry(key, "ui"), 78 base::Bind(&InsertRule, registry_service.GetRulesRegistry(key, "ui"),
78 "ui_task")); 79 "ui_task"));
79 80
80 content::BrowserThread::PostTask( 81 content::BrowserThread::PostTask(
81 content::BrowserThread::IO, FROM_HERE, 82 content::BrowserThread::IO, FROM_HERE,
82 base::Bind(&InsertRule, registry_service.GetRulesRegistry(key, "io"), 83 base::Bind(&InsertRule, registry_service.GetRulesRegistry(key, "io"),
83 "io_task")); 84 "io_task"));
84 85
85 content::BrowserThread::PostTask( 86 content::BrowserThread::PostTask(
86 content::BrowserThread::UI, FROM_HERE, 87 content::BrowserThread::UI, FROM_HERE,
87 base::Bind(&VerifyNumberOfRules, 88 base::Bind(&VerifyNumberOfRules,
88 registry_service.GetRulesRegistry(key, "ui"), 1)); 89 registry_service.GetRulesRegistry(key, "ui"), 1));
89 90
90 content::BrowserThread::PostTask( 91 content::BrowserThread::PostTask(
91 content::BrowserThread::IO, FROM_HERE, 92 content::BrowserThread::IO, FROM_HERE,
92 base::Bind(&VerifyNumberOfRules, 93 base::Bind(&VerifyNumberOfRules,
93 registry_service.GetRulesRegistry(key, "io"), 1)); 94 registry_service.GetRulesRegistry(key, "io"), 1));
94 95
95 message_loop_.RunUntilIdle(); 96 message_loop_.RunUntilIdle();
96 97
97 // Test extension uninstalling. 98 // Test extension uninstalling.
98 99
99 registry_service.SimulateExtensionUninstalled(kExtensionId); 100 registry_service.SimulateExtensionUninstalled(kExtensionId);
100 101
101 content::BrowserThread::PostTask( 102 content::BrowserThread::PostTask(
102 content::BrowserThread::UI, FROM_HERE, 103 content::BrowserThread::UI, FROM_HERE,
103 base::Bind(&VerifyNumberOfRules, 104 base::Bind(&VerifyNumberOfRules,
104 registry_service.GetRulesRegistry(key, "ui"), 0)); 105 registry_service.GetRulesRegistry(key, "ui"), 0));
105 106
106 content::BrowserThread::PostTask( 107 content::BrowserThread::PostTask(
107 content::BrowserThread::IO, FROM_HERE, 108 content::BrowserThread::IO, FROM_HERE,
108 base::Bind(&VerifyNumberOfRules, 109 base::Bind(&VerifyNumberOfRules,
109 registry_service.GetRulesRegistry(key, "io"), 0)); 110 registry_service.GetRulesRegistry(key, "io"), 0));
110 111
111 message_loop_.RunUntilIdle(); 112 message_loop_.RunUntilIdle();
112 } 113 }
113 114
114 // This test verifies that removing rules registries by process ID works as
115 // intended. This test ensures that removing registries associated with one
116 // Webview embedder process does not remove registries associated with the
117 // other.
118 TEST_F(RulesRegistryServiceTest, TestWebViewKey) {
119 const int kEmbedderProcessID1 = 1;
120 const int kEmbedderProcessID2 = 2;
121 const int kWebViewInstanceID = 1;
122
123 const RulesRegistry::WebViewKey key1(kEmbedderProcessID1, kWebViewInstanceID);
124 const RulesRegistry::WebViewKey key2(kEmbedderProcessID2, kWebViewInstanceID);
125
126 TestRulesRegistry* ui_registry_key1 =
127 new TestRulesRegistry(content::BrowserThread::UI, "ui", key1);
128 TestRulesRegistry* ui_registry_key2 =
129 new TestRulesRegistry(content::BrowserThread::UI, "ui", key2);
130
131 RulesRegistryService registry_service(NULL);
132 registry_service.RegisterRulesRegistry(make_scoped_refptr(ui_registry_key1));
133 registry_service.RegisterRulesRegistry(make_scoped_refptr(ui_registry_key2));
134
135 content::BrowserThread::PostTask(
136 content::BrowserThread::UI, FROM_HERE,
137 base::Bind(&InsertRule, registry_service.GetRulesRegistry(key1, "ui"),
138 "ui_task"));
139 content::BrowserThread::PostTask(
140 content::BrowserThread::UI, FROM_HERE,
141 base::Bind(&InsertRule, registry_service.GetRulesRegistry(key2, "ui"),
142 "ui_task"));
143 message_loop_.RunUntilIdle();
144
145 registry_service.RemoveWebViewRulesRegistries(kEmbedderProcessID1);
146 EXPECT_FALSE(registry_service.GetRulesRegistry(key1, "ui").get());
147 EXPECT_TRUE(registry_service.GetRulesRegistry(key2, "ui").get());
148 }
149
150 TEST_F(RulesRegistryServiceTest, TestWebViewWebRequestRegistryHasNoCache) {
151 const int kEmbedderProcessID = 1;
152 const int kWebViewInstanceID = 1;
153 const RulesRegistry::WebViewKey key(kEmbedderProcessID, kWebViewInstanceID);
154 TestingProfile profile;
155 RulesRegistryService registry_service(&profile);
156 RulesRegistry* registry =
157 registry_service.GetRulesRegistry(
158 key,
159 declarative_webrequest_constants::kOnRequest).get();
160 EXPECT_TRUE(registry);
161 EXPECT_FALSE(registry->rules_cache_delegate_for_testing());
162 }
163
164 } // namespace extensions 115 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698