OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 <string> | 5 #include <string> |
6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
7 #include "chrome/browser/chromeos/gview_request_interceptor.h" | 7 #include "chrome/browser/chromeos/gview_request_interceptor.h" |
8 #include "chrome/browser/plugin_service.h" | 8 #include "chrome/browser/plugin_service.h" |
9 #include "chrome/common/chrome_paths.h" | 9 #include "chrome/common/chrome_paths.h" |
10 #include "net/base/load_flags.h" | 10 #include "net/base/load_flags.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 public: | 21 public: |
22 explicit GViewURLRequestTestJob(net::URLRequest* request) | 22 explicit GViewURLRequestTestJob(net::URLRequest* request) |
23 : URLRequestTestJob(request, true) { | 23 : URLRequestTestJob(request, true) { |
24 } | 24 } |
25 | 25 |
26 virtual bool GetMimeType(std::string* mime_type) const { | 26 virtual bool GetMimeType(std::string* mime_type) const { |
27 // During the course of a single test, two URLRequestJobs are | 27 // During the course of a single test, two URLRequestJobs are |
28 // created -- the first is for the viewable document URL, and the | 28 // created -- the first is for the viewable document URL, and the |
29 // second is for the rediected URL. In order to test the | 29 // second is for the rediected URL. In order to test the |
30 // interceptor, the mime type of the first request must be one of | 30 // interceptor, the mime type of the first request must be one of |
31 // the supported viewable mime types. So when the URLRequestJob | 31 // the supported viewable mime types. So when the net::URLRequestJob |
32 // is a request for one of the test URLs that point to viewable | 32 // is a request for one of the test URLs that point to viewable |
33 // content, return an appropraite mime type. Otherwise, return | 33 // content, return an appropraite mime type. Otherwise, return |
34 // "text/html". | 34 // "text/html". |
35 if (request_->url() == GURL("http://foo.com/file.pdf")) { | 35 if (request_->url() == GURL("http://foo.com/file.pdf")) { |
36 *mime_type = "application/pdf"; | 36 *mime_type = "application/pdf"; |
37 } else if (request_->url() == GURL("http://foo.com/file.ppt")) { | 37 } else if (request_->url() == GURL("http://foo.com/file.ppt")) { |
38 *mime_type = "application/vnd.ms-powerpoint"; | 38 *mime_type = "application/vnd.ms-powerpoint"; |
39 } else { | 39 } else { |
40 *mime_type = "text/html"; | 40 *mime_type = "text/html"; |
41 } | 41 } |
(...skipping 11 matching lines...) Expand all Loading... |
53 &GViewRequestInterceptorTest::Factory); | 53 &GViewRequestInterceptorTest::Factory); |
54 interceptor_ = GViewRequestInterceptor::GetGViewRequestInterceptor(); | 54 interceptor_ = GViewRequestInterceptor::GetGViewRequestInterceptor(); |
55 ASSERT_TRUE(PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path_)); | 55 ASSERT_TRUE(PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path_)); |
56 } | 56 } |
57 | 57 |
58 virtual void TearDown() { | 58 virtual void TearDown() { |
59 net::URLRequest::RegisterProtocolFactory("http", NULL); | 59 net::URLRequest::RegisterProtocolFactory("http", NULL); |
60 message_loop_.RunAllPending(); | 60 message_loop_.RunAllPending(); |
61 } | 61 } |
62 | 62 |
63 static URLRequestJob* Factory(net::URLRequest* request, | 63 static net::URLRequestJob* Factory(net::URLRequest* request, |
64 const std::string& scheme) { | 64 const std::string& scheme) { |
65 return new GViewURLRequestTestJob(request); | 65 return new GViewURLRequestTestJob(request); |
66 } | 66 } |
67 | 67 |
68 void RegisterPDFPlugin() { | 68 void RegisterPDFPlugin() { |
69 NPAPI::PluginVersionInfo info; | 69 NPAPI::PluginVersionInfo info; |
70 info.path = pdf_path_; | 70 info.path = pdf_path_; |
71 memset(&info.entry_points, 0, sizeof(info.entry_points)); | 71 memset(&info.entry_points, 0, sizeof(info.entry_points)); |
72 NPAPI::PluginList::Singleton()->RegisterInternalPlugin(info); | 72 NPAPI::PluginList::Singleton()->RegisterInternalPlugin(info); |
73 NPAPI::PluginList::Singleton()->RefreshPlugins(); | 73 NPAPI::PluginList::Singleton()->RefreshPlugins(); |
74 } | 74 } |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 TEST_F(GViewRequestInterceptorTest, InterceptPowerpoint) { | 173 TEST_F(GViewRequestInterceptorTest, InterceptPowerpoint) { |
174 net::URLRequest request(GURL("http://foo.com/file.ppt"), &test_delegate_); | 174 net::URLRequest request(GURL("http://foo.com/file.ppt"), &test_delegate_); |
175 request.Start(); | 175 request.Start(); |
176 MessageLoop::current()->Run(); | 176 MessageLoop::current()->Run(); |
177 EXPECT_EQ(1, test_delegate_.received_redirect_count()); | 177 EXPECT_EQ(1, test_delegate_.received_redirect_count()); |
178 EXPECT_EQ(GURL("http://docs.google.com/gview?url=http%3A//foo.com/file.ppt"), | 178 EXPECT_EQ(GURL("http://docs.google.com/gview?url=http%3A//foo.com/file.ppt"), |
179 request.url()); | 179 request.url()); |
180 } | 180 } |
181 | 181 |
182 } // namespace chromeos | 182 } // namespace chromeos |
OLD | NEW |