OLD | NEW |
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. | 22 // Designated init. |browsingDataStore| cannot be null. |
23 - (instancetype)initWithBrowsingDataStore: | 23 - (instancetype)initWithBrowsingDataStore: |
24 (CRWBrowsingDataStore*)browsingDataStore NS_DESIGNATED_INITIALIZER; | 24 (CRWBrowsingDataStore*)browsingDataStore NS_DESIGNATED_INITIALIZER; |
| 25 - (instancetype)init NS_UNAVAILABLE; |
25 // The number of times that the mode of the underlying CRWBrowsingDataStore | 26 // The number of times that the mode of the underlying CRWBrowsingDataStore |
26 // changed. | 27 // changed. |
27 @property(nonatomic, assign) NSUInteger modeChangeCount; | 28 @property(nonatomic, assign) NSUInteger modeChangeCount; |
28 @end | 29 @end |
29 | 30 |
30 @implementation CRWTestBrowsingDataStoreObserver { | 31 @implementation CRWTestBrowsingDataStoreObserver { |
31 // The underlying CRWBrowsingDataStore. | 32 // The underlying CRWBrowsingDataStore. |
32 __weak CRWBrowsingDataStore* _browsingDataStore; | 33 __weak CRWBrowsingDataStore* _browsingDataStore; |
33 } | 34 } |
34 | 35 |
35 @synthesize modeChangeCount = _modeChangeCount; | 36 @synthesize modeChangeCount = _modeChangeCount; |
36 | 37 |
37 - (instancetype)initWithBrowsingDataStore: | 38 - (instancetype)initWithBrowsingDataStore: |
38 (CRWBrowsingDataStore*)browsingDataStore { | 39 (CRWBrowsingDataStore*)browsingDataStore { |
39 self = [super init]; | 40 self = [super init]; |
40 if (self) { | 41 if (self) { |
41 DCHECK(browsingDataStore); | 42 DCHECK(browsingDataStore); |
42 [browsingDataStore addObserver:self | 43 [browsingDataStore addObserver:self |
43 forKeyPath:@"mode" | 44 forKeyPath:@"mode" |
44 options:0 | 45 options:0 |
45 context:nil]; | 46 context:nil]; |
46 _browsingDataStore = browsingDataStore; | 47 _browsingDataStore = browsingDataStore; |
47 } | 48 } |
48 return self; | 49 return self; |
49 } | 50 } |
50 | 51 |
| 52 - (instancetype)init { |
| 53 NOTREACHED(); |
| 54 return nil; |
| 55 } |
| 56 |
51 - (void)observeValueForKeyPath:(NSString*)keyPath | 57 - (void)observeValueForKeyPath:(NSString*)keyPath |
52 ofObject:(id)object | 58 ofObject:(id)object |
53 change:(NSDictionary*)change | 59 change:(NSDictionary*)change |
54 context:(void*)context { | 60 context:(void*)context { |
55 DCHECK([keyPath isEqual:@"mode"]); | 61 DCHECK([keyPath isEqual:@"mode"]); |
56 DCHECK_EQ(_browsingDataStore, object); | 62 DCHECK_EQ(_browsingDataStore, object); |
57 | 63 |
58 ++self.modeChangeCount; | 64 ++self.modeChangeCount; |
59 } | 65 } |
60 | 66 |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 | 237 |
232 ASSERT_EQ(ACTIVE, [browsing_data_store_ mode]); | 238 ASSERT_EQ(ACTIVE, [browsing_data_store_ mode]); |
233 | 239 |
234 [browsing_data_store_ makeInactiveWithCompletionHandler:nil]; | 240 [browsing_data_store_ makeInactiveWithCompletionHandler:nil]; |
235 // |removeDataOfTypes| is called immediately after a |makeInactive| call. | 241 // |removeDataOfTypes| is called immediately after a |makeInactive| call. |
236 RemoveDataOfTypes(BROWSING_DATA_TYPE_COOKIES); | 242 RemoveDataOfTypes(BROWSING_DATA_TYPE_COOKIES); |
237 EXPECT_EQ(INACTIVE, [browsing_data_store_ mode]); | 243 EXPECT_EQ(INACTIVE, [browsing_data_store_ mode]); |
238 } | 244 } |
239 | 245 |
240 } // namespace web | 246 } // namespace web |
OLD | NEW |