OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 <windows.h> | 5 #include <windows.h> |
6 #include <atlsecurity.h> | 6 #include <atlsecurity.h> |
7 #include <shellapi.h> | 7 #include <shellapi.h> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
13 #include "base/process_util.h" | 13 #include "base/process_util.h" |
14 #include "base/ref_counted.h" | 14 #include "base/ref_counted.h" |
15 #include "base/scoped_handle.h" | 15 #include "base/scoped_handle.h" |
16 #include "base/task.h" | 16 #include "base/task.h" |
17 #include "base/win_util.h" | 17 #include "base/win_util.h" |
18 #include "net/base/net_util.h" | 18 #include "net/base/net_util.h" |
19 | 19 |
20 #include "chrome_frame/test/chrome_frame_unittests.h" | 20 #include "chrome_frame/test/chrome_frame_unittests.h" |
21 #include "chrome_frame/chrome_frame_automation.h" | 21 #include "chrome_frame/chrome_frame_automation.h" |
22 #include "chrome_frame/chrome_frame_delegate.h" | 22 #include "chrome_frame/chrome_frame_delegate.h" |
23 #include "chrome_frame/html_utils.h" | 23 #include "chrome_frame/html_utils.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
25 | 25 |
| 26 const char kChromeFrameUserAgent[] = "chromeframe"; |
| 27 |
26 class HtmlUtilUnittest : public testing::Test { | 28 class HtmlUtilUnittest : public testing::Test { |
27 protected: | 29 protected: |
28 // Constructor | 30 // Constructor |
29 HtmlUtilUnittest() {} | 31 HtmlUtilUnittest() {} |
30 | 32 |
31 // Returns the test path given a test case. | 33 // Returns the test path given a test case. |
32 virtual bool GetTestPath(const std::wstring& test_case, std::wstring* path) { | 34 virtual bool GetTestPath(const std::wstring& test_case, std::wstring* path) { |
33 if (!path) { | 35 if (!path) { |
34 NOTREACHED(); | 36 NOTREACHED(); |
35 return false; | 37 return false; |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 std::wstring test_data( | 208 std::wstring test_data( |
207 L"<!-- comment> <META http-equiv=X-UA-Compatible content='chrome=1'/>-->"); | 209 L"<!-- comment> <META http-equiv=X-UA-Compatible content='chrome=1'/>-->"); |
208 | 210 |
209 HTMLScanner scanner(test_data.c_str()); | 211 HTMLScanner scanner(test_data.c_str()); |
210 | 212 |
211 // Grab the meta tag from the document and ensure that we get exactly one. | 213 // Grab the meta tag from the document and ensure that we get exactly one. |
212 HTMLScanner::StringRangeList tag_list; | 214 HTMLScanner::StringRangeList tag_list; |
213 scanner.GetTagsByName(L"meta", &tag_list, L"body"); | 215 scanner.GetTagsByName(L"meta", &tag_list, L"body"); |
214 ASSERT_TRUE(tag_list.empty()); | 216 ASSERT_TRUE(tag_list.empty()); |
215 } | 217 } |
| 218 |
| 219 TEST_F(HtmlUtilUnittest, AddChromeFrameToUserAgentValue) { |
| 220 struct TestCase { |
| 221 std::string input_; |
| 222 std::string expected_; |
| 223 } test_cases[] = { |
| 224 { |
| 225 "", "" |
| 226 }, { |
| 227 "Mozilla/4.7 [en] (WinNT; U)", |
| 228 "Mozilla/4.7 [en] (WinNT; U) chromeframe/0.0" |
| 229 }, { |
| 230 "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT)", |
| 231 "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT) chromeframe/0.0" |
| 232 }, { |
| 233 "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; T312461; " |
| 234 ".NET CLR 1.1.4322)", |
| 235 "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; T312461; " |
| 236 ".NET CLR 1.1.4322) chromeframe/0.0" |
| 237 }, { |
| 238 "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT 4.0) Opera 5.11 [en]", |
| 239 "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT 4.0) " |
| 240 "Opera 5.11 [en] chromeframe/0.0" |
| 241 }, { |
| 242 "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2) " |
| 243 "Gecko/20030208 Netscape/7.02", |
| 244 "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2) " |
| 245 "Gecko/20030208 Netscape/7.02 chromeframe/0.0" |
| 246 }, { |
| 247 "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040612 " |
| 248 "Firefox/0.8", |
| 249 "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040612 " |
| 250 "Firefox/0.8 chromeframe/0.0" |
| 251 }, { |
| 252 "Mozilla/5.0 (compatible; Konqueror/3.2; Linux) (KHTML, like Gecko)", |
| 253 "Mozilla/5.0 (compatible; Konqueror/3.2; Linux) " |
| 254 "(KHTML, like Gecko) chromeframe/0.0" |
| 255 }, { |
| 256 "Lynx/2.8.4rel.1 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.6h", |
| 257 "Lynx/2.8.4rel.1 libwww-FM/2.14 SSL-MM/1.4.1 " |
| 258 "OpenSSL/0.9.6h chromeframe/0.0", |
| 259 }, { |
| 260 "Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.7.10) " |
| 261 "Gecko/20050716 Firefox/1.0.6", |
| 262 "Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.7.10) " |
| 263 "Gecko/20050716 Firefox/1.0.6 chromeframe/0.0" |
| 264 }, { |
| 265 "Invalid/1.1 ((((((", |
| 266 "Invalid/1.1 (((((( chromeframe/0.0", |
| 267 }, { |
| 268 "Invalid/1.1 ()))))", |
| 269 "Invalid/1.1 ())))) chromeframe/0.0", |
| 270 }, { |
| 271 "Strange/1.1 ()", |
| 272 "Strange/1.1 () chromeframe/0.0", |
| 273 } |
| 274 }; |
| 275 |
| 276 for (int i = 0; i < arraysize(test_cases); ++i) { |
| 277 std::string new_ua( |
| 278 http_utils::AddChromeFrameToUserAgentValue(test_cases[i].input_)); |
| 279 EXPECT_EQ(test_cases[i].expected_, new_ua); |
| 280 } |
| 281 |
| 282 // Now do the same test again, but test that we don't add the chromeframe |
| 283 // tag if we've already added it. |
| 284 for (int i = 0; i < arraysize(test_cases); ++i) { |
| 285 std::string ua(test_cases[i].expected_); |
| 286 std::string new_ua(http_utils::AddChromeFrameToUserAgentValue(ua)); |
| 287 EXPECT_EQ(test_cases[i].expected_, new_ua); |
| 288 } |
| 289 } |
| 290 |
| 291 TEST_F(HtmlUtilUnittest, GetDefaultUserAgentHeaderWithCFTag) { |
| 292 std::string ua(http_utils::GetDefaultUserAgentHeaderWithCFTag()); |
| 293 EXPECT_NE(0, ua.length()); |
| 294 EXPECT_NE(std::string::npos, ua.find("Mozilla")); |
| 295 EXPECT_NE(std::string::npos, ua.find(kChromeFrameUserAgent)); |
| 296 } |
| 297 |
| 298 TEST_F(HtmlUtilUnittest, GetDefaultUserAgent) { |
| 299 std::string ua(http_utils::GetDefaultUserAgent()); |
| 300 EXPECT_NE(0, ua.length()); |
| 301 EXPECT_NE(std::string::npos, ua.find("Mozilla")); |
| 302 } |
| 303 |
| 304 TEST_F(HtmlUtilUnittest, GetChromeFrameUserAgent) { |
| 305 const char* call1 = http_utils::GetChromeFrameUserAgent(); |
| 306 const char* call2 = http_utils::GetChromeFrameUserAgent(); |
| 307 // Expect static buffer since caller does no cleanup. |
| 308 EXPECT_EQ(call1, call2); |
| 309 std::string ua(call1); |
| 310 EXPECT_EQ("chromeframe/0.0", ua); |
| 311 } |
OLD | NEW |