OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 } | 61 } |
62 | 62 |
63 static net::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 webkit::npapi::WebPluginInfo info; | 69 webkit::npapi::WebPluginInfo info; |
70 info.path = pdf_path_; | 70 info.path = pdf_path_; |
71 info.enabled = true; | 71 info.name = ASCIIToUTF16("Internal PDF Plugin"); |
| 72 info.enabled = webkit::npapi::WebPluginInfo::USER_ENABLED_POLICY_UNMANAGED; |
72 webkit::npapi::PluginList::Singleton()->RegisterInternalPlugin(info); | 73 webkit::npapi::PluginList::Singleton()->RegisterInternalPlugin(info); |
73 webkit::npapi::PluginList::Singleton()->RefreshPlugins(); | 74 webkit::npapi::PluginList::Singleton()->RefreshPlugins(); |
74 } | 75 } |
75 | 76 |
76 void UnregisterPDFPlugin() { | 77 void UnregisterPDFPlugin() { |
77 webkit::npapi::PluginList::Singleton()->UnregisterInternalPlugin(pdf_path_); | 78 webkit::npapi::PluginList::Singleton()->UnregisterInternalPlugin(pdf_path_); |
78 webkit::npapi::PluginList::Singleton()->RefreshPlugins(); | 79 webkit::npapi::PluginList::Singleton()->RefreshPlugins(); |
79 } | 80 } |
80 | 81 |
81 void SetPDFPluginLoadedState(bool want_loaded, bool* out_is_enabled) { | 82 void SetPDFPluginLoadedState(bool want_loaded, bool* out_is_enabled) { |
82 webkit::npapi::WebPluginInfo info; | 83 webkit::npapi::WebPluginInfo info; |
83 bool is_loaded = | 84 bool is_loaded = |
84 webkit::npapi::PluginList::Singleton()->GetPluginInfoByPath( | 85 webkit::npapi::PluginList::Singleton()->GetPluginInfoByPath( |
85 pdf_path_, &info); | 86 pdf_path_, &info); |
86 if (is_loaded && !want_loaded) { | 87 if (is_loaded && !want_loaded) { |
87 UnregisterPDFPlugin(); | 88 UnregisterPDFPlugin(); |
88 is_loaded = webkit::npapi::PluginList::Singleton()->GetPluginInfoByPath( | 89 is_loaded = webkit::npapi::PluginList::Singleton()->GetPluginInfoByPath( |
89 pdf_path_, &info); | 90 pdf_path_, &info); |
90 } else if (!is_loaded && want_loaded) { | 91 } else if (!is_loaded && want_loaded) { |
91 // This "loads" the plug-in even if it's not present on the | 92 // This "loads" the plug-in even if it's not present on the |
92 // system - which is OK since we don't actually use it, just | 93 // system - which is OK since we don't actually use it, just |
93 // need it to be "enabled" for the test. | 94 // need it to be "enabled" for the test. |
94 RegisterPDFPlugin(); | 95 RegisterPDFPlugin(); |
95 is_loaded = webkit::npapi::PluginList::Singleton()->GetPluginInfoByPath( | 96 is_loaded = webkit::npapi::PluginList::Singleton()->GetPluginInfoByPath( |
96 pdf_path_, &info); | 97 pdf_path_, &info); |
97 } | 98 } |
98 EXPECT_EQ(want_loaded, is_loaded); | 99 EXPECT_EQ(want_loaded, is_loaded); |
99 *out_is_enabled = info.enabled; | 100 *out_is_enabled = webkit::npapi::IsPluginEnabled(info); |
100 } | 101 } |
101 | 102 |
102 protected: | 103 protected: |
103 MessageLoopForIO message_loop_; | 104 MessageLoopForIO message_loop_; |
104 TestDelegate test_delegate_; | 105 TestDelegate test_delegate_; |
105 net::URLRequest::Interceptor* interceptor_; | 106 net::URLRequest::Interceptor* interceptor_; |
106 FilePath pdf_path_; | 107 FilePath pdf_path_; |
107 }; | 108 }; |
108 | 109 |
109 TEST_F(GViewRequestInterceptorTest, DoNotInterceptHtml) { | 110 TEST_F(GViewRequestInterceptorTest, DoNotInterceptHtml) { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 TEST_F(GViewRequestInterceptorTest, InterceptPowerpoint) { | 175 TEST_F(GViewRequestInterceptorTest, InterceptPowerpoint) { |
175 net::URLRequest request(GURL("http://foo.com/file.ppt"), &test_delegate_); | 176 net::URLRequest request(GURL("http://foo.com/file.ppt"), &test_delegate_); |
176 request.Start(); | 177 request.Start(); |
177 MessageLoop::current()->Run(); | 178 MessageLoop::current()->Run(); |
178 EXPECT_EQ(1, test_delegate_.received_redirect_count()); | 179 EXPECT_EQ(1, test_delegate_.received_redirect_count()); |
179 EXPECT_EQ(GURL("http://docs.google.com/gview?url=http%3A//foo.com/file.ppt"), | 180 EXPECT_EQ(GURL("http://docs.google.com/gview?url=http%3A//foo.com/file.ppt"), |
180 request.url()); | 181 request.url()); |
181 } | 182 } |
182 | 183 |
183 } // namespace chromeos | 184 } // namespace chromeos |
OLD | NEW |