160015d27aea1b7e91deac0f3af4c0196a89dce7bandresp@webrtc.org/*
260015d27aea1b7e91deac0f3af4c0196a89dce7bandresp@webrtc.org *  Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
360015d27aea1b7e91deac0f3af4c0196a89dce7bandresp@webrtc.org *
460015d27aea1b7e91deac0f3af4c0196a89dce7bandresp@webrtc.org *  Use of this source code is governed by a BSD-style license
560015d27aea1b7e91deac0f3af4c0196a89dce7bandresp@webrtc.org *  that can be found in the LICENSE file in the root of the source
660015d27aea1b7e91deac0f3af4c0196a89dce7bandresp@webrtc.org *  tree. An additional intellectual property rights grant can be found
760015d27aea1b7e91deac0f3af4c0196a89dce7bandresp@webrtc.org *  in the file PATENTS.  All contributing project authors may
860015d27aea1b7e91deac0f3af4c0196a89dce7bandresp@webrtc.org *  be found in the AUTHORS file in the root of the source tree.
960015d27aea1b7e91deac0f3af4c0196a89dce7bandresp@webrtc.org */
1060015d27aea1b7e91deac0f3af4c0196a89dce7bandresp@webrtc.org
1160015d27aea1b7e91deac0f3af4c0196a89dce7bandresp@webrtc.org#ifndef WEBRTC_TEST_FIELD_TRIAL_H_
1260015d27aea1b7e91deac0f3af4c0196a89dce7bandresp@webrtc.org#define WEBRTC_TEST_FIELD_TRIAL_H_
1360015d27aea1b7e91deac0f3af4c0196a89dce7bandresp@webrtc.org
1460015d27aea1b7e91deac0f3af4c0196a89dce7bandresp@webrtc.org#include <string>
1519492f1c4c7411b7632fe34824226c1c579a6412pbos#include <map>
1660015d27aea1b7e91deac0f3af4c0196a89dce7bandresp@webrtc.org
1760015d27aea1b7e91deac0f3af4c0196a89dce7bandresp@webrtc.orgnamespace webrtc {
1860015d27aea1b7e91deac0f3af4c0196a89dce7bandresp@webrtc.orgnamespace test {
1960015d27aea1b7e91deac0f3af4c0196a89dce7bandresp@webrtc.org
2060015d27aea1b7e91deac0f3af4c0196a89dce7bandresp@webrtc.org// Parses enabled field trials from a string config, such as the one passed
2160015d27aea1b7e91deac0f3af4c0196a89dce7bandresp@webrtc.org// to chrome's argument --force-fieldtrials and initializes webrtc::field_trial
2260015d27aea1b7e91deac0f3af4c0196a89dce7bandresp@webrtc.org// with such a config.
2360015d27aea1b7e91deac0f3af4c0196a89dce7bandresp@webrtc.org//  E.g.:
2460015d27aea1b7e91deac0f3af4c0196a89dce7bandresp@webrtc.org//    "WebRTC-experimentFoo/Enabled/WebRTC-experimentBar/Enabled100kbps/"
2560015d27aea1b7e91deac0f3af4c0196a89dce7bandresp@webrtc.org//    Assigns the process to group "Enabled" on WebRTCExperimentFoo trial
2660015d27aea1b7e91deac0f3af4c0196a89dce7bandresp@webrtc.org//    and to group "Enabled100kbps" on WebRTCExperimentBar.
2760015d27aea1b7e91deac0f3af4c0196a89dce7bandresp@webrtc.org//
2860015d27aea1b7e91deac0f3af4c0196a89dce7bandresp@webrtc.org//  E.g. invalid config:
2960015d27aea1b7e91deac0f3af4c0196a89dce7bandresp@webrtc.org//    "WebRTC-experiment1/Enabled"  (note missing / separator at the end).
3060015d27aea1b7e91deac0f3af4c0196a89dce7bandresp@webrtc.org//
3160015d27aea1b7e91deac0f3af4c0196a89dce7bandresp@webrtc.org// Note: This method crashes with an error message if an invalid config is
3260015d27aea1b7e91deac0f3af4c0196a89dce7bandresp@webrtc.org// passed to it. That can be used to find out if a binary is parsing the flags.
3360015d27aea1b7e91deac0f3af4c0196a89dce7bandresp@webrtc.orgvoid InitFieldTrialsFromString(const std::string& config);
3460015d27aea1b7e91deac0f3af4c0196a89dce7bandresp@webrtc.org
3519492f1c4c7411b7632fe34824226c1c579a6412pbos// This class is used to override field-trial configs within specific tests.
3619492f1c4c7411b7632fe34824226c1c579a6412pbos// After this class goes out of scope previous field trials will be restored.
3719492f1c4c7411b7632fe34824226c1c579a6412pbosclass ScopedFieldTrials {
3819492f1c4c7411b7632fe34824226c1c579a6412pbos public:
3919492f1c4c7411b7632fe34824226c1c579a6412pbos  explicit ScopedFieldTrials(const std::string& config);
4019492f1c4c7411b7632fe34824226c1c579a6412pbos  ~ScopedFieldTrials();
4119492f1c4c7411b7632fe34824226c1c579a6412pbos private:
4237ebcf0ce5ad1685bcf659ea75960beb96019647phoglund  std::string current_field_trials_;
4337ebcf0ce5ad1685bcf659ea75960beb96019647phoglund  const char* previous_field_trials_;
4419492f1c4c7411b7632fe34824226c1c579a6412pbos};
4519492f1c4c7411b7632fe34824226c1c579a6412pbos
4660015d27aea1b7e91deac0f3af4c0196a89dce7bandresp@webrtc.org}  // namespace test
4760015d27aea1b7e91deac0f3af4c0196a89dce7bandresp@webrtc.org}  // namespace webrtc
4860015d27aea1b7e91deac0f3af4c0196a89dce7bandresp@webrtc.org
4960015d27aea1b7e91deac0f3af4c0196a89dce7bandresp@webrtc.org#endif  // WEBRTC_TEST_FIELD_TRIAL_H_
50