| 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 <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/at_exit.h" | 8 #include "base/at_exit.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "chrome/browser/chrome_plugin_service_filter.h" | 10 #include "chrome/browser/chrome_plugin_service_filter.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 const char kPdfUrl[] = "http://foo.com/file.pdf"; | 37 const char kPdfUrl[] = "http://foo.com/file.pdf"; |
| 38 const char kPptUrl[] = "http://foo.com/file.ppt"; | 38 const char kPptUrl[] = "http://foo.com/file.ppt"; |
| 39 const char kHtmlUrl[] = "http://foo.com/index.html"; | 39 const char kHtmlUrl[] = "http://foo.com/index.html"; |
| 40 const char kPdfBlob[] = "blob:blobinternal:///d17c4eef-28e7-42bd-bafa-78d5cb8"; | 40 const char kPdfBlob[] = "blob:blobinternal:///d17c4eef-28e7-42bd-bafa-78d5cb8"; |
| 41 | 41 |
| 42 const char kPdfUrlIntercepted[] = | 42 const char kPdfUrlIntercepted[] = |
| 43 "http://docs.google.com/gview?url=http%3A//foo.com/file.pdf"; | 43 "http://docs.google.com/gview?url=http%3A//foo.com/file.pdf"; |
| 44 const char kPptUrlIntercepted[] = | 44 const char kPptUrlIntercepted[] = |
| 45 "http://docs.google.com/gview?url=http%3A//foo.com/file.ppt"; | 45 "http://docs.google.com/gview?url=http%3A//foo.com/file.ppt"; |
| 46 | 46 |
| 47 void AssertPluginEnabled(bool did_enable) { |
| 48 ASSERT_TRUE(did_enable); |
| 49 MessageLoop::current()->QuitWhenIdle(); |
| 50 } |
| 51 |
| 47 class GViewURLRequestTestJob : public net::URLRequestTestJob { | 52 class GViewURLRequestTestJob : public net::URLRequestTestJob { |
| 48 public: | 53 public: |
| 49 GViewURLRequestTestJob(net::URLRequest* request, | 54 GViewURLRequestTestJob(net::URLRequest* request, |
| 50 net::NetworkDelegate* network_delegate) | 55 net::NetworkDelegate* network_delegate) |
| 51 : net::URLRequestTestJob(request, network_delegate, true) { | 56 : net::URLRequestTestJob(request, network_delegate, true) { |
| 52 } | 57 } |
| 53 | 58 |
| 54 virtual bool GetMimeType(std::string* mime_type) const { | 59 virtual bool GetMimeType(std::string* mime_type) const { |
| 55 // During the course of a single test, two URLRequestJobs are | 60 // During the course of a single test, two URLRequestJobs are |
| 56 // created -- the first is for the viewable document URL, and the | 61 // created -- the first is for the viewable document URL, and the |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 SetupRequest(&request); | 204 SetupRequest(&request); |
| 200 request.set_load_flags(net::LOAD_IS_DOWNLOAD); | 205 request.set_load_flags(net::LOAD_IS_DOWNLOAD); |
| 201 request.Start(); | 206 request.Start(); |
| 202 MessageLoop::current()->Run(); | 207 MessageLoop::current()->Run(); |
| 203 EXPECT_EQ(0, test_delegate_.received_redirect_count()); | 208 EXPECT_EQ(0, test_delegate_.received_redirect_count()); |
| 204 EXPECT_EQ(GURL(kPdfUrl), request.url()); | 209 EXPECT_EQ(GURL(kPdfUrl), request.url()); |
| 205 } | 210 } |
| 206 | 211 |
| 207 TEST_F(GViewRequestInterceptorTest, DoNotInterceptPdfWhenEnabled) { | 212 TEST_F(GViewRequestInterceptorTest, DoNotInterceptPdfWhenEnabled) { |
| 208 ASSERT_NO_FATAL_FAILURE(SetPDFPluginLoadedState(true)); | 213 ASSERT_NO_FATAL_FAILURE(SetPDFPluginLoadedState(true)); |
| 209 plugin_prefs_->EnablePlugin(true, pdf_path_, MessageLoop::QuitClosure()); | 214 plugin_prefs_->EnablePlugin(true, pdf_path_, |
| 215 base::Bind(&AssertPluginEnabled)); |
| 210 MessageLoop::current()->Run(); | 216 MessageLoop::current()->Run(); |
| 211 | 217 |
| 212 net::URLRequest request( | 218 net::URLRequest request( |
| 213 GURL(kPdfUrl), &test_delegate_, resource_context_.GetRequestContext()); | 219 GURL(kPdfUrl), &test_delegate_, resource_context_.GetRequestContext()); |
| 214 SetupRequest(&request); | 220 SetupRequest(&request); |
| 215 request.Start(); | 221 request.Start(); |
| 216 MessageLoop::current()->Run(); | 222 MessageLoop::current()->Run(); |
| 217 EXPECT_EQ(0, test_delegate_.received_redirect_count()); | 223 EXPECT_EQ(0, test_delegate_.received_redirect_count()); |
| 218 EXPECT_EQ(GURL(kPdfUrl), request.url()); | 224 EXPECT_EQ(GURL(kPdfUrl), request.url()); |
| 219 } | 225 } |
| 220 | 226 |
| 221 TEST_F(GViewRequestInterceptorTest, InterceptPdfWhenDisabled) { | 227 TEST_F(GViewRequestInterceptorTest, InterceptPdfWhenDisabled) { |
| 222 ASSERT_NO_FATAL_FAILURE(SetPDFPluginLoadedState(true)); | 228 ASSERT_NO_FATAL_FAILURE(SetPDFPluginLoadedState(true)); |
| 223 plugin_prefs_->EnablePlugin(false, pdf_path_, MessageLoop::QuitClosure()); | 229 plugin_prefs_->EnablePlugin(false, pdf_path_, |
| 230 base::Bind(&AssertPluginEnabled)); |
| 224 MessageLoop::current()->Run(); | 231 MessageLoop::current()->Run(); |
| 225 | 232 |
| 226 net::URLRequest request( | 233 net::URLRequest request( |
| 227 GURL(kPdfUrl), &test_delegate_, resource_context_.GetRequestContext()); | 234 GURL(kPdfUrl), &test_delegate_, resource_context_.GetRequestContext()); |
| 228 SetupRequest(&request); | 235 SetupRequest(&request); |
| 229 request.Start(); | 236 request.Start(); |
| 230 MessageLoop::current()->Run(); | 237 MessageLoop::current()->Run(); |
| 231 EXPECT_EQ(1, test_delegate_.received_redirect_count()); | 238 EXPECT_EQ(1, test_delegate_.received_redirect_count()); |
| 232 EXPECT_EQ(GURL(kPdfUrlIntercepted), request.url()); | 239 EXPECT_EQ(GURL(kPdfUrlIntercepted), request.url()); |
| 233 } | 240 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 SetupRequest(&request); | 287 SetupRequest(&request); |
| 281 request.Start(); | 288 request.Start(); |
| 282 MessageLoop::current()->Run(); | 289 MessageLoop::current()->Run(); |
| 283 EXPECT_EQ(0, test_delegate_.received_redirect_count()); | 290 EXPECT_EQ(0, test_delegate_.received_redirect_count()); |
| 284 EXPECT_EQ(GURL(kPdfBlob), request.url()); | 291 EXPECT_EQ(GURL(kPdfBlob), request.url()); |
| 285 } | 292 } |
| 286 | 293 |
| 287 } // namespace | 294 } // namespace |
| 288 | 295 |
| 289 } // namespace chromeos | 296 } // namespace chromeos |
| OLD | NEW |