| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "components/variations/net/variations_http_headers.h" | 5 #include "components/variations/net/variations_http_headers.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "url/gurl.h" | 11 #include "url/gurl.h" |
| 12 | 12 |
| 13 namespace variations { | 13 namespace variations { |
| 14 | 14 |
| 15 TEST(VariationsHttpHeadersTest, ShouldAppendHeaders) { | 15 TEST(VariationsHttpHeadersTest, ShouldAppendHeaders) { |
| 16 struct { | 16 struct { |
| 17 const char* url; | 17 const char* url; |
| 18 bool should_append_headers; | 18 bool should_append_headers; |
| 19 } cases[] = { | 19 } cases[] = { |
| 20 {"http://google.com", true}, | 20 {"http://google.com", false}, |
| 21 {"http://www.google.com", true}, | 21 {"https://google.com", true}, |
| 22 {"http://m.google.com", true}, | 22 {"http://www.google.com", false}, |
| 23 {"http://google.ca", true}, | 23 {"https://www.google.com", true}, |
| 24 {"http://m.google.com", false}, |
| 25 {"https://m.google.com", true}, |
| 26 {"http://google.ca", false}, |
| 24 {"https://google.ca", true}, | 27 {"https://google.ca", true}, |
| 25 {"http://google.co.uk", true}, | 28 {"http://google.co.uk", false}, |
| 26 {"http://google.co.uk:8080/", true}, | 29 {"https://google.co.uk", true}, |
| 27 {"http://www.google.co.uk:8080/", true}, | 30 {"http://google.co.uk:8080/", false}, |
| 28 {"http://google", false}, | 31 {"https://google.co.uk:8080/", true}, |
| 32 {"http://www.google.co.uk:8080/", false}, |
| 33 {"https://www.google.co.uk:8080/", true}, |
| 34 {"https://google", false}, |
| 29 | 35 |
| 30 {"http://youtube.com", true}, | 36 {"http://youtube.com", false}, |
| 31 {"http://www.youtube.com", true}, | 37 {"https://youtube.com", true}, |
| 32 {"http://www.youtube.ca", true}, | 38 {"http://www.youtube.com", false}, |
| 33 {"http://www.youtube.co.uk:8080/", true}, | |
| 34 {"https://www.youtube.com", true}, | 39 {"https://www.youtube.com", true}, |
| 35 {"http://youtube", false}, | 40 {"http://www.youtube.ca", false}, |
| 41 {"https://www.youtube.ca", true}, |
| 42 {"http://www.youtube.co.uk:8080/", false}, |
| 43 {"https://www.youtube.co.uk:8080/", true}, |
| 44 {"https://youtube", false}, |
| 36 | 45 |
| 37 {"http://www.yahoo.com", false}, | 46 {"https://www.yahoo.com", false}, |
| 38 | 47 |
| 39 {"http://ad.doubleclick.net", true}, | 48 {"http://ad.doubleclick.net", false}, |
| 49 {"https://ad.doubleclick.net", true}, |
| 40 {"https://a.b.c.doubleclick.net", true}, | 50 {"https://a.b.c.doubleclick.net", true}, |
| 41 {"https://a.b.c.doubleclick.net:8081", true}, | 51 {"https://a.b.c.doubleclick.net:8081", true}, |
| 42 {"http://www.doubleclick.com", true}, | 52 {"http://www.doubleclick.com", false}, |
| 43 {"http://www.doubleclick.org", false}, | 53 {"https://www.doubleclick.com", true}, |
| 54 {"https://www.doubleclick.org", false}, |
| 44 {"http://www.doubleclick.net.com", false}, | 55 {"http://www.doubleclick.net.com", false}, |
| 45 {"https://www.doubleclick.net.com", false}, | 56 {"https://www.doubleclick.net.com", false}, |
| 46 | 57 |
| 47 {"http://ad.googlesyndication.com", true}, | 58 {"http://ad.googlesyndication.com", false}, |
| 59 {"https://ad.googlesyndication.com", true}, |
| 48 {"https://a.b.c.googlesyndication.com", true}, | 60 {"https://a.b.c.googlesyndication.com", true}, |
| 49 {"https://a.b.c.googlesyndication.com:8080", true}, | 61 {"https://a.b.c.googlesyndication.com:8080", true}, |
| 50 {"http://www.doubleclick.edu", false}, | 62 {"http://www.doubleclick.edu", false}, |
| 51 {"http://www.googlesyndication.com.edu", false}, | 63 {"http://www.googlesyndication.com.edu", false}, |
| 52 {"https://www.googlesyndication.com.com", false}, | 64 {"https://www.googlesyndication.com.com", false}, |
| 53 | 65 |
| 54 {"http://www.googleadservices.com", true}, | 66 {"http://www.googleadservices.com", false}, |
| 55 {"http://www.googleadservices.com:8080", true}, | |
| 56 {"https://www.googleadservices.com", true}, | 67 {"https://www.googleadservices.com", true}, |
| 68 {"http://www.googleadservices.com:8080", false}, |
| 69 {"https://www.googleadservices.com:8080", true}, |
| 57 {"https://www.internal.googleadservices.com", true}, | 70 {"https://www.internal.googleadservices.com", true}, |
| 58 {"https://www2.googleadservices.com", true}, | 71 {"https://www2.googleadservices.com", true}, |
| 59 {"https://www.googleadservices.org", false}, | 72 {"https://www.googleadservices.org", false}, |
| 60 {"https://www.googleadservices.com.co.uk", false}, | 73 {"https://www.googleadservices.com.co.uk", false}, |
| 61 | 74 |
| 62 {"http://WWW.ANDROID.COM", true}, | 75 {"http://WWW.ANDROID.COM", false}, |
| 63 {"http://www.android.com", true}, | 76 {"https://WWW.ANDROID.COM", true}, |
| 64 {"http://www.doubleclick.com", true}, | 77 {"http://www.android.com", false}, |
| 65 {"http://www.doubleclick.net", true}, | 78 {"https://www.android.com", true}, |
| 66 {"http://www.ggpht.com", true}, | 79 {"http://www.doubleclick.com", false}, |
| 67 {"http://www.googleadservices.com", true}, | 80 {"https://www.doubleclick.com", true}, |
| 68 {"http://www.googleapis.com", true}, | 81 {"http://www.doubleclick.net", false}, |
| 69 {"http://www.googlesyndication.com", true}, | 82 {"https://www.doubleclick.net", true}, |
| 70 {"http://www.googleusercontent.com", true}, | 83 {"http://www.ggpht.com", false}, |
| 71 {"http://www.googlevideo.com", true}, | 84 {"https://www.ggpht.com", true}, |
| 72 {"http://ssl.gstatic.com", true}, | 85 {"http://www.googleadservices.com", false}, |
| 73 {"http://www.gstatic.com", true}, | 86 {"https://www.googleadservices.com", true}, |
| 74 {"http://www.ytimg.com", true}, | 87 {"http://www.googleapis.com", false}, |
| 75 {"http://wwwytimg.com", false}, | 88 {"https://www.googleapis.com", true}, |
| 76 {"http://ytimg.com", false}, | 89 {"http://www.googlesyndication.com", false}, |
| 90 {"https://www.googlesyndication.com", true}, |
| 91 {"http://www.googleusercontent.com", false}, |
| 92 {"https://www.googleusercontent.com", true}, |
| 93 {"http://www.googlevideo.com", false}, |
| 94 {"https://www.googlevideo.com", true}, |
| 95 {"http://ssl.gstatic.com", false}, |
| 96 {"https://ssl.gstatic.com", true}, |
| 97 {"http://www.gstatic.com", false}, |
| 98 {"https://www.gstatic.com", true}, |
| 99 {"http://www.ytimg.com", false}, |
| 100 {"https://www.ytimg.com", true}, |
| 101 {"https://wwwytimg.com", false}, |
| 102 {"https://ytimg.com", false}, |
| 77 | 103 |
| 78 {"http://www.android.org", false}, | 104 {"https://www.android.org", false}, |
| 79 {"http://www.doubleclick.org", false}, | 105 {"https://www.doubleclick.org", false}, |
| 80 {"http://www.doubleclick.net", true}, | 106 {"http://www.doubleclick.net", false}, |
| 81 {"http://www.ggpht.org", false}, | 107 {"https://www.doubleclick.net", true}, |
| 82 {"http://www.googleadservices.org", false}, | 108 {"https://www.ggpht.org", false}, |
| 83 {"http://www.googleapis.org", false}, | 109 {"https://www.googleadservices.org", false}, |
| 84 {"http://www.googlesyndication.org", false}, | 110 {"https://www.googleapis.org", false}, |
| 85 {"http://www.googleusercontent.org", false}, | 111 {"https://www.googlesyndication.org", false}, |
| 86 {"http://www.googlevideo.org", false}, | 112 {"https://www.googleusercontent.org", false}, |
| 87 {"http://ssl.gstatic.org", false}, | 113 {"https://www.googlevideo.org", false}, |
| 88 {"http://www.gstatic.org", false}, | 114 {"https://ssl.gstatic.org", false}, |
| 89 {"http://www.ytimg.org", false}, | 115 {"https://www.gstatic.org", false}, |
| 116 {"https://www.ytimg.org", false}, |
| 90 | 117 |
| 91 {"http://a.b.android.com", true}, | 118 {"http://a.b.android.com", false}, |
| 92 {"http://a.b.doubleclick.com", true}, | 119 {"https://a.b.android.com", true}, |
| 93 {"http://a.b.doubleclick.net", true}, | 120 {"http://a.b.doubleclick.com", false}, |
| 94 {"http://a.b.ggpht.com", true}, | 121 {"https://a.b.doubleclick.com", true}, |
| 95 {"http://a.b.googleadservices.com", true}, | 122 {"http://a.b.doubleclick.net", false}, |
| 96 {"http://a.b.googleapis.com", true}, | 123 {"https://a.b.doubleclick.net", true}, |
| 97 {"http://a.b.googlesyndication.com", true}, | 124 {"http://a.b.ggpht.com", false}, |
| 98 {"http://a.b.googleusercontent.com", true}, | 125 {"https://a.b.ggpht.com", true}, |
| 99 {"http://a.b.googlevideo.com", true}, | 126 {"http://a.b.googleadservices.com", false}, |
| 100 {"http://ssl.gstatic.com", true}, | 127 {"https://a.b.googleadservices.com", true}, |
| 101 {"http://a.b.gstatic.com", true}, | 128 {"http://a.b.googleapis.com", false}, |
| 102 {"http://a.b.ytimg.com", true}, | 129 {"https://a.b.googleapis.com", true}, |
| 103 {"http://googleweblight.com", true}, | 130 {"http://a.b.googlesyndication.com", false}, |
| 131 {"https://a.b.googlesyndication.com", true}, |
| 132 {"http://a.b.googleusercontent.com", false}, |
| 133 {"https://a.b.googleusercontent.com", true}, |
| 134 {"http://a.b.googlevideo.com", false}, |
| 135 {"https://a.b.googlevideo.com", true}, |
| 136 {"http://ssl.gstatic.com", false}, |
| 137 {"https://ssl.gstatic.com", true}, |
| 138 {"http://a.b.gstatic.com", false}, |
| 139 {"https://a.b.gstatic.com", true}, |
| 140 {"http://a.b.ytimg.com", false}, |
| 141 {"https://a.b.ytimg.com", true}, |
| 142 {"http://googleweblight.com", false}, |
| 104 {"https://googleweblight.com", true}, | 143 {"https://googleweblight.com", true}, |
| 105 {"http://wwwgoogleweblight.com", false}, | 144 {"http://wwwgoogleweblight.com", false}, |
| 106 {"http://www.googleweblight.com", false}, | 145 {"https://www.googleweblight.com", false}, |
| 107 {"http://a.b.googleweblight.com", false}, | 146 {"https://a.b.googleweblight.com", false}, |
| 108 }; | 147 }; |
| 109 | 148 |
| 110 for (size_t i = 0; i < arraysize(cases); ++i) { | 149 for (size_t i = 0; i < arraysize(cases); ++i) { |
| 111 const GURL url(cases[i].url); | 150 const GURL url(cases[i].url); |
| 112 EXPECT_EQ(cases[i].should_append_headers, | 151 EXPECT_EQ(cases[i].should_append_headers, |
| 113 internal::ShouldAppendVariationHeaders(url)) | 152 internal::ShouldAppendVariationHeaders(url)) |
| 114 << url; | 153 << url; |
| 115 } | 154 } |
| 116 } | 155 } |
| 117 | 156 |
| 118 } // namespace variations | 157 } // namespace variations |
| OLD | NEW |