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/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/metrics/histogram.h" | |
9 #include "base/metrics/statistics_recorder.h" | |
8 #include "base/path_service.h" | 10 #include "base/path_service.h" |
9 #include "base/values.h" | 11 #include "base/values.h" |
10 #include "chrome/browser/ui/browser_tabstrip.h" | 12 #include "chrome/browser/ui/browser_tabstrip.h" |
11 #include "chrome/common/chrome_paths.h" | 13 #include "chrome/common/chrome_paths.h" |
12 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
13 #include "chrome/test/base/in_process_browser_test.h" | 15 #include "chrome/test/base/in_process_browser_test.h" |
14 #include "chrome/test/base/javascript_test_observer.h" | 16 #include "chrome/test/base/javascript_test_observer.h" |
15 #include "chrome/test/base/ui_test_utils.h" | 17 #include "chrome/test/base/ui_test_utils.h" |
18 #include "content/public/browser/histogram_fetcher.h" | |
16 #include "content/public/browser/plugin_service.h" | 19 #include "content/public/browser/plugin_service.h" |
17 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
21 #include "native_client/src/trusted/service_runtime/nacl_error_code.h" | |
18 #include "net/base/net_util.h" | 22 #include "net/base/net_util.h" |
23 #include "ppapi/native_client/src/trusted/plugin/plugin_error.h" | |
19 #include "webkit/plugins/webplugininfo.h" | 24 #include "webkit/plugins/webplugininfo.h" |
20 | 25 |
21 namespace { | 26 namespace { |
22 | 27 |
23 // A helper base class that decodes structured automation messages of the form: | 28 // A helper base class that decodes structured automation messages of the form: |
24 // {"type": type_name, ...} | 29 // {"type": type_name, ...} |
25 class StructuredMessageHandler : public TestMessageHandler { | 30 class StructuredMessageHandler : public TestMessageHandler { |
26 public: | 31 public: |
27 virtual MessageResponse HandleMessage(const std::string& json) OVERRIDE { | 32 virtual MessageResponse HandleMessage(const std::string& json) OVERRIDE { |
28 scoped_ptr<Value> value; | 33 scoped_ptr<Value> value; |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 #if !(defined(ADDRESS_SANITIZER) && defined(OS_LINUX)) | 224 #if !(defined(ADDRESS_SANITIZER) && defined(OS_LINUX)) |
220 | 225 |
221 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib, SimpleLoadTest) { | 226 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib, SimpleLoadTest) { |
222 RunLoadTest(FILE_PATH_LITERAL("nacl_load_test.html")); | 227 RunLoadTest(FILE_PATH_LITERAL("nacl_load_test.html")); |
223 } | 228 } |
224 | 229 |
225 IN_PROC_BROWSER_TEST_F(NaClBrowserTestGLibc, SimpleLoadTest) { | 230 IN_PROC_BROWSER_TEST_F(NaClBrowserTestGLibc, SimpleLoadTest) { |
226 RunLoadTest(FILE_PATH_LITERAL("nacl_load_test.html")); | 231 RunLoadTest(FILE_PATH_LITERAL("nacl_load_test.html")); |
227 } | 232 } |
228 | 233 |
234 class HistogramHelper { | |
235 public: | |
236 HistogramHelper() {} | |
237 | |
238 // Each child process may have its own histogram data, make sure this data | |
239 // gets accumulated into the browser process before we examine the histograms. | |
240 void Fetch() { | |
241 base::Closure callback = base::Bind(&HistogramHelper::FetchCallback, | |
242 base::Unretained(this)); | |
243 | |
244 content::FetchHistogramsAsynchronously( | |
245 MessageLoop::current(), | |
246 callback, | |
247 // Give up after 60 seconds, which is longer than the 45 second timeout | |
248 // for browser tests. If this call times out, it means that a child | |
249 // process is not responding which is something we should not ignore. | |
250 base::TimeDelta::FromMilliseconds(60000)); | |
251 content::RunMessageLoop(); | |
252 } | |
253 | |
254 // We know the exact number of samples in a bucket, and that no other bucket | |
255 // should have samples. | |
256 void ExpectUniqueSample(const std::string& name, size_t bucket, | |
257 base::Histogram::Count expected_count) { | |
258 base::Histogram* histogram = base::StatisticsRecorder::FindHistogram(name); | |
259 ASSERT_NE(static_cast<base::Histogram*>(NULL), histogram) << | |
260 "Histogram \"" << name << "\" does not exist."; | |
261 | |
262 base::Histogram::SampleSet samples; | |
263 histogram->SnapshotSample(&samples); | |
264 CheckBucketCount(name, bucket, expected_count, samples); | |
265 CheckTotalCount(name, expected_count, samples); | |
266 } | |
267 | |
268 // We don't know the values of the samples, but we know how many there are. | |
269 void ExpectTotalCount(const std::string& name, base::Histogram::Count count) { | |
270 base::Histogram* histogram = base::StatisticsRecorder::FindHistogram(name); | |
271 ASSERT_NE((base::Histogram*)NULL, histogram) << "Histogram \"" << name << | |
272 "\" does not exist."; | |
273 | |
274 base::Histogram::SampleSet samples; | |
275 histogram->SnapshotSample(&samples); | |
276 CheckTotalCount(name, count, samples); | |
277 } | |
278 | |
279 private: | |
280 void FetchCallback() { | |
281 MessageLoopForUI::current()->Quit(); | |
282 } | |
283 | |
284 void CheckBucketCount(const std::string& name, size_t bucket, | |
285 base::Histogram::Count expected_count, | |
286 base::Histogram::SampleSet& samples) { | |
287 EXPECT_EQ(expected_count, samples.counts(bucket)) << "Histogram \"" << | |
288 name << "\" does not have the right number of samples (" << | |
289 expected_count << ") in the expected bucket (" << bucket << ")."; | |
290 } | |
291 | |
292 void CheckTotalCount(const std::string& name, | |
293 base::Histogram::Count expected_count, | |
294 base::Histogram::SampleSet& samples) { | |
295 EXPECT_EQ(expected_count, samples.TotalCount()) << "Histogram \"" << name << | |
296 "\" does not have the right total number of samples (" << | |
297 expected_count << ")."; | |
298 } | |
299 }; | |
300 | |
301 // TODO(ncbray) create multiple variants (newlib, glibc, pnacl) of the same test | |
302 // via macros. | |
303 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib, UMALoadTest) { | |
304 // Sanity check. | |
305 ASSERT_TRUE(base::StatisticsRecorder::IsActive()); | |
306 | |
307 // Load a NaCl module to generate UMA data. | |
308 RunLoadTest(FILE_PATH_LITERAL("nacl_load_test.html")); | |
309 | |
310 // Make sure histograms from child processes have been accumulated in the | |
311 // browser brocess. | |
312 HistogramHelper histograms; | |
313 histograms.Fetch(); | |
314 | |
315 // Did the plugin report success? | |
316 histograms.ExpectUniqueSample("NaCl.LoadStatus.Plugin", | |
317 plugin::ERROR_LOAD_SUCCESS, 1); | |
318 | |
319 // Did the sel_ldr report success? | |
320 histograms.ExpectUniqueSample("NaCl.LoadStatus.SelLdr", | |
321 LOAD_OK, 1); | |
322 | |
323 // Make sure we have other important histograms. | |
324 histograms.ExpectTotalCount("NaCl.Perf.StartupTime.LoadModule", 1); | |
325 histograms.ExpectTotalCount("NaCl.Perf.StartupTime.Total", 1); | |
326 histograms.ExpectTotalCount("NaCl.Perf.Size.Manifest", 1); | |
327 histograms.ExpectTotalCount("NaCl.Perf.Size.Nexe", 1); | |
328 } | |
329 | |
330 // TODO(ncbray) convert the rest of nacl_uma.py and test validation failiures | |
Mark Seaborn
2012/08/24 19:30:42
Clarify that nacl_uma.py is from the native_client
Nick Bray (chromium)
2012/08/24 21:13:56
Done.
| |
331 // and crashes. | |
332 | |
229 #endif // !(defined(ADDRESS_SANITIZER) && defined(OS_LINUX)) | 333 #endif // !(defined(ADDRESS_SANITIZER) && defined(OS_LINUX)) |
230 | 334 |
231 } // namespace anonymous | 335 } // namespace anonymous |
OLD | NEW |