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

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

Issue 1221663009: Expose API to store and load data usage stats from UI task runner. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Breakdown
Patch Set: Add DCHECK Created 5 years, 5 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
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/prefs/pref_registry_simple.h" 7 #include "base/prefs/pref_registry_simple.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "base/thread_task_runner_handle.h" 11 #include "base/thread_task_runner_handle.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/browser/data_store.h"
26 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs.h" 27 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs.h"
27 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h" 28 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h"
28 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_ names.h" 29 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_ names.h"
29 #include "content/public/browser/web_contents.h" 30 #include "content/public/browser/web_contents.h"
30 #include "content/public/test/web_contents_tester.h" 31 #include "content/public/test/web_contents_tester.h"
31 32
32 #include "extensions/browser/extension_prefs.h" 33 #include "extensions/browser/extension_prefs.h"
33 #include "extensions/common/url_pattern.h" 34 #include "extensions/common/url_pattern.h"
34 #include "testing/gtest/include/gtest/gtest.h" 35 #include "testing/gtest/include/gtest/gtest.h"
35 #include "third_party/WebKit/public/web/WebContextMenuData.h" 36 #include "third_party/WebKit/public/web/WebContextMenuData.h"
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 registry->RegisterDictionaryPref(prefs::kProxy); 384 registry->RegisterDictionaryPref(prefs::kProxy);
384 385
385 drp_test_context_->pref_service()->SetBoolean( 386 drp_test_context_->pref_service()->SetBoolean(
386 data_reduction_proxy::prefs::kDataReductionProxyEnabled, 387 data_reduction_proxy::prefs::kDataReductionProxyEnabled,
387 enable_data_reduction_proxy); 388 enable_data_reduction_proxy);
388 drp_test_context_->InitSettings(); 389 drp_test_context_->InitSettings();
389 390
390 settings->InitDataReductionProxySettings( 391 settings->InitDataReductionProxySettings(
391 drp_test_context_->io_data(), drp_test_context_->pref_service(), 392 drp_test_context_->io_data(), drp_test_context_->pref_service(),
392 drp_test_context_->request_context_getter(), 393 drp_test_context_->request_context_getter(),
394 make_scoped_ptr(new data_reduction_proxy::DataStore()),
395 base::ThreadTaskRunnerHandle::Get(),
393 base::ThreadTaskRunnerHandle::Get()); 396 base::ThreadTaskRunnerHandle::Get());
394 } 397 }
395 398
399 // Force destruction of |DataReductionProxySettings| so that objects on DB
400 // task runner can be destroyed before test threads are destroyed. This method
401 // must be called by tests that call |SetupDataReductionProxy|. We cannot
402 // destroy |drp_test_context_| until browser context keyed services are
403 // destroyed since |DataReductionProxyChromeSettings| holds a pointer to the
404 // |PrefService|, which is owned by |drp_test_context_|.
405 void DestroyDataReductionProxySettings() {
406 drp_test_context_->DestroySettings();
407 }
408
396 protected: 409 protected:
397 scoped_ptr<data_reduction_proxy::DataReductionProxyTestContext> 410 scoped_ptr<data_reduction_proxy::DataReductionProxyTestContext>
398 drp_test_context_; 411 drp_test_context_;
399 412
400 private: 413 private:
401 scoped_ptr<ProtocolHandlerRegistry> registry_; 414 scoped_ptr<ProtocolHandlerRegistry> registry_;
402 }; 415 };
403 416
404 // Verifies when Incognito Mode is not available (disabled by policy), 417 // Verifies when Incognito Mode is not available (disabled by policy),
405 // Open Link in Incognito Window link in the context menu is disabled. 418 // Open Link in Incognito Window link in the context menu is disabled.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 content::WebContents* wc = web_contents(); 455 content::WebContents* wc = web_contents();
443 scoped_ptr<TestRenderViewContextMenu> menu( 456 scoped_ptr<TestRenderViewContextMenu> menu(
444 new TestRenderViewContextMenu(wc->GetMainFrame(), params)); 457 new TestRenderViewContextMenu(wc->GetMainFrame(), params));
445 458
446 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS, 0); 459 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS, 0);
447 460
448 const std::string& headers = 461 const std::string& headers =
449 content::WebContentsTester::For(web_contents())->GetSaveFrameHeaders(); 462 content::WebContentsTester::For(web_contents())->GetSaveFrameHeaders();
450 EXPECT_TRUE(headers.find("Chrome-Proxy: pass-through") != std::string::npos); 463 EXPECT_TRUE(headers.find("Chrome-Proxy: pass-through") != std::string::npos);
451 EXPECT_TRUE(headers.find("Cache-Control: no-cache") != std::string::npos); 464 EXPECT_TRUE(headers.find("Cache-Control: no-cache") != std::string::npos);
465
466 DestroyDataReductionProxySettings();
452 } 467 }
453 468
454 // Verify that request headers do not specify pass through when "Save Image 469 // Verify that request headers do not specify pass through when "Save Image
455 // As..." is used with Data Saver disabled. 470 // As..." is used with Data Saver disabled.
456 TEST_F(RenderViewContextMenuPrefsTest, DataSaverDisabledSaveImageAs) { 471 TEST_F(RenderViewContextMenuPrefsTest, DataSaverDisabledSaveImageAs) {
457 SetupDataReductionProxy(false); 472 SetupDataReductionProxy(false);
458 473
459 content::ContextMenuParams params = CreateParams(MenuItem::IMAGE); 474 content::ContextMenuParams params = CreateParams(MenuItem::IMAGE);
460 params.unfiltered_link_url = params.link_url; 475 params.unfiltered_link_url = params.link_url;
461 content::WebContents* wc = web_contents(); 476 content::WebContents* wc = web_contents();
462 scoped_ptr<TestRenderViewContextMenu> menu( 477 scoped_ptr<TestRenderViewContextMenu> menu(
463 new TestRenderViewContextMenu(wc->GetMainFrame(), params)); 478 new TestRenderViewContextMenu(wc->GetMainFrame(), params));
464 479
465 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS, 0); 480 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS, 0);
466 481
467 const std::string& headers = 482 const std::string& headers =
468 content::WebContentsTester::For(web_contents())->GetSaveFrameHeaders(); 483 content::WebContentsTester::For(web_contents())->GetSaveFrameHeaders();
469 EXPECT_TRUE(headers.find("Chrome-Proxy: pass-through") == std::string::npos); 484 EXPECT_TRUE(headers.find("Chrome-Proxy: pass-through") == std::string::npos);
470 EXPECT_TRUE(headers.find("Cache-Control: no-cache") == std::string::npos); 485 EXPECT_TRUE(headers.find("Cache-Control: no-cache") == std::string::npos);
486
487 DestroyDataReductionProxySettings();
471 } 488 }
472 489
473 // Verify that the Chrome-Proxy Lo-Fi directive causes the context menu to 490 // Verify that the Chrome-Proxy Lo-Fi directive causes the context menu to
474 // display the "Load Image" menu item. 491 // display the "Load Image" menu item.
475 TEST_F(RenderViewContextMenuPrefsTest, DataSaverLoadImage) { 492 TEST_F(RenderViewContextMenuPrefsTest, DataSaverLoadImage) {
476 SetupDataReductionProxy(true); 493 SetupDataReductionProxy(true);
477 content::ContextMenuParams params = CreateParams(MenuItem::IMAGE); 494 content::ContextMenuParams params = CreateParams(MenuItem::IMAGE);
478 params.properties[data_reduction_proxy::chrome_proxy_header()] = 495 params.properties[data_reduction_proxy::chrome_proxy_header()] =
479 data_reduction_proxy::chrome_proxy_lo_fi_directive(); 496 data_reduction_proxy::chrome_proxy_lo_fi_directive();
480 params.unfiltered_link_url = params.link_url; 497 params.unfiltered_link_url = params.link_url;
481 content::WebContents* wc = web_contents(); 498 content::WebContents* wc = web_contents();
482 scoped_ptr<TestRenderViewContextMenu> menu( 499 scoped_ptr<TestRenderViewContextMenu> menu(
483 new TestRenderViewContextMenu(wc->GetMainFrame(), params)); 500 new TestRenderViewContextMenu(wc->GetMainFrame(), params));
484 AppendImageItems(menu.get()); 501 AppendImageItems(menu.get());
485 502
486 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_LOAD_ORIGINAL_IMAGE)); 503 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_LOAD_ORIGINAL_IMAGE));
504
505 DestroyDataReductionProxySettings();
487 } 506 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698