OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/macros.h" | 5 #include "base/macros.h" |
| 6 #include "chrome/browser/ui/browser.h" |
| 7 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
6 #include "chrome/common/url_constants.h" | 8 #include "chrome/common/url_constants.h" |
7 #include "chrome/test/base/in_process_browser_test.h" | 9 #include "chrome/test/base/in_process_browser_test.h" |
8 #include "chrome/test/base/ui_test_utils.h" | 10 #include "chrome/test/base/ui_test_utils.h" |
9 #include "content/public/browser/navigation_details.h" | 11 #include "content/public/browser/navigation_details.h" |
| 12 #include "content/public/browser/navigation_handle.h" |
10 #include "content/public/browser/notification_registrar.h" | 13 #include "content/public/browser/notification_registrar.h" |
11 #include "content/public/browser/notification_service.h" | 14 #include "content/public/browser/notification_service.h" |
12 #include "content/public/browser/notification_source.h" | 15 #include "content/public/browser/notification_source.h" |
13 #include "content/public/browser/notification_types.h" | 16 #include "content/public/browser/notification_types.h" |
14 | 17 |
15 namespace { | 18 namespace { |
16 | 19 |
17 class NavigationNotificationObserver : public content::NotificationObserver { | 20 class NavigationNotificationObserver : public content::NotificationObserver { |
18 public: | 21 public: |
19 NavigationNotificationObserver() | 22 NavigationNotificationObserver() |
(...skipping 17 matching lines...) Expand all Loading... |
37 bool got_navigation() const { return got_navigation_; } | 40 bool got_navigation() const { return got_navigation_; } |
38 | 41 |
39 private: | 42 private: |
40 content::NotificationRegistrar registrar_; | 43 content::NotificationRegistrar registrar_; |
41 int got_navigation_; | 44 int got_navigation_; |
42 int http_status_code_; | 45 int http_status_code_; |
43 | 46 |
44 DISALLOW_COPY_AND_ASSIGN(NavigationNotificationObserver); | 47 DISALLOW_COPY_AND_ASSIGN(NavigationNotificationObserver); |
45 }; | 48 }; |
46 | 49 |
| 50 class NavigationObserver : public content::WebContentsObserver { |
| 51 public: |
| 52 enum NavigationResult { |
| 53 NOT_FINISHED, |
| 54 ERROR_PAGE, |
| 55 SUCCESS, |
| 56 }; |
| 57 |
| 58 explicit NavigationObserver(content::WebContents* web_contents) |
| 59 : WebContentsObserver(web_contents), navigation_result_(NOT_FINISHED) {} |
| 60 ~NavigationObserver() override = default; |
| 61 |
| 62 void DidFinishNavigation( |
| 63 content::NavigationHandle* navigation_handle) override { |
| 64 navigation_result_ = |
| 65 navigation_handle->IsErrorPage() ? ERROR_PAGE : SUCCESS; |
| 66 } |
| 67 |
| 68 NavigationResult navigation_result() const { return navigation_result_; } |
| 69 |
| 70 void Reset() { navigation_result_ = NOT_FINISHED; } |
| 71 |
| 72 private: |
| 73 NavigationResult navigation_result_; |
| 74 |
| 75 DISALLOW_COPY_AND_ASSIGN(NavigationObserver); |
| 76 }; |
| 77 |
47 } // namespace | 78 } // namespace |
48 | 79 |
49 typedef InProcessBrowserTest ChromeURLDataManagerTest; | 80 typedef InProcessBrowserTest ChromeURLDataManagerTest; |
50 | 81 |
51 // Makes sure navigating to the new tab page results in a http status code | 82 // Makes sure navigating to the new tab page results in a http status code |
52 // of 200. | 83 // of 200. |
53 IN_PROC_BROWSER_TEST_F(ChromeURLDataManagerTest, 200) { | 84 IN_PROC_BROWSER_TEST_F(ChromeURLDataManagerTest, 200) { |
54 NavigationNotificationObserver observer; | 85 NavigationNotificationObserver observer; |
55 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL)); | 86 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL)); |
56 EXPECT_TRUE(observer.got_navigation()); | 87 EXPECT_TRUE(observer.got_navigation()); |
57 EXPECT_EQ(200, observer.http_status_code()); | 88 EXPECT_EQ(200, observer.http_status_code()); |
58 } | 89 } |
59 | 90 |
| 91 // Makes sure browser does not crash when navigating to an unknown resource. |
| 92 IN_PROC_BROWSER_TEST_F(ChromeURLDataManagerTest, UnknownResource) { |
| 93 // Known resource |
| 94 NavigationObserver observer( |
| 95 browser()->tab_strip_model()->GetActiveWebContents()); |
| 96 ui_test_utils::NavigateToURL( |
| 97 browser(), GURL("chrome://theme/IDR_SETTINGS_FAVICON")); |
| 98 EXPECT_EQ(NavigationObserver::SUCCESS, observer.navigation_result()); |
| 99 |
| 100 // Unknown resource |
| 101 observer.Reset(); |
| 102 ui_test_utils::NavigateToURL( |
| 103 browser(), GURL("chrome://theme/IDR_ASDFGHJKL")); |
| 104 EXPECT_EQ(NavigationObserver::ERROR_PAGE, observer.navigation_result()); |
| 105 } |
| 106 |
60 // Makes sure browser does not crash when the resource scale is very large. | 107 // Makes sure browser does not crash when the resource scale is very large. |
61 IN_PROC_BROWSER_TEST_F(ChromeURLDataManagerTest, ResourceScaleTest) { | 108 IN_PROC_BROWSER_TEST_F(ChromeURLDataManagerTest, LargeResourceScale) { |
| 109 // Valid scale |
| 110 NavigationObserver observer( |
| 111 browser()->tab_strip_model()->GetActiveWebContents()); |
62 ui_test_utils::NavigateToURL( | 112 ui_test_utils::NavigateToURL( |
63 browser(), GURL("chrome://theme/IDR_SETTINGS_FAVICON@2x")); | 113 browser(), GURL("chrome://theme/IDR_SETTINGS_FAVICON@2x")); |
| 114 EXPECT_EQ(NavigationObserver::SUCCESS, observer.navigation_result()); |
64 | 115 |
| 116 // Unreasonably large scale |
| 117 observer.Reset(); |
65 ui_test_utils::NavigateToURL( | 118 ui_test_utils::NavigateToURL( |
66 browser(), GURL("chrome://theme/IDR_SETTINGS_FAVICON@99999x")); | 119 browser(), GURL("chrome://theme/IDR_SETTINGS_FAVICON@99999x")); |
| 120 EXPECT_EQ(NavigationObserver::SUCCESS, observer.navigation_result()); |
67 } | 121 } |
OLD | NEW |