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

Side by Side Diff: chrome/browser/renderer_context_menu/render_view_context_menu_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698