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

Unified 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: Refactor common setup code. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | content/public/test/web_contents_tester.h » ('j') | content/public/test/web_contents_tester.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/renderer_context_menu/render_view_context_menu_unittest.cc
diff --git a/chrome/browser/renderer_context_menu/render_view_context_menu_unittest.cc b/chrome/browser/renderer_context_menu/render_view_context_menu_unittest.cc
index 6437c31a4041a323123066abe28eb01dba47b951..65d0ced98ad3db2d16102c1d7a8299dda4156c87 100644
--- a/chrome/browser/renderer_context_menu/render_view_context_menu_unittest.cc
+++ b/chrome/browser/renderer_context_menu/render_view_context_menu_unittest.cc
@@ -4,7 +4,9 @@
#include "chrome/browser/renderer_context_menu/render_view_context_menu.h"
+#include "base/prefs/pref_registry_simple.h"
#include "base/prefs/pref_service.h"
+#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
@@ -12,11 +14,19 @@
#include "chrome/browser/extensions/menu_manager_factory.h"
#include "chrome/browser/extensions/test_extension_environment.h"
#include "chrome/browser/extensions/test_extension_prefs.h"
+#include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
+#include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_factory.h"
#include "chrome/browser/prefs/incognito_mode_prefs.h"
#include "chrome/browser/renderer_context_menu/render_view_context_menu_test_util.h"
+#include "chrome/common/pref_names.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "chrome/test/base/testing_profile.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h"
+#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
+#include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.h"
#include "content/public/browser/web_contents.h"
+#include "content/public/test/web_contents_tester.h"
+
#include "extensions/browser/extension_prefs.h"
#include "extensions/common/url_pattern.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -345,6 +355,45 @@ class RenderViewContextMenuPrefsTest : public ChromeRenderViewHostTestHarness {
return menu;
}
+ void SetupDataReductionProxy(bool enable_data_reduction_proxy) {
+ drp_test_context_ =
+ data_reduction_proxy::DataReductionProxyTestContext::Builder()
+ .WithParamsFlags(
+ data_reduction_proxy::DataReductionProxyParams::kAllowed |
+ data_reduction_proxy::DataReductionProxyParams::
+ kFallbackAllowed |
+ data_reduction_proxy::DataReductionProxyParams::kPromoAllowed)
+ .WithMockConfig()
+ .SkipSettingsInitialization()
+ .Build();
+
+ DataReductionProxyChromeSettings* settings =
+ DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
+ profile());
+
+ // TODO(bengr): Remove prefs::kProxy registration after M46. See
+ // http://crbug.com/445599.
+ PrefRegistrySimple* registry =
+ drp_test_context_->pref_service()->registry();
+ registry->RegisterDictionaryPref(prefs::kProxy);
+
+ drp_test_context_->pref_service()->SetBoolean(
+ data_reduction_proxy::prefs::kDataReductionProxyEnabled,
+ enable_data_reduction_proxy);
+ drp_test_context_->InitSettings();
+ 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.
+ drp_test_context_->io_data();
+
+ settings->InitDataReductionProxySettings(
+ io_data, drp_test_context_->pref_service(),
+ drp_test_context_->request_context_getter(),
+ 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.
+ }
+
+ protected:
+ scoped_ptr<data_reduction_proxy::DataReductionProxyTestContext>
+ drp_test_context_;
+
private:
scoped_ptr<ProtocolHandlerRegistry> registry_;
};
@@ -378,3 +427,44 @@ TEST_F(RenderViewContextMenuPrefsTest,
EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_CUSTOM_FIRST));
}
+
+// Verify that request headers specify that data reduction proxy should return
+// the original non compressed resource when "Save Image As..." is used with
+// Data Saver enabled.
+TEST_F(RenderViewContextMenuPrefsTest, DataSaverEnabledSaveImageAs) {
+ SetupDataReductionProxy(true);
+
+ content::ContextMenuParams params = CreateParams(MenuItem::IMAGE);
+ params.unfiltered_link_url = params.link_url;
+ content::WebContents* wc = web_contents();
+ TestRenderViewContextMenu* menu =
+ new TestRenderViewContextMenu(wc->GetMainFrame(), params);
+
+ menu->ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS, 0);
+
+ const std::string& headers =
+ content::WebContentsTester::For(web_contents())->GetSaveFrameHeaders();
+ EXPECT_TRUE(headers.find("X-PSA-Client-Options: v=1,m=1") !=
+ std::string::npos &&
+ headers.find("Cache-Control: no-cache") != std::string::npos);
+}
+
+// Verify that request headers do not specify pass through when "Save Image
+// As..." is used with Data Saver disabled.
+TEST_F(RenderViewContextMenuPrefsTest, DataSaverDisabledSaveImageAs) {
+ SetupDataReductionProxy(false);
+
+ content::ContextMenuParams params = CreateParams(MenuItem::IMAGE);
+ params.unfiltered_link_url = params.link_url;
+ content::WebContents* wc = web_contents();
+ TestRenderViewContextMenu* menu =
+ new TestRenderViewContextMenu(wc->GetMainFrame(), params);
+
+ menu->ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS, 0);
+
+ const std::string& headers =
+ content::WebContentsTester::For(web_contents())->GetSaveFrameHeaders();
+ EXPECT_TRUE(headers.find("X-PSA-Client-Options: v=1,m=1") ==
+ std::string::npos &&
+ headers.find("Cache-Control: no-cache") == std::string::npos);
+}
« no previous file with comments | « no previous file | content/public/test/web_contents_tester.h » ('j') | content/public/test/web_contents_tester.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698