Remove CHROME_EG_ASSERT_NO_ERROR usage from tab_usage_recorder_test_util.mm
Local helpers can assert inside. Existance of CHROME_EG_ASSERT_NO_ERROR
will not prevent people from asserting outside of the tests.
Bug: 963613
Change-Id: I13230d5ab79eaac442055f22bf069cfc28dedcda
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1658636
Auto-Submit: Eugene But <eugenebut@chromium.org>
Reviewed-by: Rohit Rao <rohitrao@chromium.org>
Commit-Queue: Eugene But <eugenebut@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#669393}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: d6b68f0edf7c64090710b752ef91229e9319c2da
diff --git a/chrome/browser/metrics/tab_usage_recorder_egtest.mm b/chrome/browser/metrics/tab_usage_recorder_egtest.mm
index 0ead77b..90c7c14 100644
--- a/chrome/browser/metrics/tab_usage_recorder_egtest.mm
+++ b/chrome/browser/metrics/tab_usage_recorder_egtest.mm
@@ -23,7 +23,6 @@
#import "ios/chrome/test/earl_grey/chrome_actions.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h"
-#import "ios/chrome/test/earl_grey/chrome_error_util.h"
#import "ios/chrome/test/earl_grey/chrome_matchers.h"
#import "ios/chrome/test/earl_grey/chrome_test_case.h"
#import "ios/web/public/test/earl_grey/web_view_matchers.h"
@@ -143,13 +142,14 @@
kSelectedTabHistogramName, TabUsageRecorder::IN_MEMORY, 1, failureBlock);
// Evict the tab.
- CHROME_EG_ASSERT_NO_ERROR(OpenNewIncognitoTabUsingUIAndEvictMainTabs());
+ GREYAssertTrue(OpenNewIncognitoTabUsingUIAndEvictMainTabs(),
+ @"Failed to open Incognito Tab");
GREYAssertTrue([ChromeEarlGrey isIncognitoMode],
@"Failed to switch to incognito mode");
// Switch back to the normal tabs. Should be on tab one.
- CHROME_EG_ASSERT_NO_ERROR(SwitchToNormalMode());
+ SwitchToNormalMode();
[ChromeEarlGrey waitForWebStateContainingText:kURL1FirstWord];
@@ -211,11 +211,12 @@
// Evict the tab. Create a dummy tab so that switching back to normal mode
// does not trigger a reload immediately.
[ChromeEarlGrey openNewTab];
- CHROME_EG_ASSERT_NO_ERROR(OpenNewIncognitoTabUsingUIAndEvictMainTabs());
+ GREYAssertTrue(OpenNewIncognitoTabUsingUIAndEvictMainTabs(),
+ @"Failed to open Incognito Tab");
[ChromeEarlGrey waitForIncognitoTabCount:1];
// Switch back to the normal tabs. Should be on tab one.
- CHROME_EG_ASSERT_NO_ERROR(SwitchToNormalMode());
+ SwitchToNormalMode();
[ChromeEarlGrey selectTabAtIndex:0];
[ChromeEarlGrey waitForWebStateContainingText:kURL1FirstWord];
@@ -249,13 +250,15 @@
[ChromeEarlGrey setCurrentTabsToBeColdStartTabs];
// Open two incognito tabs with urls, clearing normal tabs from memory.
- CHROME_EG_ASSERT_NO_ERROR(OpenNewIncognitoTabUsingUIAndEvictMainTabs());
- CHROME_EG_ASSERT_NO_ERROR(OpenNewIncognitoTabUsingUIAndEvictMainTabs());
+ GREYAssertTrue(OpenNewIncognitoTabUsingUIAndEvictMainTabs(),
+ @"Failed to open first Incognito Tab");
+ GREYAssertTrue(OpenNewIncognitoTabUsingUIAndEvictMainTabs(),
+ @"Failed to open second Incognito Tab");
[ChromeEarlGrey waitForIncognitoTabCount:2];
// Switch back to the normal tabs.
- CHROME_EG_ASSERT_NO_ERROR(SwitchToNormalMode());
+ SwitchToNormalMode();
[ChromeEarlGrey waitForWebStateContainingText:kURL2FirstWord];
@@ -304,13 +307,14 @@
[ChromeEarlGrey simulateTabsBackgrounding];
// Open incognito and clear normal tabs from memory.
- CHROME_EG_ASSERT_NO_ERROR(OpenNewIncognitoTabUsingUIAndEvictMainTabs());
+ GREYAssertTrue(OpenNewIncognitoTabUsingUIAndEvictMainTabs(),
+ @"Failed to open Incognito Tab");
GREYAssertTrue([ChromeEarlGrey isIncognitoMode],
@"Failed to switch to incognito mode");
histogramTester.ExpectTotalCount(kEvictedTabReloadTime, 0, failureBlock);
// Switch back to the normal tabs.
- CHROME_EG_ASSERT_NO_ERROR(SwitchToNormalMode());
+ SwitchToNormalMode();
[ChromeEarlGrey waitForWebStateContainingText:kURL2FirstWord];
@@ -342,8 +346,9 @@
[ChromeEarlGrey closeAllTabsInCurrentMode];
GURL URL = web::test::HttpServer::MakeUrl(kTestUrl1);
NewMainTabWithURL(URL, kURL1FirstWord);
- CHROME_EG_ASSERT_NO_ERROR(OpenNewIncognitoTabUsingUIAndEvictMainTabs());
- CHROME_EG_ASSERT_NO_ERROR(SwitchToNormalMode());
+ GREYAssertTrue(OpenNewIncognitoTabUsingUIAndEvictMainTabs(),
+ @"Failed to open Incognito Tab");
+ SwitchToNormalMode();
[ChromeEarlGrey waitForWebStateContainingText:kURL1FirstWord];
[ChromeEarlGrey waitForMainTabCount:1];
@@ -376,17 +381,13 @@
[ChromeEarlGrey openNewTab];
[ChromeEarlGrey openNewTab];
[ChromeEarlGrey loadURL:slowURL waitForCompletion:NO];
- CHROME_EG_ASSERT_NO_ERROR(OpenNewIncognitoTabUsingUIAndEvictMainTabs());
+ GREYAssertTrue(OpenNewIncognitoTabUsingUIAndEvictMainTabs(),
+ @"Failed to open Incognito Tab");
web::test::SetUpHttpServer(std::make_unique<web::DelayedResponseProvider>(
std::make_unique<HtmlResponseProvider>(responses), kSlowURLDelay));
- NSError* switchError = SwitchToNormalMode();
- // TODO(crbug.com/951600): Avoid asserting directly unless the test fails,
- // due to timing issues.
- if (switchError != nil) {
- GREYAssert(false, switchError.localizedDescription);
- }
+ SwitchToNormalMode();
// Turn off synchronization of GREYAssert to test the pending states.
[[GREYConfiguration sharedInstance]
@@ -428,16 +429,13 @@
NewMainTabWithURL(slowURL, "Slow");
- CHROME_EG_ASSERT_NO_ERROR(OpenNewIncognitoTabUsingUIAndEvictMainTabs());
+ GREYAssertTrue(OpenNewIncognitoTabUsingUIAndEvictMainTabs(),
+ @"Failed to open Incognito Tab");
+
web::test::SetUpHttpServer(std::make_unique<web::DelayedResponseProvider>(
std::make_unique<HtmlResponseProvider>(responses), kSlowURLDelay));
- NSError* switchError = SwitchToNormalMode();
- // TODO(crbug.com/951600): Avoid asserting directly unless the test fails,
- // due to timing issues.
- if (switchError != nil) {
- GREYAssert(false, switchError.localizedDescription);
- }
+ SwitchToNormalMode();
// Letting page load start.
base::test::ios::SpinRunLoopWithMinDelay(base::TimeDelta::FromSecondsD(0.5));
@@ -478,8 +476,10 @@
};
NewMainTabWithURL(slowURL, responses[slowURL]);
- CHROME_EG_ASSERT_NO_ERROR(OpenNewIncognitoTabUsingUIAndEvictMainTabs());
- CHROME_EG_ASSERT_NO_ERROR(SwitchToNormalMode());
+ GREYAssertTrue(OpenNewIncognitoTabUsingUIAndEvictMainTabs(),
+ @"Failed to open Incognito Tab");
+
+ SwitchToNormalMode();
[ChromeEarlGreyUI openSettingsMenu];
[ChromeEarlGreyUI tapSettingsMenuButton:SettingsMenuPrivacyButton()];
@@ -507,16 +507,12 @@
chrome_test_util::HistogramTester histogramTester;
[ChromeEarlGrey openNewTab];
[ChromeEarlGrey loadURL:slowURL waitForCompletion:NO];
- CHROME_EG_ASSERT_NO_ERROR(OpenNewIncognitoTabUsingUIAndEvictMainTabs());
+ GREYAssertTrue(OpenNewIncognitoTabUsingUIAndEvictMainTabs(),
+ @"Failed to open Incognito Tab");
web::test::SetUpHttpServer(std::make_unique<web::DelayedResponseProvider>(
std::make_unique<HtmlResponseProvider>(responses), kSlowURLDelay));
- NSError* switchError = SwitchToNormalMode();
- // TODO(crbug.com/951600): Avoid asserting directly unless the test fails,
- // due to timing issues.
- if (switchError != nil) {
- GREYAssert(false, switchError.localizedDescription);
- }
+ SwitchToNormalMode();
// Letting page load start.
base::test::ios::SpinRunLoopWithMinDelay(base::TimeDelta::FromSecondsD(0.5));
@@ -596,8 +592,10 @@
NSUInteger tabIndex = [ChromeEarlGrey mainTabCount] - 1;
[ChromeEarlGrey openNewTab];
- CHROME_EG_ASSERT_NO_ERROR(OpenNewIncognitoTabUsingUIAndEvictMainTabs());
- CHROME_EG_ASSERT_NO_ERROR(SwitchToNormalMode());
+ GREYAssertTrue(OpenNewIncognitoTabUsingUIAndEvictMainTabs(),
+ @"Failed to open Incognito Tab");
+
+ SwitchToNormalMode();
[ChromeEarlGrey selectTabAtIndex:tabIndex];
[ChromeEarlGrey waitForWebStateContainingText:"arrived"];
@@ -643,8 +641,9 @@
[ChromeEarlGrey waitForWebStateContainingText:"Whee"];
NSUInteger tabIndex = [ChromeEarlGrey mainTabCount] - 1;
[ChromeEarlGrey openNewTab];
- CHROME_EG_ASSERT_NO_ERROR(OpenNewIncognitoTabUsingUIAndEvictMainTabs());
- CHROME_EG_ASSERT_NO_ERROR(SwitchToNormalMode());
+ GREYAssertTrue(OpenNewIncognitoTabUsingUIAndEvictMainTabs(),
+ @"Failed to open Incognito Tab");
+ SwitchToNormalMode();
[ChromeEarlGrey selectTabAtIndex:tabIndex];
[ChromeEarlGrey waitForWebStateContainingText:"Whee"];
diff --git a/chrome/browser/metrics/tab_usage_recorder_test_util.h b/chrome/browser/metrics/tab_usage_recorder_test_util.h
index 89c0f6d..7ff4d42 100644
--- a/chrome/browser/metrics/tab_usage_recorder_test_util.h
+++ b/chrome/browser/metrics/tab_usage_recorder_test_util.h
@@ -12,11 +12,13 @@
namespace tab_usage_recorder_test_util {
// Opens a new incognito tab using the UI and evicts any main tab model tabs.
-NSError* OpenNewIncognitoTabUsingUIAndEvictMainTabs() WARN_UNUSED_RESULT;
+// Returns false on failure.
+bool OpenNewIncognitoTabUsingUIAndEvictMainTabs() WARN_UNUSED_RESULT;
// Switches to normal mode using the tab switcher and selects the
// previously-selected normal tab. Assumes current mode is Incognito.
-NSError* SwitchToNormalMode() WARN_UNUSED_RESULT;
+// Induces EG assert on failure.
+void SwitchToNormalMode();
} // namespace tab_usage_recorder_test_util
diff --git a/chrome/browser/metrics/tab_usage_recorder_test_util.mm b/chrome/browser/metrics/tab_usage_recorder_test_util.mm
index 68bff0a..c5a16ec 100644
--- a/chrome/browser/metrics/tab_usage_recorder_test_util.mm
+++ b/chrome/browser/metrics/tab_usage_recorder_test_util.mm
@@ -28,6 +28,8 @@
#error "This file requires ARC support."
#endif
+using base::test::ios::WaitUntilConditionOrTimeout;
+
namespace {
// The delay to wait for an element to appear before tapping on it.
@@ -57,7 +59,7 @@
namespace tab_usage_recorder_test_util {
-NSError* OpenNewIncognitoTabUsingUIAndEvictMainTabs() {
+bool OpenNewIncognitoTabUsingUIAndEvictMainTabs() {
int nb_incognito_tab = [ChromeEarlGrey incognitoTabCount];
[ChromeEarlGreyUI openToolsMenu];
id<GREYMatcher> new_incognito_tab_button_matcher =
@@ -65,32 +67,23 @@
[[EarlGrey selectElementWithMatcher:new_incognito_tab_button_matcher]
performAction:grey_tap()];
[ChromeEarlGrey waitForIncognitoTabCount:(nb_incognito_tab + 1)];
- ConditionBlock condition = ^bool {
+ bool success = WaitUntilConditionOrTimeout(kWaitElementTimeout, ^{
return [ChromeEarlGrey isIncognitoMode];
- };
-
- bool success = base::test::ios::WaitUntilConditionOrTimeout(
- kWaitElementTimeout, condition);
+ });
if (!success) {
- return testing::NSErrorWithLocalizedDescription(
- @"Waiting switch to incognito mode.");
+ return false;
}
[ChromeEarlGrey evictOtherTabModelTabs];
- return nil;
+ return true;
}
-NSError* SwitchToNormalMode() {
- if (![ChromeEarlGrey isIncognitoMode]) {
- return testing::NSErrorWithLocalizedDescription(
- @"Switching to normal mode is only allowed from Incognito.");
- }
+void SwitchToNormalMode() {
+ GREYAssertTrue([ChromeEarlGrey isIncognitoMode],
+ @"Switching to normal mode is only allowed from Incognito.");
// Enter the tab grid to switch modes.
- if (!ShowTabSwitcher()) {
- return testing::NSErrorWithLocalizedDescription(
- @"Tab switcher could not be tapped.");
- }
+ GREYAssertTrue(ShowTabSwitcher(), @"Tab switcher could not be tapped.");
// Switch modes and exit the tab grid.
TabModel* model = chrome_test_util::GetMainController()
@@ -106,20 +99,19 @@
[[GREYConfiguration sharedInstance]
setValue:@(NO)
forConfigKey:kGREYConfigKeySynchronizationEnabled];
- ConditionBlock condition = ^bool {
- return ![ChromeEarlGrey isIncognitoMode];
- };
- if (!base::test::ios::WaitUntilConditionOrTimeout(kWaitElementTimeout,
- condition)) {
- return testing::NSErrorWithLocalizedDescription(
- @"Waiting switch to normal mode.");
- }
+ bool success = WaitUntilConditionOrTimeout(kWaitElementTimeout, ^{
+ return ![ChromeEarlGrey isIncognitoMode];
+ });
[[GREYConfiguration sharedInstance]
setValue:@(YES)
forConfigKey:kGREYConfigKeySynchronizationEnabled];
- return nil;
+ if (!success) {
+ // TODO(crbug.com/951600): Avoid asserting directly unless the test fails,
+ // due to timing issues.
+ GREYFail(@"Failed to switch to normal mode.");
+ }
}
} // namespace tab_usage_recorder_test_util