OLD | NEW |
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/event_router_forwarder.h" | 5 #include "chrome/browser/extensions/event_router_forwarder.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 "base/power_monitor/power_monitor.h" | 9 #include "base/power_monitor/power_monitor.h" |
10 #include "base/power_monitor/power_monitor_device_source.h" | 10 #include "base/power_monitor/power_monitor_device_source.h" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 virtual void SetUp() { | 103 virtual void SetUp() { |
104 ASSERT_TRUE(profile_manager_.SetUp()); | 104 ASSERT_TRUE(profile_manager_.SetUp()); |
105 | 105 |
106 // Inject a BrowserProcess with a ProfileManager. | 106 // Inject a BrowserProcess with a ProfileManager. |
107 ASSERT_TRUE(io_thread_.Start()); | 107 ASSERT_TRUE(io_thread_.Start()); |
108 | 108 |
109 profile1_ = profile_manager_.CreateTestingProfile("one"); | 109 profile1_ = profile_manager_.CreateTestingProfile("one"); |
110 profile2_ = profile_manager_.CreateTestingProfile("two"); | 110 profile2_ = profile_manager_.CreateTestingProfile("two"); |
111 } | 111 } |
112 | 112 |
113 TestingProfile* CreateIncognitoProfile(TestingProfile* base) { | |
114 TestingProfile::Builder builder; | |
115 builder.SetIncognito(); | |
116 scoped_ptr<TestingProfile> incognito = builder.Build(); | |
117 TestingProfile* incognito_ptr = incognito.get(); | |
118 // Incognito profile now owned by |base| | |
119 base->SetOffTheRecordProfile(incognito.PassAs<Profile>()); | |
120 return incognito_ptr; | |
121 } | |
122 | |
123 base::MessageLoopForUI message_loop_; | 113 base::MessageLoopForUI message_loop_; |
124 content::TestBrowserThread ui_thread_; | 114 content::TestBrowserThread ui_thread_; |
125 content::TestBrowserThread io_thread_; | 115 content::TestBrowserThread io_thread_; |
126 TestingProfileManager profile_manager_; | 116 TestingProfileManager profile_manager_; |
127 scoped_ptr<base::PowerMonitor> dummy; | 117 scoped_ptr<base::PowerMonitor> dummy; |
128 // Profiles are weak pointers, owned by ProfileManager in |browser_process_|. | 118 // Profiles are weak pointers, owned by ProfileManager in |browser_process_|. |
129 TestingProfile* profile1_; | 119 TestingProfile* profile1_; |
130 TestingProfile* profile2_; | 120 TestingProfile* profile2_; |
131 }; | 121 }; |
132 | 122 |
133 TEST_F(EventRouterForwarderTest, BroadcastRendererUI) { | 123 TEST_F(EventRouterForwarderTest, BroadcastRendererUI) { |
134 scoped_refptr<MockEventRouterForwarder> event_router( | 124 scoped_refptr<MockEventRouterForwarder> event_router( |
135 new MockEventRouterForwarder); | 125 new MockEventRouterForwarder); |
136 GURL url; | 126 GURL url; |
137 EXPECT_CALL(*event_router.get(), | 127 EXPECT_CALL(*event_router.get(), |
138 CallEventRouter(profile1_, "", kEventName, profile1_, url)); | 128 CallEventRouter(profile1_, "", kEventName, profile1_, url)); |
139 EXPECT_CALL(*event_router.get(), | 129 EXPECT_CALL(*event_router.get(), |
140 CallEventRouter(profile2_, "", kEventName, profile2_, url)); | 130 CallEventRouter(profile2_, "", kEventName, profile2_, url)); |
141 BroadcastEventToRenderers(event_router.get(), kEventName, url); | 131 BroadcastEventToRenderers(event_router.get(), kEventName, url); |
142 } | 132 } |
143 | 133 |
144 TEST_F(EventRouterForwarderTest, BroadcastRendererUIIncognito) { | 134 TEST_F(EventRouterForwarderTest, BroadcastRendererUIIncognito) { |
145 scoped_refptr<MockEventRouterForwarder> event_router( | 135 scoped_refptr<MockEventRouterForwarder> event_router( |
146 new MockEventRouterForwarder); | 136 new MockEventRouterForwarder); |
147 using ::testing::_; | 137 using ::testing::_; |
148 GURL url; | 138 GURL url; |
149 Profile* incognito = CreateIncognitoProfile(profile1_); | 139 Profile* incognito = profile1_->GetOffTheRecordProfile(); |
150 EXPECT_CALL(*event_router.get(), | 140 EXPECT_CALL(*event_router.get(), |
151 CallEventRouter(profile1_, "", kEventName, profile1_, url)); | 141 CallEventRouter(profile1_, "", kEventName, profile1_, url)); |
152 EXPECT_CALL(*event_router.get(), CallEventRouter(incognito, _, _, _, _)) | 142 EXPECT_CALL(*event_router.get(), CallEventRouter(incognito, _, _, _, _)) |
153 .Times(0); | 143 .Times(0); |
154 EXPECT_CALL(*event_router.get(), | 144 EXPECT_CALL(*event_router.get(), |
155 CallEventRouter(profile2_, "", kEventName, profile2_, url)); | 145 CallEventRouter(profile2_, "", kEventName, profile2_, url)); |
156 BroadcastEventToRenderers(event_router.get(), kEventName, url); | 146 BroadcastEventToRenderers(event_router.get(), kEventName, url); |
157 } | 147 } |
158 | 148 |
159 // This is the canonical test for passing control flow from the IO thread | 149 // This is the canonical test for passing control flow from the IO thread |
(...skipping 29 matching lines...) Expand all Loading... |
189 CallEventRouter(profile1_, "", kEventName, profile1_, url)); | 179 CallEventRouter(profile1_, "", kEventName, profile1_, url)); |
190 EXPECT_CALL(*event_router.get(), CallEventRouter(profile2_, _, _, _, _)) | 180 EXPECT_CALL(*event_router.get(), CallEventRouter(profile2_, _, _, _, _)) |
191 .Times(0); | 181 .Times(0); |
192 DispatchEventToRenderers(event_router.get(), kEventName, profile1_, true, | 182 DispatchEventToRenderers(event_router.get(), kEventName, profile1_, true, |
193 url); | 183 url); |
194 } | 184 } |
195 | 185 |
196 TEST_F(EventRouterForwarderTest, UnicastRendererUIRestrictedIncognito1) { | 186 TEST_F(EventRouterForwarderTest, UnicastRendererUIRestrictedIncognito1) { |
197 scoped_refptr<MockEventRouterForwarder> event_router( | 187 scoped_refptr<MockEventRouterForwarder> event_router( |
198 new MockEventRouterForwarder); | 188 new MockEventRouterForwarder); |
199 Profile* incognito = CreateIncognitoProfile(profile1_); | 189 Profile* incognito = profile1_->GetOffTheRecordProfile(); |
200 using ::testing::_; | 190 using ::testing::_; |
201 GURL url; | 191 GURL url; |
202 EXPECT_CALL(*event_router.get(), | 192 EXPECT_CALL(*event_router.get(), |
203 CallEventRouter(profile1_, "", kEventName, profile1_, url)); | 193 CallEventRouter(profile1_, "", kEventName, profile1_, url)); |
204 EXPECT_CALL(*event_router.get(), CallEventRouter(incognito, _, _, _, _)) | 194 EXPECT_CALL(*event_router.get(), CallEventRouter(incognito, _, _, _, _)) |
205 .Times(0); | 195 .Times(0); |
206 EXPECT_CALL(*event_router.get(), CallEventRouter(profile2_, _, _, _, _)) | 196 EXPECT_CALL(*event_router.get(), CallEventRouter(profile2_, _, _, _, _)) |
207 .Times(0); | 197 .Times(0); |
208 DispatchEventToRenderers(event_router.get(), kEventName, profile1_, true, | 198 DispatchEventToRenderers(event_router.get(), kEventName, profile1_, true, |
209 url); | 199 url); |
210 } | 200 } |
211 | 201 |
212 TEST_F(EventRouterForwarderTest, UnicastRendererUIRestrictedIncognito2) { | 202 TEST_F(EventRouterForwarderTest, UnicastRendererUIRestrictedIncognito2) { |
213 scoped_refptr<MockEventRouterForwarder> event_router( | 203 scoped_refptr<MockEventRouterForwarder> event_router( |
214 new MockEventRouterForwarder); | 204 new MockEventRouterForwarder); |
215 Profile* incognito = CreateIncognitoProfile(profile1_); | 205 Profile* incognito = profile1_->GetOffTheRecordProfile(); |
216 using ::testing::_; | 206 using ::testing::_; |
217 GURL url; | 207 GURL url; |
218 EXPECT_CALL(*event_router.get(), CallEventRouter(profile1_, _, _, _, _)) | 208 EXPECT_CALL(*event_router.get(), CallEventRouter(profile1_, _, _, _, _)) |
219 .Times(0); | 209 .Times(0); |
220 EXPECT_CALL(*event_router.get(), | 210 EXPECT_CALL(*event_router.get(), |
221 CallEventRouter(incognito, "", kEventName, incognito, url)); | 211 CallEventRouter(incognito, "", kEventName, incognito, url)); |
222 EXPECT_CALL(*event_router.get(), CallEventRouter(profile2_, _, _, _, _)) | 212 EXPECT_CALL(*event_router.get(), CallEventRouter(profile2_, _, _, _, _)) |
223 .Times(0); | 213 .Times(0); |
224 DispatchEventToRenderers(event_router.get(), kEventName, incognito, true, | 214 DispatchEventToRenderers(event_router.get(), kEventName, incognito, true, |
225 url); | 215 url); |
226 } | 216 } |
227 | 217 |
228 TEST_F(EventRouterForwarderTest, UnicastRendererUIUnrestricted) { | 218 TEST_F(EventRouterForwarderTest, UnicastRendererUIUnrestricted) { |
229 scoped_refptr<MockEventRouterForwarder> event_router( | 219 scoped_refptr<MockEventRouterForwarder> event_router( |
230 new MockEventRouterForwarder); | 220 new MockEventRouterForwarder); |
231 using ::testing::_; | 221 using ::testing::_; |
232 GURL url; | 222 GURL url; |
233 EXPECT_CALL(*event_router.get(), | 223 EXPECT_CALL(*event_router.get(), |
234 CallEventRouter(profile1_, "", kEventName, NULL, url)); | 224 CallEventRouter(profile1_, "", kEventName, NULL, url)); |
235 EXPECT_CALL(*event_router.get(), CallEventRouter(profile2_, _, _, _, _)) | 225 EXPECT_CALL(*event_router.get(), CallEventRouter(profile2_, _, _, _, _)) |
236 .Times(0); | 226 .Times(0); |
237 DispatchEventToRenderers(event_router.get(), kEventName, profile1_, false, | 227 DispatchEventToRenderers(event_router.get(), kEventName, profile1_, false, |
238 url); | 228 url); |
239 } | 229 } |
240 | 230 |
241 TEST_F(EventRouterForwarderTest, UnicastRendererUIUnrestrictedIncognito) { | 231 TEST_F(EventRouterForwarderTest, UnicastRendererUIUnrestrictedIncognito) { |
242 scoped_refptr<MockEventRouterForwarder> event_router( | 232 scoped_refptr<MockEventRouterForwarder> event_router( |
243 new MockEventRouterForwarder); | 233 new MockEventRouterForwarder); |
244 Profile* incognito = CreateIncognitoProfile(profile1_); | 234 Profile* incognito = profile1_->GetOffTheRecordProfile(); |
245 using ::testing::_; | 235 using ::testing::_; |
246 GURL url; | 236 GURL url; |
247 EXPECT_CALL(*event_router.get(), | 237 EXPECT_CALL(*event_router.get(), |
248 CallEventRouter(profile1_, "", kEventName, NULL, url)); | 238 CallEventRouter(profile1_, "", kEventName, NULL, url)); |
249 EXPECT_CALL(*event_router.get(), CallEventRouter(incognito, _, _, _, _)) | 239 EXPECT_CALL(*event_router.get(), CallEventRouter(incognito, _, _, _, _)) |
250 .Times(0); | 240 .Times(0); |
251 EXPECT_CALL(*event_router.get(), CallEventRouter(profile2_, _, _, _, _)) | 241 EXPECT_CALL(*event_router.get(), CallEventRouter(profile2_, _, _, _, _)) |
252 .Times(0); | 242 .Times(0); |
253 DispatchEventToRenderers(event_router.get(), kEventName, profile1_, false, | 243 DispatchEventToRenderers(event_router.get(), kEventName, profile1_, false, |
254 url); | 244 url); |
(...skipping 30 matching lines...) Expand all Loading... |
285 GURL url; | 275 GURL url; |
286 EXPECT_CALL(*event_router.get(), | 276 EXPECT_CALL(*event_router.get(), |
287 CallEventRouter(profile1_, kExt, kEventName, NULL, url)); | 277 CallEventRouter(profile1_, kExt, kEventName, NULL, url)); |
288 EXPECT_CALL(*event_router.get(), CallEventRouter(profile2_, _, _, _, _)) | 278 EXPECT_CALL(*event_router.get(), CallEventRouter(profile2_, _, _, _, _)) |
289 .Times(0); | 279 .Times(0); |
290 DispatchEventToExtension(event_router.get(), kExt, kEventName, profile1_, | 280 DispatchEventToExtension(event_router.get(), kExt, kEventName, profile1_, |
291 false, url); | 281 false, url); |
292 } | 282 } |
293 | 283 |
294 } // namespace extensions | 284 } // namespace extensions |
OLD | NEW |