| 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 |
| 11 #include "base/hash.h" | 11 #include "base/hash.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/test/histogram_tester.h" | 13 #include "base/test/histogram_tester.h" |
| 14 #include "base/test/scoped_feature_list.h" | |
| 15 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/browser_commands.h" | 15 #include "chrome/browser/ui/browser_commands.h" |
| 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 18 #include "chrome/common/chrome_features.h" | |
| 19 #include "chrome/common/url_constants.h" | 17 #include "chrome/common/url_constants.h" |
| 20 #include "chrome/grit/generated_resources.h" | 18 #include "chrome/grit/generated_resources.h" |
| 21 #include "chrome/test/base/in_process_browser_test.h" | 19 #include "chrome/test/base/in_process_browser_test.h" |
| 22 #include "chrome/test/base/ui_test_utils.h" | 20 #include "chrome/test/base/ui_test_utils.h" |
| 23 #include "content/public/common/url_constants.h" | 21 #include "content/public/common/url_constants.h" |
| 24 #include "content/public/test/browser_test_utils.h" | 22 #include "content/public/test/browser_test_utils.h" |
| 25 #include "extensions/features/features.h" | 23 #include "extensions/features/features.h" |
| 26 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
| 27 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
| 28 #include "url/gurl.h" | 26 #include "url/gurl.h" |
| 29 | 27 |
| 30 using base::Bucket; | 28 using base::Bucket; |
| 31 using testing::ElementsAre; | 29 using testing::ElementsAre; |
| 32 | 30 |
| 33 namespace webui { | 31 namespace webui { |
| 34 | 32 |
| 35 class LogWebUIUrlTest : public InProcessBrowserTest { | 33 class LogWebUIUrlTest : public InProcessBrowserTest { |
| 36 public: | 34 public: |
| 37 LogWebUIUrlTest() {} | 35 LogWebUIUrlTest() {} |
| 38 ~LogWebUIUrlTest() override {} | 36 ~LogWebUIUrlTest() override {} |
| 39 | 37 |
| 40 std::vector<Bucket> GetSamples() { | 38 std::vector<Bucket> GetSamples() { |
| 41 return histogram_tester_.GetAllSamples(webui::kWebUICreatedForUrl); | 39 return histogram_tester_.GetAllSamples(webui::kWebUICreatedForUrl); |
| 42 } | 40 } |
| 43 | 41 |
| 44 void SetUpOnMainThread() override { | |
| 45 // Disable MD Settings to test non-MD settings page. | |
| 46 scoped_feature_list_.InitAndDisableFeature( | |
| 47 features::kMaterialDesignSettings); | |
| 48 } | |
| 49 | |
| 50 private: | 42 private: |
| 51 base::test::ScopedFeatureList scoped_feature_list_; | |
| 52 base::HistogramTester histogram_tester_; | 43 base::HistogramTester histogram_tester_; |
| 53 | 44 |
| 54 DISALLOW_COPY_AND_ASSIGN(LogWebUIUrlTest); | 45 DISALLOW_COPY_AND_ASSIGN(LogWebUIUrlTest); |
| 55 }; | 46 }; |
| 56 | 47 |
| 57 IN_PROC_BROWSER_TEST_F(LogWebUIUrlTest, TestSettingsFrame) { | |
| 58 GURL settings_frame_url(chrome::kChromeUISettingsFrameURL); | |
| 59 | |
| 60 ui_test_utils::NavigateToURL(browser(), settings_frame_url); | |
| 61 | |
| 62 uint32_t settings_frame_url_hash = base::Hash(settings_frame_url.spec()); | |
| 63 EXPECT_THAT(GetSamples(), ElementsAre(Bucket(settings_frame_url_hash, 1))); | |
| 64 | |
| 65 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); | |
| 66 | |
| 67 EXPECT_THAT(GetSamples(), ElementsAre(Bucket(settings_frame_url_hash, 2))); | |
| 68 } | |
| 69 | |
| 70 #if BUILDFLAG(ENABLE_EXTENSIONS) | 48 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 71 IN_PROC_BROWSER_TEST_F(LogWebUIUrlTest, TestExtensionsPage) { | 49 IN_PROC_BROWSER_TEST_F(LogWebUIUrlTest, TestExtensionsPage) { |
| 72 content::WebContents* tab = | 50 content::WebContents* tab = |
| 73 browser()->tab_strip_model()->GetActiveWebContents(); | 51 browser()->tab_strip_model()->GetActiveWebContents(); |
| 74 | 52 |
| 75 base::string16 extension_title = | 53 base::string16 extension_title = |
| 76 l10n_util::GetStringUTF16(IDS_MANAGE_EXTENSIONS_SETTING_WINDOWS_TITLE); | 54 l10n_util::GetStringUTF16(IDS_MANAGE_EXTENSIONS_SETTING_WINDOWS_TITLE); |
| 77 | 55 |
| 78 { | 56 { |
| 79 content::TitleWatcher title_watcher(tab, extension_title); | 57 content::TitleWatcher title_watcher(tab, extension_title); |
| 80 ui_test_utils::NavigateToURL(browser(), | 58 ui_test_utils::NavigateToURL(browser(), |
| 81 GURL(chrome::kChromeUIExtensionsURL)); | 59 GURL(chrome::kChromeUIExtensionsURL)); |
| 82 ASSERT_EQ(extension_title, title_watcher.WaitAndGetTitle()); | 60 ASSERT_EQ(extension_title, title_watcher.WaitAndGetTitle()); |
| 83 } | 61 } |
| 84 | 62 |
| 85 std::string scheme(content::kChromeUIScheme); | 63 std::string scheme(content::kChromeUIScheme); |
| 86 GURL uber_url(scheme + "://" + chrome::kChromeUIUberHost); | 64 GURL uber_url(scheme + "://" + chrome::kChromeUIUberHost); |
| 87 uint32_t uber_url_hash = base::Hash(uber_url.spec()); | 65 uint32_t uber_url_hash = base::Hash(uber_url.spec()); |
| 88 | 66 |
| 89 GURL uber_frame_url(chrome::kChromeUIUberFrameURL); | 67 GURL uber_frame_url(chrome::kChromeUIUberFrameURL); |
| 90 uint32_t uber_frame_url_hash = base::Hash(uber_frame_url.spec()); | 68 uint32_t uber_frame_url_hash = base::Hash(uber_frame_url.spec()); |
| 91 | 69 |
| 92 GURL extensions_frame_url(chrome::kChromeUIExtensionsFrameURL); | 70 GURL extensions_frame_url(chrome::kChromeUIExtensionsFrameURL); |
| 93 uint32_t extensions_frame_url_hash = base::Hash(extensions_frame_url.spec()); | 71 uint32_t extensions_frame_url_hash = base::Hash(extensions_frame_url.spec()); |
| 94 | 72 |
| 95 EXPECT_THAT(GetSamples(), ElementsAre(Bucket(extensions_frame_url_hash, 1), | 73 EXPECT_THAT(GetSamples(), ElementsAre(Bucket(extensions_frame_url_hash, 1), |
| 96 Bucket(uber_frame_url_hash, 1), | 74 Bucket(uber_frame_url_hash, 1), |
| 97 Bucket(uber_url_hash, 1))); | 75 Bucket(uber_url_hash, 1))); |
| 98 | |
| 99 { | |
| 100 // Pretend a user clicked on "Settings". | |
| 101 base::string16 settings_title = | |
| 102 l10n_util::GetStringUTF16(IDS_SETTINGS_SETTINGS); | |
| 103 content::TitleWatcher title_watcher(tab, settings_title); | |
| 104 std::string javascript = | |
| 105 "uber.invokeMethodOnWindow(window, 'showPage', {pageId: 'settings'})"; | |
| 106 ASSERT_TRUE(content::ExecuteScript(tab, javascript)); | |
| 107 ASSERT_EQ(settings_title, title_watcher.WaitAndGetTitle()); | |
| 108 } | |
| 109 | |
| 110 GURL settings_frame_url(chrome::kChromeUISettingsFrameURL); | |
| 111 uint32_t settings_frame_url_hash = base::Hash(settings_frame_url.spec()); | |
| 112 | |
| 113 EXPECT_THAT(GetSamples(), ElementsAre(Bucket(extensions_frame_url_hash, 1), | |
| 114 Bucket(settings_frame_url_hash, 1), | |
| 115 Bucket(uber_frame_url_hash, 1), | |
| 116 Bucket(uber_url_hash, 1))); | |
| 117 } | 76 } |
| 118 #endif | 77 #endif |
| 119 | 78 |
| 120 } // namespace webui | 79 } // namespace webui |
| OLD | NEW |