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

Side by Side Diff: chrome/browser/extensions/api/mdns/mdns_api_unittest.cc

Issue 1165913002: [Cleanup] Used scoped pointers in KeyedServiceFactory's SetTestingFactory functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Finish renaming profile -> context Created 5 years, 6 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "base/memory/scoped_ptr.h"
5 #include "chrome/browser/extensions/api/mdns/mdns_api.h" 6 #include "chrome/browser/extensions/api/mdns/mdns_api.h"
6 #include "chrome/browser/extensions/extension_service.h" 7 #include "chrome/browser/extensions/extension_service.h"
7 #include "chrome/browser/extensions/extension_service_test_base.h" 8 #include "chrome/browser/extensions/extension_service_test_base.h"
8 #include "chrome/browser/extensions/test_extension_system.h" 9 #include "chrome/browser/extensions/test_extension_system.h"
9 #include "chrome/common/extensions/api/mdns.h" 10 #include "chrome/common/extensions/api/mdns.h"
10 #include "content/public/browser/browser_context.h" 11 #include "content/public/browser/browser_context.h"
11 #include "content/public/test/mock_render_process_host.h" 12 #include "content/public/test/mock_render_process_host.h"
12 #include "extensions/browser/event_router_factory.h" 13 #include "extensions/browser/event_router_factory.h"
13 #include "extensions/browser/extension_prefs_factory.h" 14 #include "extensions/browser/extension_prefs.h"
14 #include "extensions/browser/extension_registry.h" 15 #include "extensions/browser/extension_registry.h"
15 #include "extensions/common/manifest_constants.h" 16 #include "extensions/common/manifest_constants.h"
16 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
18 19
19 namespace extensions { 20 namespace extensions {
20 21
21 namespace { 22 namespace {
22 23
23 KeyedService* MDnsAPITestingFactoryFunction(content::BrowserContext* context) { 24 scoped_ptr<KeyedService> MDnsAPITestingFactoryFunction(
24 return new MDnsAPI(context); 25 content::BrowserContext* context) {
26 return make_scoped_ptr(new MDnsAPI(context));
25 } 27 }
26 28
27 KeyedService* BuildEventRouter(content::BrowserContext* profile) { 29 scoped_ptr<KeyedService> BuildEventRouter(content::BrowserContext* context) {
28 return new extensions::EventRouter( 30 return make_scoped_ptr(
29 profile, 31 new extensions::EventRouter(context, ExtensionPrefs::Get(context)));
30 ExtensionPrefsFactory::GetInstance()->GetForBrowserContext((profile)));
31 } 32 }
32 33
33 // For ExtensionService interface when it requires a path that is not used. 34 // For ExtensionService interface when it requires a path that is not used.
34 base::FilePath bogus_file_pathname(const std::string& name) { 35 base::FilePath bogus_file_pathname(const std::string& name) {
35 return base::FilePath(FILE_PATH_LITERAL("//foobar_nonexistent")) 36 return base::FilePath(FILE_PATH_LITERAL("//foobar_nonexistent"))
36 .AppendASCII(name); 37 .AppendASCII(name);
37 } 38 }
38 39
39 class MockDnsSdRegistry : public DnsSdRegistry { 40 class MockDnsSdRegistry : public DnsSdRegistry {
40 public: 41 public:
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 render_process_host_.reset( 87 render_process_host_.reset(
87 new content::MockRenderProcessHost(browser_context())); 88 new content::MockRenderProcessHost(browser_context()));
88 } 89 }
89 90
90 void TearDown() override { 91 void TearDown() override {
91 EXPECT_CALL(*dns_sd_registry(), 92 EXPECT_CALL(*dns_sd_registry(),
92 RemoveObserver(MDnsAPI::Get(browser_context()))) 93 RemoveObserver(MDnsAPI::Get(browser_context())))
93 .Times(1); 94 .Times(1);
94 render_process_host_.reset(); 95 render_process_host_.reset();
95 extensions::ExtensionServiceTestBase::TearDown(); 96 extensions::ExtensionServiceTestBase::TearDown();
96 MDnsAPI::GetFactoryInstance()->SetTestingFactory(
97 browser_context(),
98 nullptr);
99
100 registry_ = nullptr;
101 } 97 }
102 98
103 virtual MockDnsSdRegistry* dns_sd_registry() { 99 virtual MockDnsSdRegistry* dns_sd_registry() {
104 return registry_; 100 return registry_;
105 } 101 }
106 102
107 // Constructs an extension according to the parameters that matter most to 103 // Constructs an extension according to the parameters that matter most to
108 // MDnsAPI the local unit tests. 104 // MDnsAPI the local unit tests.
109 const scoped_refptr<extensions::Extension> CreateExtension( 105 const scoped_refptr<extensions::Extension> CreateExtension(
110 std::string name, 106 std::string name,
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 ExtensionPrefs* extension_prefs) : 215 ExtensionPrefs* extension_prefs) :
220 EventRouter(browser_context, extension_prefs) {} 216 EventRouter(browser_context, extension_prefs) {}
221 virtual ~MockEventRouter() {} 217 virtual ~MockEventRouter() {}
222 218
223 virtual void BroadcastEvent(scoped_ptr<Event> event) { 219 virtual void BroadcastEvent(scoped_ptr<Event> event) {
224 BroadcastEventPtr(event.get()); 220 BroadcastEventPtr(event.get());
225 } 221 }
226 MOCK_METHOD1(BroadcastEventPtr, void(Event* event)); 222 MOCK_METHOD1(BroadcastEventPtr, void(Event* event));
227 }; 223 };
228 224
229 KeyedService* MockEventRouterFactoryFunction(content::BrowserContext* profile) { 225 scoped_ptr<KeyedService> MockEventRouterFactoryFunction(
230 return new MockEventRouter( 226 content::BrowserContext* context) {
231 profile, 227 return make_scoped_ptr(
232 ExtensionPrefsFactory::GetInstance()->GetForBrowserContext((profile))); 228 new MockEventRouter(context, ExtensionPrefs::Get(context)));
233 } 229 }
234 230
235 class MDnsAPIMaxServicesTest : public MDnsAPITest { 231 class MDnsAPIMaxServicesTest : public MDnsAPITest {
236 public: 232 public:
237 MockEventRouter* event_router() { 233 MockEventRouter* event_router() {
238 return static_cast<MockEventRouter*>(EventRouter::Get(browser_context())); 234 return static_cast<MockEventRouter*>(EventRouter::Get(browser_context()));
239 } 235 }
240 }; 236 };
241 237
242 class EventServiceListSizeMatcher : 238 class EventServiceListSizeMatcher :
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 *event_router(), 304 *event_router(),
309 BroadcastEventPtr( 305 BroadcastEventPtr(
310 testing::Pointee(EventServiceListSize(size_t(64))))) 306 testing::Pointee(EventServiceListSize(size_t(64)))))
311 .Times(1); 307 .Times(1);
312 dns_sd_registry()->DispatchMDnsEvent("_testing._tcp.local", services); 308 dns_sd_registry()->DispatchMDnsEvent("_testing._tcp.local", services);
313 } 309 }
314 310
315 } // empty namespace 311 } // empty namespace
316 312
317 } // namespace extensions 313 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698