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

Side by Side Diff: chrome/test/base/scoped_bundle_swizzler_mac.mm

Issue 1211213003: mac: Swizzle out +[NSBundle mainBundle] for in process browser tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor formatting, nits. 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/test/base/scoped_bundle_swizzler_mac.h"
6
7 #import <Foundation/Foundation.h>
8
9 #include "base/logging.h"
10 #include "base/mac/scoped_objc_class_swizzler.h"
11 #import "third_party/ocmock/OCMock/OCMock.h"
12
13 static NSBundle* g_original_main_bundle = nil;
14 static id g_swizzled_main_bundle = nil;
15
16 // A donor class that provides a +[NSBundle mainBundle] method that can be
17 // swapped with NSBundle.
18 @interface TestBundle : NSObject
19 + (NSBundle*)mainBundle;
20 @end
21
22 @implementation TestBundle
23 + (NSBundle*)mainBundle {
24 return g_swizzled_main_bundle;
25 }
26 @end
27
28 ScopedBundleSwizzlerMac::ScopedBundleSwizzlerMac() {
29 DCHECK(!g_swizzled_main_bundle);
30 DCHECK(!g_original_main_bundle);
31
32 g_original_main_bundle = [NSBundle mainBundle];
33 g_swizzled_main_bundle =
34 [[OCMockObject partialMockForObject:g_original_main_bundle] retain];
35 [[[g_swizzled_main_bundle stub]
36 andReturn:@"swizzled.bundle.id"] bundleIdentifier];
Robert Sesek 2015/06/26 22:36:54 Can this use bae::mac::BaseBundleID()?
erikchen 2015/06/26 23:14:53 Yup, done.
37
38 class_swizzler_.reset(new base::mac::ScopedObjCClassSwizzler(
39 [NSBundle class], [TestBundle class], @selector(mainBundle)));
40 }
41
42 ScopedBundleSwizzlerMac::~ScopedBundleSwizzlerMac() {
43 [g_swizzled_main_bundle release];
44 g_swizzled_main_bundle = nil;
45 g_original_main_bundle = nil;
46 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698