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/prefs/pref_registry_simple.h" | |
7 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/run_loop.h" | |
8 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/app/chrome_command_ids.h" | 11 #include "chrome/app/chrome_command_ids.h" |
10 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 12 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
11 #include "chrome/browser/extensions/menu_manager.h" | 13 #include "chrome/browser/extensions/menu_manager.h" |
12 #include "chrome/browser/extensions/menu_manager_factory.h" | 14 #include "chrome/browser/extensions/menu_manager_factory.h" |
13 #include "chrome/browser/extensions/test_extension_environment.h" | 15 #include "chrome/browser/extensions/test_extension_environment.h" |
14 #include "chrome/browser/extensions/test_extension_prefs.h" | 16 #include "chrome/browser/extensions/test_extension_prefs.h" |
17 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" | |
18 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact ory.h" | |
15 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 19 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
16 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h" | 20 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h" |
21 #include "chrome/common/pref_names.h" | |
17 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 22 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
18 #include "chrome/test/base/testing_profile.h" | 23 #include "chrome/test/base/testing_profile.h" |
24 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test _utils.h" | |
25 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h" | |
26 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_ names.h" | |
19 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
28 #include "content/public/test/web_contents_tester.h" | |
29 | |
20 #include "extensions/browser/extension_prefs.h" | 30 #include "extensions/browser/extension_prefs.h" |
21 #include "extensions/common/url_pattern.h" | 31 #include "extensions/common/url_pattern.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
23 #include "third_party/WebKit/public/web/WebContextMenuData.h" | 33 #include "third_party/WebKit/public/web/WebContextMenuData.h" |
24 #include "url/gurl.h" | 34 #include "url/gurl.h" |
25 | 35 |
26 using extensions::Extension; | 36 using extensions::Extension; |
27 using extensions::MenuItem; | 37 using extensions::MenuItem; |
28 using extensions::MenuManager; | 38 using extensions::MenuManager; |
29 using extensions::MenuManagerFactory; | 39 using extensions::MenuManagerFactory; |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
338 content::WebContents* wc = web_contents(); | 348 content::WebContents* wc = web_contents(); |
339 TestRenderViewContextMenu* menu = new TestRenderViewContextMenu( | 349 TestRenderViewContextMenu* menu = new TestRenderViewContextMenu( |
340 wc->GetMainFrame(), params); | 350 wc->GetMainFrame(), params); |
341 // TestingProfile (returned by profile()) does not provide a protocol | 351 // TestingProfile (returned by profile()) does not provide a protocol |
342 // registry. | 352 // registry. |
343 menu->protocol_handler_registry_ = registry_.get(); | 353 menu->protocol_handler_registry_ = registry_.get(); |
344 menu->Init(); | 354 menu->Init(); |
345 return menu; | 355 return menu; |
346 } | 356 } |
347 | 357 |
358 void SetupDataReductionProxy(bool enable_data_reduction_proxy) { | |
359 drp_test_context_ = | |
360 data_reduction_proxy::DataReductionProxyTestContext::Builder() | |
361 .WithParamsFlags( | |
362 data_reduction_proxy::DataReductionProxyParams::kAllowed | | |
363 data_reduction_proxy::DataReductionProxyParams:: | |
364 kFallbackAllowed | | |
365 data_reduction_proxy::DataReductionProxyParams::kPromoAllowed) | |
366 .WithMockConfig() | |
367 .SkipSettingsInitialization() | |
368 .Build(); | |
369 | |
370 DataReductionProxyChromeSettings* settings = | |
371 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | |
372 profile()); | |
373 | |
374 // TODO(bengr): Remove prefs::kProxy registration after M46. See | |
375 // http://crbug.com/445599. | |
376 PrefRegistrySimple* registry = | |
377 drp_test_context_->pref_service()->registry(); | |
378 registry->RegisterDictionaryPref(prefs::kProxy); | |
379 | |
380 drp_test_context_->pref_service()->SetBoolean( | |
381 data_reduction_proxy::prefs::kDataReductionProxyEnabled, | |
382 enable_data_reduction_proxy); | |
383 drp_test_context_->InitSettings(); | |
384 data_reduction_proxy::DataReductionProxyIOData* io_data = | |
bengr
2015/05/13 17:35:47
No need for this temporary.
Not at Google. Contact bengr
2015/05/13 20:24:09
Done.
| |
385 drp_test_context_->io_data(); | |
386 | |
387 settings->InitDataReductionProxySettings( | |
388 io_data, drp_test_context_->pref_service(), | |
389 drp_test_context_->request_context_getter(), | |
390 base::MessageLoopProxy::current()); | |
bengr
2015/05/13 17:35:47
#include "base/message_loop/message_loop_proxy.h"
Not at Google. Contact bengr
2015/05/13 20:24:09
Done.
| |
391 } | |
392 | |
393 protected: | |
394 scoped_ptr<data_reduction_proxy::DataReductionProxyTestContext> | |
395 drp_test_context_; | |
396 | |
348 private: | 397 private: |
349 scoped_ptr<ProtocolHandlerRegistry> registry_; | 398 scoped_ptr<ProtocolHandlerRegistry> registry_; |
350 }; | 399 }; |
351 | 400 |
352 // Verifies when Incognito Mode is not available (disabled by policy), | 401 // Verifies when Incognito Mode is not available (disabled by policy), |
353 // Open Link in Incognito Window link in the context menu is disabled. | 402 // Open Link in Incognito Window link in the context menu is disabled. |
354 TEST_F(RenderViewContextMenuPrefsTest, | 403 TEST_F(RenderViewContextMenuPrefsTest, |
355 DisableOpenInIncognitoWindowWhenIncognitoIsDisabled) { | 404 DisableOpenInIncognitoWindowWhenIncognitoIsDisabled) { |
356 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenu()); | 405 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenu()); |
357 | 406 |
(...skipping 13 matching lines...) Expand all Loading... | |
371 } | 420 } |
372 | 421 |
373 // Make sure the checking custom command id that is not enabled will not | 422 // Make sure the checking custom command id that is not enabled will not |
374 // cause DCHECK failure. | 423 // cause DCHECK failure. |
375 TEST_F(RenderViewContextMenuPrefsTest, | 424 TEST_F(RenderViewContextMenuPrefsTest, |
376 IsCustomCommandIdEnabled) { | 425 IsCustomCommandIdEnabled) { |
377 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenu()); | 426 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenu()); |
378 | 427 |
379 EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_CUSTOM_FIRST)); | 428 EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_CUSTOM_FIRST)); |
380 } | 429 } |
430 | |
431 // Verify that request headers specify that data reduction proxy should return | |
432 // the original non compressed resource when "Save Image As..." is used with | |
433 // Data Saver enabled. | |
434 TEST_F(RenderViewContextMenuPrefsTest, DataSaverEnabledSaveImageAs) { | |
435 SetupDataReductionProxy(true); | |
436 | |
437 content::ContextMenuParams params = CreateParams(MenuItem::IMAGE); | |
438 params.unfiltered_link_url = params.link_url; | |
439 content::WebContents* wc = web_contents(); | |
440 TestRenderViewContextMenu* menu = | |
441 new TestRenderViewContextMenu(wc->GetMainFrame(), params); | |
442 | |
443 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS, 0); | |
444 | |
445 const std::string& headers = | |
446 content::WebContentsTester::For(web_contents())->GetSaveFrameHeaders(); | |
447 EXPECT_TRUE(headers.find("X-PSA-Client-Options: v=1,m=1") != | |
448 std::string::npos && | |
449 headers.find("Cache-Control: no-cache") != std::string::npos); | |
450 } | |
451 | |
452 // Verify that request headers do not specify pass through when "Save Image | |
453 // As..." is used with Data Saver disabled. | |
454 TEST_F(RenderViewContextMenuPrefsTest, DataSaverDisabledSaveImageAs) { | |
455 SetupDataReductionProxy(false); | |
456 | |
457 content::ContextMenuParams params = CreateParams(MenuItem::IMAGE); | |
458 params.unfiltered_link_url = params.link_url; | |
459 content::WebContents* wc = web_contents(); | |
460 TestRenderViewContextMenu* menu = | |
461 new TestRenderViewContextMenu(wc->GetMainFrame(), params); | |
462 | |
463 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS, 0); | |
464 | |
465 const std::string& headers = | |
466 content::WebContentsTester::For(web_contents())->GetSaveFrameHeaders(); | |
467 EXPECT_TRUE(headers.find("X-PSA-Client-Options: v=1,m=1") == | |
468 std::string::npos && | |
469 headers.find("Cache-Control: no-cache") == std::string::npos); | |
470 } | |
OLD | NEW |