Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/json/json_reader.h" | 6 #include "base/json/json_reader.h" |
| 7 #include "base/metrics/histogram.h" | |
| 8 #include "base/metrics/statistics_recorder.h" | |
| 7 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 8 #include "base/timer.h" | 10 #include "base/timer.h" |
| 9 #include "chrome/browser/ui/browser_tabstrip.h" | 11 #include "chrome/browser/ui/browser_tabstrip.h" |
| 10 #include "chrome/common/chrome_paths.h" | 12 #include "chrome/common/chrome_paths.h" |
| 11 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
| 12 #include "chrome/test/base/in_process_browser_test.h" | 14 #include "chrome/test/base/in_process_browser_test.h" |
| 13 #include "chrome/test/base/ui_test_utils.h" | 15 #include "chrome/test/base/ui_test_utils.h" |
| 14 #include "content/public/browser/dom_operation_notification_details.h" | 16 #include "content/public/browser/dom_operation_notification_details.h" |
| 17 #include "content/public/browser/histogram_fetcher.h" | |
| 15 #include "content/public/browser/notification_observer.h" | 18 #include "content/public/browser/notification_observer.h" |
| 16 #include "content/public/browser/notification_registrar.h" | 19 #include "content/public/browser/notification_registrar.h" |
| 17 #include "content/public/browser/notification_types.h" | 20 #include "content/public/browser/notification_types.h" |
| 18 #include "content/public/browser/plugin_service.h" | 21 #include "content/public/browser/plugin_service.h" |
| 19 #include "content/public/browser/render_view_host.h" | 22 #include "content/public/browser/render_view_host.h" |
| 20 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
| 24 #include "native_client/src/trusted/service_runtime/nacl_error_code.h" | |
| 21 #include "net/base/net_util.h" | 25 #include "net/base/net_util.h" |
| 26 #include "ppapi/native_client/src/trusted/plugin/plugin_error.h" | |
| 22 #include "webkit/plugins/webplugininfo.h" | 27 #include "webkit/plugins/webplugininfo.h" |
| 23 | 28 |
| 24 namespace { | 29 namespace { |
| 25 | 30 |
| 26 // Base class for handling a stream of automation messages produced by a | 31 // Base class for handling a stream of automation messages produced by a |
| 27 // JavascriptTestObserver. | 32 // JavascriptTestObserver. |
| 28 class TestMessageHandler { | 33 class TestMessageHandler { |
| 29 public: | 34 public: |
| 30 enum MessageResponse { | 35 enum MessageResponse { |
| 31 // Reset the timeout and keep running. | 36 // Reset the timeout and keep running. |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 305 #if !(defined(ADDRESS_SANITIZER) && defined(OS_LINUX)) | 310 #if !(defined(ADDRESS_SANITIZER) && defined(OS_LINUX)) |
| 306 | 311 |
| 307 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib, SimpleLoadTest) { | 312 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib, SimpleLoadTest) { |
| 308 RunLoadTest(FILE_PATH_LITERAL("nacl_load_test.html")); | 313 RunLoadTest(FILE_PATH_LITERAL("nacl_load_test.html")); |
| 309 } | 314 } |
| 310 | 315 |
| 311 IN_PROC_BROWSER_TEST_F(NaClBrowserTestGLibc, SimpleLoadTest) { | 316 IN_PROC_BROWSER_TEST_F(NaClBrowserTestGLibc, SimpleLoadTest) { |
| 312 RunLoadTest(FILE_PATH_LITERAL("nacl_load_test.html")); | 317 RunLoadTest(FILE_PATH_LITERAL("nacl_load_test.html")); |
| 313 } | 318 } |
| 314 | 319 |
| 320 class HistogramHelper { | |
|
Mark Seaborn
2012/08/21 19:41:37
Should this all be in a separate file to be more o
Nick Bray (chromium)
2012/08/24 18:17:48
I agree, but I was planning to do structural refor
| |
| 321 public: | |
| 322 HistogramHelper() {} | |
| 323 | |
| 324 // Each child process may have its own histogram data, make sure this data | |
| 325 // gets accumulated into the browser process before we examine the histograms. | |
| 326 void Fetch() { | |
| 327 base::Closure callback = base::Bind( | |
| 328 &HistogramHelper::FetchCallback, | |
|
jar (doing other things)
2012/08/23 00:35:39
nit: move 328 to end of 327. For function calls,
Nick Bray (chromium)
2012/08/24 18:17:48
Done.
| |
| 329 base::Unretained(this)); | |
| 330 | |
| 331 content::FetchHistogramsAsynchronously( | |
| 332 MessageLoop::current(), callback, | |
|
Mark Seaborn
2012/08/21 19:41:37
Should you be creating a new message loop object s
Nick Bray (chromium)
2012/08/24 18:17:48
As far as I know, this is idiomatic for browser_te
| |
| 333 base::TimeDelta::FromMilliseconds(60000)); | |
|
Mark Seaborn
2012/08/21 19:41:37
Comment: "give up after 60s, which anyway is longe
Nick Bray (chromium)
2012/08/24 18:17:48
Done.
| |
| 334 content::RunMessageLoop(); | |
| 335 } | |
| 336 | |
| 337 // We know the exact number of samples in a bucket, and that no other bucket | |
| 338 // should have samples. | |
| 339 void ExpectUniqueSample(const std::string &name, size_t bucket, | |
|
Mark Seaborn
2012/08/21 19:41:37
"&" spacing style. 'bucket' -> 'bucket_id', perha
jar (doing other things)
2012/08/23 00:35:39
nit: For function definitions... one arg per line
Mark Seaborn
2012/08/24 19:30:42
Ping.
Nick Bray (chromium)
2012/08/24 21:13:56
Done.
| |
| 340 base::Histogram::Count count) { | |
|
Mark Seaborn
2012/08/21 19:41:37
'count' -> 'expected_count', just for clarity? Sa
Nick Bray (chromium)
2012/08/24 18:17:48
Done.
| |
| 341 base::Histogram* histogram = base::StatisticsRecorder::FindHistogram(name); | |
| 342 ASSERT_NE((base::Histogram*)NULL, histogram) << "Histogram \"" << name << | |
|
jar (doing other things)
2012/08/23 00:35:39
nit: avoid C style cast (here and below). Best is
Nick Bray (chromium)
2012/08/24 18:17:48
Done.
| |
| 343 "\" does not exist."; | |
| 344 | |
| 345 base::Histogram::SampleSet samples; | |
| 346 histogram->SnapshotSample(&samples); | |
| 347 CheckBucketCount(name, bucket, count, samples); | |
| 348 CheckTotalCount(name, count, samples); | |
| 349 } | |
| 350 | |
| 351 // We don't know the values of the samples, but we know how many there are. | |
| 352 void ExpectTotalCount(const std::string &name, base::Histogram::Count count) { | |
|
Mark Seaborn
2012/08/21 19:41:37
"&" spacing style.
Nick Bray (chromium)
2012/08/24 18:17:48
Done.
| |
| 353 base::Histogram* histogram = base::StatisticsRecorder::FindHistogram(name); | |
| 354 ASSERT_NE((base::Histogram*)NULL, histogram) << "Histogram \"" << name << | |
| 355 "\" does not exist."; | |
| 356 | |
| 357 base::Histogram::SampleSet samples; | |
| 358 histogram->SnapshotSample(&samples); | |
| 359 CheckTotalCount(name, count, samples); | |
| 360 } | |
| 361 | |
| 362 private: | |
| 363 void FetchCallback() { | |
| 364 MessageLoopForUI::current()->Quit(); | |
| 365 } | |
| 366 | |
| 367 void CheckBucketCount( | |
| 368 const std::string &name, | |
| 369 size_t bucket, | |
| 370 base::Histogram::Count count, | |
| 371 base::Histogram::SampleSet& samples) { | |
|
jar (doing other things)
2012/08/23 00:35:39
nit: prefer aligning args with paren in definition
Nick Bray (chromium)
2012/08/24 18:17:48
Done.
| |
| 372 EXPECT_EQ(count, samples.counts(bucket)) << "Histogram \"" << name << | |
| 373 "\" does not have the right number of samples (" << count << | |
| 374 ") in the expected bucket (" << bucket << ")."; | |
| 375 } | |
| 376 | |
| 377 void CheckTotalCount( | |
| 378 const std::string &name, | |
| 379 base::Histogram::Count count, | |
| 380 base::Histogram::SampleSet& samples) { | |
| 381 EXPECT_EQ(count, samples.TotalCount()) << "Histogram \"" << name << | |
| 382 "\" does not have the right total number of samples (" << count << ")."; | |
| 383 } | |
| 384 }; | |
| 385 | |
| 386 // TODO(ncbray) create multiple variants via macros. | |
|
Mark Seaborn
2012/08/21 19:41:37
Multiple variants to do what?
Nick Bray (chromium)
2012/08/24 18:17:48
Done.
| |
| 387 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib, UMALoadTest) { | |
| 388 // Sanity check. | |
| 389 ASSERT_TRUE(base::StatisticsRecorder::IsActive()); | |
| 390 | |
| 391 // Load a NaCl module to generate UMA data. | |
| 392 RunLoadTest(FILE_PATH_LITERAL("nacl_load_test.html")); | |
| 393 | |
| 394 // Make sure histograms from child processes have been accumulated in the | |
| 395 // browser brocess. | |
| 396 HistogramHelper histograms; | |
| 397 histograms.Fetch(); | |
| 398 | |
| 399 // Did the plugin report success? | |
| 400 histograms.ExpectUniqueSample("NaCl.LoadStatus.Plugin", | |
| 401 plugin::ERROR_LOAD_SUCCESS, 1); | |
| 402 | |
| 403 // Did the sel_ldr report success? | |
| 404 histograms.ExpectUniqueSample("NaCl.LoadStatus.SelLdr", | |
| 405 LOAD_OK, 1); | |
| 406 | |
| 407 // Make sure we have other important histograms. | |
| 408 histograms.ExpectTotalCount("NaCl.Perf.StartupTime.LoadModule", 1); | |
| 409 histograms.ExpectTotalCount("NaCl.Perf.StartupTime.Total", 1); | |
| 410 histograms.ExpectTotalCount("NaCl.Perf.Size.Manifest", 1); | |
| 411 histograms.ExpectTotalCount("NaCl.Perf.Size.Nexe", 1); | |
|
Mark Seaborn
2012/08/21 19:41:37
Can you add a comment saying something like:
This
Nick Bray (chromium)
2012/08/24 18:17:48
Done.
| |
| 412 } | |
| 413 | |
| 315 #endif // !(defined(ADDRESS_SANITIZER) && defined(OS_LINUX)) | 414 #endif // !(defined(ADDRESS_SANITIZER) && defined(OS_LINUX)) |
| 316 | 415 |
| 317 } // namespace anonymous | 416 } // namespace anonymous |
| OLD | NEW |