OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/metrics/histogram.h" | 5 #include "base/metrics/histogram.h" |
6 #include "base/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
7 #include "chrome/browser/extensions/activity_log/uma_policy.h" | 7 #include "chrome/browser/extensions/activity_log/uma_policy.h" |
8 #include "chrome/browser/extensions/extension_apitest.h" | 8 #include "chrome/browser/extensions/extension_apitest.h" |
9 #include "chrome/browser/extensions/extension_browsertest.h" | 9 #include "chrome/browser/extensions/extension_browsertest.h" |
10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
11 #include "chrome/browser/extensions/test_extension_dir.h" | 11 #include "chrome/browser/extensions/test_extension_dir.h" |
12 #include "chrome/browser/ui/browser_window.h" | 12 #include "chrome/browser/ui/browser_window.h" |
13 #include "chrome/test/base/ui_test_utils.h" | 13 #include "chrome/test/base/ui_test_utils.h" |
14 #include "extensions/common/manifest_constants.h" | 14 #include "extensions/common/manifest_constants.h" |
15 #include "net/dns/mock_host_resolver.h" | 15 #include "net/dns/mock_host_resolver.h" |
16 | 16 |
17 using extensions::UmaPolicy; | 17 using extensions::UmaPolicy; |
18 | 18 |
19 const char* kGooglePrefix = "ExtensionActivity.Google"; | 19 const char kGooglePrefix[] = "ExtensionActivity.Google"; |
20 const char* kNonGooglePrefix = "ExtensionActivity"; | 20 const char kNonGooglePrefix[] = "ExtensionActivity"; |
21 | 21 |
22 // These tests need to ensure that all of the extension JavaScript completes | 22 // These tests need to ensure that all of the extension JavaScript completes |
23 // before the histograms are checked. To accomplish this, the test relies on | 23 // before the histograms are checked. To accomplish this, the test relies on |
24 // some JavaScript in chrome/test/data/extensions/api_test/uma_policy/: | 24 // some JavaScript in chrome/test/data/extensions/api_test/uma_policy/: |
25 // * When the test navigates to opener.com, opener.js will use window.open() to | 25 // * When the test navigates to opener.com, opener.js will use window.open() to |
26 // pop open a new window with the appropriate URL for the test case. This | 26 // pop open a new window with the appropriate URL for the test case. This |
27 // ensures that the testing framework never reuses a window that's still | 27 // ensures that the testing framework never reuses a window that's still |
28 // running a previous test case. | 28 // running a previous test case. |
29 // * The test extension code in content_script.js tells background.js when it's | 29 // * The test extension code in content_script.js tells background.js when it's |
30 // done. When it's finished, background.js closes the blocker.com window. So | 30 // done. When it's finished, background.js closes the blocker.com window. So |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 | 202 |
203 // This runs with multiple extensions installed. | 203 // This runs with multiple extensions installed. |
204 IN_PROC_BROWSER_TEST_F(ActivityLogUmaPolicyTest, DISABLED_MultipleExtensions) { | 204 IN_PROC_BROWSER_TEST_F(ActivityLogUmaPolicyTest, DISABLED_MultipleExtensions) { |
205 host_resolver()->AddRule("*", "127.0.0.1"); | 205 host_resolver()->AddRule("*", "127.0.0.1"); |
206 StartEmbeddedTestServer(); | 206 StartEmbeddedTestServer(); |
207 | 207 |
208 const extensions::Extension* ext = | 208 const extensions::Extension* ext = |
209 LoadExtension(test_data_dir_.AppendASCII("uma_policy")); | 209 LoadExtension(test_data_dir_.AppendASCII("uma_policy")); |
210 ASSERT_TRUE(ext); | 210 ASSERT_TRUE(ext); |
211 | 211 |
212 const char* script2 = | 212 const char script2[] = |
213 "document.createElement('script');" | 213 "document.createElement('script');" |
214 "document.createElement('iframe');" | 214 "document.createElement('iframe');" |
215 "document.createElement('div');" | 215 "document.createElement('div');" |
216 "document.createElement('embed');" | 216 "document.createElement('embed');" |
217 "document.createElement('object');"; | 217 "document.createElement('object');"; |
218 | 218 |
219 const char* manifest = | 219 const char manifest[] = |
220 "{" | 220 "{" |
221 " \"name\": \"Activity Log UMA Policy Test Extension\"," | 221 " \"name\": \"Activity Log UMA Policy Test Extension\"," |
222 " \"version\": \"0.%s\"," | 222 " \"version\": \"0.%s\"," |
223 " \"description\": \"Testing the histogramming\"," | 223 " \"description\": \"Testing the histogramming\"," |
224 " \"content_scripts\": [" | 224 " \"content_scripts\": [" |
225 " {" | 225 " {" |
226 " \"matches\": " | 226 " \"matches\": " |
227 " [\"http://www.google.com/*\"," | 227 " [\"http://www.google.com/*\"," |
228 " \"http://www.cnn.com/*\"]," | 228 " \"http://www.cnn.com/*\"]," |
229 " \"js\": [\"content_script.js\"]" | 229 " \"js\": [\"content_script.js\"]" |
(...skipping 11 matching lines...) Expand all Loading... |
241 browser(), GURL("http://www.opener.com/#google"), NEW_WINDOW, | 241 browser(), GURL("http://www.opener.com/#google"), NEW_WINDOW, |
242 ui_test_utils::BROWSER_TEST_NONE); | 242 ui_test_utils::BROWSER_TEST_NONE); |
243 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | 243 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
244 browser(), GURL("http://www.blocker.com"), 2); | 244 browser(), GURL("http://www.blocker.com"), 2); |
245 ui_test_utils::NavigateToURLWithDisposition( | 245 ui_test_utils::NavigateToURLWithDisposition( |
246 browser(), GURL("http://www.opener.com/#cnn?q=b"), NEW_WINDOW, | 246 browser(), GURL("http://www.opener.com/#cnn?q=b"), NEW_WINDOW, |
247 ui_test_utils::BROWSER_TEST_NONE); | 247 ui_test_utils::BROWSER_TEST_NONE); |
248 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | 248 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
249 browser(), GURL("http://www.blocker.com"), 2); | 249 browser(), GURL("http://www.blocker.com"), 2); |
250 | 250 |
251 const char* subset_one[] = { | 251 const char* const subset_one[] = { |
252 "CreatedLink", | 252 "CreatedLink", |
253 "InnerHtml", | 253 "InnerHtml", |
254 "DocumentWrite" | 254 "DocumentWrite" |
255 }; | 255 }; |
256 | 256 |
257 const char* subset_two[] = { | 257 const char* const subset_two[] = { |
258 "ContentScript", | 258 "ContentScript", |
259 "CreatedScript", | 259 "CreatedScript", |
260 "CreatedIframe", | 260 "CreatedIframe", |
261 "CreatedDiv", | 261 "CreatedDiv", |
262 "CreatedEmbed", | 262 "CreatedEmbed", |
263 "CreatedObject", | 263 "CreatedObject", |
264 "InvokedDomMethod" | 264 "InvokedDomMethod" |
265 }; | 265 }; |
266 | 266 |
267 // These were only touched by one of the scripts. | 267 // These were only touched by one of the scripts. |
(...skipping 22 matching lines...) Expand all Loading... |
290 google_histogram->SnapshotSamples(); | 290 google_histogram->SnapshotSamples(); |
291 EXPECT_EQ(1, google_samples->GetCount(2)); | 291 EXPECT_EQ(1, google_samples->GetCount(2)); |
292 | 292 |
293 base::HistogramBase* cnn_histogram = base::Histogram::FactoryGet( | 293 base::HistogramBase* cnn_histogram = base::Histogram::FactoryGet( |
294 std::string(kNonGooglePrefix) + "." + std::string(subset_two[i]), | 294 std::string(kNonGooglePrefix) + "." + std::string(subset_two[i]), |
295 1, 100, 50, base::HistogramBase::kNoFlags); | 295 1, 100, 50, base::HistogramBase::kNoFlags); |
296 scoped_ptr<base::HistogramSamples> cnn_samples = | 296 scoped_ptr<base::HistogramSamples> cnn_samples = |
297 cnn_histogram->SnapshotSamples(); | 297 cnn_histogram->SnapshotSamples(); |
298 EXPECT_EQ(1, cnn_samples->GetCount(2)); | 298 EXPECT_EQ(1, cnn_samples->GetCount(2)); |
299 } | 299 } |
300 | |
301 } | 300 } |
OLD | NEW |