OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/chrome/test/app/history_test_util.h" | 5 #import "ios/chrome/test/app/history_test_util.h" |
6 | 6 |
7 #import "base/mac/bind_objc_block.h" | 7 #import "base/mac/bind_objc_block.h" |
8 #import "base/test/ios/wait_util.h" | 8 #import "base/test/ios/wait_util.h" |
9 #include "components/browsing_data/core/browsing_data_utils.h" | 9 #include "components/browsing_data/core/browsing_data_utils.h" |
10 #import "ios/chrome/app/main_controller.h" | 10 #import "ios/chrome/app/main_controller.h" |
11 #import "ios/chrome/app/main_controller_private.h" | 11 #import "ios/chrome/app/main_controller_private.h" |
12 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 12 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
13 #include "ios/chrome/browser/browsing_data/ios_chrome_browsing_data_remover.h" | 13 #include "ios/chrome/browser/browsing_data/ios_chrome_browsing_data_remover.h" |
14 #include "ios/chrome/browser/callback_counter.h" | 14 #include "ios/chrome/browser/callback_counter.h" |
15 #import "ios/chrome/test/app/chrome_test_util.h" | 15 #import "ios/chrome/test/app/chrome_test_util.h" |
16 | 16 |
| 17 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 18 #error "This file requires ARC support." |
| 19 #endif |
| 20 |
17 namespace chrome_test_util { | 21 namespace chrome_test_util { |
18 | 22 |
19 void ClearBrowsingHistory() { | 23 void ClearBrowsingHistory() { |
20 MainController* main_controller = GetMainController(); | 24 MainController* main_controller = GetMainController(); |
21 ios::ChromeBrowserState* active_state = GetOriginalBrowserState(); | 25 ios::ChromeBrowserState* active_state = GetOriginalBrowserState(); |
22 scoped_refptr<CallbackCounter> callback_counter( | 26 scoped_refptr<CallbackCounter> callback_counter( |
23 new CallbackCounter(base::BindBlock(^{ | 27 new CallbackCounter(base::BindBlockArc(^{ |
24 }))); | 28 }))); |
25 callback_counter->IncrementCount(); | 29 callback_counter->IncrementCount(); |
26 __block bool did_complete = false; | 30 __block bool did_complete = false; |
27 [main_controller | 31 [main_controller |
28 removeBrowsingDataFromBrowserState:active_state | 32 removeBrowsingDataFromBrowserState:active_state |
29 mask:IOSChromeBrowsingDataRemover:: | 33 mask:IOSChromeBrowsingDataRemover:: |
30 REMOVE_HISTORY | 34 REMOVE_HISTORY |
31 timePeriod:browsing_data::TimePeriod::ALL_TIME | 35 timePeriod:browsing_data::TimePeriod::ALL_TIME |
32 completionHandler:^{ | 36 completionHandler:^{ |
33 callback_counter->DecrementCount(); | 37 callback_counter->DecrementCount(); |
34 did_complete = true; | 38 did_complete = true; |
35 }]; | 39 }]; |
36 // TODO(crbug.com/631795): This is a workaround that will be removed soon. | 40 // TODO(crbug.com/631795): This is a workaround that will be removed soon. |
37 // This code waits for success or timeout, then returns. This needs to be | 41 // This code waits for success or timeout, then returns. This needs to be |
38 // fixed so that failure is correctly marked here, or the caller handles | 42 // fixed so that failure is correctly marked here, or the caller handles |
39 // waiting for the operation to complete. | 43 // waiting for the operation to complete. |
40 // Wait for history to be cleared. | 44 // Wait for history to be cleared. |
41 NSDate* deadline = [NSDate dateWithTimeIntervalSinceNow:4.0]; | 45 NSDate* deadline = [NSDate dateWithTimeIntervalSinceNow:4.0]; |
42 while (!did_complete && | 46 while (!did_complete && |
43 [[NSDate date] compare:deadline] != NSOrderedDescending) { | 47 [[NSDate date] compare:deadline] != NSOrderedDescending) { |
44 base::test::ios::SpinRunLoopWithMaxDelay( | 48 base::test::ios::SpinRunLoopWithMaxDelay( |
45 base::TimeDelta::FromSecondsD(0.1)); | 49 base::TimeDelta::FromSecondsD(0.1)); |
46 } | 50 } |
47 } | 51 } |
48 | 52 |
49 } // namespace chrome_test_util | 53 } // namespace chrome_test_util |
OLD | NEW |