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

Unified Diff: chrome/browser/ui/webui/chrome_url_data_manager_browsertest.cc

Issue 2279293004: Fix DCHECK in debug build when navigating to an unknown chrome://theme/ URL. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Better name Created 4 years, 4 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 | content/browser/webui/url_data_manager_backend.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/webui/chrome_url_data_manager_browsertest.cc
diff --git a/chrome/browser/ui/webui/chrome_url_data_manager_browsertest.cc b/chrome/browser/ui/webui/chrome_url_data_manager_browsertest.cc
index 78ffc3226fe4942b391eb4eca82d348e638988c2..0343abce9ad7f36da79694e6f0a5fd41e5f3d9a8 100644
--- a/chrome/browser/ui/webui/chrome_url_data_manager_browsertest.cc
+++ b/chrome/browser/ui/webui/chrome_url_data_manager_browsertest.cc
@@ -3,10 +3,13 @@
// found in the LICENSE file.
#include "base/macros.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/navigation_details.h"
+#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_source.h"
@@ -44,6 +47,34 @@ class NavigationNotificationObserver : public content::NotificationObserver {
DISALLOW_COPY_AND_ASSIGN(NavigationNotificationObserver);
};
+class NavigationObserver : public content::WebContentsObserver {
+public:
+ enum NavigationResult {
+ NOT_FINISHED,
+ ERROR_PAGE,
+ SUCCESS,
+ };
+
+ explicit NavigationObserver(content::WebContents* web_contents)
+ : WebContentsObserver(web_contents), navigation_result_(NOT_FINISHED) {}
+ ~NavigationObserver() override = default;
+
+ void DidFinishNavigation(
+ content::NavigationHandle* navigation_handle) override {
+ navigation_result_ =
+ navigation_handle->IsErrorPage() ? ERROR_PAGE : SUCCESS;
+ }
+
+ NavigationResult navigation_result() const { return navigation_result_; }
+
+ void Reset() { navigation_result_ = NOT_FINISHED; }
+
+ private:
+ NavigationResult navigation_result_;
+
+ DISALLOW_COPY_AND_ASSIGN(NavigationObserver);
+};
+
} // namespace
typedef InProcessBrowserTest ChromeURLDataManagerTest;
@@ -57,11 +88,34 @@ IN_PROC_BROWSER_TEST_F(ChromeURLDataManagerTest, 200) {
EXPECT_EQ(200, observer.http_status_code());
}
+// Makes sure browser does not crash when navigating to an unknown resource.
+IN_PROC_BROWSER_TEST_F(ChromeURLDataManagerTest, UnknownResource) {
+ // Known resource
+ NavigationObserver observer(
+ browser()->tab_strip_model()->GetActiveWebContents());
+ ui_test_utils::NavigateToURL(
+ browser(), GURL("chrome://theme/IDR_SETTINGS_FAVICON"));
+ EXPECT_EQ(NavigationObserver::SUCCESS, observer.navigation_result());
+
+ // Unknown resource
+ observer.Reset();
+ ui_test_utils::NavigateToURL(
+ browser(), GURL("chrome://theme/IDR_ASDFGHJKL"));
+ EXPECT_EQ(NavigationObserver::ERROR_PAGE, observer.navigation_result());
+}
+
// Makes sure browser does not crash when the resource scale is very large.
-IN_PROC_BROWSER_TEST_F(ChromeURLDataManagerTest, ResourceScaleTest) {
+IN_PROC_BROWSER_TEST_F(ChromeURLDataManagerTest, LargeResourceScale) {
+ // Valid scale
+ NavigationObserver observer(
+ browser()->tab_strip_model()->GetActiveWebContents());
ui_test_utils::NavigateToURL(
browser(), GURL("chrome://theme/IDR_SETTINGS_FAVICON@2x"));
+ EXPECT_EQ(NavigationObserver::SUCCESS, observer.navigation_result());
+ // Unreasonably large scale
+ observer.Reset();
ui_test_utils::NavigateToURL(
browser(), GURL("chrome://theme/IDR_SETTINGS_FAVICON@99999x"));
+ EXPECT_EQ(NavigationObserver::SUCCESS, observer.navigation_result());
}
« no previous file with comments | « no previous file | content/browser/webui/url_data_manager_backend.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698