Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/metrics/variations/variations_http_header_provider.h" | 5 #include "chrome/browser/metrics/variations/variations_http_header_provider.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 VariationsHttpHeaderProviderTest() {} | 59 VariationsHttpHeaderProviderTest() {} |
| 60 | 60 |
| 61 virtual ~VariationsHttpHeaderProviderTest() {} | 61 virtual ~VariationsHttpHeaderProviderTest() {} |
| 62 | 62 |
| 63 virtual void TearDown() OVERRIDE { | 63 virtual void TearDown() OVERRIDE { |
| 64 testing::ClearAllVariationIDs(); | 64 testing::ClearAllVariationIDs(); |
| 65 } | 65 } |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 TEST_F(VariationsHttpHeaderProviderTest, ShouldAppendHeaders) { | 68 TEST_F(VariationsHttpHeaderProviderTest, ShouldAppendHeaders) { |
| 69 VariationsHttpHeaderProvider provider; | |
| 69 struct { | 70 struct { |
| 70 const char* url; | 71 const char* url; |
| 71 bool should_append_headers; | 72 bool should_append_headers; |
| 72 } cases[] = { | 73 } cases[] = { |
| 73 { "http://google.com", true }, | 74 { "http://google.com", true }, |
| 74 { "http://www.google.com", true }, | 75 { "http://www.google.com", true }, |
| 75 { "http://m.google.com", true }, | 76 { "http://m.google.com", true }, |
| 76 { "http://google.ca", true }, | 77 { "http://google.ca", true }, |
| 77 { "https://google.ca", true }, | 78 { "https://google.ca", true }, |
| 78 { "http://google.co.uk", true }, | 79 { "http://google.co.uk", true }, |
| 79 { "http://google.co.uk:8080/", true }, | 80 { "http://google.co.uk:8080/", true }, |
| 80 { "http://www.google.co.uk:8080/", true }, | 81 { "http://www.google.co.uk:8080/", true }, |
| 81 { "http://google", false }, | 82 { "http://google", false }, |
| 82 | 83 |
| 83 { "http://youtube.com", true }, | 84 { "http://youtube.com", true }, |
| 84 { "http://www.youtube.com", true }, | 85 { "http://www.youtube.com", true }, |
| 85 { "http://www.youtube.ca", true }, | 86 { "http://www.youtube.ca", true }, |
| 86 { "http://www.youtube.co.uk:8080/", true }, | 87 { "http://www.youtube.co.uk:8080/", true }, |
| 87 { "https://www.youtube.com", true }, | 88 { "https://www.youtube.com", true }, |
| 88 { "http://youtube", false }, | 89 { "http://youtube", false }, |
| 89 | 90 |
| 90 { "http://www.yahoo.com", false }, | 91 { "http://www.yahoo.com", false }, |
| 91 | 92 |
| 92 { "http://ad.doubleclick.net", true }, | 93 { "http://ad.doubleclick.net", true }, |
| 93 { "https://a.b.c.doubleclick.net", true }, | 94 { "https://a.b.c.doubleclick.net", true }, |
| 94 { "https://a.b.c.doubleclick.net:8081", true }, | 95 { "https://a.b.c.doubleclick.net:8081", true }, |
| 95 { "http://www.doubleclick.com", false }, | 96 { "http://www.doubleclick.com", true }, |
| 97 { "http://www.doubleclick.org", false }, | |
| 96 { "http://www.doubleclick.net.com", false }, | 98 { "http://www.doubleclick.net.com", false }, |
| 97 { "https://www.doubleclick.net.com", false }, | 99 { "https://www.doubleclick.net.com", false }, |
| 98 | 100 |
| 99 { "http://ad.googlesyndication.com", true }, | 101 { "http://ad.googlesyndication.com", true }, |
| 100 { "https://a.b.c.googlesyndication.com", true }, | 102 { "https://a.b.c.googlesyndication.com", true }, |
| 101 { "https://a.b.c.googlesyndication.com:8080", true }, | 103 { "https://a.b.c.googlesyndication.com:8080", true }, |
| 102 { "http://www.doubleclick.edu", false }, | 104 { "http://www.doubleclick.edu", false }, |
| 103 { "http://www.googlesyndication.com.edu", false }, | 105 { "http://www.googlesyndication.com.edu", false }, |
| 104 { "https://www.googlesyndication.com.com", false }, | 106 { "https://www.googlesyndication.com.com", false }, |
| 105 | 107 |
| 106 { "http://www.googleadservices.com", true }, | 108 { "http://www.googleadservices.com", true }, |
| 107 { "http://www.googleadservices.com:8080", true }, | 109 { "http://www.googleadservices.com:8080", true }, |
| 108 { "https://www.googleadservices.com", true }, | 110 { "https://www.googleadservices.com", true }, |
| 109 { "https://www.internal.googleadservices.com", false }, | 111 { "https://www.internal.googleadservices.com", true }, |
| 110 { "https://www2.googleadservices.com", false }, | 112 { "https://www2.googleadservices.com", true }, |
| 111 { "https://www.googleadservices.org", false }, | 113 { "https://www.googleadservices.org", false }, |
| 112 { "https://www.googleadservices.com.co.uk", false }, | 114 { "https://www.googleadservices.com.co.uk", false }, |
| 115 | |
| 116 { "http://WWW.ANDROID.COM", true }, | |
|
avd
2014/05/29 23:38:20
thanks for adding a test case with mixed case.
Ryan Hamilton
2014/05/29 23:48:38
My pleasure!
| |
| 117 { "http://www.android.com", true }, | |
| 118 { "http://www.doubleclick.com", true }, | |
| 119 { "http://www.doubleclick.net", true }, | |
| 120 { "http://www.ggpht.com", true }, | |
| 121 { "http://www.googleadservices.com", true }, | |
| 122 { "http://www.googleapis.com", true }, | |
| 123 { "http://www.googlesyndication.com", true }, | |
| 124 { "http://www.googleusercontent.com", true }, | |
| 125 { "http://www.googlevideo.com", true }, | |
| 126 { "http://ssl.gstatic.com", true }, | |
| 127 { "http://www.gstatic.com", true }, | |
| 128 { "http://www.ytimg.com", true }, | |
|
avd
2014/05/29 23:38:20
+ { "http://wwwytimg.com", false },
+ { "htt
Ryan Hamilton
2014/05/29 23:48:38
Done.
| |
| 129 | |
| 130 { "http://www.android.org", false }, | |
| 131 { "http://www.doubleclick.org", false }, | |
| 132 { "http://www.doubleclick.net", true }, | |
| 133 { "http://www.ggpht.org", false }, | |
| 134 { "http://www.googleadservices.org", false }, | |
| 135 { "http://www.googleapis.org", false }, | |
| 136 { "http://www.googlesyndication.org", false }, | |
| 137 { "http://www.googleusercontent.org", false }, | |
| 138 { "http://www.googlevideo.org", false }, | |
| 139 { "http://ssl.gstatic.org", false }, | |
| 140 { "http://www.gstatic.org", false }, | |
| 141 { "http://www.ytimg.org", false }, | |
| 142 | |
| 143 { "http://a.b.android.com", true }, | |
| 144 { "http://a.b.doubleclick.com", true }, | |
| 145 { "http://a.b.doubleclick.net", true }, | |
| 146 { "http://a.b.ggpht.com", true }, | |
| 147 { "http://a.b.googleadservices.com", true }, | |
| 148 { "http://a.b.googleapis.com", true }, | |
| 149 { "http://a.b.googlesyndication.com", true }, | |
| 150 { "http://a.b.googleusercontent.com", true }, | |
| 151 { "http://a.b.googlevideo.com", true }, | |
| 152 { "http://ssl.gstatic.com", true }, | |
| 153 { "http://a.b.gstatic.com", true }, | |
| 154 { "http://a.b.ytimg.com", true }, | |
| 155 | |
| 113 }; | 156 }; |
| 114 | 157 |
| 115 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | 158 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { |
| 116 const GURL url(cases[i].url); | 159 const GURL url(cases[i].url); |
| 117 EXPECT_EQ(cases[i].should_append_headers, | 160 EXPECT_EQ(cases[i].should_append_headers, |
| 118 VariationsHttpHeaderProvider::ShouldAppendHeaders(url)) << url; | 161 provider.ShouldAppendHeaders(url)) << url; |
| 119 } | 162 } |
| 120 } | 163 } |
| 121 | 164 |
| 122 TEST_F(VariationsHttpHeaderProviderTest, SetDefaultVariationIds_Valid) { | 165 TEST_F(VariationsHttpHeaderProviderTest, SetDefaultVariationIds_Valid) { |
| 123 base::MessageLoop loop; | 166 base::MessageLoop loop; |
| 124 VariationsHttpHeaderProvider provider; | 167 VariationsHttpHeaderProvider provider; |
| 125 GURL url("http://www.google.com"); | 168 GURL url("http://www.google.com"); |
| 126 net::HttpRequestHeaders headers; | 169 net::HttpRequestHeaders headers; |
| 127 std::string variations; | 170 std::string variations; |
| 128 | 171 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 headers.GetHeader("X-Client-Data", &variations); | 232 headers.GetHeader("X-Client-Data", &variations); |
| 190 | 233 |
| 191 std::set<VariationID> variation_ids; | 234 std::set<VariationID> variation_ids; |
| 192 std::set<VariationID> trigger_ids; | 235 std::set<VariationID> trigger_ids; |
| 193 ASSERT_TRUE(ExtractVariationIds(variations, &variation_ids, &trigger_ids)); | 236 ASSERT_TRUE(ExtractVariationIds(variations, &variation_ids, &trigger_ids)); |
| 194 EXPECT_TRUE(variation_ids.find(123) != variation_ids.end()); | 237 EXPECT_TRUE(variation_ids.find(123) != variation_ids.end()); |
| 195 EXPECT_TRUE(trigger_ids.find(456) != trigger_ids.end()); | 238 EXPECT_TRUE(trigger_ids.find(456) != trigger_ids.end()); |
| 196 } | 239 } |
| 197 | 240 |
| 198 } // namespace chrome_variations | 241 } // namespace chrome_variations |
| OLD | NEW |