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

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: Rebase 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_factory.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* profile) {
Devlin 2015/06/08 19:29:43 nit: rename |profile| to |browser_context| or |con
Ilya Sherman 2015/06/08 22:11:43 Done.
28 return new extensions::EventRouter( 30 return make_scoped_ptr(new extensions::EventRouter(
29 profile, 31 profile,
30 ExtensionPrefsFactory::GetInstance()->GetForBrowserContext((profile))); 32 ExtensionPrefsFactory::GetInstance()->GetForBrowserContext((profile))));
Devlin 2015/06/08 19:29:43 nit: Since you're here, could you update this to b
Ilya Sherman 2015/06/08 22:11:43 Done.
31 } 33 }
32 34
33 // For ExtensionService interface when it requires a path that is not used. 35 // For ExtensionService interface when it requires a path that is not used.
34 base::FilePath bogus_file_pathname(const std::string& name) { 36 base::FilePath bogus_file_pathname(const std::string& name) {
35 return base::FilePath(FILE_PATH_LITERAL("//foobar_nonexistent")) 37 return base::FilePath(FILE_PATH_LITERAL("//foobar_nonexistent"))
36 .AppendASCII(name); 38 .AppendASCII(name);
37 } 39 }
38 40
39 class MockDnsSdRegistry : public DnsSdRegistry { 41 class MockDnsSdRegistry : public DnsSdRegistry {
40 public: 42 public:
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 render_process_host_.reset( 88 render_process_host_.reset(
87 new content::MockRenderProcessHost(browser_context())); 89 new content::MockRenderProcessHost(browser_context()));
88 } 90 }
89 91
90 void TearDown() override { 92 void TearDown() override {
91 EXPECT_CALL(*dns_sd_registry(), 93 EXPECT_CALL(*dns_sd_registry(),
92 RemoveObserver(MDnsAPI::Get(browser_context()))) 94 RemoveObserver(MDnsAPI::Get(browser_context())))
93 .Times(1); 95 .Times(1);
94 render_process_host_.reset(); 96 render_process_host_.reset();
95 extensions::ExtensionServiceTestBase::TearDown(); 97 extensions::ExtensionServiceTestBase::TearDown();
96 MDnsAPI::GetFactoryInstance()->SetTestingFactory(
97 browser_context(),
98 nullptr);
99
100 registry_ = nullptr;
101 } 98 }
102 99
103 virtual MockDnsSdRegistry* dns_sd_registry() { 100 virtual MockDnsSdRegistry* dns_sd_registry() {
104 return registry_; 101 return registry_;
105 } 102 }
106 103
107 // Constructs an extension according to the parameters that matter most to 104 // Constructs an extension according to the parameters that matter most to
108 // MDnsAPI the local unit tests. 105 // MDnsAPI the local unit tests.
109 const scoped_refptr<extensions::Extension> CreateExtension( 106 const scoped_refptr<extensions::Extension> CreateExtension(
110 std::string name, 107 std::string name,
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 ExtensionPrefs* extension_prefs) : 216 ExtensionPrefs* extension_prefs) :
220 EventRouter(browser_context, extension_prefs) {} 217 EventRouter(browser_context, extension_prefs) {}
221 virtual ~MockEventRouter() {} 218 virtual ~MockEventRouter() {}
222 219
223 virtual void BroadcastEvent(scoped_ptr<Event> event) { 220 virtual void BroadcastEvent(scoped_ptr<Event> event) {
224 BroadcastEventPtr(event.get()); 221 BroadcastEventPtr(event.get());
225 } 222 }
226 MOCK_METHOD1(BroadcastEventPtr, void(Event* event)); 223 MOCK_METHOD1(BroadcastEventPtr, void(Event* event));
227 }; 224 };
228 225
229 KeyedService* MockEventRouterFactoryFunction(content::BrowserContext* profile) { 226 scoped_ptr<KeyedService> MockEventRouterFactoryFunction(
230 return new MockEventRouter( 227 content::BrowserContext* profile) {
228 return make_scoped_ptr(new MockEventRouter(
231 profile, 229 profile,
232 ExtensionPrefsFactory::GetInstance()->GetForBrowserContext((profile))); 230 ExtensionPrefsFactory::GetInstance()->GetForBrowserContext((profile))));
233 } 231 }
234 232
235 class MDnsAPIMaxServicesTest : public MDnsAPITest { 233 class MDnsAPIMaxServicesTest : public MDnsAPITest {
236 public: 234 public:
237 MockEventRouter* event_router() { 235 MockEventRouter* event_router() {
238 return static_cast<MockEventRouter*>(EventRouter::Get(browser_context())); 236 return static_cast<MockEventRouter*>(EventRouter::Get(browser_context()));
239 } 237 }
240 }; 238 };
241 239
242 class EventServiceListSizeMatcher : 240 class EventServiceListSizeMatcher :
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 *event_router(), 306 *event_router(),
309 BroadcastEventPtr( 307 BroadcastEventPtr(
310 testing::Pointee(EventServiceListSize(size_t(64))))) 308 testing::Pointee(EventServiceListSize(size_t(64)))))
311 .Times(1); 309 .Times(1);
312 dns_sd_registry()->DispatchMDnsEvent("_testing._tcp.local", services); 310 dns_sd_registry()->DispatchMDnsEvent("_testing._tcp.local", services);
313 } 311 }
314 312
315 } // empty namespace 313 } // empty namespace
316 314
317 } // namespace extensions 315 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698