Skip to content

Commit

Permalink
Split chrome_error_util into a second file, nserror_util.
Browse files Browse the repository at this point in the history
chrome_error_util will contain EarlGrey-specific code, while generic
NSError generation will go in nserror_util.

Bug: 922813
Change-Id: Id9fcbd978e420956361cb0542e157020f6f33945
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1579469
Commit-Queue: ericale <ericale@chromium.org>
Reviewed-by: Rohit Rao <rohitrao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#653677}
  • Loading branch information
totoriott authored and Commit Bot committed Apr 24, 2019
1 parent 09a78d9 commit 03dcc60
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 33 deletions.
10 changes: 5 additions & 5 deletions ios/chrome/browser/metrics/tab_usage_recorder_test_util.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#import "ios/chrome/test/app/tab_test_util.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/testing/nserror_util.h"
#include "ui/base/l10n/l10n_util_mac.h"

#if !defined(__has_feature) || !__has_feature(objc_arc)
Expand Down Expand Up @@ -73,7 +73,7 @@ bool ShowTabSwitcher() {
bool success = base::test::ios::WaitUntilConditionOrTimeout(
kWaitElementTimeout, condition);
if (!success) {
return chrome_test_util::NSErrorWithLocalizedDescription(
return testing::NSErrorWithLocalizedDescription(
@"Waiting switch to incognito mode.");
}

Expand All @@ -83,13 +83,13 @@ bool ShowTabSwitcher() {

NSError* SwitchToNormalMode() {
if (!chrome_test_util::IsIncognitoMode()) {
return chrome_test_util::NSErrorWithLocalizedDescription(
return testing::NSErrorWithLocalizedDescription(
@"Switching to normal mode is only allowed from Incognito.");
}

// Enter the tab grid to switch modes.
if (!ShowTabSwitcher()) {
return chrome_test_util::NSErrorWithLocalizedDescription(
return testing::NSErrorWithLocalizedDescription(
@"Tab switcher could not be tapped.");
}

Expand All @@ -113,7 +113,7 @@ bool ShowTabSwitcher() {

if (!base::test::ios::WaitUntilConditionOrTimeout(kWaitElementTimeout,
condition)) {
return chrome_test_util::NSErrorWithLocalizedDescription(
return testing::NSErrorWithLocalizedDescription(
@"Waiting switch to normal mode.");
}

Expand Down
8 changes: 4 additions & 4 deletions ios/chrome/browser/ui/authentication/signin_earlgrey_utils.mm
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/signin/identity_manager_factory.h"
#import "ios/chrome/test/app/chrome_test_util.h"
#import "ios/chrome/test/earl_grey/chrome_error_util.h"
#import "ios/public/provider/chrome/browser/signin/fake_chrome_identity.h"
#import "ios/testing/nserror_util.h"
#include "services/identity/public/cpp/identity_manager.h"

#if !defined(__has_feature) || !__has_feature(objc_arc)
Expand Down Expand Up @@ -41,7 +41,7 @@ + (ChromeIdentity*)fakeManagedIdentity {

+ (NSError*)checkSignedInWithIdentity:(ChromeIdentity*)identity {
if (identity == nil) {
return chrome_test_util::NSErrorWithLocalizedDescription(
return testing::NSErrorWithLocalizedDescription(
@"Need to give an identity");
}

Expand All @@ -62,7 +62,7 @@ + (NSError*)checkSignedInWithIdentity:(ChromeIdentity*)identity {
@"Unexpected Gaia ID of the signed in user [expected = "
@"\"%@\", actual = \"%s\"]",
identity.gaiaID, info.gaia.c_str()];
return chrome_test_util::NSErrorWithLocalizedDescription(errorStr);
return testing::NSErrorWithLocalizedDescription(errorStr);
}

return nil;
Expand All @@ -79,7 +79,7 @@ + (NSError*)checkSignedOut {

if (IdentityManagerFactory::GetForBrowserState(browser_state)
->HasPrimaryAccount()) {
return chrome_test_util::NSErrorWithLocalizedDescription(
return testing::NSErrorWithLocalizedDescription(
@"Unexpected signed in user");
}

Expand Down
7 changes: 3 additions & 4 deletions ios/chrome/browser/ui/payments/payment_request_egtest_base.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#include "ios/chrome/browser/payments/ios_payment_request_cache_factory.h"
#import "ios/chrome/test/app/chrome_test_util.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
#import "ios/chrome/test/earl_grey/chrome_error_util.h"
#import "ios/chrome/test/earl_grey/chrome_matchers.h"
#import "ios/testing/nserror_util.h"
#import "ios/web/public/test/http_server/http_server.h"
#import "ios/web/public/test/web_view_interaction_test_util.h"

Expand Down Expand Up @@ -93,8 +93,7 @@ - (NSError*)addAutofillProfile:(const autofill::AutofillProfile&)profile {
[self personalDataManager] -> GetProfiles().size();
});
if (!isProfileAdded) {
return chrome_test_util::NSErrorWithLocalizedDescription(
@"Failed to add profile.");
return testing::NSErrorWithLocalizedDescription(@"Failed to add profile.");
}
return nil;
}
Expand All @@ -109,7 +108,7 @@ - (NSError*)addCreditCard:(const autofill::CreditCard&)card {
[self personalDataManager] -> GetCreditCards().size();
});
if (!isCreditCardAdded) {
return chrome_test_util::NSErrorWithLocalizedDescription(
return testing::NSErrorWithLocalizedDescription(
@"Failed to add credit card.");
}
return nil;
Expand Down
6 changes: 2 additions & 4 deletions ios/chrome/test/earl_grey/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ source_set("test_support") {
"chrome_earl_grey_ui.h",
"chrome_earl_grey_ui.mm",
"chrome_error_util.h",
"chrome_error_util.mm",
"chrome_matchers.h",
"chrome_matchers.mm",
"chrome_matchers_app_interface.h",
Expand Down Expand Up @@ -282,6 +281,7 @@ source_set("test_support") {

public_deps = [
"//build/config/ios:xctest",
"//ios/testing:nserror_support",
"//ios/third_party/earl_grey:earl_grey+link",
"//ios/third_party/gtx:gtx+link",
"//ios/web/public/test",
Expand Down Expand Up @@ -317,8 +317,6 @@ source_set("eg_app_support+eg2") {
sources = [
"chrome_actions_app_interface.h",
"chrome_actions_app_interface.mm",
"chrome_error_util.h",
"chrome_error_util.mm",
"chrome_matchers_app_interface.h",
"chrome_matchers_app_interface.mm",
]
Expand All @@ -345,6 +343,7 @@ source_set("eg_app_support+eg2") {
"//ios/chrome/browser/ui/toolbar/public",
"//ios/chrome/browser/ui/util",
"//ios/chrome/test/app:test_support",
"//ios/testing:nserror_support",
"//ios/testing/earl_grey:eg_app_support+eg2",
"//ios/testing/earl_grey:eg_app_support+eg2",
"//ios/third_party/earl_grey2:app_framework+link",
Expand All @@ -368,7 +367,6 @@ source_set("eg_test_support+eg2") {
"chrome_actions.mm",
"chrome_actions_app_interface.h",
"chrome_error_util.h",
"chrome_error_util.mm",
"chrome_matchers.h",
"chrome_matchers.mm",
"chrome_matchers_app_interface.h",
Expand Down
4 changes: 2 additions & 2 deletions ios/chrome/test/earl_grey/chrome_earl_grey_ui.mm
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
#include "ios/chrome/grit/ios_strings.h"
#import "ios/chrome/test/app/chrome_test_util.h"
#include "ios/chrome/test/app/navigation_test_util.h"
#import "ios/chrome/test/earl_grey/chrome_error_util.h"
#import "ios/chrome/test/earl_grey/chrome_matchers.h"
#import "ios/testing/nserror_util.h"
#import "ios/web/public/test/earl_grey/js_test_util.h"
#import "ios/web/public/test/earl_grey/web_view_matchers.h"
#include "ui/base/l10n/l10n_util.h"
Expand Down Expand Up @@ -219,7 +219,7 @@ + (NSError*)waitForToolbarVisible:(BOOL)isVisible {

if (!base::test::ios::WaitUntilConditionOrTimeout(
kWaitForToolbarAnimationTimeout, condition)) {
return chrome_test_util::NSErrorWithLocalizedDescription(errorMessage);
return testing::NSErrorWithLocalizedDescription(errorMessage);
}

return nil;
Expand Down
11 changes: 0 additions & 11 deletions ios/chrome/test/earl_grey/chrome_error_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
#ifndef IOS_CHROME_TEST_EARL_GREY_CHROME_ERROR_UTIL_H_
#define IOS_CHROME_TEST_EARL_GREY_CHROME_ERROR_UTIL_H_

@class NSError;
@class NSString;

// Wraps an expression that returns an NSError*, asserting if an error is
// returned. Used in EG test code to assert if app helpers fail. For example:
// CHROME_EG_ASSERT_NO_ERROR(helperReturningNSError());
Expand All @@ -20,12 +17,4 @@
GREYAssertNil(error, error.localizedDescription); \
}

namespace chrome_test_util {

// Returns a NSError with generic domain and error code, and the provided string
// as localizedDescription.
NSError* NSErrorWithLocalizedDescription(NSString* error_description);

} // namespace chrome_test_util

#endif // IOS_CHROME_TEST_EARL_GREY_CHROME_ERROR_UTIL_H_
9 changes: 9 additions & 0 deletions ios/testing/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ group("all_tests") {
]
}

source_set("nserror_support") {
configs += [ "//build/config/compiler:enable_arc" ]
testonly = true
sources = [
"nserror_util.h",
"nserror_util.mm",
]
}

source_set("embedded_test_server_support") {
configs += [ "//build/config/compiler:enable_arc" ]
testonly = true
Expand Down
19 changes: 19 additions & 0 deletions ios/testing/nserror_util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef IOS_TESTING_NSERROR_UTIL_H_
#define IOS_TESTING_NSERROR_UTIL_H_

@class NSError;
@class NSString;

namespace testing {

// Returns a NSError with generic domain and error code, and the provided string
// as localizedDescription.
NSError* NSErrorWithLocalizedDescription(NSString* error_description);

} // namespace testing

#endif // IOS_TESTING_NSERROR_UTIL_H_
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "ios/chrome/test/earl_grey/chrome_error_util.h"
#import "ios/testing/nserror_util.h"

#import <Foundation/Foundation.h>

#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif

namespace chrome_test_util {
namespace testing {

NSError* NSErrorWithLocalizedDescription(NSString* error_description) {
NSDictionary* userInfo = @{
Expand All @@ -22,4 +22,4 @@
userInfo:userInfo];
}

} // namespace chrome_test_util
} // namespace testing

0 comments on commit 03dcc60

Please sign in to comment.