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 "chrome/browser/printing/print_preview_dialog_controller.h" | 5 #include "chrome/browser/printing/print_preview_dialog_controller.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 chrome::Print(browser()); | 173 chrome::Print(browser()); |
174 run_loop.Run(); | 174 run_loop.Run(); |
175 } | 175 } |
176 | 176 |
177 WebContents* GetPrintPreviewDialog() { | 177 WebContents* GetPrintPreviewDialog() { |
178 printing::PrintPreviewDialogController* dialog_controller = | 178 printing::PrintPreviewDialogController* dialog_controller = |
179 printing::PrintPreviewDialogController::GetInstance(); | 179 printing::PrintPreviewDialogController::GetInstance(); |
180 return dialog_controller->GetPrintPreviewForContents(initiator_); | 180 return dialog_controller->GetPrintPreviewForContents(initiator_); |
181 } | 181 } |
182 | 182 |
| 183 void SetAlwaysOpenPdfExternallyForTests(bool always_open_pdf_externally) { |
| 184 PluginPrefs::GetForProfile(browser()->profile()) |
| 185 ->SetAlwaysOpenPdfExternallyForTests(always_open_pdf_externally); |
| 186 } |
| 187 |
183 private: | 188 private: |
184 void SetUpOnMainThread() override { | 189 void SetUpOnMainThread() override { |
185 WebContents* first_tab = | 190 WebContents* first_tab = |
186 browser()->tab_strip_model()->GetActiveWebContents(); | 191 browser()->tab_strip_model()->GetActiveWebContents(); |
187 ASSERT_TRUE(first_tab); | 192 ASSERT_TRUE(first_tab); |
188 | 193 |
189 // Open a new tab so |cloned_tab_observer_| can see it first and attach a | 194 // Open a new tab so |cloned_tab_observer_| can see it first and attach a |
190 // RequestPrintPreviewObserver to it before the real | 195 // RequestPrintPreviewObserver to it before the real |
191 // PrintPreviewMessageHandler gets created. Thus enabling | 196 // PrintPreviewMessageHandler gets created. Thus enabling |
192 // RequestPrintPreviewObserver to get messages first for the purposes of | 197 // RequestPrintPreviewObserver to get messages first for the purposes of |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 base::RunLoop run_loop; | 290 base::RunLoop run_loop; |
286 content::PluginService::GetInstance()->GetPlugins( | 291 content::PluginService::GetInstance()->GetPlugins( |
287 base::Bind(&PluginsLoadedCallback, run_loop.QuitClosure())); | 292 base::Bind(&PluginsLoadedCallback, run_loop.QuitClosure())); |
288 run_loop.Run(); | 293 run_loop.Run(); |
289 } | 294 } |
290 // Get the PDF plugin info. | 295 // Get the PDF plugin info. |
291 content::WebPluginInfo pdf_plugin_info; | 296 content::WebPluginInfo pdf_plugin_info; |
292 ASSERT_TRUE(GetPdfPluginInfo(&pdf_plugin_info)); | 297 ASSERT_TRUE(GetPdfPluginInfo(&pdf_plugin_info)); |
293 | 298 |
294 // Disable the PDF plugin. | 299 // Disable the PDF plugin. |
295 { | 300 SetAlwaysOpenPdfExternallyForTests(true); |
296 base::RunLoop run_loop; | |
297 PluginPrefs::GetForProfile(browser()->profile())->EnablePlugin( | |
298 false, | |
299 base::FilePath::FromUTF8Unsafe(ChromeContentClient::kPDFPluginPath), | |
300 base::Bind(&PluginEnabledCallback, run_loop.QuitClosure())); | |
301 run_loop.Run(); | |
302 } | |
303 | 301 |
304 // Make sure it is actually disabled for webpages. | 302 // Make sure it is actually disabled for webpages. |
305 ChromePluginServiceFilter* filter = ChromePluginServiceFilter::GetInstance(); | 303 ChromePluginServiceFilter* filter = ChromePluginServiceFilter::GetInstance(); |
306 content::WebPluginInfo dummy_pdf_plugin_info = pdf_plugin_info; | 304 content::WebPluginInfo dummy_pdf_plugin_info = pdf_plugin_info; |
307 EXPECT_FALSE(filter->IsPluginAvailable( | 305 EXPECT_FALSE(filter->IsPluginAvailable( |
308 initiator()->GetRenderProcessHost()->GetID(), | 306 initiator()->GetRenderProcessHost()->GetID(), |
309 initiator()->GetMainFrame()->GetRoutingID(), | 307 initiator()->GetMainFrame()->GetRoutingID(), |
310 browser()->profile()->GetResourceContext(), GURL(), | 308 browser()->profile()->GetResourceContext(), GURL(), |
311 url::Origin(GURL("http://google.com")), &dummy_pdf_plugin_info)); | 309 url::Origin(GURL("http://google.com")), &dummy_pdf_plugin_info)); |
312 | 310 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 content::BrowserAccessibilityState::GetInstance()->EnableAccessibility(); | 395 content::BrowserAccessibilityState::GetInstance()->EnableAccessibility(); |
398 ui_test_utils::NavigateToURL(browser(), GURL("data:text/html,HelloWorld")); | 396 ui_test_utils::NavigateToURL(browser(), GURL("data:text/html,HelloWorld")); |
399 PrintPreview(); | 397 PrintPreview(); |
400 WebContents* preview_dialog = GetPrintPreviewDialog(); | 398 WebContents* preview_dialog = GetPrintPreviewDialog(); |
401 WaitForAccessibilityTreeToContainNodeWithName(preview_dialog, "HelloWorld"); | 399 WaitForAccessibilityTreeToContainNodeWithName(preview_dialog, "HelloWorld"); |
402 } | 400 } |
403 | 401 |
404 } // namespace | 402 } // namespace |
405 | 403 |
406 #endif // defined(ENABLE_TASK_MANAGER) | 404 #endif // defined(ENABLE_TASK_MANAGER) |
OLD | NEW |