Commit 1dbf3e8a authored by Alexander Alekseev's avatar Alexander Alekseev Committed by Commit Bot

Chrome OS: Remove possible anchors from EULA screen.

This removes anchord from EULA screen webview because disabled navigation
and anchors may confuse users.

Bug: 757721
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: Ifb8f37f7b0691e9c85c75bb89863bf49f8ca4053
Reviewed-on: https://chromium-review.googlesource.com/918282
Commit-Queue: Alexander Alekseev <alemate@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarChris Palmer <palmer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#538996}
parent c7d4c175
......@@ -95,36 +95,31 @@ class EulaTest : public OobeBaseTest {
embedded_test_server()->RegisterRequestHandler(
base::Bind(&EulaTest::HandleRequest, base::Unretained(this)));
}
void SetUpOnMainThread() override {
OobeBaseTest::SetUpOnMainThread();
OverrideOnlineEulaUrl();
eula_contents_ = FindEulaContents();
ASSERT_NE(nullptr, eula_contents_);
}
void OverrideOnlineEulaUrl() {
// Override with the embedded test server's base url. Otherwise, the load
// would not hit the embedded test server.
const GURL fake_eula_url =
embedded_test_server()->base_url().Resolve(kFakeOnlineEulaPath);
JS().Evaluate(base::StringPrintf(
"loadTimeData.overrideValues({eulaOnlineUrl: '%s'});",
fake_eula_url.spec().c_str()));
JS().Evaluate(
base::StringPrintf("loadTimeData.overrideValues({eulaOnlineUrl: '%s'});"
"Oobe.updateLocalizedContent();",
fake_eula_url.spec().c_str()));
}
void ShowEulaScreen() {
LoginDisplayHost::default_host()->StartWizard(OobeScreen::SCREEN_OOBE_EULA);
OverrideOnlineEulaUrl();
OobeScreenWaiter(OobeScreen::SCREEN_OOBE_EULA).Wait();
}
std::string GetLoadedEulaAsText() {
// Wait the contents to load.
WebContentsLoadFinishedWaiter(eula_contents_).Wait();
WebContentsLoadFinishedWaiter(FindEulaContents()).Wait();
std::string eula_text;
EXPECT_TRUE(content::ExecuteScriptAndExtractString(
eula_contents_,
FindEulaContents(),
"window.domAutomationController.send(document.body.textContent);",
&eula_text));
......@@ -132,31 +127,8 @@ class EulaTest : public OobeBaseTest {
}
void set_allow_online_eula(bool allow) { allow_online_eula_ = allow; }
content::WebContents* eula_contents() { return eula_contents_; }
private:
std::unique_ptr<HttpResponse> HandleRequest(const HttpRequest& request) {
GURL request_url = GURL("http://localhost").Resolve(request.relative_url);
const std::string request_path = request_url.path();
if (!base::EndsWith(request_path, "/eula_text.html",
base::CompareCase::SENSITIVE)) {
return std::unique_ptr<HttpResponse>();
}
std::unique_ptr<BasicHttpResponse> http_response =
std::make_unique<BasicHttpResponse>();
if (allow_online_eula_) {
http_response->set_code(net::HTTP_OK);
http_response->set_content_type("text/html");
http_response->set_content(kFakeOnlineEula);
} else {
http_response->set_code(net::HTTP_SERVICE_UNAVAILABLE);
}
return std::move(http_response);
}
protected:
content::WebContents* FindEulaContents() {
// Tag the Eula webview in use with a unique name.
constexpr char kUniqueEulaWebviewName[] = "unique-eula-webview-name";
......@@ -181,10 +153,30 @@ class EulaTest : public OobeBaseTest {
return *frame_set.begin();
}
bool allow_online_eula_ = false;
private:
std::unique_ptr<HttpResponse> HandleRequest(const HttpRequest& request) {
GURL request_url = GURL("http://localhost").Resolve(request.relative_url);
const std::string request_path = request_url.path();
if (!base::EndsWith(request_path, "/eula_text.html",
base::CompareCase::SENSITIVE)) {
return std::unique_ptr<HttpResponse>();
}
std::unique_ptr<BasicHttpResponse> http_response =
std::make_unique<BasicHttpResponse>();
// WebContents of the webview hosting the Eula contents.
content::WebContents* eula_contents_ = nullptr;
if (allow_online_eula_) {
http_response->set_code(net::HTTP_OK);
http_response->set_content_type("text/html");
http_response->set_content(kFakeOnlineEula);
} else {
http_response->set_code(net::HTTP_SERVICE_UNAVAILABLE);
}
return std::move(http_response);
}
bool allow_online_eula_ = false;
DISALLOW_COPY_AND_ASSIGN(EulaTest);
};
......@@ -203,9 +195,11 @@ IN_PROC_BROWSER_TEST_F(EulaTest, LoadOffline) {
set_allow_online_eula(false);
ShowEulaScreen();
content::WebContents* eula_contents = FindEulaContents();
ASSERT_TRUE(eula_contents);
// Wait for the fallback offline page (loaded as data url) to be loaded.
while (!eula_contents()->GetLastCommittedURL().SchemeIs("data"))
WebContentsLoadFinishedWaiter(eula_contents()).Wait();
while (!eula_contents->GetLastCommittedURL().SchemeIs("data"))
WebContentsLoadFinishedWaiter(eula_contents).Wait();
EXPECT_TRUE(GetLoadedEulaAsText().find(kOfflineEULAWarning) !=
std::string::npos);
......
......@@ -8,6 +8,15 @@
login.createScreen('EulaScreen', 'eula', function() {
var CONTEXT_KEY_USAGE_STATS_ENABLED = 'usageStatsEnabled';
var CLEAR_ANCHORS_CONTENT_SCRIPT = {
code: 'A=Array.from(document.getElementsByTagName("a"));' +
'for(var i = 0; i < A.length; ++i) {' +
' const el = A[i];' +
' let e = document.createElement("span");' +
' e.textContent=el.textContent;' +
' el.parentNode.replaceChild(e,el);' +
'}'
};
/**
* Load text/html contents from the given url into the given webview. The
......@@ -335,6 +344,15 @@ login.createScreen('EulaScreen', 'eula', function() {
loadUrlToWebview(webview, TERMS_URL);
};
webview.addContentScripts([{
name: 'clearAnchors',
matches: ['<all_urls>'],
js: CLEAR_ANCHORS_CONTENT_SCRIPT,
}]);
webview.addEventListener('contentload', () => {
webview.executeScript(CLEAR_ANCHORS_CONTENT_SCRIPT);
});
var onlineEulaUrl = loadTimeData.getString('eulaOnlineUrl');
if (!onlineEulaUrl) {
loadBundledEula();
......
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