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

Side by Side Diff: ios/web/crw_browsing_data_store_unittest.mm

Issue 1215433003: CL for Objective-C readability (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
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 #import "ios/web/public/crw_browsing_data_store.h" 5 #import "ios/web/public/crw_browsing_data_store.h"
6 6
7 #include "base/ios/ios_util.h" 7 #include "base/ios/ios_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #import "base/mac/scoped_nsobject.h" 9 #import "base/mac/scoped_nsobject.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #import "base/test/ios/wait_util.h" 11 #import "base/test/ios/wait_util.h"
12 #include "ios/web/public/active_state_manager.h" 12 #include "ios/web/public/active_state_manager.h"
13 #include "ios/web/public/browser_state.h" 13 #include "ios/web/public/browser_state.h"
14 #include "ios/web/public/test/test_browser_state.h" 14 #include "ios/web/public/test/test_browser_state.h"
15 #include "ios/web/public/test/test_web_thread_bundle.h" 15 #include "ios/web/public/test/test_web_thread_bundle.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "testing/platform_test.h" 17 #include "testing/platform_test.h"
18 18
19 // An observer to observe the |mode| key changes to a CRWBrowsingDataStore. 19 // An observer to observe the |mode| key changes to a CRWBrowsingDataStore.
20 // Used for testing purposes. 20 // Used for testing purposes.
21 @interface CRWTestBrowsingDataStoreObserver : NSObject 21 @interface CRWTestBrowsingDataStoreObserver : NSObject
22 // Designated init. |browsingDataStore| cannot be null.
23 - (instancetype)initWithBrowsingDataStore:
24 (CRWBrowsingDataStore*)browsingDataStore NS_DESIGNATED_INITIALIZER;
25 - (instancetype)init NS_UNAVAILABLE;
26 // The number of times that the mode of the underlying CRWBrowsingDataStore 22 // The number of times that the mode of the underlying CRWBrowsingDataStore
27 // changed. 23 // changed.
28 @property(nonatomic, assign) NSUInteger modeChangeCount; 24 @property(nonatomic, assign) NSUInteger modeChangeCount;
25
26 // |browsingDataStore| cannot be null.
27 - (instancetype)initWithBrowsingDataStore:
28 (CRWBrowsingDataStore*)browsingDataStore NS_DESIGNATED_INITIALIZER;
29 - (instancetype)init NS_UNAVAILABLE;
29 @end 30 @end
30 31
31 @implementation CRWTestBrowsingDataStoreObserver { 32 @implementation CRWTestBrowsingDataStoreObserver {
32 // The underlying CRWBrowsingDataStore. 33 // The underlying CRWBrowsingDataStore.
33 __weak CRWBrowsingDataStore* _browsingDataStore; 34 __weak CRWBrowsingDataStore* _browsingDataStore;
34 } 35 }
35 36
36 @synthesize modeChangeCount = _modeChangeCount; 37 @synthesize modeChangeCount = _modeChangeCount;
37 38
38 - (instancetype)initWithBrowsingDataStore: 39 - (instancetype)initWithBrowsingDataStore:
39 (CRWBrowsingDataStore*)browsingDataStore { 40 (CRWBrowsingDataStore*)browsingDataStore {
40 self = [super init]; 41 self = [super init];
41 if (self) { 42 if (self) {
42 DCHECK(browsingDataStore); 43 DCHECK(browsingDataStore);
43 [browsingDataStore addObserver:self 44 [browsingDataStore addObserver:self
44 forKeyPath:@"mode" 45 forKeyPath:@"mode"
45 options:0 46 options:0
46 context:nil]; 47 context:nil];
47 _browsingDataStore = browsingDataStore; 48 _browsingDataStore = browsingDataStore;
48 } 49 }
49 return self; 50 return self;
50 } 51 }
51 52
52 - (instancetype)init { 53 - (void)dealloc {
53 NOTREACHED(); 54 [_browsingDataStore removeObserver:self forKeyPath:@"mode"];
54 return nil; 55 [super dealloc];
55 } 56 }
56 57
57 - (void)observeValueForKeyPath:(NSString*)keyPath 58 - (void)observeValueForKeyPath:(NSString*)keyPath
58 ofObject:(id)object 59 ofObject:(id)object
59 change:(NSDictionary*)change 60 change:(NSDictionary*)change
60 context:(void*)context { 61 context:(void*)context {
61 DCHECK([keyPath isEqual:@"mode"]); 62 DCHECK([keyPath isEqual:@"mode"]);
62 DCHECK_EQ(_browsingDataStore, object); 63 DCHECK_EQ(_browsingDataStore, object);
63 64
64 ++self.modeChangeCount; 65 ++self.modeChangeCount;
65 } 66 }
66 67
67 - (void)dealloc {
68 [_browsingDataStore removeObserver:self forKeyPath:@"mode"];
69 [super dealloc];
70 }
71
72 @end 68 @end
73 69
74 namespace web { 70 namespace web {
75 namespace { 71 namespace {
76 72
77 class BrowsingDataStoreTest : public PlatformTest { 73 class BrowsingDataStoreTest : public PlatformTest {
78 protected: 74 protected:
79 void SetUp() override { 75 void SetUp() override {
80 PlatformTest::SetUp(); 76 PlatformTest::SetUp();
81 browser_state_.reset(new TestBrowserState()); 77 browser_state_.reset(new TestBrowserState());
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 246
251 ASSERT_EQ(ACTIVE, [browsing_data_store_ mode]); 247 ASSERT_EQ(ACTIVE, [browsing_data_store_ mode]);
252 248
253 [browsing_data_store_ makeInactiveWithCompletionHandler:nil]; 249 [browsing_data_store_ makeInactiveWithCompletionHandler:nil];
254 // |removeDataOfTypes| is called immediately after a |makeInactive| call. 250 // |removeDataOfTypes| is called immediately after a |makeInactive| call.
255 RemoveDataOfTypes(BROWSING_DATA_TYPE_COOKIES); 251 RemoveDataOfTypes(BROWSING_DATA_TYPE_COOKIES);
256 EXPECT_EQ(INACTIVE, [browsing_data_store_ mode]); 252 EXPECT_EQ(INACTIVE, [browsing_data_store_ mode]);
257 } 253 }
258 254
259 } // namespace web 255 } // namespace web
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698