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 "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #undef LOG | 9 #undef LOG |
10 | 10 |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "net/url_request/url_request_unittest.h" | 12 #include "net/url_request/url_request_unittest.h" |
13 #include "webkit/glue/unittest_test_server.h" | 13 #include "webkit/glue/unittest_test_server.h" |
14 #include "webkit/glue/webkit_glue.h" | 14 #include "webkit/glue/webkit_glue.h" |
15 #include "webkit/glue/webview.h" | 15 #include "webkit/glue/webview.h" |
16 #include "webkit/tools/test_shell/test_shell_test.h" | 16 #include "webkit/tools/test_shell/test_shell_test.h" |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 class MimeTypeTests : public TestShellTest { | 20 class MimeTypeTests : public TestShellTest { |
21 public: | 21 public: |
22 void LoadURL(const GURL& url) { | 22 void LoadURL(const GURL& url) { |
23 test_shell_->LoadURL(UTF8ToWide(url.spec()).c_str()); | 23 test_shell_->LoadURL(UTF8ToWide(url.spec()).c_str()); |
24 test_shell_->WaitTestFinished(); | 24 test_shell_->WaitTestFinished(); |
25 } | 25 } |
26 | 26 |
27 void CheckMimeType(const char* mimetype, const std::wstring& expected) { | 27 void CheckMimeType(const char* mimetype, const std::wstring& expected) { |
28 std::string path("contenttype?"); | 28 std::string path("contenttype?"); |
29 GURL url = server_->TestServerPage(path + mimetype); | 29 GURL url = server_->TestServerPage(path + mimetype); |
30 LoadURL(url); | 30 LoadURL(url); |
31 WebFrame* frame = test_shell_->webView()->GetMainFrame(); | 31 WebFrame* frame = test_shell_->webView()->GetMainFrame(); |
32 EXPECT_EQ(expected, webkit_glue::DumpDocumentText(frame)); | 32 EXPECT_EQ(expected, webkit_glue::DumpDocumentText(frame)); |
33 } | 33 } |
34 | 34 |
35 scoped_refptr<UnittestTestServer> server_; | 35 scoped_ptr<UnittestTestServer> server_; |
36 }; | 36 }; |
37 | 37 |
38 TEST_F(MimeTypeTests, MimeTypeTests) { | 38 TEST_F(MimeTypeTests, MimeTypeTests) { |
39 server_ = UnittestTestServer::CreateServer(); | 39 server_.reset(new UnittestTestServer); |
40 ASSERT_TRUE(NULL != server_.get()); | |
41 | 40 |
42 std::wstring expected_src(L"<html>\n<body>\n" | 41 std::wstring expected_src(L"<html>\n<body>\n" |
43 L"<p>HTML text</p>\n</body>\n</html>\n"); | 42 L"<p>HTML text</p>\n</body>\n</html>\n"); |
44 | 43 |
45 // These files should all be displayed as plain text. | 44 // These files should all be displayed as plain text. |
46 const char* plain_text[] = { | 45 const char* plain_text[] = { |
47 "text/css", | 46 "text/css", |
48 "text/foo", | 47 "text/foo", |
49 "text/richext", | 48 "text/richext", |
50 "text/rtf", | 49 "text/rtf", |
51 "application/x-javascript", | 50 "application/x-javascript", |
52 }; | 51 }; |
53 for (size_t i = 0; i < arraysize(plain_text); ++i) { | 52 for (size_t i = 0; i < arraysize(plain_text); ++i) { |
54 CheckMimeType(plain_text[i], expected_src); | 53 CheckMimeType(plain_text[i], expected_src); |
(...skipping 19 matching lines...) Expand all Loading... |
74 "image/bmp", | 73 "image/bmp", |
75 }; | 74 }; |
76 for (size_t i = 0; i < arraysize(not_text); ++i) { | 75 for (size_t i = 0; i < arraysize(not_text); ++i) { |
77 CheckMimeType(not_text[i], L""); | 76 CheckMimeType(not_text[i], L""); |
78 test_shell_->webView()->StopLoading(); | 77 test_shell_->webView()->StopLoading(); |
79 } | 78 } |
80 | 79 |
81 // TODO(tc): make sure other mime types properly go to download (e.g., | 80 // TODO(tc): make sure other mime types properly go to download (e.g., |
82 // image/foo). | 81 // image/foo). |
83 | 82 |
| 83 server_.reset(NULL); |
84 } | 84 } |
85 | 85 |
86 } // namespace | 86 } // namespace |
87 | 87 |
OLD | NEW |