OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "net/url_request/url_request_unittest.h" | 8 #include "net/url_request/url_request_unittest.h" |
9 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" | 9 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" |
10 #include "third_party/WebKit/WebKit/chromium/public/WebView.h" | 10 #include "third_party/WebKit/WebKit/chromium/public/WebView.h" |
11 #include "webkit/glue/unittest_test_server.h" | 11 #include "webkit/glue/unittest_test_server.h" |
12 #include "webkit/glue/webkit_glue.h" | 12 #include "webkit/glue/webkit_glue.h" |
13 #include "webkit/tools/test_shell/test_shell_test.h" | 13 #include "webkit/tools/test_shell/test_shell_test.h" |
14 | 14 |
15 using WebKit::WebFrame; | 15 using WebKit::WebFrame; |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 class MimeTypeTests : public TestShellTest { | 19 class MimeTypeTests : public TestShellTest { |
20 public: | 20 public: |
21 void LoadURL(const GURL& url) { | 21 void LoadURL(const GURL& url) { |
22 test_shell_->LoadURL(url); | 22 test_shell_->LoadURL(url); |
23 test_shell_->WaitTestFinished(); | 23 test_shell_->WaitTestFinished(); |
24 } | 24 } |
25 | 25 |
26 void CheckMimeType(const char* mimetype, const std::wstring& expected) { | 26 void CheckMimeType(const char* mimetype, const std::string& expected) { |
27 std::string path("contenttype?"); | 27 std::string path("contenttype?"); |
28 GURL url(test_server_.GetURL(path + mimetype)); | 28 GURL url(test_server_.GetURL(path + mimetype)); |
29 LoadURL(url); | 29 LoadURL(url); |
30 WebFrame* frame = test_shell_->webView()->mainFrame(); | 30 WebFrame* frame = test_shell_->webView()->mainFrame(); |
31 EXPECT_EQ(expected, webkit_glue::DumpDocumentText(frame)); | 31 EXPECT_EQ(expected, UTF16ToASCII(webkit_glue::DumpDocumentText(frame))); |
32 } | 32 } |
33 | 33 |
34 UnittestTestServer test_server_; | 34 UnittestTestServer test_server_; |
35 }; | 35 }; |
36 | 36 |
37 TEST_F(MimeTypeTests, MimeTypeTests) { | 37 TEST_F(MimeTypeTests, MimeTypeTests) { |
38 ASSERT_TRUE(test_server_.Start()); | 38 ASSERT_TRUE(test_server_.Start()); |
39 | 39 |
40 std::wstring expected_src(L"<html>\n<body>\n" | 40 std::string expected_src("<html>\n<body>\n" |
41 L"<p>HTML text</p>\n</body>\n</html>\n"); | 41 "<p>HTML text</p>\n</body>\n</html>\n"); |
42 | 42 |
43 // These files should all be displayed as plain text. | 43 // These files should all be displayed as plain text. |
44 const char* plain_text[] = { | 44 const char* plain_text[] = { |
45 // It is unclear whether to display text/css or download it. | 45 // It is unclear whether to display text/css or download it. |
46 // Firefox 3: Display | 46 // Firefox 3: Display |
47 // Internet Explorer 7: Download | 47 // Internet Explorer 7: Download |
48 // Safari 3.2: Download | 48 // Safari 3.2: Download |
49 // We choose to match Firefox due to the lot of complains | 49 // We choose to match Firefox due to the lot of complains |
50 // from the users if css files are downloaded: | 50 // from the users if css files are downloaded: |
51 // http://code.google.com/p/chromium/issues/detail?id=7192 | 51 // http://code.google.com/p/chromium/issues/detail?id=7192 |
52 "text/css", | 52 "text/css", |
53 "text/javascript", | 53 "text/javascript", |
54 "text/plain", | 54 "text/plain", |
55 "application/x-javascript", | 55 "application/x-javascript", |
56 }; | 56 }; |
57 for (size_t i = 0; i < arraysize(plain_text); ++i) { | 57 for (size_t i = 0; i < arraysize(plain_text); ++i) { |
58 CheckMimeType(plain_text[i], expected_src); | 58 CheckMimeType(plain_text[i], expected_src); |
59 } | 59 } |
60 | 60 |
61 // These should all be displayed as html content. | 61 // These should all be displayed as html content. |
62 const char* html_src[] = { | 62 const char* html_src[] = { |
63 "text/html", | 63 "text/html", |
64 "text/xml", | 64 "text/xml", |
65 "text/xsl", | 65 "text/xsl", |
66 "application/xhtml+xml", | 66 "application/xhtml+xml", |
67 }; | 67 }; |
68 for (size_t i = 0; i < arraysize(html_src); ++i) { | 68 for (size_t i = 0; i < arraysize(html_src); ++i) { |
69 CheckMimeType(html_src[i], L"HTML text"); | 69 CheckMimeType(html_src[i], "HTML text"); |
70 } | 70 } |
71 | 71 |
72 // These shouldn't be rendered as text or HTML, but shouldn't download | 72 // These shouldn't be rendered as text or HTML, but shouldn't download |
73 // either. | 73 // either. |
74 const char* not_text[] = { | 74 const char* not_text[] = { |
75 "image/png", | 75 "image/png", |
76 "image/gif", | 76 "image/gif", |
77 "image/jpeg", | 77 "image/jpeg", |
78 "image/bmp", | 78 "image/bmp", |
79 }; | 79 }; |
80 for (size_t i = 0; i < arraysize(not_text); ++i) { | 80 for (size_t i = 0; i < arraysize(not_text); ++i) { |
81 CheckMimeType(not_text[i], L""); | 81 CheckMimeType(not_text[i], ""); |
82 test_shell_->webView()->mainFrame()->stopLoading(); | 82 test_shell_->webView()->mainFrame()->stopLoading(); |
83 } | 83 } |
84 | 84 |
85 // TODO(tc): make sure other mime types properly go to download (e.g., | 85 // TODO(tc): make sure other mime types properly go to download (e.g., |
86 // image/foo). | 86 // image/foo). |
87 | 87 |
88 } | 88 } |
89 | 89 |
90 } // namespace | 90 } // namespace |
OLD | NEW |