Home | History | Annotate | Download | only in experience_sampling_private
      1 // Copyright 2014 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 "base/metrics/field_trial.h"
      6 #include "chrome/browser/extensions/api/experience_sampling_private/experience_sampling_private_api.h"
      7 #include "chrome/browser/extensions/extension_api_unittest.h"
      8 #include "chrome/browser/extensions/extension_function_test_utils.h"
      9 
     10 
     11 namespace utils = extension_function_test_utils;
     12 
     13 namespace extensions {
     14 
     15 typedef ExtensionApiUnittest ExperienceSamplingPrivateTest;
     16 
     17 // Tests that chrome.experienceSamplingPrivate.getBrowserInfo() returns expected
     18 // field trials and groups.
     19 TEST_F(ExperienceSamplingPrivateTest, GetBrowserInfoTest) {
     20   // Start with an empty FieldTrialList.
     21   scoped_ptr<base::FieldTrialList> trial_list(new base::FieldTrialList(NULL));
     22   scoped_ptr<base::DictionaryValue> result(RunFunctionAndReturnDictionary(
     23       new ExperienceSamplingPrivateGetBrowserInfoFunction(), "[]"));
     24   ASSERT_TRUE(result->HasKey("variations"));
     25   std::string trials_string;
     26   EXPECT_TRUE(result->GetStringWithoutPathExpansion("variations",
     27                                                     &trials_string));
     28   ASSERT_EQ("", trials_string);
     29 
     30   // Set field trials using a string.
     31   base::FieldTrialList::CreateTrialsFromString(
     32       "Some name/Winner/xxx/yyyy/zzz/default/",
     33       base::FieldTrialList::ACTIVATE_TRIALS,
     34       std::set<std::string>());
     35   result = RunFunctionAndReturnDictionary(
     36       new ExperienceSamplingPrivateGetBrowserInfoFunction(), "[]");
     37   ASSERT_TRUE(result->HasKey("variations"));
     38   EXPECT_TRUE(result->GetStringWithoutPathExpansion("variations",
     39                                                     &trials_string));
     40   ASSERT_EQ("Some name/Winner/xxx/yyyy/zzz/default/", trials_string);
     41 }
     42 
     43 }  // namespace extensions
     44