| 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 "chrome/browser/renderer_context_menu/render_view_context_menu.h" | 5 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 protected: | 796 protected: |
| 797 void SetupAndLoadImagePage(const std::string& image_path) { | 797 void SetupAndLoadImagePage(const std::string& image_path) { |
| 798 ASSERT_TRUE(embedded_test_server()->Start()); | 798 ASSERT_TRUE(embedded_test_server()->Start()); |
| 799 // Go to a page with an image in it. The test server doesn't serve the image | 799 // Go to a page with an image in it. The test server doesn't serve the image |
| 800 // with the right MIME type, so use a data URL to make a page containing it. | 800 // with the right MIME type, so use a data URL to make a page containing it. |
| 801 GURL image_url(embedded_test_server()->GetURL(image_path)); | 801 GURL image_url(embedded_test_server()->GetURL(image_path)); |
| 802 GURL page("data:text/html,<img src='" + image_url.spec() + "'>"); | 802 GURL page("data:text/html,<img src='" + image_url.spec() + "'>"); |
| 803 ui_test_utils::NavigateToURL(browser(), page); | 803 ui_test_utils::NavigateToURL(browser(), page); |
| 804 } | 804 } |
| 805 | 805 |
| 806 void SetupAndLoadImageMapPage(const std::string& image_path) { |
| 807 ASSERT_TRUE(embedded_test_server()->Start()); |
| 808 GURL image_url(embedded_test_server()->GetURL(image_path)); |
| 809 GURL page("data:text/html,<body style='margin:0px'><a href='http://test/test
.cgi'><img src='" + image_url.spec() + "' ismap></a></body>"); |
| 810 ui_test_utils::NavigateToURL(browser(), page); |
| 811 } |
| 812 |
| 806 void AddLoadImageInterceptor(const std::string& image_path) { | 813 void AddLoadImageInterceptor(const std::string& image_path) { |
| 807 interceptor_ = new LoadImageRequestInterceptor(); | 814 interceptor_ = new LoadImageRequestInterceptor(); |
| 808 scoped_ptr<net::URLRequestInterceptor> owned_interceptor(interceptor_); | 815 scoped_ptr<net::URLRequestInterceptor> owned_interceptor(interceptor_); |
| 809 content::BrowserThread::PostTask( | 816 content::BrowserThread::PostTask( |
| 810 content::BrowserThread::IO, FROM_HERE, | 817 content::BrowserThread::IO, FROM_HERE, |
| 811 base::Bind(&LoadImageBrowserTest::AddInterceptorForURL, | 818 base::Bind(&LoadImageBrowserTest::AddInterceptorForURL, |
| 812 base::Unretained(this), | 819 base::Unretained(this), |
| 813 GURL(embedded_test_server()->GetURL(image_path).spec()), | 820 GURL(embedded_test_server()->GetURL(image_path).spec()), |
| 814 base::Passed(&owned_interceptor))); | 821 base::Passed(&owned_interceptor))); |
| 815 } | 822 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 840 | 847 |
| 841 IN_PROC_BROWSER_TEST_F(LoadImageBrowserTest, LoadImage) { | 848 IN_PROC_BROWSER_TEST_F(LoadImageBrowserTest, LoadImage) { |
| 842 static const char kValidImage[] = "/load_image/image.png"; | 849 static const char kValidImage[] = "/load_image/image.png"; |
| 843 SetupAndLoadImagePage(kValidImage); | 850 SetupAndLoadImagePage(kValidImage); |
| 844 AddLoadImageInterceptor(kValidImage); | 851 AddLoadImageInterceptor(kValidImage); |
| 845 AttemptLoadImage(); | 852 AttemptLoadImage(); |
| 846 interceptor_->WaitForRequests(1); | 853 interceptor_->WaitForRequests(1); |
| 847 EXPECT_EQ(1, interceptor_->num_requests()); | 854 EXPECT_EQ(1, interceptor_->num_requests()); |
| 848 } | 855 } |
| 849 | 856 |
| 857 // Verify that Server-side image map click location with "Open link in new tab" |
| 858 IN_PROC_BROWSER_TEST_F(LoadImageBrowserTest, OpenInNewTabImageMap) { |
| 859 static const char kValidImage[] = "/webui/test_image.png"; |
| 860 ContextMenuNotificationObserver new_tab_observer( |
| 861 IDC_CONTENT_CONTEXT_OPENLINKNEWTAB); |
| 862 ContextMenuNotificationObserver menu_observer( |
| 863 IDC_CONTENT_CONTEXT_LOAD_ORIGINAL_IMAGE); |
| 864 ui_test_utils::WindowedTabAddedNotificationObserver tab_observer( |
| 865 content::NotificationService::AllSources()); |
| 866 |
| 867 // Go to a page with a image map |
| 868 SetupAndLoadImageMapPage(kValidImage); |
| 869 AddLoadImageInterceptor(kValidImage); |
| 870 |
| 871 // Open a context menu. |
| 872 blink::WebMouseEvent mouse_event; |
| 873 mouse_event.type = blink::WebInputEvent::MouseDown; |
| 874 mouse_event.button = blink::WebMouseEvent::ButtonRight; |
| 875 mouse_event.x = 20; |
| 876 mouse_event.y = 20; |
| 877 content::WebContents* tab = |
| 878 browser()->tab_strip_model()->GetActiveWebContents(); |
| 879 gfx::Rect offset = tab->GetContainerBounds(); |
| 880 mouse_event.globalX = 20 + offset.x(); |
| 881 mouse_event.globalY = 20 + offset.y(); |
| 882 mouse_event.clickCount = 1; |
| 883 tab->GetRenderViewHost()->GetWidget()->ForwardMouseEvent(mouse_event); |
| 884 mouse_event.type = blink::WebInputEvent::MouseUp; |
| 885 tab->GetRenderViewHost()->GetWidget()->ForwardMouseEvent(mouse_event); |
| 886 |
| 887 // Wait for Image Context Menu |
| 888 interceptor_->WaitForRequests(1); |
| 889 |
| 890 // The menu_observer will select "Open link in new tab", wait for the new |
| 891 // tab to be added. |
| 892 tab_observer.Wait(); |
| 893 tab = tab_observer.GetTab(); |
| 894 content::WaitForLoadStop(tab); |
| 895 |
| 896 // Verify whether URL include click location or not. |
| 897 EXPECT_EQ(GURL("http://test/test.cgi?20,20"), tab->GetURL()); |
| 898 } |
| 899 |
| 850 } // namespace | 900 } // namespace |
| OLD | NEW |