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

Side by Side Diff: ios/chrome/test/app/tab_test_util.mm

Issue 2580333003: Upstream Chrome on iOS source code [10/11]. (Closed)
Patch Set: Created 4 years 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #import "ios/chrome/test/app/tab_test_util.h"
6
7 #import <Foundation/Foundation.h>
8
9 #import "base/mac/foundation_util.h"
10 #import "base/mac/scoped_nsobject.h"
11 #import "ios/chrome/app/main_controller_private.h"
12 #import "ios/chrome/browser/autofill/form_input_accessory_view_controller.h"
13 #include "ios/chrome/browser/experimental_flags.h"
14 #import "ios/chrome/browser/metrics/tab_usage_recorder.h"
15 #import "ios/chrome/browser/tabs/tab.h"
16 #import "ios/chrome/browser/tabs/tab_model.h"
17 #import "ios/chrome/browser/tabs/tab_private.h"
18 #import "ios/chrome/browser/ui/browser_view_controller.h"
19 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h"
20 #include "ios/chrome/browser/ui/commands/ios_command_ids.h"
21 #import "ios/chrome/browser/ui/tabs/tab_strip_controller_private.h"
22 #import "ios/chrome/test/app/chrome_test_util.h"
23 #import "ios/testing/wait_util.h"
24
25 namespace chrome_test_util {
26
27 namespace {
28
29 // Returns the tab model for the current mode (incognito or normal).
30 TabModel* GetCurrentTabModel() {
31 return IsIncognitoMode()
32 ? [[GetMainController() browserViewInformation] otrTabModel]
33 : [[GetMainController() browserViewInformation] mainTabModel];
34 }
35
36 } // namespace
37
38 BOOL IsIncognitoMode() {
39 MainController* main_controller = GetMainController();
40 BrowserViewController* otr_bvc =
41 [[main_controller browserViewInformation] otrBVC];
42 BrowserViewController* current_bvc =
43 [[main_controller browserViewInformation] currentBVC];
44 return otr_bvc == current_bvc;
45 }
46
47 void OpenNewTab() {
48 @autoreleasepool { // Make sure that all internals are deallocated.
49 base::scoped_nsobject<GenericChromeCommand> command(
50 [[GenericChromeCommand alloc] initWithTag:IDC_NEW_TAB]);
51 chrome_test_util::RunCommandWithActiveViewController(command);
52 }
53 }
54
55 void OpenNewIncognitoTab() {
56 @autoreleasepool { // Make sure that all internals are deallocated.
57 base::scoped_nsobject<GenericChromeCommand> command(
58 [[GenericChromeCommand alloc] initWithTag:IDC_NEW_INCOGNITO_TAB]);
59 chrome_test_util::RunCommandWithActiveViewController(command);
60 }
61 }
62
63 Tab* GetCurrentTab() {
64 TabModel* tab_model = GetCurrentTabModel();
65 return tab_model.currentTab;
66 }
67
68 Tab* GetNextTab() {
69 TabModel* tabModel = GetCurrentTabModel();
70 NSUInteger tabCount = [tabModel count];
71 if (tabCount < 2)
72 return nil;
73 Tab* currentTab = [tabModel currentTab];
74 NSUInteger nextTabIndex = [tabModel indexOfTab:currentTab] + 1;
75 if (nextTabIndex >= tabCount)
76 nextTabIndex = 0;
77 return [tabModel tabAtIndex:nextTabIndex];
78 }
79
80 void CloseCurrentTab() {
81 TabModel* tab_model = GetCurrentTabModel();
82 [tab_model closeTab:tab_model.currentTab];
83 }
84
85 void CloseTabAtIndex(NSUInteger index) {
86 @autoreleasepool { // Make sure that all internals are deallocated.
87 [GetCurrentTabModel() closeTabAtIndex:index];
88 }
89 }
90
91 void CloseAllTabsInCurrentMode() {
92 [GetCurrentTabModel() closeAllTabs];
93 }
94
95 void CloseAllTabs() {
96 if (GetIncognitoTabCount()) {
97 [[[GetMainController() browserViewInformation] otrTabModel] closeAllTabs];
98 }
99 if (GetMainTabCount()) {
100 [[[GetMainController() browserViewInformation] mainTabModel] closeAllTabs];
101 }
102 }
103
104 void SelectTabAtIndexInCurrentMode(NSUInteger index) {
105 @autoreleasepool { // Make sure that all internals are deallocated.
106 TabModel* tab_model = GetCurrentTabModel();
107 [tab_model setCurrentTab:[tab_model tabAtIndex:index]];
108 }
109 }
110
111 NSUInteger GetMainTabCount() {
112 return [[[GetMainController() browserViewInformation] mainTabModel] count];
113 }
114
115 NSUInteger GetIncognitoTabCount() {
116 return [[[GetMainController() browserViewInformation] otrTabModel] count];
117 }
118
119 BOOL ResetTabUsageRecorder() {
120 if (!GetCurrentTabModel().tabUsageRecorder)
121 return NO;
122 GetCurrentTabModel().tabUsageRecorder->ResetAll();
123 return YES;
124 }
125
126 BOOL SetCurrentTabsToBeColdStartTabs() {
127 if (!GetCurrentTabModel().tabUsageRecorder)
128 return NO;
129 TabModel* tab_model = GetCurrentTabModel();
130 NSMutableArray* tabs = [NSMutableArray array];
131 for (Tab* tab in tab_model) {
132 [tabs addObject:tab];
133 }
134 tab_model.tabUsageRecorder->InitialRestoredTabs(tab_model.currentTab, tabs);
135 return YES;
136 }
137
138 BOOL SimulateTabsBackgrounding() {
139 if (!GetCurrentTabModel().tabUsageRecorder)
140 return NO;
141 GetCurrentTabModel().tabUsageRecorder->AppDidEnterBackground();
142 return YES;
143 }
144
145 void EvictOtherTabModelTabs() {
146 TabModel* otherTabModel =
147 IsIncognitoMode()
148 ? [GetMainController().browserViewInformation mainTabModel]
149 : [GetMainController().browserViewInformation otrTabModel];
150 NSUInteger count = otherTabModel.count;
151 for (NSUInteger i = 0; i < count; i++) {
152 Tab* tab = [otherTabModel tabAtIndex:i];
153 [tab.webController handleLowMemory];
154 }
155 }
156
157 void CloseAllIncognitoTabs() {
158 MainController* main_controller = chrome_test_util::GetMainController();
159 DCHECK(main_controller);
160 TabModel* tabModel = [[main_controller browserViewInformation] otrTabModel];
161 DCHECK(tabModel);
162 [tabModel closeAllTabs];
163 if (!IsIPadIdiom() || !experimental_flags::IsTabSwitcherEnabled()) {
164 // If the OTR BVC is active, wait until it isn't (since all of the
165 // tabs are now closed)
166 testing::WaitUntilConditionOrTimeout(testing::kWaitForUIElementTimeout, ^{
167 return !IsIncognitoMode();
168 });
169 }
170 }
171
172 TabView* GetTabViewForTab(Tab* tab) {
173 MainController* main_controller = GetMainController();
174 BrowserViewController* current_bvc =
175 [[main_controller browserViewInformation] currentBVC];
176 TabStripController* tabStrip = [current_bvc tabStripController];
177 return [tabStrip existingTabViewForTab:tab];
178 }
179
180 NSUInteger GetEvictedMainTabCount() {
181 if (![[GetMainController() browserViewInformation] mainTabModel]
182 .tabUsageRecorder)
183 return 0;
184 return [[GetMainController() browserViewInformation] mainTabModel]
185 .tabUsageRecorder->EvictedTabsMapSize();
186 }
187
188 FormInputAccessoryViewController* GetInputAccessoryViewController() {
189 Tab* current_tab = GetCurrentTab();
190 return [current_tab inputAccessoryViewController];
191 }
192
193 } // namespace chrome_test_util
OLDNEW
« no previous file with comments | « ios/chrome/test/app/tab_test_util.h ('k') | ios/chrome/test/app/web_view_interaction_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698