Commit 62c46102 authored by sandromaggi's avatar sandromaggi Committed by Commit Bot

[Autofill Assistant] Adding more browser tests for OOPIF

Add a test for selecting an option.
Add a test for getting outer HTML.

Bug: b/141853667
Change-Id: If420e913d4be4e3eb43614aa9faddcb7524399e3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1863019
Commit-Queue: Sandro Maggi <sandromaggi@google.com>
Reviewed-by: default avatarMathias Carlen <mcarlen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#707321}
parent f3a33367
...@@ -1050,11 +1050,14 @@ IN_PROC_BROWSER_TEST_F(WebControllerBrowserTest, SelectOption) { ...@@ -1050,11 +1050,14 @@ IN_PROC_BROWSER_TEST_F(WebControllerBrowserTest, SelectOption) {
SelectOption(selector, "two").proto_status()); SelectOption(selector, "two").proto_status());
} }
IN_PROC_BROWSER_TEST_F(WebControllerBrowserTest, SelectOptionInIframe) { IN_PROC_BROWSER_TEST_F(WebControllerBrowserTest, SelectOptionInIFrame) {
Selector selector; Selector select_selector;
selector.selectors.emplace_back("#iframe");
selector.selectors.emplace_back("select[name=state]"); // IFrame.
EXPECT_EQ(ACTION_APPLIED, SelectOption(selector, "NY").proto_status()); select_selector.selectors.clear();
select_selector.selectors.emplace_back("#iframe");
select_selector.selectors.emplace_back("select[name=state]");
EXPECT_EQ(ACTION_APPLIED, SelectOption(select_selector, "NY").proto_status());
const std::string javascript = R"( const std::string javascript = R"(
let iframe = document.querySelector("iframe").contentDocument; let iframe = document.querySelector("iframe").contentDocument;
...@@ -1062,16 +1065,46 @@ IN_PROC_BROWSER_TEST_F(WebControllerBrowserTest, SelectOptionInIframe) { ...@@ -1062,16 +1065,46 @@ IN_PROC_BROWSER_TEST_F(WebControllerBrowserTest, SelectOptionInIframe) {
select.options[select.selectedIndex].label; select.options[select.selectedIndex].label;
)"; )";
EXPECT_EQ("NY", content::EvalJs(shell(), javascript)); EXPECT_EQ("NY", content::EvalJs(shell(), javascript));
// OOPIF.
// Checking elements through EvalJs in OOPIF is blocked by cross-site.
select_selector.selectors.clear();
select_selector.selectors.emplace_back("#iframeExternal");
select_selector.selectors.emplace_back("select[name=pet]");
EXPECT_EQ(ACTION_APPLIED,
SelectOption(select_selector, "Cat").proto_status());
Selector result_selector;
result_selector.selectors.emplace_back("#iframeExternal");
result_selector.selectors.emplace_back("#myPet");
GetFieldsValue({result_selector}, {"Cat"});
} }
IN_PROC_BROWSER_TEST_F(WebControllerBrowserTest, GetOuterHtml) { IN_PROC_BROWSER_TEST_F(WebControllerBrowserTest, GetOuterHtml) {
Selector selector;
selector.selectors.emplace_back("#testOuterHtml");
std::string html; std::string html;
ASSERT_EQ(ACTION_APPLIED, GetOuterHtml(selector, &html).proto_status());
// Div.
Selector div_selector;
div_selector.selectors.emplace_back("#testOuterHtml");
ASSERT_EQ(ACTION_APPLIED, GetOuterHtml(div_selector, &html).proto_status());
EXPECT_EQ( EXPECT_EQ(
R"(<div id="testOuterHtml"><span>Span</span><p>Paragraph</p></div>)", R"(<div id="testOuterHtml"><span>Span</span><p>Paragraph</p></div>)",
html); html);
// IFrame.
Selector iframe_selector;
iframe_selector.selectors.emplace_back("#iframe");
iframe_selector.selectors.emplace_back("#input");
ASSERT_EQ(ACTION_APPLIED,
GetOuterHtml(iframe_selector, &html).proto_status());
EXPECT_EQ(R"(<input id="input" type="text">)", html);
// OOPIF.
Selector oopif_selector;
oopif_selector.selectors.emplace_back("#iframeExternal");
oopif_selector.selectors.emplace_back("#divToRemove");
ASSERT_EQ(ACTION_APPLIED, GetOuterHtml(oopif_selector, &html).proto_status());
EXPECT_EQ(R"(<div id="divToRemove">Text</div>)", html);
} }
IN_PROC_BROWSER_TEST_F(WebControllerBrowserTest, GetAndSetFieldValue) { IN_PROC_BROWSER_TEST_F(WebControllerBrowserTest, GetAndSetFieldValue) {
......
...@@ -13,15 +13,29 @@ found in the LICENSE file. ...@@ -13,15 +13,29 @@ found in the LICENSE file.
<script> <script>
var removeDiv = function() { var removeDiv = function() {
var div = document.getElementById("div"); var div = document.getElementById("divToRemove");
div.parentNode.removeChild(div); div.parentNode.removeChild(div);
} }
var setText = function() {
var select = document.getElementById("select");
var input = document.getElementById("myPet");
input.value = select.options[select.selectedIndex].label;
}
</script> </script>
</head> </head>
<body> <body>
<button id="button" type="button" onclick="removeDiv()">Button</button> <button id="button" type="button" onclick="removeDiv()">Button</button>
<div id="div">Text</div> <div id="divToRemove">Text</div>
<input id="input" type="text" /> <input id="input" type="text" />
<select id="select" name="pet" onchange="setText()">
<option value="Dog">Dog</option>
<option value="Cat">Cat</option>
<option value="Hamster">Hamster</option>
<option value="Fish">Fish</option>
</select>
<input type="text" id="myPet"/>
</body> </body>
</html> </html>
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