Commit be790f0d authored by Yiming Zhou's avatar Yiming Zhou Committed by Commit Bot

Add new actions to the Captured Sites Automation framework.

Adding a list of new actions to the Captured Sites Automation framework,
as well as a measure to hide the geolocation dialog, and a measure to
dismiss modal beforeunload JavaScript dialogs.

Bug: 847905
Change-Id: Icb687ebc46a339c0ecc6be799200aac73b32b5ae
Reviewed-on: https://chromium-review.googlesource.com/1207892
Commit-Queue: Yiming Zhou <uwyiming@google.com>
Reviewed-by: default avatarSebastien Seguin-Gagnon <sebsg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#589310}
parent b4bebe1a
......@@ -200,31 +200,6 @@ class AutofillCapturedSitesInteractiveTest
bool ShowAutofillSuggestion(content::RenderFrameHost* frame,
const std::string& target_element_xpath) {
const std::string get_target_field_x_js(base::StringPrintf(
"window.domAutomationController.send("
" (function() {"
" try {"
" const element = automation_helper.getElementByXpath(`%s`);"
" const rect = element.getBoundingClientRect();"
" console.log(`Window href x: ${location.href}`);"
" return Math.floor(rect.left + rect.width / 2);"
" } catch(ex) {}"
" return -1;"
" })());",
target_element_xpath.c_str()));
const std::string get_target_field_y_js(base::StringPrintf(
"window.domAutomationController.send("
" (function() {"
" try {"
" const element = automation_helper.getElementByXpath(`%s`);"
" const rect = element.getBoundingClientRect();"
" console.log(`Window href y: ${location.href}`);"
" return Math.floor(rect.top + rect.height / 2);"
" } catch(ex) {}"
" return -1;"
" })());",
target_element_xpath.c_str()));
// First, automation should focus on the frame containg the autofill form.
// Doing so ensures that Chrome scrolls the element into view if the
// element is off the page.
......@@ -232,16 +207,10 @@ class AutofillCapturedSitesInteractiveTest
frame, target_element_xpath))
return false;
int x;
if (!content::ExecuteScriptAndExtractInt(frame, get_target_field_x_js, &x))
return false;
if (x == -1)
return false;
int y;
if (!content::ExecuteScriptAndExtractInt(frame, get_target_field_y_js, &y))
return false;
if (y == -1)
int x, y;
if (!captured_sites_test_utils::TestRecipeReplayer::
GetCenterCoordinateOfTargetElement(frame, target_element_xpath, x,
y))
return false;
test_delegate()->Reset();
......
......@@ -27,6 +27,10 @@ namespace captured_sites_test_utils {
// has expired for the page to load or for the page to respond to the last
// user action.
const base::TimeDelta default_action_timeout = base::TimeDelta::FromSeconds(30);
// The amount of time to wait for a page to trigger a paint in response to a
// an ation. The Captured Site Automation Framework uses this timeout to
// break out of a wait loop after a hover action.
const base::TimeDelta visual_update_timeout = base::TimeDelta::FromSeconds(5);
std::string FilePathToUTF8(const base::FilePath::StringType& str);
......@@ -68,6 +72,9 @@ class PageActivityObserver : public content::WebContentsObserver {
// finished loading the page.
void WaitTillPageIsIdle(
base::TimeDelta continuous_paint_timeout = default_action_timeout);
// Wait until Chrome makes at least 1 visual update, or until timeout
// expires.
bool WaitForVisualUpdate(base::TimeDelta timeout = visual_update_timeout);
private:
// PageActivityObserver determines if Chrome stopped painting by checking if
......@@ -185,11 +192,19 @@ class TestRecipeReplayer {
static void SetUpCommandLine(base::CommandLine* command_line);
static bool PlaceFocusOnElement(content::RenderFrameHost* frame,
const std::string& element_xpath);
static bool GetCenterCoordinateOfTargetElement(
content::RenderFrameHost* frame,
const std::string& target_element_xpath,
int& x,
int& y);
static bool SimulateLeftMouseClickAt(
content::RenderFrameHost* render_frame_host,
const gfx::Point& point);
static bool SimulateMouseHoverAt(content::RenderFrameHost* render_frame_host,
const gfx::Point& point);
private:
Browser* browser();
TestRecipeReplayChromeFeatureActionExecutor* feature_action_executor();
content::WebContents* GetWebContents();
void CleanupSiteData();
......@@ -209,8 +224,12 @@ class TestRecipeReplayer {
std::unique_ptr<base::DictionaryValue>& recipe);
bool ExecuteAutofillAction(const base::DictionaryValue& action);
bool ExecuteClickAction(const base::DictionaryValue& action);
bool ExecuteHoverAction(const base::DictionaryValue& action);
bool ExecutePressEnterAction(const base::DictionaryValue& action);
bool ExecuteRunCommandAction(const base::DictionaryValue& action);
bool ExecuteSelectDropdownAction(const base::DictionaryValue& action);
bool ExecuteTypeAction(const base::DictionaryValue& action);
bool ExecuteTypePasswordAction(const base::DictionaryValue& action);
bool ExecuteValidateFieldValueAction(const base::DictionaryValue& action);
bool ExecuteWaitForStateAction(const base::DictionaryValue& action);
bool GetTargetHTMLElementXpathFromAction(const base::DictionaryValue& action,
......@@ -236,6 +255,7 @@ class TestRecipeReplayer {
const std::string& get_property_function_body,
const std::string& expected_value,
const bool ignoreCase = false);
void NavigateAwayAndDismissBeforeUnloadDialog();
Browser* browser_;
TestRecipeReplayChromeFeatureActionExecutor* feature_action_executor_;
......
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