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

Side by Side Diff: chrome/browser/previews/previews_infobar_tab_helper_unittest.cc

Issue 2266653002: Previews infobar tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@newLoFiInfoBarAddUMA
Patch Set: clamy comments Created 4 years, 3 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/previews/previews_infobar_tab_helper.h"
6
7 #include "base/memory/ref_counted.h"
8 #include "chrome/browser/infobars/infobar_service.h"
9 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
10 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact ory.h"
11 #include "chrome/browser/previews/previews_infobar_tab_helper.h"
12 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
13 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test _utils.h"
14 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs.h"
15 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_ names.h"
16 #include "components/prefs/pref_registry_simple.h"
17 #include "components/proxy_config/proxy_config_pref_names.h"
18 #include "content/public/browser/navigation_handle.h"
19 #include "content/public/test/web_contents_tester.h"
20 #include "net/http/http_response_headers.h"
21
22 namespace {
23
bengr 2016/09/09 19:40:52 nit: can remove blank lines above and below.
megjablon 2016/09/09 20:38:41 Done.
24 const char kTestUrl[] = "http://www.test.com/";
25
26 }
27
28 class PreviewsInfoBarTabHelperUnitTest
29 : public ChromeRenderViewHostTestHarness {
30 protected:
31 void SetUp() override {
32 ChromeRenderViewHostTestHarness::SetUp();
33 InfoBarService::CreateForWebContents(web_contents());
34 PreviewsInfoBarTabHelper::CreateForWebContents(web_contents());
35 test_handle_ = content::NavigationHandle::CreateNavigationHandleForTesting(
36 GURL(kTestUrl), main_rfh());
37
38 drp_test_context_ =
39 data_reduction_proxy::DataReductionProxyTestContext::Builder()
40 .WithMockConfig()
41 .SkipSettingsInitialization()
42 .Build();
43
44 auto* data_reduction_proxy_settings =
45 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
46 web_contents()->GetBrowserContext());
47
48 PrefRegistrySimple* registry =
49 drp_test_context_->pref_service()->registry();
50 registry->RegisterDictionaryPref(proxy_config::prefs::kProxy);
51 data_reduction_proxy_settings
52 ->set_data_reduction_proxy_enabled_pref_name_for_test(
53 drp_test_context_->GetDataReductionProxyEnabledPrefName());
54 data_reduction_proxy_settings->InitDataReductionProxySettings(
55 drp_test_context_->io_data(), drp_test_context_->pref_service(),
56 drp_test_context_->request_context_getter(),
57 base::WrapUnique(new data_reduction_proxy::DataStore()),
58 base::ThreadTaskRunnerHandle::Get(),
59 base::ThreadTaskRunnerHandle::Get());
60 }
61
62 void TearDown() override {
63 drp_test_context_->DestroySettings();
64 ChromeRenderViewHostTestHarness::TearDown();
65 }
66
67 void SimulateWillProcessResponse() {
68 scoped_refptr<net::HttpResponseHeaders> headers =
69 new net::HttpResponseHeaders("");
70 headers->AddHeader(
71 std::string(data_reduction_proxy::chrome_proxy_header()) + ": " +
bengr 2016/09/09 19:40:52 I'd use StringPrintF in base to construct the stri
megjablon 2016/09/09 20:38:41 Done.
72 data_reduction_proxy::chrome_proxy_lo_fi_preview_directive());
73 test_handle_->CallWillProcessResponseForTesting(main_rfh(), headers);
74 test_handle_->CallDidCommitNavigationForTesting(GURL(kTestUrl));
75 }
76
77 void CallDidFinishNavigation() {
78 test_handle_.reset();
79 }
80
81 private:
82 std::unique_ptr<content::NavigationHandle> test_handle_;
83 std::unique_ptr<data_reduction_proxy::DataReductionProxyTestContext>
84 drp_test_context_;
85 };
86
87 TEST_F(PreviewsInfoBarTabHelperUnitTest, CreateLitePageInfoBar) {
88 PreviewsInfoBarTabHelper* infobar_tab_helper =
89 PreviewsInfoBarTabHelper::FromWebContents(web_contents());
90 EXPECT_FALSE(infobar_tab_helper->displayed_preview_infobar());
91
92 SimulateWillProcessResponse();
93 CallDidFinishNavigation();
94
95 InfoBarService* infobar_service =
96 InfoBarService::FromWebContents(web_contents());
97 EXPECT_EQ(1U, infobar_service->infobar_count());
98 EXPECT_TRUE(infobar_tab_helper->displayed_preview_infobar());
99
100 // Navigate to reset the displayed state.
101 content::WebContentsTester::For(web_contents())->
102 NavigateAndCommit(GURL(kTestUrl));
103 EXPECT_FALSE(infobar_tab_helper->displayed_preview_infobar());
104 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698