| 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/location.h" | 11 #include "base/location.h" |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 13 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| 17 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" | 18 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" |
| 18 #include "chrome/browser/plugins/plugin_prefs.h" | 19 #include "chrome/browser/plugins/plugin_prefs.h" |
| 20 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/task_management/mock_web_contents_task_manager.h" | 21 #include "chrome/browser/task_management/mock_web_contents_task_manager.h" |
| 20 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
| 21 #include "chrome/browser/ui/browser_commands.h" | 23 #include "chrome/browser/ui/browser_commands.h" |
| 22 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 24 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 23 #include "chrome/common/chrome_content_client.h" | 25 #include "chrome/common/chrome_content_client.h" |
| 24 #include "chrome/common/url_constants.h" | 26 #include "chrome/common/url_constants.h" |
| 25 #include "chrome/grit/generated_resources.h" | 27 #include "chrome/grit/generated_resources.h" |
| 26 #include "chrome/test/base/in_process_browser_test.h" | 28 #include "chrome/test/base/in_process_browser_test.h" |
| 27 #include "chrome/test/base/ui_test_utils.h" | 29 #include "chrome/test/base/ui_test_utils.h" |
| 28 #include "components/printing/common/print_messages.h" | 30 #include "components/printing/common/print_messages.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 | 117 |
| 116 DISALLOW_COPY_AND_ASSIGN(PrintPreviewDialogDestroyedObserver); | 118 DISALLOW_COPY_AND_ASSIGN(PrintPreviewDialogDestroyedObserver); |
| 117 }; | 119 }; |
| 118 | 120 |
| 119 void PluginsLoadedCallback( | 121 void PluginsLoadedCallback( |
| 120 const base::Closure& quit_closure, | 122 const base::Closure& quit_closure, |
| 121 const std::vector<content::WebPluginInfo>& /* info */) { | 123 const std::vector<content::WebPluginInfo>& /* info */) { |
| 122 quit_closure.Run(); | 124 quit_closure.Run(); |
| 123 } | 125 } |
| 124 | 126 |
| 127 void PluginEnabledCallback(const base::Closure& quit_closure, bool can_enable) { |
| 128 EXPECT_TRUE(can_enable); |
| 129 quit_closure.Run(); |
| 130 } |
| 131 |
| 125 bool GetPdfPluginInfo(content::WebPluginInfo* info) { | 132 bool GetPdfPluginInfo(content::WebPluginInfo* info) { |
| 126 base::FilePath pdf_plugin_path = base::FilePath::FromUTF8Unsafe( | 133 base::FilePath pdf_plugin_path = base::FilePath::FromUTF8Unsafe( |
| 127 ChromeContentClient::kPDFPluginPath); | 134 ChromeContentClient::kPDFPluginPath); |
| 128 return content::PluginService::GetInstance()->GetPluginInfoByPath( | 135 return content::PluginService::GetInstance()->GetPluginInfoByPath( |
| 129 pdf_plugin_path, info); | 136 pdf_plugin_path, info); |
| 130 } | 137 } |
| 131 | 138 |
| 132 const char kDummyPrintUrl[] = "chrome://print/dummy.pdf"; | 139 const char kDummyPrintUrl[] = "chrome://print/dummy.pdf"; |
| 133 | 140 |
| 134 void CountFrames(int* frame_count, | 141 void CountFrames(int* frame_count, |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 base::RunLoop run_loop; | 285 base::RunLoop run_loop; |
| 279 content::PluginService::GetInstance()->GetPlugins( | 286 content::PluginService::GetInstance()->GetPlugins( |
| 280 base::Bind(&PluginsLoadedCallback, run_loop.QuitClosure())); | 287 base::Bind(&PluginsLoadedCallback, run_loop.QuitClosure())); |
| 281 run_loop.Run(); | 288 run_loop.Run(); |
| 282 } | 289 } |
| 283 // Get the PDF plugin info. | 290 // Get the PDF plugin info. |
| 284 content::WebPluginInfo pdf_plugin_info; | 291 content::WebPluginInfo pdf_plugin_info; |
| 285 ASSERT_TRUE(GetPdfPluginInfo(&pdf_plugin_info)); | 292 ASSERT_TRUE(GetPdfPluginInfo(&pdf_plugin_info)); |
| 286 | 293 |
| 287 // Disable the PDF plugin. | 294 // Disable the PDF plugin. |
| 288 PluginPrefs::GetForProfile(browser()->profile())->EnablePluginGroup( | 295 { |
| 289 false, base::ASCIIToUTF16(ChromeContentClient::kPDFPluginName)); | 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 } |
| 290 | 303 |
| 291 // Make sure it is actually disabled for webpages. | 304 // Make sure it is actually disabled for webpages. |
| 292 ChromePluginServiceFilter* filter = ChromePluginServiceFilter::GetInstance(); | 305 ChromePluginServiceFilter* filter = ChromePluginServiceFilter::GetInstance(); |
| 293 content::WebPluginInfo dummy_pdf_plugin_info = pdf_plugin_info; | 306 content::WebPluginInfo dummy_pdf_plugin_info = pdf_plugin_info; |
| 294 EXPECT_FALSE(filter->IsPluginAvailable( | 307 EXPECT_FALSE(filter->IsPluginAvailable( |
| 295 initiator()->GetRenderProcessHost()->GetID(), | 308 initiator()->GetRenderProcessHost()->GetID(), |
| 296 initiator()->GetMainFrame()->GetRoutingID(), | 309 initiator()->GetMainFrame()->GetRoutingID(), |
| 297 nullptr, | 310 browser()->profile()->GetResourceContext(), |
| 298 GURL("http://google.com"), | 311 GURL("http://google.com"), |
| 299 GURL(), | 312 GURL(), |
| 300 &dummy_pdf_plugin_info)); | 313 &dummy_pdf_plugin_info)); |
| 301 | 314 |
| 302 PrintPreview(); | 315 PrintPreview(); |
| 303 | 316 |
| 304 // Check a new print preview dialog got created. | 317 // Check a new print preview dialog got created. |
| 305 WebContents* preview_dialog = GetPrintPreviewDialog(); | 318 WebContents* preview_dialog = GetPrintPreviewDialog(); |
| 306 ASSERT_TRUE(preview_dialog); | 319 ASSERT_TRUE(preview_dialog); |
| 307 ASSERT_NE(initiator(), preview_dialog); | 320 ASSERT_NE(initiator(), preview_dialog); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 content::BrowserAccessibilityState::GetInstance()->EnableAccessibility(); | 400 content::BrowserAccessibilityState::GetInstance()->EnableAccessibility(); |
| 388 ui_test_utils::NavigateToURL(browser(), GURL("data:text/html,HelloWorld")); | 401 ui_test_utils::NavigateToURL(browser(), GURL("data:text/html,HelloWorld")); |
| 389 PrintPreview(); | 402 PrintPreview(); |
| 390 WebContents* preview_dialog = GetPrintPreviewDialog(); | 403 WebContents* preview_dialog = GetPrintPreviewDialog(); |
| 391 WaitForAccessibilityTreeToContainNodeWithName(preview_dialog, "HelloWorld"); | 404 WaitForAccessibilityTreeToContainNodeWithName(preview_dialog, "HelloWorld"); |
| 392 } | 405 } |
| 393 | 406 |
| 394 } // namespace | 407 } // namespace |
| 395 | 408 |
| 396 #endif // defined(ENABLE_TASK_MANAGER) | 409 #endif // defined(ENABLE_TASK_MANAGER) |
| OLD | NEW |