Skip to content

Commit

Permalink
View-source now works on chrome://interstitials/...
Browse files Browse the repository at this point in the history
View source was not working correctly on individual subsites of
chrome://interstitials (e.g. chrome://interstitials/ssl) due to
web_contents not holding a correct URL when a call to StartDataRequest
was triggered from a view-source: url. The "chrome://interstitials/"
URL is now hardcoded in InterstitialHTMLSource::StartDataRequest (since
calls to that function only happen when opening a
chrome://interstitials page). Tests were also added for this case.

R=estark@chromium.org

Bug: 769876
Change-Id: I432c02be1b873918ac2bb9a8e0f17dea39aa5043
Reviewed-on: https://chromium-review.googlesource.com/692976
Reviewed-by: Emily Stark <estark@chromium.org>
Reviewed-by: Lucas Garron <lgarron@chromium.org>
Commit-Queue: Carlos IL <carlosil@chromium.org>
Cr-Commit-Position: refs/heads/master@{#505709}
  • Loading branch information
carlosjoan91 authored and Commit Bot committed Oct 2, 2017
1 parent 8068345 commit 5dc1ae2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
3 changes: 2 additions & 1 deletion chrome/browser/ui/webui/interstitials/interstitial_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,8 @@ void InterstitialHTMLSource::StartDataRequest(
std::string html;
// Using this form of the path so we can do exact matching, while ignoring the
// query (everything after the ? character).
GURL url = web_contents->GetURL().GetWithEmptyPath().Resolve(path);
GURL url =
GURL(chrome::kChromeUIInterstitialURL).GetWithEmptyPath().Resolve(path);
std::string path_without_query = url.path();
if (path_without_query == "/ssl") {
interstitial_delegate.reset(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,37 @@ IN_PROC_BROWSER_TEST_F(InterstitialUITest, InterstitialBackButton) {
EXPECT_EQ(title, base::ASCIIToUTF16("Interstitials"));
}

// Tests that view-source: works correctly on chrome://interstitials.
IN_PROC_BROWSER_TEST_F(InterstitialUITest, InterstitialViewSource) {
ui_test_utils::NavigateToURL(browser(),
GURL("view-source:chrome://interstitials/"));
int found;
base::string16 expected_title =
base::ASCIIToUTF16("<title>Interstitials</title>");
found = ui_test_utils::FindInPage(
browser()->tab_strip_model()->GetActiveWebContents(), expected_title,
true, /* Forward */
true, /* case_sensitive */
nullptr, nullptr);
EXPECT_EQ(found, 1);
}

// Tests that view-source: works correctly on a subpage of
// chrome://interstitials (using chrome://interstitials/ssl).
IN_PROC_BROWSER_TEST_F(InterstitialUITest, InterstitialWithPathViewSource) {
ui_test_utils::NavigateToURL(browser(),
GURL("view-source:chrome://interstitials/ssl"));
int found;
base::string16 expected_title =
base::ASCIIToUTF16("<title>Privacy error</title");
found = ui_test_utils::FindInPage(
browser()->tab_strip_model()->GetActiveWebContents(), expected_title,
true, /* Forward */
true, /* case_sensitive */
nullptr, nullptr);
EXPECT_EQ(found, 1);
}

// Checks that the interstitial page uses correct web contents. If not, closing
// the tab might result in a freed web contents pointer and cause a crash.
// See https://crbug.com/611706 for details.
Expand Down

0 comments on commit 5dc1ae2

Please sign in to comment.