Commit 8d972fd2 authored by Eric Aleshire's avatar Eric Aleshire Committed by Commit Bot

Move GREYAsserts from automation_action (for autofill) into the corresponding EG tests.

This is part of EG1 to EG2 migration, which involves moving EarlGrey code from
app-side helpers into test code. For GREYAsserts, the policy is to take assert-
containing-helpers, modify them to return NSError* with localizedDescription
containing the assert failure (in the event of a failure), and then assert
on the result of the helper on the test side.

Confirmed locally that autofill site tests still work after the refactor. I feel the
way in which NSErrors are passed around automation_action could be cleaned up in a
neater fashion given greater code refactoring (instead of just modifying methods to
take NSErrors) but I am not sure what form that would take at the moment.

Bug: 922813
Change-Id: I0d4e92970c9184662d7b147eee0babcb4cfbede8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1580581Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Commit-Queue: ericale <ericale@chromium.org>
Cr-Commit-Position: refs/heads/master@{#653775}
parent 49784001
......@@ -17,14 +17,14 @@
// Returns an concrete instance of a subclass of AutomationAction.
+ (instancetype)actionWithValueDictionary:
(const base::DictionaryValue&)actionDictionary;
(const base::DictionaryValue&)actionDictionary
error:(NSError**)error;
// Prevents creating rogue instances, the init methods are private.
- (instancetype)init NS_UNAVAILABLE;
// For subclasses to implement, execute the action. Use GREYAssert in case of
// issue.
- (void)execute;
// For subclasses to implement, execute the action.
- (NSError*)execute WARN_UNUSED_RESULT;
@end
#endif // IOS_CHROME_BROWSER_AUTOFILL_AUTOMATION_AUTOMATION_ACTION_H_
......@@ -8,6 +8,7 @@
#import "ios/chrome/browser/autofill/automation/automation_action.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_test_case.h"
#import "ios/web/public/test/js_test_util.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
......@@ -44,8 +45,13 @@ const char kTestPageUrl[] = "/credit_card_upload_form_address_and_cc.html";
base::DictionaryValue dict = base::DictionaryValue();
dict.SetKey("type", base::Value("click"));
dict.SetKey("selector", base::Value("//*[@id=\"fill_form\"]"));
AutomationAction* action = [AutomationAction actionWithValueDictionary:dict];
[action execute];
NSError* actionCreationError = nil;
AutomationAction* action =
[AutomationAction actionWithValueDictionary:dict
error:&actionCreationError];
CHROME_EG_ASSERT_NO_ERROR(actionCreationError);
CHROME_EG_ASSERT_NO_ERROR([action execute]);
NSError* error;
id result = chrome_test_util::ExecuteJavaScript(
......@@ -63,9 +69,13 @@ const char kTestPageUrl[] = "/credit_card_upload_form_address_and_cc.html";
base::DictionaryValue clickDict = base::DictionaryValue();
clickDict.SetKey("type", base::Value("click"));
clickDict.SetKey("selector", base::Value("//*[@id=\"fill_form_delay\"]"));
NSError* actionCreationError = nil;
AutomationAction* clickAction =
[AutomationAction actionWithValueDictionary:clickDict];
[clickAction execute];
[AutomationAction actionWithValueDictionary:clickDict
error:&actionCreationError];
CHROME_EG_ASSERT_NO_ERROR(actionCreationError);
CHROME_EG_ASSERT_NO_ERROR([clickAction execute]);
base::DictionaryValue waitForDict = base::DictionaryValue();
waitForDict.SetKey("type", base::Value("waitFor"));
......@@ -75,8 +85,10 @@ const char kTestPageUrl[] = "/credit_card_upload_form_address_and_cc.html";
"Smith\";"));
waitForDict.SetKey("assertions", std::move(assertions));
AutomationAction* waitForAction =
[AutomationAction actionWithValueDictionary:waitForDict];
[waitForAction execute];
[AutomationAction actionWithValueDictionary:waitForDict
error:&actionCreationError];
CHROME_EG_ASSERT_NO_ERROR(actionCreationError);
CHROME_EG_ASSERT_NO_ERROR([waitForAction execute]);
}
- (void)testAutomationActionSelectDropdown {
......@@ -84,9 +96,13 @@ const char kTestPageUrl[] = "/credit_card_upload_form_address_and_cc.html";
selectDict.SetKey("type", base::Value("select"));
selectDict.SetKey("selector", base::Value("//*[@name=\"cc_month_exp\"]"));
selectDict.SetKey("index", base::Value(5));
AutomationAction* selectAction =
[AutomationAction actionWithValueDictionary:selectDict];
[selectAction execute];
NSError* actionCreationError = nil;
AutomationAction* clickAction =
[AutomationAction actionWithValueDictionary:selectDict
error:&actionCreationError];
CHROME_EG_ASSERT_NO_ERROR(actionCreationError);
CHROME_EG_ASSERT_NO_ERROR([clickAction execute]);
NSError* error;
id result = chrome_test_util::ExecuteJavaScript(
......
......@@ -26,6 +26,7 @@
#include "components/autofill/ios/browser/autofill_driver_ios.h"
#import "ios/chrome/browser/autofill/form_suggestion_label.h"
#import "ios/chrome/test/app/chrome_test_util.h"
#import "ios/chrome/test/earl_grey/chrome_error_util.h"
#import "ios/web/public/test/earl_grey/web_view_actions.h"
#import "ios/web/public/test/earl_grey/web_view_matchers.h"
#include "ios/web/public/test/element_selector.h"
......@@ -232,10 +233,14 @@ static const int kRecipeRetryLimit = 5;
for (auto const& actionValue : actionsValues) {
GREYAssert(actionValue.is_dict(),
@"Expecting each action to be a dictionary in the JSON file.");
[actions_ addObject:[AutomationAction
actionWithValueDictionary:
static_cast<const base::DictionaryValue&>(
actionValue)]];
NSError* actionCreationError = nil;
AutomationAction* action = [AutomationAction
actionWithValueDictionary:static_cast<const base::DictionaryValue&>(
actionValue)
error:&actionCreationError];
CHROME_EG_ASSERT_NO_ERROR(actionCreationError);
[actions_ addObject:action];
}
}
......@@ -284,7 +289,7 @@ static const int kRecipeRetryLimit = 5;
[ChromeEarlGrey loadURL:startUrl];
for (AutomationAction* action in actions_) {
[action execute];
CHROME_EG_ASSERT_NO_ERROR([action execute]);
}
} @catch (NSException* e) {
return false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment