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 <EarlGrey/EarlGrey.h> | 5 #import <EarlGrey/EarlGrey.h> |
6 #import <XCTest/XCTest.h> | 6 #import <XCTest/XCTest.h> |
7 | 7 |
8 #include "base/mac/bind_objc_block.h" | 8 #include "base/mac/bind_objc_block.h" |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 117 |
118 // Opens a new incognito tab using the UI and evicts any main tab model tabs. | 118 // Opens a new incognito tab using the UI and evicts any main tab model tabs. |
119 void OpenNewIncognitoTabUsingUIAndEvictMainTabs() { | 119 void OpenNewIncognitoTabUsingUIAndEvictMainTabs() { |
120 int nb_incognito_tab = chrome_test_util::GetIncognitoTabCount(); | 120 int nb_incognito_tab = chrome_test_util::GetIncognitoTabCount(); |
121 [ChromeEarlGreyUI openToolsMenu]; | 121 [ChromeEarlGreyUI openToolsMenu]; |
122 id<GREYMatcher> new_incognito_tab_button_matcher = | 122 id<GREYMatcher> new_incognito_tab_button_matcher = |
123 grey_accessibilityID(kToolsMenuNewIncognitoTabId); | 123 grey_accessibilityID(kToolsMenuNewIncognitoTabId); |
124 [[EarlGrey selectElementWithMatcher:new_incognito_tab_button_matcher] | 124 [[EarlGrey selectElementWithMatcher:new_incognito_tab_button_matcher] |
125 performAction:grey_tap()]; | 125 performAction:grey_tap()]; |
126 chrome_test_util::AssertIncognitoTabCount(nb_incognito_tab + 1); | 126 chrome_test_util::AssertIncognitoTabCount(nb_incognito_tab + 1); |
127 | 127 ConditionBlock condition = ^bool { |
| 128 return chrome_test_util::IsIncognitoMode(); |
| 129 }; |
| 130 GREYAssert( |
| 131 testing::WaitUntilConditionOrTimeout(kWaitElementTimeout, condition), |
| 132 @"Waiting switch to incognito mode."); |
128 chrome_test_util::EvictOtherTabModelTabs(); | 133 chrome_test_util::EvictOtherTabModelTabs(); |
129 } | 134 } |
130 | 135 |
131 // Closes a tab in the current tab model. Synchronize on tab number afterwards. | 136 // Closes a tab in the current tab model. Synchronize on tab number afterwards. |
132 void CloseTabAtIndexAndSync(NSUInteger i) { | 137 void CloseTabAtIndexAndSync(NSUInteger i) { |
133 NSUInteger nb_main_tab = chrome_test_util::GetMainTabCount(); | 138 NSUInteger nb_main_tab = chrome_test_util::GetMainTabCount(); |
134 chrome_test_util::CloseTabAtIndex(i); | 139 chrome_test_util::CloseTabAtIndex(i); |
135 ConditionBlock condition = ^{ | 140 ConditionBlock condition = ^{ |
136 return chrome_test_util::GetMainTabCount() == (nb_main_tab - 1); | 141 return chrome_test_util::GetMainTabCount() == (nb_main_tab - 1); |
137 }; | 142 }; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 IDS_IOS_SWITCH_BROWSER_MODE_LEAVE_INCOGNITO)] | 181 IDS_IOS_SWITCH_BROWSER_MODE_LEAVE_INCOGNITO)] |
177 performAction:grey_tap()]; | 182 performAction:grey_tap()]; |
178 } | 183 } |
179 } else { | 184 } else { |
180 [[EarlGrey selectElementWithMatcher: | 185 [[EarlGrey selectElementWithMatcher: |
181 chrome_test_util::buttonWithAccessibilityLabelId( | 186 chrome_test_util::buttonWithAccessibilityLabelId( |
182 IDS_IOS_TOOLBAR_SHOW_TABS)] performAction:grey_tap()]; | 187 IDS_IOS_TOOLBAR_SHOW_TABS)] performAction:grey_tap()]; |
183 [[EarlGrey selectElementWithMatcher: | 188 [[EarlGrey selectElementWithMatcher: |
184 chrome_test_util::buttonWithAccessibilityLabelId( | 189 chrome_test_util::buttonWithAccessibilityLabelId( |
185 IDS_IOS_TOOLS_MENU_NEW_INCOGNITO_TAB)] | 190 IDS_IOS_TOOLS_MENU_NEW_INCOGNITO_TAB)] |
186 performAction:grey_swipeFastInDirection(kGREYDirectionRight)]; | 191 performAction:grey_swipeSlowInDirection(kGREYDirectionRight)]; |
187 [[EarlGrey selectElementWithMatcher: | 192 [[EarlGrey selectElementWithMatcher: |
188 chrome_test_util::buttonWithAccessibilityLabelId( | 193 chrome_test_util::buttonWithAccessibilityLabelId( |
189 IDS_IOS_TOOLBAR_SHOW_TABS)] performAction:grey_tap()]; | 194 IDS_IOS_TOOLBAR_SHOW_TABS)] performAction:grey_tap()]; |
190 } | 195 } |
191 GREYAssertFalse(chrome_test_util::IsIncognitoMode(), | 196 ConditionBlock condition = ^bool { |
192 @"Switching to normal mode failed."); | 197 return !chrome_test_util::IsIncognitoMode(); |
| 198 }; |
| 199 GREYAssert( |
| 200 testing::WaitUntilConditionOrTimeout(kWaitElementTimeout, condition), |
| 201 @"Waiting switch to normal mode."); |
193 } | 202 } |
194 | 203 |
195 // Check that the error page is visible. | 204 // Check that the error page is visible. |
196 void CheckErrorPageIsVisible() { | 205 void CheckErrorPageIsVisible() { |
197 // The DNS error page is static HTML content, so it isn't part of the webview | 206 // The DNS error page is static HTML content, so it isn't part of the webview |
198 // owned by the webstate. | 207 // owned by the webstate. |
199 [[EarlGrey selectElementWithMatcher:chrome_test_util:: | 208 [[EarlGrey selectElementWithMatcher:chrome_test_util:: |
200 webViewBelongingToWebController()] | 209 webViewBelongingToWebController()] |
201 assertWithMatcher:grey_nil()]; | 210 assertWithMatcher:grey_nil()]; |
202 NSString* const kError = | 211 NSString* const kError = |
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
947 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; | 956 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; |
948 } | 957 } |
949 // The deleted tabs are purged during foregrounding and backgrounding. | 958 // The deleted tabs are purged during foregrounding and backgrounding. |
950 chrome_test_util::SimulateTabsBackgrounding(); | 959 chrome_test_util::SimulateTabsBackgrounding(); |
951 // Make sure |evicted_tabs_| purged the deleted tabs. | 960 // Make sure |evicted_tabs_| purged the deleted tabs. |
952 int evicted = chrome_test_util::GetEvictedMainTabCount(); | 961 int evicted = chrome_test_util::GetEvictedMainTabCount(); |
953 GREYAssertEqual(evicted, 0, @"Check number of evicted tabs"); | 962 GREYAssertEqual(evicted, 0, @"Check number of evicted tabs"); |
954 } | 963 } |
955 | 964 |
956 @end | 965 @end |
OLD | NEW |