Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/base_paths.h" | 7 #include "base/base_paths.h" |
| 8 #include "base/files/file_enumerator.h" | 8 #include "base/files/file_enumerator.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/hash.h" | 10 #include "base/hash.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "chrome/browser/chrome_notification_types.h" | 15 #include "chrome/browser/chrome_notification_types.h" |
| 16 #include "chrome/browser/extensions/component_loader.h" | 16 #include "chrome/browser/extensions/component_loader.h" |
| 17 #include "chrome/browser/extensions/extension_apitest.h" | 17 #include "chrome/browser/extensions/extension_apitest.h" |
| 18 #include "chrome/browser/extensions/extension_service.h" | 18 #include "chrome/browser/extensions/extension_service.h" |
| 19 #include "chrome/browser/pdf/pdf_extension_test_util.h" | 19 #include "chrome/browser/pdf/pdf_extension_test_util.h" |
| 20 #include "chrome/browser/pdf/pdf_extension_util.h" | 20 #include "chrome/browser/pdf/pdf_extension_util.h" |
| 21 #include "chrome/browser/plugins/plugin_prefs.h" | 21 #include "chrome/browser/plugins/plugin_prefs.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/browser/ui/browser.h" | 23 #include "chrome/browser/ui/browser.h" |
| 24 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 24 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 25 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" | |
| 26 #include "chrome/common/chrome_content_client.h" | 25 #include "chrome/common/chrome_content_client.h" |
| 27 #include "chrome/common/chrome_paths.h" | 26 #include "chrome/common/chrome_paths.h" |
| 28 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
| 29 #include "chrome/test/base/ui_test_utils.h" | 28 #include "chrome/test/base/ui_test_utils.h" |
| 30 #include "components/ui/zoom/page_zoom.h" | 29 #include "components/ui/zoom/page_zoom.h" |
| 30 #include "components/ui/zoom/test/zoom_test_utils.h" | |
| 31 #include "components/ui/zoom/zoom_controller.h" | 31 #include "components/ui/zoom/zoom_controller.h" |
| 32 #include "components/ui/zoom/zoom_test_utils.h" | |
| 33 #include "content/public/browser/browser_plugin_guest_manager.h" | 32 #include "content/public/browser/browser_plugin_guest_manager.h" |
| 34 #include "content/public/browser/download_item.h" | 33 #include "content/public/browser/download_item.h" |
| 35 #include "content/public/browser/download_manager.h" | 34 #include "content/public/browser/download_manager.h" |
| 36 #include "content/public/browser/notification_observer.h" | 35 #include "content/public/browser/notification_observer.h" |
| 37 #include "content/public/browser/notification_registrar.h" | 36 #include "content/public/browser/notification_registrar.h" |
| 38 #include "content/public/browser/plugin_service.h" | 37 #include "content/public/browser/plugin_service.h" |
| 39 #include "content/public/browser/render_process_host.h" | 38 #include "content/public/browser/render_process_host.h" |
| 40 #include "content/public/browser/render_view_host.h" | 39 #include "content/public/browser/render_view_host.h" |
| 41 #include "content/public/browser/render_widget_host.h" | 40 #include "content/public/browser/render_widget_host.h" |
| 42 #include "content/public/browser/web_contents.h" | 41 #include "content/public/browser/web_contents.h" |
| 43 #include "content/public/test/browser_test_utils.h" | 42 #include "content/public/test/browser_test_utils.h" |
| 44 #include "extensions/browser/extension_registry.h" | 43 #include "extensions/browser/extension_registry.h" |
| 45 #include "extensions/common/manifest_handlers/mime_types_handler.h" | 44 #include "extensions/common/manifest_handlers/mime_types_handler.h" |
| 46 #include "extensions/test/result_catcher.h" | 45 #include "extensions/test/result_catcher.h" |
| 47 #include "net/test/embedded_test_server/embedded_test_server.h" | 46 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 48 #include "ui/base/resource/resource_bundle.h" | 47 #include "ui/base/resource/resource_bundle.h" |
| 49 #include "url/gurl.h" | 48 #include "url/gurl.h" |
| 50 | 49 |
| 50 #if defined(TOOLKIT_VIEWS) | |
|
Lei Zhang
2015/10/29 16:40:33
I'd do this for now: #if defined(TOOLKIT_VIEWS) &&
| |
| 51 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" | |
| 52 #endif | |
| 53 | |
| 51 const int kNumberLoadTestParts = 10; | 54 const int kNumberLoadTestParts = 10; |
| 52 | 55 |
| 53 bool GetGuestCallback(content::WebContents** guest_out, | 56 bool GetGuestCallback(content::WebContents** guest_out, |
| 54 content::WebContents* guest) { | 57 content::WebContents* guest) { |
| 55 EXPECT_FALSE(*guest_out); | 58 EXPECT_FALSE(*guest_out); |
| 56 *guest_out = guest; | 59 *guest_out = guest; |
| 57 // Return false so that we iterate through all the guests and verify there is | 60 // Return false so that we iterate through all the guests and verify there is |
| 58 // only one. | 61 // only one. |
| 59 return false; | 62 return false; |
| 60 } | 63 } |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 411 GURL unfiltered_valid_link_url(valid_link_url); | 414 GURL unfiltered_valid_link_url(valid_link_url); |
| 412 content::RenderProcessHost* rph = guest_contents->GetRenderProcessHost(); | 415 content::RenderProcessHost* rph = guest_contents->GetRenderProcessHost(); |
| 413 rph->FilterURL(true, &valid_link_url); | 416 rph->FilterURL(true, &valid_link_url); |
| 414 rph->FilterURL(true, &invalid_link_url); | 417 rph->FilterURL(true, &invalid_link_url); |
| 415 | 418 |
| 416 // Invalid link URLs should be changed to "about:blank" when filtered. | 419 // Invalid link URLs should be changed to "about:blank" when filtered. |
| 417 EXPECT_EQ(unfiltered_valid_link_url, valid_link_url); | 420 EXPECT_EQ(unfiltered_valid_link_url, valid_link_url); |
| 418 EXPECT_EQ(GURL("about:blank"), invalid_link_url); | 421 EXPECT_EQ(GURL("about:blank"), invalid_link_url); |
| 419 } | 422 } |
| 420 | 423 |
| 421 #if !defined(OS_MACOSX) | |
| 422 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, PdfZoomWithoutBubble) { | 424 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, PdfZoomWithoutBubble) { |
| 423 using namespace ui_zoom; | 425 using namespace ui_zoom; |
| 424 | 426 |
| 425 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test.pdf")); | 427 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test.pdf")); |
| 426 content::WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url); | 428 content::WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url); |
| 427 ASSERT_TRUE(guest_contents); | 429 ASSERT_TRUE(guest_contents); |
| 428 content::WebContents* web_contents = | 430 content::WebContents* web_contents = |
| 429 browser()->tab_strip_model()->GetActiveWebContents(); | 431 browser()->tab_strip_model()->GetActiveWebContents(); |
| 430 | 432 |
| 431 // The PDF viewer always starts at default zoom, which for tests is 100% or | 433 // The PDF viewer always starts at default zoom, which for tests is 100% or |
| 432 // zoom level 0.0. Here we look at the presets to find the next zoom level | 434 // zoom level 0.0. Here we look at the presets to find the next zoom level |
| 433 // above 0. Ideally we should look at the zoom levels from the PDF viewer | 435 // above 0. Ideally we should look at the zoom levels from the PDF viewer |
| 434 // javascript, but we assume they'll always match the browser presets, which | 436 // javascript, but we assume they'll always match the browser presets, which |
| 435 // are easier to access. | 437 // are easier to access. |
| 436 std::vector<double> preset_zoom_levels = PageZoom::PresetZoomLevels(0.0); | 438 std::vector<double> preset_zoom_levels = PageZoom::PresetZoomLevels(0.0); |
| 437 std::vector<double>::iterator it = | 439 std::vector<double>::iterator it = |
| 438 find(preset_zoom_levels.begin(), preset_zoom_levels.end(), 0.0); | 440 std::find(preset_zoom_levels.begin(), preset_zoom_levels.end(), 0.0); |
| 439 ASSERT_TRUE(it != preset_zoom_levels.end()); | 441 ASSERT_TRUE(it != preset_zoom_levels.end()); |
| 440 it++; | 442 it++; |
| 441 ASSERT_TRUE(it != preset_zoom_levels.end()); | 443 ASSERT_TRUE(it != preset_zoom_levels.end()); |
| 442 double new_zoom_level = *it; | 444 double new_zoom_level = *it; |
| 443 | 445 |
| 444 auto zoom_controller = ZoomController::FromWebContents(web_contents); | 446 auto zoom_controller = ZoomController::FromWebContents(web_contents); |
| 447 // We expect a ZoomChangedEvent with can_show_bubble == false if the PDF | |
| 448 // extension behaviour is properly picked up. The test times out otherwise. | |
| 445 ZoomChangedWatcher watcher(zoom_controller, | 449 ZoomChangedWatcher watcher(zoom_controller, |
| 446 ZoomController::ZoomChangedEventData( | 450 ZoomController::ZoomChangedEventData( |
| 447 web_contents, 0.f, new_zoom_level, | 451 web_contents, 0.f, new_zoom_level, |
| 448 ZoomController::ZOOM_MODE_MANUAL, true)); | 452 ZoomController::ZOOM_MODE_MANUAL, false)); |
| 449 | 453 |
| 450 // Zoom PDF via script. | 454 // Zoom PDF via script. |
| 455 #if defined(TOOLKIT_VIEWS) | |
| 451 EXPECT_EQ(nullptr, ZoomBubbleView::GetZoomBubble()); | 456 EXPECT_EQ(nullptr, ZoomBubbleView::GetZoomBubble()); |
| 457 #endif | |
| 452 ASSERT_TRUE( | 458 ASSERT_TRUE( |
| 453 content::ExecuteScript(guest_contents, "viewer.viewport.zoomIn();")); | 459 content::ExecuteScript(guest_contents, "viewer.viewport.zoomIn();")); |
| 454 | 460 |
| 455 watcher.Wait(); | 461 watcher.Wait(); |
| 462 #if defined(TOOLKIT_VIEWS) | |
| 456 EXPECT_EQ(nullptr, ZoomBubbleView::GetZoomBubble()); | 463 EXPECT_EQ(nullptr, ZoomBubbleView::GetZoomBubble()); |
| 464 #endif | |
| 457 } | 465 } |
| 458 #endif | |
| 459 | 466 |
| 460 class MaterialPDFExtensionTest : public PDFExtensionTest { | 467 class MaterialPDFExtensionTest : public PDFExtensionTest { |
| 461 void SetUpCommandLine(base::CommandLine* command_line) override { | 468 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 462 command_line->AppendSwitch(switches::kEnablePdfMaterialUI); | 469 command_line->AppendSwitch(switches::kEnablePdfMaterialUI); |
| 463 } | 470 } |
| 464 }; | 471 }; |
| 465 | 472 |
| 466 IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, Basic) { | 473 IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, Basic) { |
| 467 RunTestsInFile("basic_test_material.js", "test.pdf"); | 474 RunTestsInFile("basic_test_material.js", "test.pdf"); |
| 468 } | 475 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 505 RunTestsInFile("title_test.js", "test-title.pdf"); | 512 RunTestsInFile("title_test.js", "test-title.pdf"); |
| 506 } | 513 } |
| 507 | 514 |
| 508 IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, WhitespaceTitle) { | 515 IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, WhitespaceTitle) { |
| 509 RunTestsInFile("whitespace_title_test.js", "test-whitespace-title.pdf"); | 516 RunTestsInFile("whitespace_title_test.js", "test-whitespace-title.pdf"); |
| 510 } | 517 } |
| 511 | 518 |
| 512 IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, PageChange) { | 519 IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, PageChange) { |
| 513 RunTestsInFile("page_change_test.js", "test-bookmarks.pdf"); | 520 RunTestsInFile("page_change_test.js", "test-bookmarks.pdf"); |
| 514 } | 521 } |
| OLD | NEW |