| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/browser/ui/webui/log_web_ui_url.h" | 5 #include "chrome/browser/ui/webui/log_web_ui_url.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 class LogWebUIUrlTest : public InProcessBrowserTest { | 36 class LogWebUIUrlTest : public InProcessBrowserTest { |
| 37 public: | 37 public: |
| 38 LogWebUIUrlTest() {} | 38 LogWebUIUrlTest() {} |
| 39 ~LogWebUIUrlTest() override {} | 39 ~LogWebUIUrlTest() override {} |
| 40 | 40 |
| 41 std::vector<Bucket> GetSamples() { | 41 std::vector<Bucket> GetSamples() { |
| 42 return histogram_tester_.GetAllSamples(webui::kWebUICreatedForUrl); | 42 return histogram_tester_.GetAllSamples(webui::kWebUICreatedForUrl); |
| 43 } | 43 } |
| 44 | 44 |
| 45 void SetUpOnMainThread() override { | 45 void SetUpOnMainThread() override { |
| 46 // Disable MD History to test non-MD history page. | 46 // Disable MD Settings to test non-MD settings page. |
| 47 scoped_feature_list_.InitAndDisableFeature( | 47 scoped_feature_list_.InitAndDisableFeature( |
| 48 features::kMaterialDesignHistory); | 48 features::kMaterialDesignSettings); |
| 49 } | 49 } |
| 50 | 50 |
| 51 private: | 51 private: |
| 52 base::test::ScopedFeatureList scoped_feature_list_; | 52 base::test::ScopedFeatureList scoped_feature_list_; |
| 53 base::HistogramTester histogram_tester_; | 53 base::HistogramTester histogram_tester_; |
| 54 | 54 |
| 55 DISALLOW_COPY_AND_ASSIGN(LogWebUIUrlTest); | 55 DISALLOW_COPY_AND_ASSIGN(LogWebUIUrlTest); |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 IN_PROC_BROWSER_TEST_F(LogWebUIUrlTest, TestHistoryFrame) { | 58 IN_PROC_BROWSER_TEST_F(LogWebUIUrlTest, TestSettingsFrame) { |
| 59 GURL history_frame_url(chrome::kChromeUIHistoryFrameURL); | 59 GURL settings_frame_url(chrome::kChromeUISettingsFrameURL); |
| 60 | 60 |
| 61 ui_test_utils::NavigateToURL(browser(), history_frame_url); | 61 ui_test_utils::NavigateToURL(browser(), settings_frame_url); |
| 62 | 62 |
| 63 uint32_t history_frame_url_hash = base::Hash(history_frame_url.spec()); | 63 uint32_t settings_frame_url_hash = base::Hash(settings_frame_url.spec()); |
| 64 EXPECT_THAT(GetSamples(), ElementsAre(Bucket(history_frame_url_hash, 1))); | 64 EXPECT_THAT(GetSamples(), ElementsAre(Bucket(settings_frame_url_hash, 1))); |
| 65 | 65 |
| 66 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); | 66 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); |
| 67 | 67 |
| 68 EXPECT_THAT(GetSamples(), ElementsAre(Bucket(history_frame_url_hash, 2))); | 68 EXPECT_THAT(GetSamples(), ElementsAre(Bucket(settings_frame_url_hash, 2))); |
| 69 } | 69 } |
| 70 | 70 |
| 71 #if BUILDFLAG(ENABLE_EXTENSIONS) | 71 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 72 IN_PROC_BROWSER_TEST_F(LogWebUIUrlTest, TestUberPage) { | |
| 73 content::WebContents* tab = | |
| 74 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 75 | |
| 76 base::string16 history_title = l10n_util::GetStringUTF16(IDS_HISTORY_TITLE); | |
| 77 | |
| 78 { | |
| 79 content::TitleWatcher title_watcher(tab, history_title); | |
| 80 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIHistoryURL)); | |
| 81 ASSERT_EQ(history_title, title_watcher.WaitAndGetTitle()); | |
| 82 } | |
| 83 | |
| 84 std::string scheme(content::kChromeUIScheme); | |
| 85 GURL uber_url(scheme + "://" + chrome::kChromeUIUberHost); | |
| 86 uint32_t uber_url_hash = base::Hash(uber_url.spec()); | |
| 87 | |
| 88 GURL uber_frame_url(chrome::kChromeUIUberFrameURL); | |
| 89 uint32_t uber_frame_url_hash = base::Hash(uber_frame_url.spec()); | |
| 90 | |
| 91 GURL history_frame_url(chrome::kChromeUIHistoryFrameURL); | |
| 92 uint32_t history_frame_url_hash = base::Hash(history_frame_url.spec()); | |
| 93 | |
| 94 EXPECT_THAT(GetSamples(), ElementsAre(Bucket(history_frame_url_hash, 1), | |
| 95 Bucket(uber_frame_url_hash, 1), | |
| 96 Bucket(uber_url_hash, 1))); | |
| 97 | |
| 98 { | |
| 99 content::TitleWatcher title_watcher(tab, history_title); | |
| 100 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); | |
| 101 ASSERT_EQ(history_title, title_watcher.WaitAndGetTitle()); | |
| 102 } | |
| 103 | |
| 104 EXPECT_THAT(GetSamples(), ElementsAre(Bucket(history_frame_url_hash, 2), | |
| 105 Bucket(uber_frame_url_hash, 2), | |
| 106 Bucket(uber_url_hash, 2))); | |
| 107 | |
| 108 { | |
| 109 // Pretend a user clicked on "Extensions". | |
| 110 base::string16 extensions_title = | |
| 111 l10n_util::GetStringUTF16(IDS_MANAGE_EXTENSIONS_SETTING_WINDOWS_TITLE); | |
| 112 content::TitleWatcher title_watcher(tab, extensions_title); | |
| 113 std::string javascript = | |
| 114 "uber.invokeMethodOnWindow(window, 'showPage', {pageId: 'extensions'})"; | |
| 115 ASSERT_TRUE(content::ExecuteScript(tab, javascript)); | |
| 116 ASSERT_EQ(extensions_title, title_watcher.WaitAndGetTitle()); | |
| 117 } | |
| 118 | |
| 119 GURL extensions_frame_url(chrome::kChromeUIExtensionsFrameURL); | |
| 120 uint32_t extensions_frame_url_hash = base::Hash(extensions_frame_url.spec()); | |
| 121 | |
| 122 EXPECT_THAT(GetSamples(), ElementsAre(Bucket(extensions_frame_url_hash, 1), | |
| 123 Bucket(history_frame_url_hash, 2), | |
| 124 Bucket(uber_frame_url_hash, 2), | |
| 125 Bucket(uber_url_hash, 2))); | |
| 126 } | |
| 127 | |
| 128 IN_PROC_BROWSER_TEST_F(LogWebUIUrlTest, TestExtensionsPage) { | 72 IN_PROC_BROWSER_TEST_F(LogWebUIUrlTest, TestExtensionsPage) { |
| 129 content::WebContents* tab = | 73 content::WebContents* tab = |
| 130 browser()->tab_strip_model()->GetActiveWebContents(); | 74 browser()->tab_strip_model()->GetActiveWebContents(); |
| 131 | 75 |
| 132 base::string16 extension_title = | 76 base::string16 extension_title = |
| 133 l10n_util::GetStringUTF16(IDS_MANAGE_EXTENSIONS_SETTING_WINDOWS_TITLE); | 77 l10n_util::GetStringUTF16(IDS_MANAGE_EXTENSIONS_SETTING_WINDOWS_TITLE); |
| 134 | 78 |
| 135 { | 79 { |
| 136 content::TitleWatcher title_watcher(tab, extension_title); | 80 content::TitleWatcher title_watcher(tab, extension_title); |
| 137 ui_test_utils::NavigateToURL(browser(), | 81 ui_test_utils::NavigateToURL(browser(), |
| 138 GURL(chrome::kChromeUIExtensionsURL)); | 82 GURL(chrome::kChromeUIExtensionsURL)); |
| 139 ASSERT_EQ(extension_title, title_watcher.WaitAndGetTitle()); | 83 ASSERT_EQ(extension_title, title_watcher.WaitAndGetTitle()); |
| 140 } | 84 } |
| 141 | 85 |
| 142 std::string scheme(content::kChromeUIScheme); | 86 std::string scheme(content::kChromeUIScheme); |
| 143 GURL uber_url(scheme + "://" + chrome::kChromeUIUberHost); | 87 GURL uber_url(scheme + "://" + chrome::kChromeUIUberHost); |
| 144 uint32_t uber_url_hash = base::Hash(uber_url.spec()); | 88 uint32_t uber_url_hash = base::Hash(uber_url.spec()); |
| 145 | 89 |
| 146 GURL uber_frame_url(chrome::kChromeUIUberFrameURL); | 90 GURL uber_frame_url(chrome::kChromeUIUberFrameURL); |
| 147 uint32_t uber_frame_url_hash = base::Hash(uber_frame_url.spec()); | 91 uint32_t uber_frame_url_hash = base::Hash(uber_frame_url.spec()); |
| 148 | 92 |
| 149 GURL extensions_frame_url(chrome::kChromeUIExtensionsFrameURL); | 93 GURL extensions_frame_url(chrome::kChromeUIExtensionsFrameURL); |
| 150 uint32_t extensions_frame_url_hash = base::Hash(extensions_frame_url.spec()); | 94 uint32_t extensions_frame_url_hash = base::Hash(extensions_frame_url.spec()); |
| 151 | 95 |
| 152 EXPECT_THAT(GetSamples(), ElementsAre(Bucket(extensions_frame_url_hash, 1), | 96 EXPECT_THAT(GetSamples(), ElementsAre(Bucket(extensions_frame_url_hash, 1), |
| 153 Bucket(uber_frame_url_hash, 1), | 97 Bucket(uber_frame_url_hash, 1), |
| 154 Bucket(uber_url_hash, 1))); | 98 Bucket(uber_url_hash, 1))); |
| 99 |
| 100 { |
| 101 // Pretend a user clicked on "Settings". |
| 102 base::string16 settings_title = |
| 103 l10n_util::GetStringUTF16(IDS_SETTINGS_SETTINGS); |
| 104 content::TitleWatcher title_watcher(tab, settings_title); |
| 105 std::string javascript = |
| 106 "uber.invokeMethodOnWindow(window, 'showPage', {pageId: 'settings'})"; |
| 107 ASSERT_TRUE(content::ExecuteScript(tab, javascript)); |
| 108 ASSERT_EQ(settings_title, title_watcher.WaitAndGetTitle()); |
| 109 } |
| 110 |
| 111 GURL settings_frame_url(chrome::kChromeUISettingsFrameURL); |
| 112 uint32_t settings_frame_url_hash = base::Hash(settings_frame_url.spec()); |
| 113 |
| 114 EXPECT_THAT(GetSamples(), ElementsAre(Bucket(extensions_frame_url_hash, 1), |
| 115 Bucket(settings_frame_url_hash, 1), |
| 116 Bucket(uber_frame_url_hash, 1), |
| 117 Bucket(uber_url_hash, 1))); |
| 155 } | 118 } |
| 156 #endif | 119 #endif |
| 157 | 120 |
| 158 } // namespace webui | 121 } // namespace webui |
| OLD | NEW |