Commit 03d3d97d authored by dbeam's avatar dbeam Committed by Commit bot

Add browser test for WebUI URL logging

R=creis@chromium.org
BUG=535059,385352

Review URL: https://codereview.chromium.org/1367343002

Cr-Commit-Position: refs/heads/master@{#351191}
parent c0ca6bac
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
namespace webui { namespace webui {
const char kWebUICreatedForUrl[] = "WebUI.CreatedForUrl";
bool LogWebUIUrl(const GURL& web_ui_url) { bool LogWebUIUrl(const GURL& web_ui_url) {
bool should_log = web_ui_url.SchemeIs(content::kChromeUIScheme) || bool should_log = web_ui_url.SchemeIs(content::kChromeUIScheme) ||
web_ui_url.SchemeIs(content::kChromeDevToolsScheme); web_ui_url.SchemeIs(content::kChromeDevToolsScheme);
...@@ -29,7 +31,7 @@ bool LogWebUIUrl(const GURL& web_ui_url) { ...@@ -29,7 +31,7 @@ bool LogWebUIUrl(const GURL& web_ui_url) {
if (should_log) { if (should_log) {
uint32 hash = base::Hash(web_ui_url.GetOrigin().spec()); uint32 hash = base::Hash(web_ui_url.GetOrigin().spec());
UMA_HISTOGRAM_SPARSE_SLOWLY("WebUI.CreatedForUrl", UMA_HISTOGRAM_SPARSE_SLOWLY(kWebUICreatedForUrl,
static_cast<base::HistogramBase::Sample>(hash)); static_cast<base::HistogramBase::Sample>(hash));
} }
......
...@@ -9,6 +9,9 @@ class GURL; ...@@ -9,6 +9,9 @@ class GURL;
namespace webui { namespace webui {
// Name of histogram that WebUI URLs are logged to.
extern const char kWebUICreatedForUrl[];
// Called when WebUI objects are created to get aggregate usage data (i.e. is // Called when WebUI objects are created to get aggregate usage data (i.e. is
// chrome://history used more than chrome://help?). Only internal (e.g. // chrome://history used more than chrome://help?). Only internal (e.g.
// chrome://) URLs are logged. Returns whether the URL was actually logged. // chrome://) URLs are logged. Returns whether the URL was actually logged.
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/webui/log_web_ui_url.h"
#include <vector>
#include "base/hash.h"
#include "base/test/histogram_tester.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.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 "testing/gmock/include/gmock/gmock.h"
#include "url/gurl.h"
using base::Bucket;
using testing::ElementsAre;
namespace webui {
class LogWebUIUrlTest : public InProcessBrowserTest {
public:
LogWebUIUrlTest() {}
~LogWebUIUrlTest() override {}
std::vector<Bucket> GetSamples() {
return histogram_tester_.GetAllSamples(webui::kWebUICreatedForUrl);
}
private:
base::HistogramTester histogram_tester_;
DISALLOW_COPY_AND_ASSIGN(LogWebUIUrlTest);
};
IN_PROC_BROWSER_TEST_F(LogWebUIUrlTest, TestHistoryFrame) {
GURL history_frame_url(chrome::kChromeUIHistoryFrameURL);
ui_test_utils::NavigateToURL(browser(), history_frame_url);
uint32 history_frame_url_hash = base::Hash(history_frame_url.spec());
EXPECT_THAT(GetSamples(), ElementsAre(Bucket(history_frame_url_hash, 1)));
chrome::Reload(browser(), CURRENT_TAB);
EXPECT_THAT(GetSamples(), ElementsAre(Bucket(history_frame_url_hash, 2)));
}
// TODO(dbeam): test an uber page URL like chrome://history.
} // namespace webui
...@@ -550,6 +550,7 @@ ...@@ -550,6 +550,7 @@
'browser/ui/webui/identity_internals_ui_browsertest.h', 'browser/ui/webui/identity_internals_ui_browsertest.h',
'browser/ui/webui/inspect_ui_browsertest.cc', 'browser/ui/webui/inspect_ui_browsertest.cc',
'browser/ui/webui/interstitials/interstitial_ui_browsertest.cc', 'browser/ui/webui/interstitials/interstitial_ui_browsertest.cc',
'browser/ui/webui/log_web_ui_url_browsertest.cc',
'browser/ui/webui/net_internals/net_internals_ui_browsertest.cc', 'browser/ui/webui/net_internals/net_internals_ui_browsertest.cc',
'browser/ui/webui/net_internals/net_internals_ui_browsertest.h', 'browser/ui/webui/net_internals/net_internals_ui_browsertest.h',
'browser/ui/webui/ntp/new_tab_page_sync_handler_browsertest.cc', 'browser/ui/webui/ntp/new_tab_page_sync_handler_browsertest.cc',
...@@ -2480,6 +2481,12 @@ ...@@ -2480,6 +2481,12 @@
'defines': [ 'FRAME_AVATAR_BUTTON=1', ], 'defines': [ 'FRAME_AVATAR_BUTTON=1', ],
'sources': [ '<@(chrome_browser_tests_views_non_cros_or_mac_sources)' ], 'sources': [ '<@(chrome_browser_tests_views_non_cros_or_mac_sources)' ],
}], }],
['OS=="ios"', {
'sources!': [
# TODO(dbeam): log webui URLs on iOS and test them.
'browser/ui/webui/log_web_ui_url_browsertest.cc',
],
}],
['OS!="android" and OS!="ios"', { ['OS!="android" and OS!="ios"', {
'sources': [ 'sources': [
'browser/copresence/chrome_whispernet_client_browsertest.cc', 'browser/copresence/chrome_whispernet_client_browsertest.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment