| 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 "content/browser/plugin_service.h" | 5 #include "content/browser/plugin_service_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/test/base/in_process_browser_test.h" | 11 #include "chrome/test/base/in_process_browser_test.h" |
| 12 #include "chrome/test/base/testing_profile.h" | 12 #include "chrome/test/base/testing_profile.h" |
| 13 #include "chrome/test/base/ui_test_utils.h" | 13 #include "chrome/test/base/ui_test_utils.h" |
| 14 #include "content/browser/resource_context.h" | 14 #include "content/browser/resource_context.h" |
| 15 #include "content/public/common/content_switches.h" | 15 #include "content/public/common/content_switches.h" |
| 16 #include "content/test/test_browser_thread.h" | 16 #include "content/test/test_browser_thread.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "webkit/plugins/npapi/plugin_list.h" | 18 #include "webkit/plugins/npapi/plugin_list.h" |
| 19 | 19 |
| 20 using content::BrowserThread; | 20 using content::BrowserThread; |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 const char kNPAPITestPluginMimeType[] = "application/vnd.npapi-test"; | 24 const char kNPAPITestPluginMimeType[] = "application/vnd.npapi-test"; |
| 25 | 25 |
| 26 void OpenChannel(PluginProcessHost::Client* client) { | 26 void OpenChannel(PluginProcessHost::Client* client) { |
| 27 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 27 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 28 // Start opening the channel | 28 // Start opening the channel |
| 29 PluginService::GetInstance()->OpenChannelToNpapiPlugin( | 29 PluginServiceImpl::GetInstance()->OpenChannelToNpapiPlugin( |
| 30 0, 0, GURL(), GURL(), kNPAPITestPluginMimeType, client); | 30 0, 0, GURL(), GURL(), kNPAPITestPluginMimeType, client); |
| 31 } | 31 } |
| 32 | 32 |
| 33 // Mock up of the Client and the Listener classes that would supply the | 33 // Mock up of the Client and the Listener classes that would supply the |
| 34 // communication channel with the plugin. | 34 // communication channel with the plugin. |
| 35 class MockPluginProcessHostClient : public PluginProcessHost::Client, | 35 class MockPluginProcessHostClient : public PluginProcessHost::Client, |
| 36 public IPC::Channel::Listener { | 36 public IPC::Channel::Listener { |
| 37 public: | 37 public: |
| 38 MockPluginProcessHostClient(const content::ResourceContext& context) | 38 MockPluginProcessHostClient(const content::ResourceContext& context) |
| 39 : context_(context), | 39 : context_(context), |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 void DoNothing() {} | 151 void DoNothing() {} |
| 152 | 152 |
| 153 void QuitUIMessageLoopFromIOThread() { | 153 void QuitUIMessageLoopFromIOThread() { |
| 154 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 154 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 155 MessageLoop::QuitClosure()); | 155 MessageLoop::QuitClosure()); |
| 156 } | 156 } |
| 157 | 157 |
| 158 void OpenChannelAndThenCancel(PluginProcessHost::Client* client) { | 158 void OpenChannelAndThenCancel(PluginProcessHost::Client* client) { |
| 159 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 159 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 160 // Start opening the channel | 160 // Start opening the channel |
| 161 PluginService::GetInstance()->OpenChannelToNpapiPlugin( | 161 PluginServiceImpl::GetInstance()->OpenChannelToNpapiPlugin( |
| 162 0, 0, GURL(), GURL(), kNPAPITestPluginMimeType, client); | 162 0, 0, GURL(), GURL(), kNPAPITestPluginMimeType, client); |
| 163 // Immediately cancel it. This is guaranteed to work since PluginService needs | 163 // Immediately cancel it. This is guaranteed to work since PluginService needs |
| 164 // to consult its filter on the FILE thread. | 164 // to consult its filter on the FILE thread. |
| 165 PluginService::GetInstance()->CancelOpenChannelToNpapiPlugin(client); | 165 PluginServiceImpl::GetInstance()->CancelOpenChannelToNpapiPlugin(client); |
| 166 // Before we terminate the test, add a roundtrip through the FILE thread to | 166 // Before we terminate the test, add a roundtrip through the FILE thread to |
| 167 // make sure that it's had a chance to post back to the IO thread. Then signal | 167 // make sure that it's had a chance to post back to the IO thread. Then signal |
| 168 // the UI thread to stop and exit the test. | 168 // the UI thread to stop and exit the test. |
| 169 BrowserThread::PostTaskAndReply( | 169 BrowserThread::PostTaskAndReply( |
| 170 BrowserThread::FILE, FROM_HERE, | 170 BrowserThread::FILE, FROM_HERE, |
| 171 base::Bind(&DoNothing), | 171 base::Bind(&DoNothing), |
| 172 base::Bind(&QuitUIMessageLoopFromIOThread)); | 172 base::Bind(&QuitUIMessageLoopFromIOThread)); |
| 173 } | 173 } |
| 174 | 174 |
| 175 // Should not attempt to open a channel, since it should be canceled early on. | 175 // Should not attempt to open a channel, since it should be canceled early on. |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 BrowserThread::IO, FROM_HERE, | 302 BrowserThread::IO, FROM_HERE, |
| 303 base::Bind(&OpenChannel, &mock_client)); | 303 base::Bind(&OpenChannel, &mock_client)); |
| 304 ui_test_utils::RunMessageLoop(); | 304 ui_test_utils::RunMessageLoop(); |
| 305 EXPECT_TRUE(mock_client.get_resource_context_called()); | 305 EXPECT_TRUE(mock_client.get_resource_context_called()); |
| 306 EXPECT_TRUE(mock_client.set_plugin_info_called()); | 306 EXPECT_TRUE(mock_client.set_plugin_info_called()); |
| 307 EXPECT_TRUE(mock_client.on_found_plugin_process_host_called()); | 307 EXPECT_TRUE(mock_client.on_found_plugin_process_host_called()); |
| 308 EXPECT_TRUE(mock_client.on_sent_plugin_channel_request_called()); | 308 EXPECT_TRUE(mock_client.on_sent_plugin_channel_request_called()); |
| 309 } | 309 } |
| 310 | 310 |
| 311 } // namespace | 311 } // namespace |
| OLD | NEW |