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

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: Comments from rsesek. Created 5 years, 5 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
« no previous file with comments | « chrome/test/base/scoped_bundle_swizzler_mac.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/foundation_util.h"
11 #include "base/mac/scoped_objc_class_swizzler.h"
12 #import "third_party/ocmock/OCMock/OCMock.h"
13
14 static NSBundle* g_original_main_bundle = nil;
15 static id g_swizzled_main_bundle = nil;
16
17 // A donor class that provides a +[NSBundle mainBundle] method that can be
18 // swapped with NSBundle.
19 @interface TestBundle : NSObject
20 + (NSBundle*)mainBundle;
21 @end
22
23 @implementation TestBundle
24 + (NSBundle*)mainBundle {
25 return g_swizzled_main_bundle;
26 }
27 @end
28
29 ScopedBundleSwizzlerMac::ScopedBundleSwizzlerMac() {
30 CHECK(!g_swizzled_main_bundle);
31 CHECK(!g_original_main_bundle);
32
33 g_original_main_bundle = [NSBundle mainBundle];
34 g_swizzled_main_bundle =
35 [[OCMockObject partialMockForObject:g_original_main_bundle] retain];
36 NSString* identifier =
37 [NSString stringWithUTF8String:base::mac::BaseBundleID()];
Robert Sesek 2015/06/30 22:21:07 sys_string_conversions.h is preferred.
erikchen 2015/07/06 22:00:06 Done.
38 CHECK(identifier);
39 [[[g_swizzled_main_bundle stub] andReturn:identifier] bundleIdentifier];
40
41 class_swizzler_.reset(new base::mac::ScopedObjCClassSwizzler(
42 [NSBundle class], [TestBundle class], @selector(mainBundle)));
43 }
44
45 ScopedBundleSwizzlerMac::~ScopedBundleSwizzlerMac() {
46 [g_swizzled_main_bundle release];
47 g_swizzled_main_bundle = nil;
48 g_original_main_bundle = nil;
49 }
OLDNEW
« no previous file with comments | « chrome/test/base/scoped_bundle_swizzler_mac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698