Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1771)

Unified Diff: chrome/browser/download/save_page_browsertest.cc

Issue 2155333002: Test for auth dialog appearing during save-page-as. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Prevent prompts during save-page-as. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/test/data/save_page/broken-image.htm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/download/save_page_browsertest.cc
diff --git a/chrome/browser/download/save_page_browsertest.cc b/chrome/browser/download/save_page_browsertest.cc
index 544d49935ad23def57a279a2ebfcfeb6611b5b31..b99e84f1f6c4bdde867232009eb9db67a7231958 100644
--- a/chrome/browser/download/save_page_browsertest.cc
+++ b/chrome/browser/download/save_page_browsertest.cc
@@ -33,6 +33,8 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_window.h"
+#include "chrome/browser/ui/login/login_handler.h"
+#include "chrome/browser/ui/login/login_handler_test_utils.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
@@ -46,14 +48,17 @@
#include "components/prefs/pref_service.h"
#include "content/public/browser/download_item.h"
#include "content/public/browser/download_manager.h"
+#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_switches.h"
+#include "content/public/common/referrer.h"
#include "content/public/common/url_constants.h"
#include "content/public/test/browser_test_utils.h"
+#include "content/public/test/test_navigation_observer.h"
#include "content/public/test/test_utils.h"
#include "net/base/filename_util.h"
#include "net/dns/mock_host_resolver.h"
@@ -984,24 +989,23 @@ class SavePageOriginalVsSavedComparisonTest
: public SavePageSitePerProcessBrowserTest,
public ::testing::WithParamInterface<content::SavePageType> {
protected:
- void TestOriginalVsSavedPage(
+ void TestCurrentVsSavedPage(
content::SavePageType save_page_type,
- const GURL& url,
int expected_number_of_frames,
const std::vector<std::string>& expected_substrings) {
- // Navigate to the test page and verify if test expectations
- // are met (this is mostly a sanity check - a failure to meet
- // expectations would probably mean that there is a test bug
- // (i.e. that we got called with wrong expected_foo argument).
- ui_test_utils::NavigateToURL(browser(), url);
+ // Verify if test expectations are met on the current page (this is mostly
+ // a sanity check - a failure to meet expectations would probably mean that
+ // there is a test bug (i.e. that we got called with wrong expected_foo
+ // argument).
+ GURL original_url = GetCurrentTab(browser())->GetLastCommittedURL();
DLOG(INFO) << "Verifying test expectations for original page... : "
- << GetCurrentTab(browser())->GetLastCommittedURL();
+ << original_url;
AssertExpectationsAboutCurrentTab(expected_number_of_frames,
expected_substrings);
// Save the page.
base::FilePath full_file_name, dir;
- SaveCurrentTab(url, save_page_type, "save_result", -1, &dir,
+ SaveCurrentTab(original_url, save_page_type, "save_result", -1, &dir,
&full_file_name);
ASSERT_FALSE(HasFailure());
@@ -1085,7 +1089,8 @@ IN_PROC_BROWSER_TEST_P(SavePageOriginalVsSavedComparisonTest, CrossSite) {
GURL url(
embedded_test_server()->GetURL("a.com", "/save_page/frames-xsite.htm"));
- TestOriginalVsSavedPage(save_page_type, url, 3, expected_substrings);
+ ui_test_utils::NavigateToURL(browser(), url);
+ TestCurrentVsSavedPage(save_page_type, 3, expected_substrings);
}
// Test compares original-vs-saved for a page with <object> elements.
@@ -1106,15 +1111,15 @@ IN_PROC_BROWSER_TEST_P(SavePageOriginalVsSavedComparisonTest, ObjectElements) {
};
std::vector<std::string> expected_substrings(std::begin(arr), std::end(arr));
- GURL url(
- embedded_test_server()->GetURL("a.com", "/save_page/frames-objects.htm"));
-
// TODO(lukasza): crbug.com/553478: Enable <object> testing of MHTML.
if (save_page_type == content::SAVE_PAGE_TYPE_AS_MHTML)
return;
- TestOriginalVsSavedPage(save_page_type, url, expected_number_of_frames,
- expected_substrings);
+ GURL url(
+ embedded_test_server()->GetURL("a.com", "/save_page/frames-objects.htm"));
+ ui_test_utils::NavigateToURL(browser(), url);
+ TestCurrentVsSavedPage(save_page_type, expected_number_of_frames,
+ expected_substrings);
}
// Test compares original-vs-saved for a page with frames at about:blank uri.
@@ -1133,8 +1138,8 @@ IN_PROC_BROWSER_TEST_P(SavePageOriginalVsSavedComparisonTest, AboutBlank) {
GURL url(embedded_test_server()->GetURL("a.com",
"/save_page/frames-about-blank.htm"));
-
- TestOriginalVsSavedPage(save_page_type, url, 4, expected_substrings);
+ ui_test_utils::NavigateToURL(browser(), url);
+ TestCurrentVsSavedPage(save_page_type, 4, expected_substrings);
}
// Test compares original-vs-saved for a page with nested frames.
@@ -1152,8 +1157,8 @@ IN_PROC_BROWSER_TEST_P(SavePageOriginalVsSavedComparisonTest, NestedFrames) {
GURL url(
embedded_test_server()->GetURL("a.com", "/save_page/frames-nested.htm"));
-
- TestOriginalVsSavedPage(save_page_type, url, 3, expected_substrings);
+ ui_test_utils::NavigateToURL(browser(), url);
+ TestCurrentVsSavedPage(save_page_type, 3, expected_substrings);
}
// Test for crbug.com/106364 and crbug.com/538188.
@@ -1175,8 +1180,8 @@ IN_PROC_BROWSER_TEST_P(SavePageOriginalVsSavedComparisonTest, RuntimeChanges) {
GURL url(embedded_test_server()->GetURL(
"a.com", "/save_page/frames-runtime-changes.htm?do_runtime_changes=1"));
-
- TestOriginalVsSavedPage(save_page_type, url, 5, expected_substrings);
+ ui_test_utils::NavigateToURL(browser(), url);
+ TestCurrentVsSavedPage(save_page_type, 5, expected_substrings);
}
// Test for saving frames with various encodings:
@@ -1204,9 +1209,6 @@ IN_PROC_BROWSER_TEST_P(SavePageOriginalVsSavedComparisonTest, Encoding) {
};
std::vector<std::string> expected_substrings(std::begin(arr), std::end(arr));
- GURL url(embedded_test_server()->GetURL("a.com",
- "/save_page/frames-encodings.htm"));
-
// TODO(lukasza): crbug.com/541699: MHTML needs to handle multi-byte encodings
// by either:
// 1. Continuing to preserve the original encoding, but starting to round-trip
@@ -1216,7 +1218,10 @@ IN_PROC_BROWSER_TEST_P(SavePageOriginalVsSavedComparisonTest, Encoding) {
if (save_page_type == content::SAVE_PAGE_TYPE_AS_MHTML)
return;
- TestOriginalVsSavedPage(save_page_type, url, 7, expected_substrings);
+ GURL url(embedded_test_server()->GetURL("a.com",
+ "/save_page/frames-encodings.htm"));
+ ui_test_utils::NavigateToURL(browser(), url);
+ TestCurrentVsSavedPage(save_page_type, 7, expected_substrings);
}
// Test for saving style element and attribute (see also crbug.com/568293).
@@ -1230,13 +1235,14 @@ IN_PROC_BROWSER_TEST_P(SavePageOriginalVsSavedComparisonTest, Style) {
std::vector<std::string> expected_substrings(std::begin(arr), std::end(arr));
GURL url(embedded_test_server()->GetURL("a.com", "/save_page/style.htm"));
-
- TestOriginalVsSavedPage(save_page_type, url, 6, expected_substrings);
+ ui_test_utils::NavigateToURL(browser(), url);
+ TestCurrentVsSavedPage(save_page_type, 6, expected_substrings);
}
// Test for saving a page with broken subresources:
// - Broken, undecodable image (see also https://crbug.com/586680)
// - Broken link, to unresolvable host (see also https://crbug.com/594219)
+// - Resource requiring authentication
IN_PROC_BROWSER_TEST_P(SavePageOriginalVsSavedComparisonTest, BrokenImage) {
// Clear resolver rules to make sure that *.no.such.host used in the test html
// doesn't resolve to 127.0.0.1
@@ -1249,10 +1255,26 @@ IN_PROC_BROWSER_TEST_P(SavePageOriginalVsSavedComparisonTest, BrokenImage) {
};
std::vector<std::string> expected_substrings(std::begin(arr), std::end(arr));
+ // Navigate to the test URL and dismiss the auth dialog.
GURL url(embedded_test_server()->GetURL("127.0.0.1",
"/save_page/broken-image.htm"));
-
- TestOriginalVsSavedPage(save_page_type, url, 1, expected_substrings);
+ content::WebContents* web_contents =
+ browser()->tab_strip_model()->GetActiveWebContents();
+ content::TestNavigationObserver navigation_observer(web_contents, 1);
+ content::NavigationController* navigation_controller =
+ &web_contents->GetController();
+ LoginPromptBrowserTestObserver login_observer;
+ login_observer.Register(
+ content::Source<content::NavigationController>(navigation_controller));
+ WindowedAuthNeededObserver auth_needed_waiter(navigation_controller);
+ web_contents->OpenURL(content::OpenURLParams(
+ url, content::Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false));
+ auth_needed_waiter.Wait();
+ ASSERT_EQ(1u, login_observer.handlers().size());
+ login_observer.handlers().front()->CancelAuth();
+ navigation_observer.Wait();
+
+ TestCurrentVsSavedPage(save_page_type, 1, expected_substrings);
}
INSTANTIATE_TEST_CASE_P(
« no previous file with comments | « no previous file | chrome/test/data/save_page/broken-image.htm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698