Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1478)

Side by Side Diff: chrome/browser/download/download_browsertest.cc

Issue 9382037: Move ContextMenuParams struct from webkit/glue to content/public/common. The reasons are: (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix mac Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 #include "content/browser/download/download_file_manager.h" 45 #include "content/browser/download/download_file_manager.h"
46 #include "content/browser/download/download_persistent_store_info.h" 46 #include "content/browser/download/download_persistent_store_info.h"
47 #include "content/browser/net/url_request_mock_http_job.h" 47 #include "content/browser/net/url_request_mock_http_job.h"
48 #include "content/browser/net/url_request_slow_download_job.h" 48 #include "content/browser/net/url_request_slow_download_job.h"
49 #include "content/browser/renderer_host/render_view_host.h" 49 #include "content/browser/renderer_host/render_view_host.h"
50 #include "content/browser/renderer_host/resource_dispatcher_host.h" 50 #include "content/browser/renderer_host/resource_dispatcher_host.h"
51 #include "content/public/browser/download_item.h" 51 #include "content/public/browser/download_item.h"
52 #include "content/public/browser/download_manager.h" 52 #include "content/public/browser/download_manager.h"
53 #include "content/public/browser/notification_source.h" 53 #include "content/public/browser/notification_source.h"
54 #include "content/public/browser/web_contents.h" 54 #include "content/public/browser/web_contents.h"
55 #include "content/public/common/context_menu_params.h"
55 #include "content/public/common/page_transition_types.h" 56 #include "content/public/common/page_transition_types.h"
56 #include "net/base/net_util.h" 57 #include "net/base/net_util.h"
57 #include "testing/gtest/include/gtest/gtest.h" 58 #include "testing/gtest/include/gtest/gtest.h"
58 #include "webkit/glue/context_menu.h"
59 59
60 using content::BrowserThread; 60 using content::BrowserThread;
61 using content::DownloadItem; 61 using content::DownloadItem;
62 using content::DownloadManager; 62 using content::DownloadManager;
63 using content::WebContents; 63 using content::WebContents;
64 64
65 namespace { 65 namespace {
66 66
67 // IDs and paths of CRX files used in tests. 67 // IDs and paths of CRX files used in tests.
68 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; 68 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf";
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 }; 251 };
252 252
253 static DownloadManager* DownloadManagerForBrowser(Browser* browser) { 253 static DownloadManager* DownloadManagerForBrowser(Browser* browser) {
254 return DownloadServiceFactory::GetForProfile(browser->profile()) 254 return DownloadServiceFactory::GetForProfile(browser->profile())
255 ->GetDownloadManager(); 255 ->GetDownloadManager();
256 } 256 }
257 257
258 class TestRenderViewContextMenu : public RenderViewContextMenu { 258 class TestRenderViewContextMenu : public RenderViewContextMenu {
259 public: 259 public:
260 TestRenderViewContextMenu(WebContents* web_contents, 260 TestRenderViewContextMenu(WebContents* web_contents,
261 const ContextMenuParams& params) 261 const content::ContextMenuParams& params)
262 : RenderViewContextMenu(web_contents, params) { 262 : RenderViewContextMenu(web_contents, params) {
263 } 263 }
264 virtual ~TestRenderViewContextMenu() {} 264 virtual ~TestRenderViewContextMenu() {}
265 265
266 private: 266 private:
267 virtual void PlatformInit() {} 267 virtual void PlatformInit() {}
268 virtual bool GetAcceleratorForCommandId(int, ui::Accelerator*) { 268 virtual bool GetAcceleratorForCommandId(int, ui::Accelerator*) {
269 return false; 269 return false;
270 } 270 }
271 271
(...skipping 1522 matching lines...) Expand 10 before | Expand all | Expand 10 after
1794 GetDownloads(browser(), &download_items); 1794 GetDownloads(browser(), &download_items);
1795 EXPECT_TRUE(waiter->select_file_dialog_seen()); 1795 EXPECT_TRUE(waiter->select_file_dialog_seen());
1796 ASSERT_EQ(1u, download_items.size()); 1796 ASSERT_EQ(1u, download_items.size());
1797 ASSERT_EQ(url, download_items[0]->GetOriginalUrl()); 1797 ASSERT_EQ(url, download_items[0]->GetOriginalUrl());
1798 1798
1799 // Try to download it via a context menu. 1799 // Try to download it via a context menu.
1800 scoped_ptr<DownloadTestObserver> waiter_context_menu( 1800 scoped_ptr<DownloadTestObserver> waiter_context_menu(
1801 new DownloadTestObserver( 1801 new DownloadTestObserver(
1802 DownloadManagerForBrowser(browser()), 1, DownloadItem::COMPLETE, 1802 DownloadManagerForBrowser(browser()), 1, DownloadItem::COMPLETE,
1803 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 1803 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
1804 ContextMenuParams context_menu_params; 1804 content::ContextMenuParams context_menu_params;
1805 context_menu_params.media_type = WebKit::WebContextMenuData::MediaTypeImage; 1805 context_menu_params.media_type = WebKit::WebContextMenuData::MediaTypeImage;
1806 context_menu_params.src_url = url; 1806 context_menu_params.src_url = url;
1807 context_menu_params.page_url = url; 1807 context_menu_params.page_url = url;
1808 TestRenderViewContextMenu menu(browser()->GetSelectedWebContents(), 1808 TestRenderViewContextMenu menu(browser()->GetSelectedWebContents(),
1809 context_menu_params); 1809 context_menu_params);
1810 menu.Init(); 1810 menu.Init();
1811 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS); 1811 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS);
1812 waiter_context_menu->WaitForFinished(); 1812 waiter_context_menu->WaitForFinished();
1813 1813
1814 // Validate that the correct file was downloaded via the context menu. 1814 // Validate that the correct file was downloaded via the context menu.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1869 GetDownloads(browser(), &download_items); 1869 GetDownloads(browser(), &download_items);
1870 EXPECT_TRUE(waiter->select_file_dialog_seen()); 1870 EXPECT_TRUE(waiter->select_file_dialog_seen());
1871 ASSERT_EQ(1u, download_items.size()); 1871 ASSERT_EQ(1u, download_items.size());
1872 ASSERT_EQ(jpeg_url, download_items[0]->GetOriginalUrl()); 1872 ASSERT_EQ(jpeg_url, download_items[0]->GetOriginalUrl());
1873 1873
1874 // Try to download it via a context menu. 1874 // Try to download it via a context menu.
1875 scoped_ptr<DownloadTestObserver> waiter_context_menu( 1875 scoped_ptr<DownloadTestObserver> waiter_context_menu(
1876 new DownloadTestObserver( 1876 new DownloadTestObserver(
1877 DownloadManagerForBrowser(browser()), 1, DownloadItem::COMPLETE, 1877 DownloadManagerForBrowser(browser()), 1, DownloadItem::COMPLETE,
1878 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 1878 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
1879 ContextMenuParams context_menu_params; 1879 content::ContextMenuParams context_menu_params;
1880 context_menu_params.media_type = WebKit::WebContextMenuData::MediaTypeImage; 1880 context_menu_params.media_type = WebKit::WebContextMenuData::MediaTypeImage;
1881 context_menu_params.src_url = jpeg_url; 1881 context_menu_params.src_url = jpeg_url;
1882 context_menu_params.page_url = jpeg_url; 1882 context_menu_params.page_url = jpeg_url;
1883 TestRenderViewContextMenu menu(web_contents, context_menu_params); 1883 TestRenderViewContextMenu menu(web_contents, context_menu_params);
1884 menu.Init(); 1884 menu.Init();
1885 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS); 1885 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS);
1886 waiter_context_menu->WaitForFinished(); 1886 waiter_context_menu->WaitForFinished();
1887 1887
1888 // Validate that the correct file was downloaded via the context menu. 1888 // Validate that the correct file was downloaded via the context menu.
1889 download_items.clear(); 1889 download_items.clear();
1890 GetDownloads(browser(), &download_items); 1890 GetDownloads(browser(), &download_items);
1891 EXPECT_TRUE(waiter_context_menu->select_file_dialog_seen()); 1891 EXPECT_TRUE(waiter_context_menu->select_file_dialog_seen());
1892 ASSERT_EQ(2u, download_items.size()); 1892 ASSERT_EQ(2u, download_items.size());
1893 ASSERT_EQ(jpeg_url, download_items[0]->GetOriginalUrl()); 1893 ASSERT_EQ(jpeg_url, download_items[0]->GetOriginalUrl());
1894 ASSERT_EQ(jpeg_url, download_items[1]->GetOriginalUrl()); 1894 ASSERT_EQ(jpeg_url, download_items[1]->GetOriginalUrl());
1895 } 1895 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698