This source file includes following definitions.
- ConcatNames
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
#include "base/metrics/histogram.h"
#include "base/strings/stringprintf.h"
#include "chrome/browser/extensions/activity_log/uma_policy.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/test_extension_dir.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/common/extensions/extension_file_util.h"
#include "chrome/test/base/ui_test_utils.h"
#include "extensions/common/manifest_constants.h"
#include "net/dns/mock_host_resolver.h"
using extensions::UmaPolicy;
const char* kGooglePrefix = "ExtensionActivity.Google";
const char* kNonGooglePrefix = "ExtensionActivity";
class ActivityLogUmaPolicyTest : public ExtensionApiTest {
};
std::string ConcatNames(const char* prefix, int status_num) {
return base::StringPrintf(
"%s.%s",
prefix,
extensions::UmaPolicy::GetHistogramName(
static_cast<extensions::UmaPolicy::PageStatus>(status_num)));
}
IN_PROC_BROWSER_TEST_F(ActivityLogUmaPolicyTest, DISABLED_SequentialNavs) {
host_resolver()->AddRule("*", "127.0.0.1");
StartEmbeddedTestServer();
const extensions::Extension* ext =
LoadExtension(test_data_dir_.AppendASCII("uma_policy"));
ASSERT_TRUE(ext);
ui_test_utils::NavigateToURLWithDisposition(
browser(), GURL("http://www.opener.com/#google"), NEW_WINDOW,
ui_test_utils::BROWSER_TEST_NONE);
ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
browser(), GURL("http://www.blocker.com"), 2);
ui_test_utils::NavigateToURLWithDisposition(
browser(), GURL("http://www.opener.com/#google?q=a"), NEW_WINDOW,
ui_test_utils::BROWSER_TEST_NONE);
ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
browser(), GURL("http://www.blocker.com"), 2);
ui_test_utils::NavigateToURLWithDisposition(
browser(), GURL("http://www.opener.com/#google?q=b"), NEW_WINDOW,
ui_test_utils::BROWSER_TEST_NONE);
ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
browser(), GURL("http://www.blocker.com"), 2);
ui_test_utils::NavigateToURLWithDisposition(
browser(), GURL("http://www.opener.com/#cnn?q=a"), NEW_WINDOW,
ui_test_utils::BROWSER_TEST_NONE);
ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
browser(), GURL("http://www.blocker.com"), 2);
ui_test_utils::NavigateToURLWithDisposition(
browser(), GURL("http://www.opener.com/#cnn?q=b"), NEW_WINDOW,
ui_test_utils::BROWSER_TEST_NONE);
ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
browser(), GURL("http://www.blocker.com"), 2);
for (int i = UmaPolicy::NONE + 1; i < UmaPolicy::MAX_STATUS - 2; ++i) {
base::HistogramBase* google_histogram = base::Histogram::FactoryGet(
ConcatNames(kGooglePrefix, i),
1, 100, 50, base::HistogramBase::kNoFlags);
scoped_ptr<base::HistogramSamples> google_samples =
google_histogram->SnapshotSamples();
EXPECT_EQ(3, google_samples->TotalCount());
EXPECT_EQ(3, google_samples->GetCount(1));
base::HistogramBase* cnn_histogram = base::Histogram::FactoryGet(
ConcatNames(kNonGooglePrefix, i),
1, 100, 50, base::HistogramBase::kNoFlags);
scoped_ptr<base::HistogramSamples> cnn_samples =
cnn_histogram->SnapshotSamples();
if (ConcatNames(kNonGooglePrefix, i) != "ExtensionActivity.ContentScript" &&
ConcatNames(kNonGooglePrefix, i) != "ExtensionActivity.ReadDom") {
EXPECT_EQ(2, cnn_samples->GetCount(1));
}
}
}
IN_PROC_BROWSER_TEST_F(
ActivityLogUmaPolicyTest, DISABLED_ParallelDistinctNavs) {
host_resolver()->AddRule("*", "127.0.0.1");
StartEmbeddedTestServer();
const extensions::Extension* ext =
LoadExtension(test_data_dir_.AppendASCII("uma_policy"));
ASSERT_TRUE(ext);
ui_test_utils::NavigateToURLWithDisposition(
browser(), GURL("http://www.opener.com/#google?p=a"), NEW_WINDOW,
ui_test_utils::BROWSER_TEST_NONE);
ui_test_utils::NavigateToURLWithDisposition(
browser(), GURL("http://www.opener.com/#google?p=b"), NEW_WINDOW,
ui_test_utils::BROWSER_TEST_NONE);
ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
browser(), GURL("http://www.blocker.com"), 2);
for (int i = UmaPolicy::NONE + 1; i < UmaPolicy::MAX_STATUS - 2; ++i) {
base::HistogramBase* google_histogram = base::Histogram::FactoryGet(
ConcatNames(kGooglePrefix, i),
1, 100, 50, base::HistogramBase::kNoFlags);
scoped_ptr<base::HistogramSamples> google_samples =
google_histogram->SnapshotSamples();
EXPECT_EQ(2, google_samples->GetCount(1));
}
}
IN_PROC_BROWSER_TEST_F(ActivityLogUmaPolicyTest, DISABLED_Google_ParallelSame) {
host_resolver()->AddRule("*", "127.0.0.1");
StartEmbeddedTestServer();
const extensions::Extension* ext =
LoadExtension(test_data_dir_.AppendASCII("uma_policy"));
ASSERT_TRUE(ext);
ui_test_utils::NavigateToURLWithDisposition(
browser(), GURL("http://www.opener.com/#googlea"), NEW_WINDOW,
ui_test_utils::BROWSER_TEST_NONE);
ui_test_utils::NavigateToURLWithDisposition(
browser(), GURL("http://www.opener.com/#googleb"), NEW_WINDOW,
ui_test_utils::BROWSER_TEST_NONE);
ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
browser(), GURL("http://www.blocker.com"), 2);
for (int i = UmaPolicy::NONE + 1; i < UmaPolicy::MAX_STATUS - 2; ++i) {
base::HistogramBase* google_histogram = base::Histogram::FactoryGet(
ConcatNames(kGooglePrefix, i),
1, 100, 50, base::HistogramBase::kNoFlags);
scoped_ptr<base::HistogramSamples> google_samples =
google_histogram->SnapshotSamples();
EXPECT_EQ(1, google_samples->GetCount(1));
}
}
IN_PROC_BROWSER_TEST_F(ActivityLogUmaPolicyTest,
DISABLED_NonGoogle_ParallelSame) {
host_resolver()->AddRule("*", "127.0.0.1");
StartEmbeddedTestServer();
const extensions::Extension* ext =
LoadExtension(test_data_dir_.AppendASCII("uma_policy"));
ASSERT_TRUE(ext);
ui_test_utils::NavigateToURLWithDisposition(
browser(), GURL("http://www.opener.com/#cnna"), NEW_WINDOW,
ui_test_utils::BROWSER_TEST_NONE);
ui_test_utils::NavigateToURLWithDisposition(
browser(), GURL("http://www.opener.com/#cnnb"), NEW_WINDOW,
ui_test_utils::BROWSER_TEST_NONE);
ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
browser(), GURL("http://www.blocker.com"), 2);
for (int i = UmaPolicy::NONE + 1; i < UmaPolicy::MAX_STATUS - 2; ++i) {
base::HistogramBase* cnn_histogram = base::Histogram::FactoryGet(
ConcatNames(kNonGooglePrefix, i),
1, 100, 50, base::HistogramBase::kNoFlags);
scoped_ptr<base::HistogramSamples> cnn_samples =
cnn_histogram->SnapshotSamples();
if (ConcatNames(kNonGooglePrefix, i) != "ExtensionActivity.ContentScript" &&
ConcatNames(kNonGooglePrefix, i) != "ExtensionActivity.ReadDom") {
EXPECT_EQ(1, cnn_samples->GetCount(1));
}
}
}
IN_PROC_BROWSER_TEST_F(ActivityLogUmaPolicyTest, DISABLED_MultipleExtensions) {
host_resolver()->AddRule("*", "127.0.0.1");
StartEmbeddedTestServer();
const extensions::Extension* ext =
LoadExtension(test_data_dir_.AppendASCII("uma_policy"));
ASSERT_TRUE(ext);
const char* script2 =
"document.createElement('script');"
"document.createElement('iframe');"
"document.createElement('div');"
"document.createElement('embed');"
"document.createElement('object');";
const char* manifest =
"{"
" \"name\": \"Activity Log UMA Policy Test Extension\","
" \"version\": \"0.%s\","
" \"description\": \"Testing the histogramming\","
" \"content_scripts\": ["
" {"
" \"matches\": "
" [\"http://www.google.com/*\","
" \"http://www.cnn.com/*\"],"
" \"js\": [\"content_script.js\"]"
" }"
" ],"
" \"manifest_version\": 2"
"}";
extensions::TestExtensionDir dir2;
dir2.WriteManifest(base::StringPrintf(manifest, "2"));
dir2.WriteFile(FILE_PATH_LITERAL("content_script.js"), script2);
LoadExtension(dir2.unpacked_path());
ui_test_utils::NavigateToURLWithDisposition(
browser(), GURL("http://www.opener.com/#google"), NEW_WINDOW,
ui_test_utils::BROWSER_TEST_NONE);
ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
browser(), GURL("http://www.blocker.com"), 2);
ui_test_utils::NavigateToURLWithDisposition(
browser(), GURL("http://www.opener.com/#cnn?q=b"), NEW_WINDOW,
ui_test_utils::BROWSER_TEST_NONE);
ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
browser(), GURL("http://www.blocker.com"), 2);
const char* subset_one[] = {
"CreatedLink",
"InnerHtml",
"DocumentWrite"
};
const char* subset_two[] = {
"ContentScript",
"CreatedScript",
"CreatedIframe",
"CreatedDiv",
"CreatedEmbed",
"CreatedObject",
"InvokedDomMethod"
};
for (size_t i = 0; i < arraysize(subset_one); ++i) {
base::HistogramBase* google_histogram = base::Histogram::FactoryGet(
std::string(kGooglePrefix) + "." + std::string(subset_one[i]),
1, 100, 50, base::HistogramBase::kNoFlags);
scoped_ptr<base::HistogramSamples> google_samples =
google_histogram->SnapshotSamples();
EXPECT_EQ(1, google_samples->GetCount(1));
base::HistogramBase* cnn_histogram = base::Histogram::FactoryGet(
std::string(kNonGooglePrefix) + "." + std::string(subset_one[i]),
1, 100, 50, base::HistogramBase::kNoFlags);
scoped_ptr<base::HistogramSamples> cnn_samples =
cnn_histogram->SnapshotSamples();
EXPECT_EQ(1, cnn_samples->GetCount(1));
}
for (size_t i = 0; i < arraysize(subset_two); ++i) {
base::HistogramBase* google_histogram = base::Histogram::FactoryGet(
std::string(kGooglePrefix) + "." + std::string(subset_two[i]),
1, 100, 50, base::HistogramBase::kNoFlags);
scoped_ptr<base::HistogramSamples> google_samples =
google_histogram->SnapshotSamples();
EXPECT_EQ(1, google_samples->GetCount(2));
base::HistogramBase* cnn_histogram = base::Histogram::FactoryGet(
std::string(kNonGooglePrefix) + "." + std::string(subset_two[i]),
1, 100, 50, base::HistogramBase::kNoFlags);
scoped_ptr<base::HistogramSamples> cnn_samples =
cnn_histogram->SnapshotSamples();
EXPECT_EQ(1, cnn_samples->GetCount(2));
}
}