Commit 162eec0c authored by Roman Sorokin's avatar Roman Sorokin Committed by Commit Bot

cros oobe: Add focus helpers into js_checker

Bug: 1108996, 1032194
Change-Id: Ib92003f7ed789e858831b518e54a36629940e2fe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2406212
Auto-Submit: Roman Sorokin [CET] <rsorokin@chromium.org>
Reviewed-by: default avatarDenis Kuznetsov [CET] <antrim@chromium.org>
Commit-Queue: Roman Sorokin [CET] <rsorokin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#806174}
parent aa201bd1
......@@ -13,6 +13,7 @@
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/aura/window.h"
namespace {
......@@ -25,6 +26,21 @@ bool CheckOobeCondition(content::WebContents* web_contents,
return chromeos::test::JSChecker(web_contents).GetBool(js_condition);
}
bool IsFocused(content::WebContents* web_contents,
const std::initializer_list<base::StringPiece>& path) {
if (!web_contents->GetContentNativeView()->HasFocus())
return false;
auto js_checker = chromeos::test::JSChecker(web_contents);
std::string current_active = "document.activeElement";
for (const auto& it : path) {
if (js_checker.GetString(current_active + ".id") != it) {
return false;
}
current_active += ".shadowRoot.activeElement";
}
return true;
}
std::string ElementHasClassCondition(
const std::string& css_class,
std::initializer_list<base::StringPiece> element_ids) {
......@@ -195,6 +211,23 @@ void JSChecker::ExpectAttributeNE(
ExpectNE(GetAttributeExpression(attribute, element_ids), result);
}
void JSChecker::ExpectFocused(
std::initializer_list<base::StringPiece> element_ids) {
ASSERT_TRUE(web_contents_->GetContentNativeView()->HasFocus());
std::string current_active = "document.activeElement";
for (const auto& it : element_ids) {
ExpectEQ(current_active + ".id", std::string(it));
current_active += ".shadowRoot.activeElement";
}
}
std::unique_ptr<TestConditionWaiter> JSChecker::CreateFocusWaiter(
const std::initializer_list<base::StringPiece>& path) {
return std::make_unique<TestPredicateWaiter>(
base::BindRepeating(&IsFocused, base::Unretained(web_contents_), path));
}
std::unique_ptr<TestConditionWaiter> JSChecker::CreateWaiter(
const std::string& js_condition) {
TestPredicateWaiter::PredicateCheck predicate = base::BindRepeating(
......
......@@ -90,6 +90,10 @@ class JSChecker {
std::initializer_list<base::StringPiece> element_id,
bool result);
void ExpectFocused(std::initializer_list<base::StringPiece> element_id);
WARN_UNUSED_RESULT std::unique_ptr<TestConditionWaiter> CreateFocusWaiter(
const std::initializer_list<base::StringPiece>& path);
// Checks test waiter that would await until |js_condition| evaluates
// to true.
WARN_UNUSED_RESULT std::unique_ptr<TestConditionWaiter> CreateWaiter(
......
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