Commit 2b91da02 authored by yilkal's avatar yilkal Committed by Commit Bot

Hide Back button on iframe interstitial error page.

The Back button should not be displayed when the error page is being
shown in an iframe.

Bug: 850328
Change-Id: Iaf7ea83abd1d1a84449a1489b296129311429333
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1832705Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Reviewed-by: default avatarMichael Giuffrida <michaelpg@chromium.org>
Commit-Queue: Yilkal Abe <yilkal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#706992}
parent f452e7b6
...@@ -125,8 +125,10 @@ function initialize() { ...@@ -125,8 +125,10 @@ function initialize() {
/** /**
* Updates the interstitial to show that the request failed or was sent. * Updates the interstitial to show that the request failed or was sent.
* @param {boolean} isSuccessful Whether the request was successful or not. * @param {boolean} isSuccessful Whether the request was successful or not.
* @param {boolean} isMainFrame Whether the interstitial is being shown in main
* frame.
*/ */
function setRequestStatus(isSuccessful) { function setRequestStatus(isSuccessful, isMainFrame) {
console.log('setRequestStatus(' + isSuccessful +')'); console.log('setRequestStatus(' + isSuccessful +')');
$('block-page-header').hidden = true; $('block-page-header').hidden = true;
$('block-page-message').hidden = true; $('block-page-message').hidden = true;
...@@ -137,7 +139,7 @@ function setRequestStatus(isSuccessful) { ...@@ -137,7 +139,7 @@ function setRequestStatus(isSuccessful) {
if (isSuccessful) { if (isSuccessful) {
$('request-failed-message').hidden = true; $('request-failed-message').hidden = true;
$('request-sent-message').hidden = false; $('request-sent-message').hidden = false;
$('back-button').hidden = false; $('back-button').hidden = !isMainFrame;
$('request-access-button').hidden = true; $('request-access-button').hidden = true;
$('show-details-link').hidden = true; $('show-details-link').hidden = true;
} else { } else {
......
...@@ -463,6 +463,69 @@ IN_PROC_BROWSER_TEST_F(SupervisedUserIframeFilterTest, BlockMultipleSubFrames) { ...@@ -463,6 +463,69 @@ IN_PROC_BROWSER_TEST_F(SupervisedUserIframeFilterTest, BlockMultipleSubFrames) {
DCHECK_EQ(GetBlockedFrames().size(), 0u); DCHECK_EQ(GetBlockedFrames().size(), 0u);
} }
IN_PROC_BROWSER_TEST_F(SupervisedUserIframeFilterTest, TestBackButton) {
BlockHost(kIframeHost1);
GURL allowed_url_with_iframes = embedded_test_server()->GetURL(
kExampleHost, "/supervised_user/with_iframes.html");
ui_test_utils::NavigateToURL(browser(), allowed_url_with_iframes);
EXPECT_FALSE(IsInterstitialBeingShown(browser()));
auto blocked = GetBlockedFrames();
EXPECT_EQ(blocked.size(), 1u);
permission_creator()->SetPermissionResult(true);
permission_creator()->DelayHandlingForNextRequests();
RequestPermissionFromFrame(blocked[0]);
std::string command =
"domAutomationController.send("
"(document.getElementById('back-button').hidden));";
auto* render_frame_host = tracker()->GetHost(blocked[0]);
DCHECK(render_frame_host->IsRenderFrameLive());
bool value = false;
auto target = content::ToRenderFrameHost(render_frame_host);
EXPECT_TRUE(content::ExecuteScriptWithoutUserGestureAndExtractBool(
target, command, &value));
// Back button should be hidden in iframes.
EXPECT_TRUE(value);
}
IN_PROC_BROWSER_TEST_F(SupervisedUserIframeFilterTest,
TestBackButtonMainFrame) {
BlockHost(kExampleHost);
GURL allowed_url_with_iframes = embedded_test_server()->GetURL(
kExampleHost, "/supervised_user/with_iframes.html");
ui_test_utils::NavigateToURL(browser(), allowed_url_with_iframes);
EXPECT_TRUE(IsInterstitialBeingShown(browser()));
auto blocked = GetBlockedFrames();
EXPECT_EQ(blocked.size(), 1u);
permission_creator()->SetPermissionResult(true);
permission_creator()->DelayHandlingForNextRequests();
RequestPermissionFromFrame(blocked[0]);
std::string command =
"domAutomationController.send("
"(document.getElementById('back-button').hidden));";
auto* render_frame_host = tracker()->GetHost(blocked[0]);
DCHECK(render_frame_host->IsRenderFrameLive());
bool value = false;
auto target = content::ToRenderFrameHost(render_frame_host);
EXPECT_TRUE(content::ExecuteScriptWithoutUserGestureAndExtractBool(
target, command, &value));
// Back button should not be hidden in main frame.
EXPECT_FALSE(value);
}
class SupervisedUserNavigationThrottleNotSupervisedTest class SupervisedUserNavigationThrottleNotSupervisedTest
: public SupervisedUserNavigationThrottleTest { : public SupervisedUserNavigationThrottleTest {
protected: protected:
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "chrome/renderer/supervised_user/supervised_user_error_page_controller.h" #include "chrome/renderer/supervised_user/supervised_user_error_page_controller.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/renderer/supervised_user/supervised_user_error_page_controller_delegate.h" #include "chrome/renderer/supervised_user/supervised_user_error_page_controller_delegate.h"
#include "content/public/renderer/render_frame.h" #include "content/public/renderer/render_frame.h"
...@@ -69,7 +70,9 @@ void SupervisedUserErrorPageController::Feedback() { ...@@ -69,7 +70,9 @@ void SupervisedUserErrorPageController::Feedback() {
void SupervisedUserErrorPageController::RequestPermissionCallback( void SupervisedUserErrorPageController::RequestPermissionCallback(
bool success) { bool success) {
std::string result = success ? "true" : "false"; std::string result = success ? "true" : "false";
std::string js = "setRequestStatus(" + result + ");"; std::string in_main_frame = render_frame_->IsMainFrame() ? "true" : "false";
std::string js = base::StringPrintf("setRequestStatus(%s, %s)",
result.c_str(), in_main_frame.c_str());
render_frame_->ExecuteJavaScript(base::ASCIIToUTF16(js)); render_frame_->ExecuteJavaScript(base::ASCIIToUTF16(js));
} }
......
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