1// Copyright (c) 2011 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "ppapi/tests/test_uma.h"
6
7#include "ppapi/cpp/instance.h"
8#include "ppapi/cpp/module.h"
9#include "ppapi/tests/testing_instance.h"
10
11REGISTER_TEST_CASE(UMA);
12
13bool TestUMA::Init() {
14  uma_interface_ = static_cast<const PPB_UMA_Private*>(
15      pp::Module::Get()->GetBrowserInterface(PPB_UMA_PRIVATE_INTERFACE));
16  return !!uma_interface_;
17}
18
19void TestUMA::RunTests(const std::string& filter) {
20  RUN_TEST(Count, filter);
21  RUN_TEST(Time, filter);
22  RUN_TEST(Enum, filter);
23}
24
25std::string TestUMA::TestCount() {
26  pp::Var name_var = pp::Var("Test.CountHistogram");
27  PP_Var name = name_var.pp_var();
28  PP_Instance instance = instance_->pp_instance();
29  uma_interface_->HistogramCustomCounts(instance, name, 10, 1, 100, 50);
30  uma_interface_->HistogramCustomCounts(instance, name, 30, 1, 100, 50);
31  uma_interface_->HistogramCustomCounts(instance, name, 20, 1, 100, 50);
32  uma_interface_->HistogramCustomCounts(instance, name, 40, 1, 100, 50);
33  // Test that passing in different construction arguments for the same
34  // histogram name does not crash.
35  uma_interface_->HistogramCustomCounts(instance, name, 40, 1, 100, 100);
36  uma_interface_->HistogramCustomCounts(instance, name, 40, 1, 90, 50);
37  uma_interface_->HistogramCustomCounts(instance, name, 40, 10, 100, 50);
38  PASS();
39}
40
41std::string TestUMA::TestTime() {
42  pp::Var name_var = pp::Var("Test.TimeHistogram");
43  PP_Var name = name_var.pp_var();
44  PP_Instance instance = instance_->pp_instance();
45  uma_interface_->HistogramCustomTimes(instance, name, 100, 1, 10000, 50);
46  uma_interface_->HistogramCustomTimes(instance, name, 1000, 1, 10000, 50);
47  uma_interface_->HistogramCustomTimes(instance, name, 5000, 1, 10000, 50);
48  uma_interface_->HistogramCustomTimes(instance, name, 10, 1, 10000, 50);
49  // Test that passing in different construction arguments for the same
50  // histogram name does not crash.
51  uma_interface_->HistogramCustomTimes(instance, name, 10, 1, 10000, 100);
52  uma_interface_->HistogramCustomTimes(instance, name, 10, 1, 9000, 50);
53  uma_interface_->HistogramCustomTimes(instance, name, 10, 100, 10000, 50);
54  PASS();
55}
56
57std::string TestUMA::TestEnum() {
58  pp::Var name_var = pp::Var("Test.EnumHistogram");
59  PP_Var name = name_var.pp_var();
60  PP_Instance instance = instance_->pp_instance();
61  uma_interface_->HistogramEnumeration(instance, name, 0, 5);
62  uma_interface_->HistogramEnumeration(instance, name, 3, 5);
63  uma_interface_->HistogramEnumeration(instance, name, 3, 5);
64  uma_interface_->HistogramEnumeration(instance, name, 1, 5);
65  uma_interface_->HistogramEnumeration(instance, name, 2, 5);
66  // Test that passing in different construction arguments for the same
67  // histogram name does not crash.
68  uma_interface_->HistogramEnumeration(instance, name, 2, 6);
69  PASS();
70}
71
72