Commit e6a5d22f authored by wjmaclean's avatar wjmaclean Committed by Commit bot

Update entry page type to include error pages when appropriate.

At present, the NavigationEntry page type always reports
PAGE_TYPE_NORMAL for all committed entries, even if an
error page is currently showing. There is a need for a
mechanism to detect when an error page is showing in order
to prevent zooming in that case, so we modify the
navigation entry to correctly report error pages.

BUG=403268

Review URL: https://codereview.chromium.org/580133002

Cr-Commit-Position: refs/heads/master@{#296614}
parent d7743bab
......@@ -27,6 +27,7 @@
#include "content/public/common/url_constants.h"
#include "extensions/common/manifest_constants.h"
#include "extensions/common/test_util.h"
#include "net/test/spawned_test_server/spawned_test_server.h"
#include "ui/gfx/rect.h"
namespace extensions {
......@@ -796,11 +797,20 @@ IN_PROC_BROWSER_TEST_F(ExtensionTabsZoomTest, SetAndGetZoom) {
}
IN_PROC_BROWSER_TEST_F(ExtensionTabsZoomTest, ZoomSettings) {
const char kNewTestTabArgsA[] = "http://hostA/";
const char kNewTestTabArgsB[] = "http://hostB/";
GURL url_A(kNewTestTabArgsA);
GURL url_B(kNewTestTabArgsB);
// In this test we need two URLs that (1) represent real pages (i.e. they
// load without causing an error page load), (2) have different domains, and
// (3) are zoomable by the extension API (this last condition rules out
// chrome:// urls). We achieve this by noting that about:blank meets these
// requirements, allowing us to spin up a spawned http server on localhost to
// get the other domain.
net::SpawnedTestServer http_server(
net::SpawnedTestServer::TYPE_HTTP,
net::SpawnedTestServer::kLocalhost,
base::FilePath(FILE_PATH_LITERAL("chrome/test/data")));
ASSERT_TRUE(http_server.Start());
GURL url_A = http_server.GetURL("files/simple.html");
GURL url_B("about:blank");
// Tabs A1 and A2 are navigated to the same origin, while B is navigated
// to a different one.
......
......@@ -99,14 +99,20 @@ enum AuthStateFlags {
NONE = 0,
DISPLAYED_INSECURE_CONTENT = 1 << 0,
RAN_INSECURE_CONTENT = 1 << 1,
SHOWING_INTERSTITIAL = 1 << 2
SHOWING_INTERSTITIAL = 1 << 2,
SHOWING_ERROR = 1 << 3
};
void Check(const NavigationEntry& entry, int expected_authentication_state) {
EXPECT_EQ(!!(expected_authentication_state & AuthState::SHOWING_INTERSTITIAL)
? content::PAGE_TYPE_INTERSTITIAL
: content::PAGE_TYPE_NORMAL,
entry.GetPageType());
if (expected_authentication_state == AuthState::SHOWING_ERROR) {
EXPECT_EQ(content::PAGE_TYPE_ERROR, entry.GetPageType());
} else {
EXPECT_EQ(
!!(expected_authentication_state & AuthState::SHOWING_INTERSTITIAL)
? content::PAGE_TYPE_INTERSTITIAL
: content::PAGE_TYPE_NORMAL,
entry.GetPageType());
}
bool displayed_insecure_content =
!!(entry.GetSSL().content_status & SSLStatus::DISPLAYED_INSECURE_CONTENT);
......@@ -197,11 +203,12 @@ class SSLUITest : public InProcessBrowserTest {
expected_authentication_state);
}
void CheckUnauthenticatedState(WebContents* tab) {
void CheckUnauthenticatedState(WebContents* tab,
int expected_authentication_state) {
CheckSecurityState(tab,
CertError::NONE,
content::SECURITY_STYLE_UNAUTHENTICATED,
AuthState::NONE);
expected_authentication_state);
}
void CheckAuthenticationBrokenState(WebContents* tab,
......@@ -381,7 +388,7 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestHTTP) {
test_server()->GetURL("files/ssl/google.html"));
CheckUnauthenticatedState(
browser()->tab_strip_model()->GetActiveWebContents());
browser()->tab_strip_model()->GetActiveWebContents(), AuthState::NONE);
}
// Visits a page over http which includes broken https resources (status should
......@@ -402,7 +409,7 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestHTTPWithBrokenHTTPSResource) {
browser(), test_server()->GetURL(replacement_path));
CheckUnauthenticatedState(
browser()->tab_strip_model()->GetActiveWebContents());
browser()->tab_strip_model()->GetActiveWebContents(), AuthState::NONE);
}
IN_PROC_BROWSER_TEST_F(SSLUITest, TestBrokenHTTPSWithInsecureContent) {
......@@ -524,7 +531,7 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, MAYBE_TestHTTPSExpiredCertAndDontProceed) {
// Try to navigate to a new page. (to make sure bug 5800 is fixed).
ui_test_utils::NavigateToURL(browser(),
test_server()->GetURL("files/ssl/google.html"));
CheckUnauthenticatedState(tab);
CheckUnauthenticatedState(tab, AuthState::NONE);
}
// Visits a page with https error and then goes back using Browser::GoBack.
......@@ -560,7 +567,7 @@ IN_PROC_BROWSER_TEST_F(SSLUITest,
// We should be back at the original good page.
EXPECT_FALSE(browser()->tab_strip_model()->GetActiveWebContents()->
GetInterstitialPage());
CheckUnauthenticatedState(tab);
CheckUnauthenticatedState(tab, AuthState::NONE);
}
// Visits a page with https error and then goes back using GoToOffset.
......@@ -589,7 +596,7 @@ IN_PROC_BROWSER_TEST_F(SSLUITest,
// We should be back at the original good page.
EXPECT_FALSE(browser()->tab_strip_model()->GetActiveWebContents()->
GetInterstitialPage());
CheckUnauthenticatedState(tab);
CheckUnauthenticatedState(tab, AuthState::NONE);
}
// Visits a page with https error and then goes forward using GoToOffset.
......@@ -638,7 +645,7 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestHTTPSExpiredCertAndGoForward) {
// We should be showing the second good page.
EXPECT_FALSE(browser()->tab_strip_model()->GetActiveWebContents()->
GetInterstitialPage());
CheckUnauthenticatedState(tab);
CheckUnauthenticatedState(tab, AuthState::NONE);
EXPECT_FALSE(tab->GetController().CanGoForward());
NavigationEntry* entry4 = tab->GetController().GetActiveEntry();
EXPECT_TRUE(entry2 == entry4);
......@@ -1139,7 +1146,7 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestDisplaysCachedInsecureContent) {
const GURL url_http = test_server()->GetURL(replacement_path);
ui_test_utils::NavigateToURL(browser(), url_http);
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
CheckUnauthenticatedState(tab);
CheckUnauthenticatedState(tab, AuthState::NONE);
// Load again but over SSL. It should be marked as displaying insecure
// content (even though the image comes from the WebCore memory cache).
......@@ -1173,7 +1180,7 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, MAYBE_TestRunsCachedInsecureContent) {
const GURL url_http = test_server()->GetURL(replacement_path);
ui_test_utils::NavigateToURL(browser(), url_http);
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
CheckUnauthenticatedState(tab);
CheckUnauthenticatedState(tab, AuthState::NONE);
// Load again but over SSL. It should be marked as displaying insecure
// content (even though the image comes from the WebCore memory cache).
......@@ -1402,7 +1409,7 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestRedirectHTTPSToHTTP) {
ui_test_utils::NavigateToURL(browser(),
GURL(https_url.spec() + http_url.spec()));
CheckUnauthenticatedState(
browser()->tab_strip_model()->GetActiveWebContents());
browser()->tab_strip_model()->GetActiveWebContents(), AuthState::NONE);
}
// Visits a page to which we could not connect (bad port) over http and https
......@@ -1410,12 +1417,14 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestRedirectHTTPSToHTTP) {
IN_PROC_BROWSER_TEST_F(SSLUITest, TestConnectToBadPort) {
ui_test_utils::NavigateToURL(browser(), GURL("http://localhost:17"));
CheckUnauthenticatedState(
browser()->tab_strip_model()->GetActiveWebContents());
browser()->tab_strip_model()->GetActiveWebContents(),
AuthState::SHOWING_ERROR);
// Same thing over HTTPS.
ui_test_utils::NavigateToURL(browser(), GURL("https://localhost:17"));
CheckUnauthenticatedState(
browser()->tab_strip_model()->GetActiveWebContents());
browser()->tab_strip_model()->GetActiveWebContents(),
AuthState::SHOWING_ERROR);
}
//
......@@ -1586,7 +1595,7 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, DISABLED_TestUnauthenticatedFrameNavigation) {
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
ui_test_utils::NavigateToURL(browser(),
test_server()->GetURL(top_frame_path));
CheckUnauthenticatedState(tab);
CheckUnauthenticatedState(tab, AuthState::NONE);
// Now navigate inside the frame to a secure HTTPS frame.
{
......@@ -1603,7 +1612,7 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, DISABLED_TestUnauthenticatedFrameNavigation) {
}
// We should still be unauthenticated.
CheckUnauthenticatedState(tab);
CheckUnauthenticatedState(tab, AuthState::NONE);
// Now navigate to a bad HTTPS frame.
{
......@@ -1620,7 +1629,7 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, DISABLED_TestUnauthenticatedFrameNavigation) {
}
// State should not have changed.
CheckUnauthenticatedState(tab);
CheckUnauthenticatedState(tab, AuthState::NONE);
// And the frame should have been blocked (see bug #2316).
bool is_content_evil = true;
......
......@@ -12,6 +12,7 @@
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/page_type.h"
#include "content/public/common/page_zoom.h"
#include "extensions/common/extension.h"
#include "grit/theme_resources.h"
......@@ -78,10 +79,14 @@ bool ZoomController::SetZoomLevel(double zoom_level) {
bool ZoomController::SetZoomLevelByExtension(
double zoom_level,
const scoped_refptr<const extensions::Extension>& extension) {
bool is_normal_page =
web_contents()->GetController().GetLastCommittedEntry()->GetPageType() ==
content::PAGE_TYPE_NORMAL;
// Cannot zoom in disabled mode. Also, don't allow changing zoom level on
// a crashed tab.
// a crashed tab, an error page or an interstitial page.
if (zoom_mode_ == ZOOM_MODE_DISABLED ||
!web_contents()->GetRenderViewHost()->IsRenderViewLive())
!web_contents()->GetRenderViewHost()->IsRenderViewLive() ||
!is_normal_page)
return false;
// Store extension data so that |extension| can be attributed when the zoom
......
......@@ -12,9 +12,11 @@
#include "chrome/common/pref_names.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/page_type.h"
#include "content/public/test/browser_test_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
......@@ -111,3 +113,23 @@ IN_PROC_BROWSER_TEST_F(ZoomControllerBrowserTest, OnPreferenceChanged) {
// we need to wait for it to propagate.
zoom_change_watcher.Wait();
}
IN_PROC_BROWSER_TEST_F(ZoomControllerBrowserTest, ErrorPagesDoNotZoom) {
ui_test_utils::NavigateToURL(browser(), GURL("http://kjfhkjsdf.com"));
content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ZoomController* zoom_controller =
ZoomController::FromWebContents(web_contents);
EXPECT_EQ(
content::PAGE_TYPE_ERROR,
web_contents->GetController().GetLastCommittedEntry()->GetPageType());
double old_zoom_level = zoom_controller->GetZoomLevel();
double new_zoom_level = old_zoom_level + 0.5;
// The following attempt to change the zoom level for an error page should
// fail.
zoom_controller->SetZoomLevel(new_zoom_level);
EXPECT_FLOAT_EQ(old_zoom_level, zoom_controller->GetZoomLevel());
}
......@@ -94,12 +94,14 @@ TEST_F(ZoomControllerTest, Observe_ZoomController) {
double old_zoom_level = zoom_controller_->GetZoomLevel();
double new_zoom_level = 110.0;
NavigateAndCommit(GURL("about:blank"));
ZoomController::ZoomChangedEventData zoom_change_data1(
web_contents(),
old_zoom_level,
old_zoom_level,
ZoomController::ZOOM_MODE_ISOLATED,
false /* can_show_bubble */);
true /* can_show_bubble */);
EXPECT_CALL(zoom_observer_, OnZoomChanged(zoom_change_data1)).Times(1);
zoom_controller_->SetZoomMode(ZoomController::ZOOM_MODE_ISOLATED);
......@@ -109,7 +111,7 @@ TEST_F(ZoomControllerTest, Observe_ZoomController) {
old_zoom_level,
new_zoom_level,
ZoomController::ZOOM_MODE_ISOLATED,
false /* can_show_bubble */);
true /* can_show_bubble */);
EXPECT_CALL(zoom_observer_, OnZoomChanged(zoom_change_data2)).Times(1);
zoom_controller_->SetZoomLevel(new_zoom_level);
......
......@@ -1060,6 +1060,8 @@ void NavigationControllerImpl::RendererDidNavigateToNewPage(
update_virtual_url = needs_update;
}
if (params.url_is_unreachable)
new_entry->set_page_type(PAGE_TYPE_ERROR);
new_entry->SetURL(params.url);
if (update_virtual_url)
UpdateVirtualURLToURL(new_entry, params.url);
......
......@@ -141,6 +141,10 @@ IPC_STRUCT_BEGIN_WITH_PARENT(FrameHostMsg_DidCommitProvisionalLoad_Params,
// The status code of the HTTP request.
IPC_STRUCT_MEMBER(int, http_status_code)
// This flag is used to warn if the renderer is displaying an error page,
// so that we can set the appropriate page type.
IPC_STRUCT_MEMBER(bool, url_is_unreachable)
// True if the connection was proxied. In this case, socket_address
// will represent the address of the proxy, rather than the remote host.
IPC_STRUCT_MEMBER(bool, was_fetched_via_proxy)
......
......@@ -3282,6 +3282,7 @@ void RenderFrameImpl::SendDidCommitProvisionalLoad(blink::WebFrame* frame) {
FrameHostMsg_DidCommitProvisionalLoad_Params params;
params.http_status_code = response.httpStatusCode();
params.url_is_unreachable = ds->hasUnreachableURL();
params.is_post = false;
params.post_id = -1;
params.page_id = render_view_->page_id_;
......
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