OLD | NEW |
---|---|
(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/strings/stringprintf.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_util.h" | |
21 | |
22 namespace { | |
23 const char kTestUrl[] = "http://www.test.com/"; | |
24 } | |
25 | |
26 class PreviewsInfoBarTabHelperUnitTest | |
27 : public ChromeRenderViewHostTestHarness { | |
28 protected: | |
29 void SetUp() override { | |
30 ChromeRenderViewHostTestHarness::SetUp(); | |
31 InfoBarService::CreateForWebContents(web_contents()); | |
32 PreviewsInfoBarTabHelper::CreateForWebContents(web_contents()); | |
33 test_handle_ = content::NavigationHandle::CreateNavigationHandleForTesting( | |
34 GURL(kTestUrl), main_rfh()); | |
35 | |
36 drp_test_context_ = | |
37 data_reduction_proxy::DataReductionProxyTestContext::Builder() | |
38 .WithMockConfig() | |
39 .SkipSettingsInitialization() | |
40 .Build(); | |
41 | |
42 auto* data_reduction_proxy_settings = | |
43 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | |
44 web_contents()->GetBrowserContext()); | |
45 | |
46 PrefRegistrySimple* registry = | |
47 drp_test_context_->pref_service()->registry(); | |
48 registry->RegisterDictionaryPref(proxy_config::prefs::kProxy); | |
49 data_reduction_proxy_settings | |
50 ->set_data_reduction_proxy_enabled_pref_name_for_test( | |
51 drp_test_context_->GetDataReductionProxyEnabledPrefName()); | |
52 data_reduction_proxy_settings->InitDataReductionProxySettings( | |
53 drp_test_context_->io_data(), drp_test_context_->pref_service(), | |
54 drp_test_context_->request_context_getter(), | |
55 base::WrapUnique(new data_reduction_proxy::DataStore()), | |
56 base::ThreadTaskRunnerHandle::Get(), | |
57 base::ThreadTaskRunnerHandle::Get()); | |
58 } | |
59 | |
60 void TearDown() override { | |
61 drp_test_context_->DestroySettings(); | |
62 ChromeRenderViewHostTestHarness::TearDown(); | |
63 } | |
64 | |
65 void SimulateWillProcessResponse() { | |
66 std::string headers = base::StringPrintf( | |
bengr
2016/09/13 23:18:18
#include <string>
megjablon
2016/09/13 23:27:12
Done.
| |
67 "HTTP/1.1 200 OK\n%s: %s\n\n", | |
68 data_reduction_proxy::chrome_proxy_header(), | |
69 data_reduction_proxy::chrome_proxy_lo_fi_preview_directive()); | |
70 test_handle_->CallWillProcessResponseForTesting( | |
71 main_rfh(), | |
72 net::HttpUtil::AssembleRawHeaders(headers.c_str(), headers.size())); | |
73 test_handle_->CallDidCommitNavigationForTesting(GURL(kTestUrl)); | |
74 } | |
75 | |
76 void CallDidFinishNavigation() { | |
77 test_handle_.reset(); | |
78 } | |
79 | |
80 private: | |
81 std::unique_ptr<content::NavigationHandle> test_handle_; | |
bengr
2016/09/13 23:18:18
#include <memory>
megjablon
2016/09/13 23:27:12
Done.
| |
82 std::unique_ptr<data_reduction_proxy::DataReductionProxyTestContext> | |
83 drp_test_context_; | |
84 }; | |
85 | |
86 TEST_F(PreviewsInfoBarTabHelperUnitTest, CreateLitePageInfoBar) { | |
87 PreviewsInfoBarTabHelper* infobar_tab_helper = | |
88 PreviewsInfoBarTabHelper::FromWebContents(web_contents()); | |
89 EXPECT_FALSE(infobar_tab_helper->displayed_preview_infobar()); | |
90 | |
91 SimulateWillProcessResponse(); | |
92 CallDidFinishNavigation(); | |
93 | |
94 InfoBarService* infobar_service = | |
95 InfoBarService::FromWebContents(web_contents()); | |
96 EXPECT_EQ(1U, infobar_service->infobar_count()); | |
97 EXPECT_TRUE(infobar_tab_helper->displayed_preview_infobar()); | |
98 | |
99 // Navigate to reset the displayed state. | |
100 content::WebContentsTester::For(web_contents())-> | |
101 NavigateAndCommit(GURL(kTestUrl)); | |
102 EXPECT_FALSE(infobar_tab_helper->displayed_preview_infobar()); | |
103 } | |
OLD | NEW |