| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <atlbase.h> | 5 #include <atlbase.h> |
| 6 #include <atlcom.h> | 6 #include <atlcom.h> |
| 7 | 7 |
| 8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 | 60 |
| 61 TEST_F(HttpNegotiateTest, BeginningTransaction) { | 61 TEST_F(HttpNegotiateTest, BeginningTransaction) { |
| 62 static const int kBeginningTransactionIndex = 3; | 62 static const int kBeginningTransactionIndex = 3; |
| 63 CComObjectStackEx<TestHttpNegotiate> test_http; | 63 CComObjectStackEx<TestHttpNegotiate> test_http; |
| 64 IHttpNegotiate_BeginningTransaction_Fn original = | 64 IHttpNegotiate_BeginningTransaction_Fn original = |
| 65 reinterpret_cast<IHttpNegotiate_BeginningTransaction_Fn>( | 65 reinterpret_cast<IHttpNegotiate_BeginningTransaction_Fn>( |
| 66 (*reinterpret_cast<void***>( | 66 (*reinterpret_cast<void***>( |
| 67 static_cast<IHttpNegotiate*>( | 67 static_cast<IHttpNegotiate*>( |
| 68 &test_http)))[kBeginningTransactionIndex]); | 68 &test_http)))[kBeginningTransactionIndex]); |
| 69 | 69 |
| 70 string16 cf_ua( | 70 base::string16 cf_ua( |
| 71 ASCIIToWide(http_utils::GetDefaultUserAgentHeaderWithCFTag())); | 71 ASCIIToWide(http_utils::GetDefaultUserAgentHeaderWithCFTag())); |
| 72 string16 cf_tag( | 72 base::string16 cf_tag(ASCIIToWide(http_utils::GetChromeFrameUserAgent())); |
| 73 ASCIIToWide(http_utils::GetChromeFrameUserAgent())); | |
| 74 | 73 |
| 75 EXPECT_NE(string16::npos, cf_ua.find(L"chromeframe/")); | 74 EXPECT_NE(base::string16::npos, cf_ua.find(L"chromeframe/")); |
| 76 | 75 |
| 77 struct TestCase { | 76 struct TestCase { |
| 78 const string16 original_headers_; | 77 const base::string16 original_headers_; |
| 79 const string16 delegate_additional_; | 78 const base::string16 delegate_additional_; |
| 80 const string16 expected_additional_; | 79 const base::string16 expected_additional_; |
| 81 HRESULT delegate_return_value_; | 80 HRESULT delegate_return_value_; |
| 82 } test_cases[] = { | 81 } test_cases[] = { |
| 83 { L"Accept: */*\r\n", | 82 { L"Accept: */*\r\n", |
| 84 L"", | 83 L"", |
| 85 cf_ua + L"\r\n", | 84 cf_ua + L"\r\n", |
| 86 S_OK }, | 85 S_OK }, |
| 87 { L"Accept: */*\r\n", | 86 { L"Accept: */*\r\n", |
| 88 L"", | 87 L"", |
| 89 L"", | 88 L"", |
| 90 E_OUTOFMEMORY }, | 89 E_OUTOFMEMORY }, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 111 wchar_t* additional = NULL; | 110 wchar_t* additional = NULL; |
| 112 test_http.beginning_transaction_ret_ = test.delegate_return_value_; | 111 test_http.beginning_transaction_ret_ = test.delegate_return_value_; |
| 113 test_http.additional_headers_ = test.delegate_additional_.c_str(); | 112 test_http.additional_headers_ = test.delegate_additional_.c_str(); |
| 114 HttpNegotiatePatch::BeginningTransaction(original, &test_http, | 113 HttpNegotiatePatch::BeginningTransaction(original, &test_http, |
| 115 L"http://www.google.com", test.original_headers_.c_str(), 0, | 114 L"http://www.google.com", test.original_headers_.c_str(), 0, |
| 116 &additional); | 115 &additional); |
| 117 EXPECT_TRUE(additional != NULL); | 116 EXPECT_TRUE(additional != NULL); |
| 118 | 117 |
| 119 if (additional) { | 118 if (additional) { |
| 120 // Check against the expected additional headers. | 119 // Check against the expected additional headers. |
| 121 EXPECT_EQ(test.expected_additional_, string16(additional)); | 120 EXPECT_EQ(test.expected_additional_, base::string16(additional)); |
| 122 ::CoTaskMemFree(additional); | 121 ::CoTaskMemFree(additional); |
| 123 } | 122 } |
| 124 } | 123 } |
| 125 } | 124 } |
| 126 | 125 |
| 127 TEST_F(HttpNegotiateTest, BeginningTransactionUARemoval) { | 126 TEST_F(HttpNegotiateTest, BeginningTransactionUARemoval) { |
| 128 static const int kBeginningTransactionIndex = 3; | 127 static const int kBeginningTransactionIndex = 3; |
| 129 CComObjectStackEx<TestHttpNegotiate> test_http; | 128 CComObjectStackEx<TestHttpNegotiate> test_http; |
| 130 IHttpNegotiate_BeginningTransaction_Fn original = | 129 IHttpNegotiate_BeginningTransaction_Fn original = |
| 131 reinterpret_cast<IHttpNegotiate_BeginningTransaction_Fn>( | 130 reinterpret_cast<IHttpNegotiate_BeginningTransaction_Fn>( |
| 132 (*reinterpret_cast<void***>( | 131 (*reinterpret_cast<void***>( |
| 133 static_cast<IHttpNegotiate*>( | 132 static_cast<IHttpNegotiate*>( |
| 134 &test_http)))[kBeginningTransactionIndex]); | 133 &test_http)))[kBeginningTransactionIndex]); |
| 135 | 134 |
| 136 string16 nocf_ua( | 135 base::string16 nocf_ua( |
| 137 ASCIIToWide(http_utils::RemoveChromeFrameFromUserAgentValue( | 136 ASCIIToWide(http_utils::RemoveChromeFrameFromUserAgentValue( |
| 138 http_utils::GetDefaultUserAgentHeaderWithCFTag()))); | 137 http_utils::GetDefaultUserAgentHeaderWithCFTag()))); |
| 139 string16 cf_ua( | 138 base::string16 cf_ua(ASCIIToWide( |
| 140 ASCIIToWide(http_utils::AddChromeFrameToUserAgentValue( | 139 http_utils::AddChromeFrameToUserAgentValue(WideToASCII(nocf_ua)))); |
| 141 WideToASCII(nocf_ua)))); | |
| 142 | 140 |
| 143 EXPECT_EQ(string16::npos, nocf_ua.find(L"chromeframe/")); | 141 EXPECT_EQ(base::string16::npos, nocf_ua.find(L"chromeframe/")); |
| 144 EXPECT_NE(string16::npos, cf_ua.find(L"chromeframe/")); | 142 EXPECT_NE(base::string16::npos, cf_ua.find(L"chromeframe/")); |
| 145 | 143 |
| 146 string16 ua_url(L"www.withua.com"); | 144 base::string16 ua_url(L"www.withua.com"); |
| 147 string16 no_ua_url(L"www.noua.com"); | 145 base::string16 no_ua_url(L"www.noua.com"); |
| 148 | 146 |
| 149 RegistryListPreferencesHolder& ua_holder = | 147 RegistryListPreferencesHolder& ua_holder = |
| 150 GetUserAgentPreferencesHolderForTesting(); | 148 GetUserAgentPreferencesHolderForTesting(); |
| 151 ua_holder.AddStringForTesting(no_ua_url); | 149 ua_holder.AddStringForTesting(no_ua_url); |
| 152 | 150 |
| 153 struct TestCase { | 151 struct TestCase { |
| 154 const string16 url_; | 152 const base::string16 url_; |
| 155 const string16 original_headers_; | 153 const base::string16 original_headers_; |
| 156 const string16 delegate_additional_; | 154 const base::string16 delegate_additional_; |
| 157 const string16 expected_additional_; | 155 const base::string16 expected_additional_; |
| 158 } test_cases[] = { | 156 } test_cases[] = { |
| 159 { ua_url, | 157 { ua_url, |
| 160 L"", | 158 L"", |
| 161 L"Accept: */*\r\n" + cf_ua + L"\r\n", | 159 L"Accept: */*\r\n" + cf_ua + L"\r\n", |
| 162 L"Accept: */*\r\n" + cf_ua + L"\r\n" }, | 160 L"Accept: */*\r\n" + cf_ua + L"\r\n" }, |
| 163 { ua_url, | 161 { ua_url, |
| 164 L"", | 162 L"", |
| 165 L"Accept: */*\r\n" + nocf_ua + L"\r\n", | 163 L"Accept: */*\r\n" + nocf_ua + L"\r\n", |
| 166 L"Accept: */*\r\n" + cf_ua + L"\r\n" }, | 164 L"Accept: */*\r\n" + cf_ua + L"\r\n" }, |
| 167 { no_ua_url, | 165 { no_ua_url, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 179 wchar_t* additional = NULL; | 177 wchar_t* additional = NULL; |
| 180 test_http.beginning_transaction_ret_ = S_OK; | 178 test_http.beginning_transaction_ret_ = S_OK; |
| 181 test_http.additional_headers_ = test.delegate_additional_.c_str(); | 179 test_http.additional_headers_ = test.delegate_additional_.c_str(); |
| 182 HttpNegotiatePatch::BeginningTransaction(original, &test_http, | 180 HttpNegotiatePatch::BeginningTransaction(original, &test_http, |
| 183 test.url_.c_str(), test.original_headers_.c_str(), 0, | 181 test.url_.c_str(), test.original_headers_.c_str(), 0, |
| 184 &additional); | 182 &additional); |
| 185 EXPECT_TRUE(additional != NULL); | 183 EXPECT_TRUE(additional != NULL); |
| 186 | 184 |
| 187 if (additional) { | 185 if (additional) { |
| 188 // Check against the expected additional headers. | 186 // Check against the expected additional headers. |
| 189 EXPECT_EQ(test.expected_additional_, string16(additional)) | 187 EXPECT_EQ(test.expected_additional_, base::string16(additional)) |
| 190 << "Iteration: " << i; | 188 << "Iteration: " << i; |
| 191 ::CoTaskMemFree(additional); | 189 ::CoTaskMemFree(additional); |
| 192 } | 190 } |
| 193 } | 191 } |
| 194 } | 192 } |
| 195 | 193 |
| 196 | 194 |
| 197 class TestInternetProtocolSink | 195 class TestInternetProtocolSink |
| 198 : public CComObjectRootEx<CComMultiThreadModel>, | 196 : public CComObjectRootEx<CComMultiThreadModel>, |
| 199 public IInternetProtocolSink { | 197 public IInternetProtocolSink { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 | 238 |
| 241 STDMETHOD(ReportResult)(HRESULT hr, DWORD err, LPCWSTR result) { | 239 STDMETHOD(ReportResult)(HRESULT hr, DWORD err, LPCWSTR result) { |
| 242 NOTREACHED(); | 240 NOTREACHED(); |
| 243 return S_OK; | 241 return S_OK; |
| 244 } | 242 } |
| 245 | 243 |
| 246 ULONG last_status() const { | 244 ULONG last_status() const { |
| 247 return status_; | 245 return status_; |
| 248 } | 246 } |
| 249 | 247 |
| 250 const string16& last_status_text() const { | 248 const base::string16& last_status_text() const { |
| 251 return status_text_; | 249 return status_text_; |
| 252 } | 250 } |
| 253 | 251 |
| 254 protected: | 252 protected: |
| 255 ULONG status_; | 253 ULONG status_; |
| 256 string16 status_text_; | 254 base::string16 status_text_; |
| 257 base::win::ScopedComPtr<IWebBrowser2> browser_; | 255 base::win::ScopedComPtr<IWebBrowser2> browser_; |
| 258 }; | 256 }; |
| 259 | 257 |
| 260 using testing::AllOf; | 258 using testing::AllOf; |
| 261 using testing::ContainsRegex; | 259 using testing::ContainsRegex; |
| 262 using testing::HasSubstr; | 260 using testing::HasSubstr; |
| 263 | 261 |
| 264 TEST(AppendUserAgent, Append) { | 262 TEST(AppendUserAgent, Append) { |
| 265 EXPECT_THAT(AppendCFUserAgentString(NULL, NULL), | 263 EXPECT_THAT(AppendCFUserAgentString(NULL, NULL), |
| 266 testing::ContainsRegex("User-Agent:.+chromeframe.+\r\n")); | 264 testing::ContainsRegex("User-Agent:.+chromeframe.+\r\n")); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 281 | 279 |
| 282 // Check additional headers are preserved. | 280 // Check additional headers are preserved. |
| 283 EXPECT_THAT(AppendCFUserAgentString(NULL, | 281 EXPECT_THAT(AppendCFUserAgentString(NULL, |
| 284 L"Authorization: A Zoo That I Ruin\r\n" | 282 L"Authorization: A Zoo That I Ruin\r\n" |
| 285 L"User-Agent: Get a Nurse;\r\n" | 283 L"User-Agent: Get a Nurse;\r\n" |
| 286 L"Accept-Language: Cleanup a Cat Egg\r\n"), | 284 L"Accept-Language: Cleanup a Cat Egg\r\n"), |
| 287 AllOf(ContainsRegex("User-Agent: Get a Nurse; chromeframe.+\r\n"), | 285 AllOf(ContainsRegex("User-Agent: Get a Nurse; chromeframe.+\r\n"), |
| 288 HasSubstr("Authorization: A Zoo That I Ruin\r\n"), | 286 HasSubstr("Authorization: A Zoo That I Ruin\r\n"), |
| 289 HasSubstr("Accept-Language: Cleanup a Cat Egg\r\n"))); | 287 HasSubstr("Accept-Language: Cleanup a Cat Egg\r\n"))); |
| 290 } | 288 } |
| OLD | NEW |