[Eraser strings] Remove/replace some supervised user strings
[chromium-blink-merge.git] / components / feedback / feedback_uploader_chrome_unittest.cc
blob810c040d906ad68334767986ee622f3e845d3a7c
1 // Copyright 2015 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.
5 #include "components/feedback/feedback_uploader_chrome.h"
7 #include "base/message_loop/message_loop.h"
8 #include "base/metrics/field_trial.h"
9 #include "components/variations/net/variations_http_header_provider.h"
10 #include "components/variations/variations_associated_data.h"
11 #include "content/public/test/test_browser_context.h"
12 #include "net/url_request/test_url_fetcher_factory.h"
13 #include "net/url_request/url_fetcher_delegate.h"
14 #include "testing/gtest/include/gtest/gtest.h"
16 namespace feedback {
18 class FeedbackUploaderChromeTest : public ::testing::Test {
19 protected:
20 FeedbackUploaderChromeTest() {}
22 ~FeedbackUploaderChromeTest() override {
23 // Clean up registered ids.
24 variations::testing::ClearAllVariationIDs();
27 // Registers a field trial with the specified name and group and an associated
28 // google web property variation id.
29 void CreateFieldTrialWithId(const std::string& trial_name,
30 const std::string& group_name,
31 int variation_id) {
32 variations::AssociateGoogleVariationID(
33 variations::GOOGLE_WEB_PROPERTIES, trial_name, group_name,
34 static_cast<variations::VariationID>(variation_id));
35 base::FieldTrialList::CreateFieldTrial(trial_name, group_name)->group();
38 private:
39 base::MessageLoopForUI message_loop_;
41 DISALLOW_COPY_AND_ASSIGN(FeedbackUploaderChromeTest);
44 TEST_F(FeedbackUploaderChromeTest, VariationHeaders) {
45 // Register a trial and variation id, so that there is data in variations
46 // headers. Also, the variations header provider may have been registered to
47 // observe some other field trial list, so reset it.
48 variations::VariationsHttpHeaderProvider::GetInstance()->ResetForTesting();
49 base::FieldTrialList field_trial_list_(NULL);
50 CreateFieldTrialWithId("Test", "Group1", 123);
52 content::TestBrowserContext context;
53 FeedbackUploaderChrome uploader(&context);
55 net::TestURLFetcherFactory factory;
56 uploader.DispatchReport("test");
58 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0);
59 net::HttpRequestHeaders headers;
60 fetcher->GetExtraRequestHeaders(&headers);
61 std::string value;
62 EXPECT_TRUE(headers.GetHeader("X-Client-Data", &value));
63 EXPECT_FALSE(value.empty());
64 // The fetcher's delegate is responsible for freeing the fetcher (and itself).
65 fetcher->delegate()->OnURLFetchComplete(fetcher);
67 variations::VariationsHttpHeaderProvider::GetInstance()->ResetForTesting();
70 } // namespace feedback