Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: components/feedback/feedback_uploader_chrome_unittest.cc

Issue 942863003: Fix variation id transmission with feedback reports. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Exclude test on Android + fix leak in test + rebase. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/feedback/feedback_uploader_chrome.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "components/feedback/feedback_uploader_chrome.h"
6
7 #include "base/message_loop/message_loop.h"
8 #include "base/metrics/field_trial.h"
9 #include "components/variations/variations_associated_data.h"
10 #include "content/public/test/test_browser_context.h"
11 #include "net/url_request/test_url_fetcher_factory.h"
12 #include "net/url_request/url_fetcher_delegate.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace feedback {
16
17 class FeedbackUploaderChromeTest : public ::testing::Test {
18 protected:
19 FeedbackUploaderChromeTest() {}
20
21 ~FeedbackUploaderChromeTest() override {
22 // Clean up registered ids.
23 variations::testing::ClearAllVariationIDs();
24 }
25
26 // Registers a field trial with the specified name and group and an associated
27 // google web property variation id.
28 void CreateFieldTrialWithId(const std::string& trial_name,
29 const std::string& group_name,
30 int variation_id) {
31 variations::AssociateGoogleVariationID(
32 variations::GOOGLE_WEB_PROPERTIES, trial_name, group_name,
33 static_cast<variations::VariationID>(variation_id));
34 base::FieldTrialList::CreateFieldTrial(trial_name, group_name)->group();
35 }
36
37 private:
38 base::MessageLoopForUI message_loop_;
39
40 DISALLOW_COPY_AND_ASSIGN(FeedbackUploaderChromeTest);
41 };
42
43 TEST_F(FeedbackUploaderChromeTest, VariationHeaders) {
44 // Register a trial and variation id, so that there is data in variations
45 // headers.
46 base::FieldTrialList field_trial_list_(NULL);
47 CreateFieldTrialWithId("Test", "Group1", 123);
48
49 content::TestBrowserContext context;
50 FeedbackUploaderChrome uploader(&context);
51
52 net::TestURLFetcherFactory factory;
53 uploader.DispatchReport("test");
54
55 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0);
56 net::HttpRequestHeaders headers;
57 fetcher->GetExtraRequestHeaders(&headers);
58 std::string value;
59 EXPECT_TRUE(headers.GetHeader("X-Client-Data", &value));
60 EXPECT_FALSE(value.empty());
61 // The fetcher's delegate is responsible for freeing the fetcher (and itself).
62 fetcher->delegate()->OnURLFetchComplete(fetcher);
63 }
64
65 } // namespace feedback
OLDNEW
« no previous file with comments | « components/feedback/feedback_uploader_chrome.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698