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 protected: | |
359 scoped_ptr<data_reduction_proxy::DataReductionProxyTestContext> | |
360 drp_test_context_; | |
361 | |
348 private: | 362 private: |
349 scoped_ptr<ProtocolHandlerRegistry> registry_; | 363 scoped_ptr<ProtocolHandlerRegistry> registry_; |
350 }; | 364 }; |
351 | 365 |
352 // Verifies when Incognito Mode is not available (disabled by policy), | 366 // Verifies when Incognito Mode is not available (disabled by policy), |
353 // Open Link in Incognito Window link in the context menu is disabled. | 367 // Open Link in Incognito Window link in the context menu is disabled. |
354 TEST_F(RenderViewContextMenuPrefsTest, | 368 TEST_F(RenderViewContextMenuPrefsTest, |
355 DisableOpenInIncognitoWindowWhenIncognitoIsDisabled) { | 369 DisableOpenInIncognitoWindowWhenIncognitoIsDisabled) { |
356 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenu()); | 370 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenu()); |
357 | 371 |
(...skipping 13 matching lines...) Expand all Loading... | |
371 } | 385 } |
372 | 386 |
373 // Make sure the checking custom command id that is not enabled will not | 387 // Make sure the checking custom command id that is not enabled will not |
374 // cause DCHECK failure. | 388 // cause DCHECK failure. |
375 TEST_F(RenderViewContextMenuPrefsTest, | 389 TEST_F(RenderViewContextMenuPrefsTest, |
376 IsCustomCommandIdEnabled) { | 390 IsCustomCommandIdEnabled) { |
377 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenu()); | 391 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenu()); |
378 | 392 |
379 EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_CUSTOM_FIRST)); | 393 EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_CUSTOM_FIRST)); |
380 } | 394 } |
395 | |
396 // Verify that request headers specify that data reduction proxy should return | |
397 // the original non compressed resource when "Save Image As..." is used with | |
398 // Data Saver enabled. | |
399 TEST_F(RenderViewContextMenuPrefsTest, DataSaverEnabledSaveImageAs) { | |
400 drp_test_context_ = | |
401 data_reduction_proxy::DataReductionProxyTestContext::Builder() | |
402 .WithParamsFlags( | |
403 data_reduction_proxy::DataReductionProxyParams::kAllowed | | |
404 data_reduction_proxy::DataReductionProxyParams:: | |
405 kFallbackAllowed | | |
406 data_reduction_proxy::DataReductionProxyParams::kPromoAllowed) | |
407 .WithMockConfig() | |
408 .SkipSettingsInitialization() | |
409 .Build(); | |
410 | |
411 DataReductionProxyChromeSettings* settings = | |
412 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(profile()); | |
413 | |
414 // TODO(bengr): Remove prefs::kProxy registration after M46. See | |
415 // http://crbug.com/445599. | |
416 PrefRegistrySimple* registry = drp_test_context_->pref_service()->registry(); | |
417 registry->RegisterDictionaryPref(prefs::kProxy); | |
418 | |
419 drp_test_context_->pref_service()->SetBoolean( | |
420 data_reduction_proxy::prefs::kDataReductionProxyEnabled, true); | |
421 drp_test_context_->InitSettings(); | |
422 data_reduction_proxy::DataReductionProxyIOData* io_data = | |
423 drp_test_context_->io_data(); | |
424 | |
425 settings->InitDataReductionProxySettings( | |
426 io_data, drp_test_context_->pref_service(), | |
427 drp_test_context_->request_context_getter(), | |
428 base::MessageLoopProxy::current()); | |
429 | |
430 content::ContextMenuParams params = CreateParams(MenuItem::IMAGE); | |
431 params.unfiltered_link_url = params.link_url; | |
432 content::WebContents* wc = web_contents(); | |
433 TestRenderViewContextMenu* menu = | |
434 new TestRenderViewContextMenu(wc->GetMainFrame(), params); | |
435 | |
436 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS, 0); | |
437 | |
438 const std::string& headers = | |
439 content::WebContentsTester::For(web_contents())->GetSaveFrameHeaders(); | |
440 EXPECT_TRUE(headers.find("X-PSA-Client-Options: v=1,m=1") != | |
441 std::string::npos && | |
442 headers.find("Cache-Control: no-cache") != std::string::npos); | |
443 } | |
444 | |
445 // Verify that request headers do not specify pass through when "Save Image | |
446 // As..." is used with Data Saver disabled. | |
447 TEST_F(RenderViewContextMenuPrefsTest, DataSaverDisabledSaveImageAs) { | |
448 drp_test_context_ = | |
449 data_reduction_proxy::DataReductionProxyTestContext::Builder() | |
450 .WithParamsFlags( | |
451 data_reduction_proxy::DataReductionProxyParams::kAllowed | | |
452 data_reduction_proxy::DataReductionProxyParams:: | |
453 kFallbackAllowed | | |
454 data_reduction_proxy::DataReductionProxyParams::kPromoAllowed) | |
455 .WithMockConfig() | |
456 .SkipSettingsInitialization() | |
457 .Build(); | |
Avi (use Gerrit)
2015/05/11 20:52:29
Can you abstract some of this duplicate code out t
Not at Google. Contact bengr
2015/05/11 22:43:14
Done.
| |
458 | |
459 DataReductionProxyChromeSettings* settings = | |
460 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(profile()); | |
461 | |
462 // TODO(bengr): Remove prefs::kProxy registration after M46. See | |
463 // http://crbug.com/445599. | |
464 PrefRegistrySimple* registry = drp_test_context_->pref_service()->registry(); | |
465 registry->RegisterDictionaryPref(prefs::kProxy); | |
466 | |
467 drp_test_context_->pref_service()->SetBoolean( | |
468 data_reduction_proxy::prefs::kDataReductionProxyEnabled, false); | |
469 drp_test_context_->InitSettings(); | |
470 data_reduction_proxy::DataReductionProxyIOData* io_data = | |
471 drp_test_context_->io_data(); | |
472 | |
473 settings->InitDataReductionProxySettings( | |
474 io_data, drp_test_context_->pref_service(), | |
475 drp_test_context_->request_context_getter(), | |
476 base::MessageLoopProxy::current()); | |
477 | |
478 content::ContextMenuParams params = CreateParams(MenuItem::IMAGE); | |
479 params.unfiltered_link_url = params.link_url; | |
480 content::WebContents* wc = web_contents(); | |
481 TestRenderViewContextMenu* menu = | |
482 new TestRenderViewContextMenu(wc->GetMainFrame(), params); | |
483 | |
484 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS, 0); | |
485 | |
486 const std::string& headers = | |
487 content::WebContentsTester::For(web_contents())->GetSaveFrameHeaders(); | |
488 EXPECT_TRUE(headers.find("X-PSA-Client-Options: v=1,m=1") == | |
489 std::string::npos && | |
490 headers.find("Cache-Control: no-cache") == std::string::npos); | |
491 } | |
OLD | NEW |