summaryrefslogtreecommitdiffstats
path: root/base/field_trial_unittest.cc
diff options
context:
space:
mode:
authorjar@google.com <jar@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-19 17:45:21 +0000
committerjar@google.com <jar@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-19 17:45:21 +0000
commitac262c9fd9775f9d85c42eaf42fccb896ba790ba (patch)
tree666a943e0537d6fdad0bf393ff0dd6939ee13b53 /base/field_trial_unittest.cc
parentaef3555aa83038b26b50cfab04d685e0f6dfc04f (diff)
downloadchromium_src-ac262c9fd9775f9d85c42eaf42fccb896ba790ba.zip
chromium_src-ac262c9fd9775f9d85c42eaf42fccb896ba790ba.tar.gz
chromium_src-ac262c9fd9775f9d85c42eaf42fccb896ba790ba.tar.bz2
Construct a field trial to see if HIGH or MEDIUM memory model "works better"
Includes definition of a FieldTrial class to support this. I have thoughts in my head about how this will eventually extend to be controllable via UMA (as well as being able to run tests defined at compile time, as was done in this example. r=mbelshe, mmentovai Review URL: http://codereview.chromium.org/7638 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3604 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/field_trial_unittest.cc')
-rw-r--r--base/field_trial_unittest.cc74
1 files changed, 74 insertions, 0 deletions
diff --git a/base/field_trial_unittest.cc b/base/field_trial_unittest.cc
new file mode 100644
index 0000000..3d8c0e2
--- /dev/null
+++ b/base/field_trial_unittest.cc
@@ -0,0 +1,74 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Test of FieldTrial class
+
+#include "base/field_trial.h"
+
+#include "base/logging.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+class FieldTrialTest : public testing::Test {
+ public:
+ FieldTrialTest() : trial_list_() { }
+ ~FieldTrialTest() { FieldTrialList::ResetConstructorCountForTestingOnly(); }
+
+ private:
+ FieldTrialList trial_list_;
+};
+
+// Test registration, and also check that destructors are called for trials
+// (and that Purify doesn't catch us leaking).
+TEST_F(FieldTrialTest, Registration) {
+ const wchar_t* name1 = L"name 1 test";
+ const wchar_t* name2 = L"name 2 test";
+ EXPECT_FALSE(FieldTrialList::Find(name1));
+ EXPECT_FALSE(FieldTrialList::Find(name2));
+
+ FieldTrial* trial1 = new FieldTrial(name1, 0.7);
+
+ EXPECT_EQ(trial1, FieldTrialList::Find(name1));
+ EXPECT_FALSE(FieldTrialList::Find(name2));
+
+ FieldTrial* trial2 = new FieldTrial(name2, 0.7);
+
+ EXPECT_EQ(trial1, FieldTrialList::Find(name1));
+ EXPECT_EQ(trial2, FieldTrialList::Find(name2));
+ // Note: FieldTrialList should delete the objects at shutdown.
+}
+
+TEST_F(FieldTrialTest, AbsoluteProbabilities) {
+ wchar_t always_true[] = L" always true";
+ wchar_t always_false[] = L" always false";
+ for (int i = 1; i < 250; ++i) {
+ // Try lots of names, by changing the first character of the name.
+ always_true[0] = i;
+ always_false[0] = i;
+ FieldTrial* trial_true = new FieldTrial(always_true, 1.0);
+ EXPECT_TRUE(trial_true->boolean_value());
+ FieldTrial* trial_false = new FieldTrial(always_false, 0.0);
+ EXPECT_FALSE(trial_false->boolean_value());
+ }
+}
+
+TEST_F(FieldTrialTest, MiddleProbabalities) {
+ wchar_t name[] = L" same name";
+ bool false_event_seen = false;
+ bool true_event_seen = false;
+ for (int i = 1; i < 250; ++i) {
+ name[0] = i;
+ FieldTrial* trial = new FieldTrial(name, 0.5);
+ if (trial->boolean_value()) {
+ true_event_seen = true;
+ } else {
+ false_event_seen = true;
+ }
+ if (false_event_seen && true_event_seen)
+ return; // Successful test!!!
+ }
+ // Very surprising to get here. Probability should be around 1 in 2 ** 250.
+ // One of the following will fail.
+ EXPECT_TRUE(false_event_seen);
+ EXPECT_TRUE(true_event_seen);
+}