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 "base/message_loop/message_loop_proxy.h" | 7 #include "base/message_loop/message_loop_proxy.h" |
8 #include "base/prefs/pref_registry_simple.h" | 8 #include "base/prefs/pref_registry_simple.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "chrome/app/chrome_command_ids.h" | 12 #include "chrome/app/chrome_command_ids.h" |
13 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 13 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
14 #include "chrome/browser/extensions/menu_manager.h" | 14 #include "chrome/browser/extensions/menu_manager.h" |
15 #include "chrome/browser/extensions/menu_manager_factory.h" | 15 #include "chrome/browser/extensions/menu_manager_factory.h" |
16 #include "chrome/browser/extensions/test_extension_environment.h" | 16 #include "chrome/browser/extensions/test_extension_environment.h" |
17 #include "chrome/browser/extensions/test_extension_prefs.h" | 17 #include "chrome/browser/extensions/test_extension_prefs.h" |
18 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" | 18 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" |
19 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact
ory.h" | 19 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact
ory.h" |
20 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 20 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
21 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti
l.h" | 21 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti
l.h" |
22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
23 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 23 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
24 #include "chrome/test/base/testing_profile.h" | 24 #include "chrome/test/base/testing_profile.h" |
25 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test
_utils.h" | 25 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test
_utils.h" |
| 26 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade
rs.h" |
26 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param
s.h" | 27 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param
s.h" |
27 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_
names.h" | 28 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_
names.h" |
28 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
29 #include "content/public/test/web_contents_tester.h" | 30 #include "content/public/test/web_contents_tester.h" |
30 | 31 |
31 #include "extensions/browser/extension_prefs.h" | 32 #include "extensions/browser/extension_prefs.h" |
32 #include "extensions/common/url_pattern.h" | 33 #include "extensions/common/url_pattern.h" |
33 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
34 #include "third_party/WebKit/public/web/WebContextMenuData.h" | 35 #include "third_party/WebKit/public/web/WebContextMenuData.h" |
35 #include "url/gurl.h" | 36 #include "url/gurl.h" |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 content::WebContents* wc = web_contents(); | 350 content::WebContents* wc = web_contents(); |
350 TestRenderViewContextMenu* menu = new TestRenderViewContextMenu( | 351 TestRenderViewContextMenu* menu = new TestRenderViewContextMenu( |
351 wc->GetMainFrame(), params); | 352 wc->GetMainFrame(), params); |
352 // TestingProfile (returned by profile()) does not provide a protocol | 353 // TestingProfile (returned by profile()) does not provide a protocol |
353 // registry. | 354 // registry. |
354 menu->protocol_handler_registry_ = registry_.get(); | 355 menu->protocol_handler_registry_ = registry_.get(); |
355 menu->Init(); | 356 menu->Init(); |
356 return menu; | 357 return menu; |
357 } | 358 } |
358 | 359 |
| 360 void AppendImageItems(TestRenderViewContextMenu* menu) { |
| 361 menu->AppendImageItems(); |
| 362 } |
| 363 |
359 void SetupDataReductionProxy(bool enable_data_reduction_proxy) { | 364 void SetupDataReductionProxy(bool enable_data_reduction_proxy) { |
360 drp_test_context_ = | 365 drp_test_context_ = |
361 data_reduction_proxy::DataReductionProxyTestContext::Builder() | 366 data_reduction_proxy::DataReductionProxyTestContext::Builder() |
362 .WithParamsFlags( | 367 .WithParamsFlags( |
363 data_reduction_proxy::DataReductionProxyParams::kAllowed | | 368 data_reduction_proxy::DataReductionProxyParams::kAllowed | |
364 data_reduction_proxy::DataReductionProxyParams:: | 369 data_reduction_proxy::DataReductionProxyParams:: |
365 kFallbackAllowed | | 370 kFallbackAllowed | |
366 data_reduction_proxy::DataReductionProxyParams::kPromoAllowed) | 371 data_reduction_proxy::DataReductionProxyParams::kPromoAllowed) |
367 .WithMockConfig() | 372 .WithMockConfig() |
368 .SkipSettingsInitialization() | 373 .SkipSettingsInitialization() |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 new TestRenderViewContextMenu(wc->GetMainFrame(), params)); | 465 new TestRenderViewContextMenu(wc->GetMainFrame(), params)); |
461 | 466 |
462 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS, 0); | 467 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS, 0); |
463 | 468 |
464 const std::string& headers = | 469 const std::string& headers = |
465 content::WebContentsTester::For(web_contents())->GetSaveFrameHeaders(); | 470 content::WebContentsTester::For(web_contents())->GetSaveFrameHeaders(); |
466 EXPECT_TRUE(headers.find("X-PSA-Client-Options: v=1,m=1") == | 471 EXPECT_TRUE(headers.find("X-PSA-Client-Options: v=1,m=1") == |
467 std::string::npos && | 472 std::string::npos && |
468 headers.find("Cache-Control: no-cache") == std::string::npos); | 473 headers.find("Cache-Control: no-cache") == std::string::npos); |
469 } | 474 } |
| 475 |
| 476 // Verify that the Chrome-Proxy Lo-Fi directive causes the context menu to |
| 477 // display the reload original image menu item. |
| 478 TEST_F(RenderViewContextMenuPrefsTest, DataSaverLoadImage) { |
| 479 SetupDataReductionProxy(true); |
| 480 content::ContextMenuParams params = CreateParams(MenuItem::IMAGE); |
| 481 params.properties[data_reduction_proxy::kChromeProxyHeader] = |
| 482 data_reduction_proxy::kChromeProxyLoFiDirective; |
| 483 params.unfiltered_link_url = params.link_url; |
| 484 content::WebContents* wc = web_contents(); |
| 485 scoped_ptr<TestRenderViewContextMenu> menu( |
| 486 new TestRenderViewContextMenu(wc->GetMainFrame(), params)); |
| 487 AppendImageItems(menu.get()); |
| 488 |
| 489 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_RELOAD_ORIGINAL_IMAGE)); |
| 490 } |
OLD | NEW |