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/tab_test_util.h" | 5 #import "ios/chrome/test/app/tab_test_util.h" |
6 | 6 |
7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
8 | 8 |
9 #import "base/mac/foundation_util.h" | 9 #import "base/mac/foundation_util.h" |
10 #import "base/mac/scoped_nsobject.h" | |
11 #import "ios/chrome/app/main_controller_private.h" | 10 #import "ios/chrome/app/main_controller_private.h" |
12 #import "ios/chrome/browser/autofill/form_input_accessory_view_controller.h" | 11 #import "ios/chrome/browser/autofill/form_input_accessory_view_controller.h" |
13 #include "ios/chrome/browser/experimental_flags.h" | 12 #include "ios/chrome/browser/experimental_flags.h" |
14 #import "ios/chrome/browser/metrics/tab_usage_recorder.h" | 13 #import "ios/chrome/browser/metrics/tab_usage_recorder.h" |
15 #import "ios/chrome/browser/tabs/tab.h" | 14 #import "ios/chrome/browser/tabs/tab.h" |
16 #import "ios/chrome/browser/tabs/tab_model.h" | 15 #import "ios/chrome/browser/tabs/tab_model.h" |
17 #import "ios/chrome/browser/tabs/tab_private.h" | 16 #import "ios/chrome/browser/tabs/tab_private.h" |
18 #import "ios/chrome/browser/ui/browser_view_controller.h" | 17 #import "ios/chrome/browser/ui/browser_view_controller.h" |
19 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" | 18 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" |
20 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" | 19 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" |
21 #import "ios/chrome/browser/ui/tabs/tab_strip_controller_private.h" | 20 #import "ios/chrome/browser/ui/tabs/tab_strip_controller_private.h" |
22 #import "ios/chrome/test/app/chrome_test_util.h" | 21 #import "ios/chrome/test/app/chrome_test_util.h" |
23 #import "ios/testing/wait_util.h" | 22 #import "ios/testing/wait_util.h" |
| 23 #import "ios/web/web_state/ui/crw_web_controller.h" |
| 24 |
| 25 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 26 #error "This file requires ARC support." |
| 27 #endif |
24 | 28 |
25 namespace chrome_test_util { | 29 namespace chrome_test_util { |
26 | 30 |
27 namespace { | 31 namespace { |
28 | 32 |
29 // Returns the tab model for the current mode (incognito or normal). | 33 // Returns the tab model for the current mode (incognito or normal). |
30 TabModel* GetCurrentTabModel() { | 34 TabModel* GetCurrentTabModel() { |
31 return IsIncognitoMode() | 35 return IsIncognitoMode() |
32 ? [[GetMainController() browserViewInformation] otrTabModel] | 36 ? [[GetMainController() browserViewInformation] otrTabModel] |
33 : [[GetMainController() browserViewInformation] mainTabModel]; | 37 : [[GetMainController() browserViewInformation] mainTabModel]; |
34 } | 38 } |
35 | 39 |
36 } // namespace | 40 } // namespace |
37 | 41 |
38 BOOL IsIncognitoMode() { | 42 BOOL IsIncognitoMode() { |
39 MainController* main_controller = GetMainController(); | 43 MainController* main_controller = GetMainController(); |
40 BrowserViewController* otr_bvc = | 44 BrowserViewController* otr_bvc = |
41 [[main_controller browserViewInformation] otrBVC]; | 45 [[main_controller browserViewInformation] otrBVC]; |
42 BrowserViewController* current_bvc = | 46 BrowserViewController* current_bvc = |
43 [[main_controller browserViewInformation] currentBVC]; | 47 [[main_controller browserViewInformation] currentBVC]; |
44 return otr_bvc == current_bvc; | 48 return otr_bvc == current_bvc; |
45 } | 49 } |
46 | 50 |
47 void OpenNewTab() { | 51 void OpenNewTab() { |
48 @autoreleasepool { // Make sure that all internals are deallocated. | 52 @autoreleasepool { // Make sure that all internals are deallocated. |
49 base::scoped_nsobject<GenericChromeCommand> command( | 53 GenericChromeCommand* command = |
50 [[GenericChromeCommand alloc] initWithTag:IDC_NEW_TAB]); | 54 [[GenericChromeCommand alloc] initWithTag:IDC_NEW_TAB]; |
51 chrome_test_util::RunCommandWithActiveViewController(command); | 55 chrome_test_util::RunCommandWithActiveViewController(command); |
52 } | 56 } |
53 } | 57 } |
54 | 58 |
55 void OpenNewIncognitoTab() { | 59 void OpenNewIncognitoTab() { |
56 @autoreleasepool { // Make sure that all internals are deallocated. | 60 @autoreleasepool { // Make sure that all internals are deallocated. |
57 base::scoped_nsobject<GenericChromeCommand> command( | 61 GenericChromeCommand* command = |
58 [[GenericChromeCommand alloc] initWithTag:IDC_NEW_INCOGNITO_TAB]); | 62 [[GenericChromeCommand alloc] initWithTag:IDC_NEW_INCOGNITO_TAB]; |
59 chrome_test_util::RunCommandWithActiveViewController(command); | 63 chrome_test_util::RunCommandWithActiveViewController(command); |
60 } | 64 } |
61 } | 65 } |
62 | 66 |
63 Tab* GetCurrentTab() { | 67 Tab* GetCurrentTab() { |
64 TabModel* tab_model = GetCurrentTabModel(); | 68 TabModel* tab_model = GetCurrentTabModel(); |
65 return tab_model.currentTab; | 69 return tab_model.currentTab; |
66 } | 70 } |
67 | 71 |
68 Tab* GetNextTab() { | 72 Tab* GetNextTab() { |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 return [[GetMainController() browserViewInformation] mainTabModel] | 188 return [[GetMainController() browserViewInformation] mainTabModel] |
185 .tabUsageRecorder->EvictedTabsMapSize(); | 189 .tabUsageRecorder->EvictedTabsMapSize(); |
186 } | 190 } |
187 | 191 |
188 FormInputAccessoryViewController* GetInputAccessoryViewController() { | 192 FormInputAccessoryViewController* GetInputAccessoryViewController() { |
189 Tab* current_tab = GetCurrentTab(); | 193 Tab* current_tab = GetCurrentTab(); |
190 return [current_tab inputAccessoryViewController]; | 194 return [current_tab inputAccessoryViewController]; |
191 } | 195 } |
192 | 196 |
193 } // namespace chrome_test_util | 197 } // namespace chrome_test_util |
OLD | NEW |