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

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

Issue 2462653002: Showing previews UI for Offline Previews (Closed)
Patch Set: fgorski comment Created 4 years, 1 month 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 | « chrome/browser/previews/previews_infobar_tab_helper.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 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/previews/previews_infobar_tab_helper.h" 5 #include "chrome/browser/previews/previews_infobar_tab_helper.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 9
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
11 #include "chrome/browser/infobars/infobar_service.h" 11 #include "chrome/browser/infobars/infobar_service.h"
12 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" 12 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
13 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact ory.h" 13 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact ory.h"
14 #include "chrome/browser/previews/previews_infobar_tab_helper.h" 14 #include "chrome/browser/previews/previews_infobar_tab_helper.h"
15 #include "chrome/common/features.h"
15 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 16 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
16 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test _utils.h" 17 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test _utils.h"
17 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs.h" 18 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs.h"
18 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_ names.h" 19 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_ names.h"
20 #include "components/offline_pages/offline_page_item.h"
21 #include "components/offline_pages/request_header/offline_page_header.h"
19 #include "components/prefs/pref_registry_simple.h" 22 #include "components/prefs/pref_registry_simple.h"
20 #include "components/proxy_config/proxy_config_pref_names.h" 23 #include "components/proxy_config/proxy_config_pref_names.h"
21 #include "content/public/browser/navigation_handle.h" 24 #include "content/public/browser/navigation_handle.h"
22 #include "content/public/test/web_contents_tester.h" 25 #include "content/public/test/web_contents_tester.h"
23 #include "net/http/http_util.h" 26 #include "net/http/http_util.h"
24 27
28 #if BUILDFLAG(ANDROID_JAVA_UI)
29 #include "chrome/browser/android/offline_pages/offline_page_tab_helper.h"
30 #endif // BUILDFLAG(ANDROID_JAVA_UI)
31
25 namespace { 32 namespace {
26 const char kTestUrl[] = "http://www.test.com/"; 33 const char kTestUrl[] = "http://www.test.com/";
27 } 34 }
28 35
29 class PreviewsInfoBarTabHelperUnitTest 36 class PreviewsInfoBarTabHelperUnitTest
30 : public ChromeRenderViewHostTestHarness { 37 : public ChromeRenderViewHostTestHarness {
31 protected: 38 protected:
32 void SetUp() override { 39 void SetUp() override {
33 ChromeRenderViewHostTestHarness::SetUp(); 40 ChromeRenderViewHostTestHarness::SetUp();
41 // Insert an OfflinePageTabHelper before PreviewsInfoBarTabHelper.
42 #if BUILDFLAG(ANDROID_JAVA_UI)
43 offline_pages::OfflinePageTabHelper::CreateForWebContents(web_contents());
44 #endif // BUILDFLAG(ANDROID_JAVA_UI)
34 InfoBarService::CreateForWebContents(web_contents()); 45 InfoBarService::CreateForWebContents(web_contents());
35 PreviewsInfoBarTabHelper::CreateForWebContents(web_contents()); 46 PreviewsInfoBarTabHelper::CreateForWebContents(web_contents());
36 test_handle_ = content::NavigationHandle::CreateNavigationHandleForTesting( 47 test_handle_ = content::NavigationHandle::CreateNavigationHandleForTesting(
37 GURL(kTestUrl), main_rfh()); 48 GURL(kTestUrl), main_rfh());
38 49
39 drp_test_context_ = 50 drp_test_context_ =
40 data_reduction_proxy::DataReductionProxyTestContext::Builder() 51 data_reduction_proxy::DataReductionProxyTestContext::Builder()
41 .WithMockConfig() 52 .WithMockConfig()
42 .SkipSettingsInitialization() 53 .SkipSettingsInitialization()
43 .Build(); 54 .Build();
(...skipping 22 matching lines...) Expand all
66 } 77 }
67 78
68 void SimulateWillProcessResponse() { 79 void SimulateWillProcessResponse() {
69 std::string headers = base::StringPrintf( 80 std::string headers = base::StringPrintf(
70 "HTTP/1.1 200 OK\n%s: %s\n\n", 81 "HTTP/1.1 200 OK\n%s: %s\n\n",
71 data_reduction_proxy::chrome_proxy_content_transform_header(), 82 data_reduction_proxy::chrome_proxy_content_transform_header(),
72 data_reduction_proxy::lite_page_directive()); 83 data_reduction_proxy::lite_page_directive());
73 test_handle_->CallWillProcessResponseForTesting( 84 test_handle_->CallWillProcessResponseForTesting(
74 main_rfh(), 85 main_rfh(),
75 net::HttpUtil::AssembleRawHeaders(headers.c_str(), headers.size())); 86 net::HttpUtil::AssembleRawHeaders(headers.c_str(), headers.size()));
87 SimulateCommit();
88 }
89
90 void SimulateCommit() {
76 test_handle_->CallDidCommitNavigationForTesting(GURL(kTestUrl)); 91 test_handle_->CallDidCommitNavigationForTesting(GURL(kTestUrl));
77 } 92 }
78 93
79 void CallDidFinishNavigation() { test_handle_.reset(); } 94 void CallDidFinishNavigation() { test_handle_.reset(); }
80 95
81 private: 96 private:
82 std::unique_ptr<content::NavigationHandle> test_handle_; 97 std::unique_ptr<content::NavigationHandle> test_handle_;
83 std::unique_ptr<data_reduction_proxy::DataReductionProxyTestContext> 98 std::unique_ptr<data_reduction_proxy::DataReductionProxyTestContext>
84 drp_test_context_; 99 drp_test_context_;
85 }; 100 };
86 101
87 TEST_F(PreviewsInfoBarTabHelperUnitTest, CreateLitePageInfoBar) { 102 TEST_F(PreviewsInfoBarTabHelperUnitTest, CreateLitePageInfoBar) {
88 PreviewsInfoBarTabHelper* infobar_tab_helper = 103 PreviewsInfoBarTabHelper* infobar_tab_helper =
89 PreviewsInfoBarTabHelper::FromWebContents(web_contents()); 104 PreviewsInfoBarTabHelper::FromWebContents(web_contents());
90 EXPECT_FALSE(infobar_tab_helper->displayed_preview_infobar()); 105 EXPECT_FALSE(infobar_tab_helper->displayed_preview_infobar());
91 106
92 SimulateWillProcessResponse(); 107 SimulateWillProcessResponse();
93 CallDidFinishNavigation(); 108 CallDidFinishNavigation();
94 109
95 InfoBarService* infobar_service = 110 InfoBarService* infobar_service =
96 InfoBarService::FromWebContents(web_contents()); 111 InfoBarService::FromWebContents(web_contents());
97 EXPECT_EQ(1U, infobar_service->infobar_count()); 112 EXPECT_EQ(1U, infobar_service->infobar_count());
98 EXPECT_TRUE(infobar_tab_helper->displayed_preview_infobar()); 113 EXPECT_TRUE(infobar_tab_helper->displayed_preview_infobar());
99 114
100 // Navigate to reset the displayed state. 115 // Navigate to reset the displayed state.
101 content::WebContentsTester::For(web_contents()) 116 content::WebContentsTester::For(web_contents())
102 ->NavigateAndCommit(GURL(kTestUrl)); 117 ->NavigateAndCommit(GURL(kTestUrl));
118
103 EXPECT_FALSE(infobar_tab_helper->displayed_preview_infobar()); 119 EXPECT_FALSE(infobar_tab_helper->displayed_preview_infobar());
104 } 120 }
121
122 #if BUILDFLAG(ANDROID_JAVA_UI)
123 TEST_F(PreviewsInfoBarTabHelperUnitTest, CreateOfflineInfoBar) {
124 PreviewsInfoBarTabHelper* infobar_tab_helper =
125 PreviewsInfoBarTabHelper::FromWebContents(web_contents());
126 EXPECT_FALSE(infobar_tab_helper->displayed_preview_infobar());
127
128 SimulateCommit();
129 offline_pages::OfflinePageItem item;
130 offline_pages::OfflinePageHeader header;
131 offline_pages::OfflinePageTabHelper::FromWebContents(web_contents())
132 ->SetOfflinePage(item, header, true);
133 CallDidFinishNavigation();
134
135 InfoBarService* infobar_service =
136 InfoBarService::FromWebContents(web_contents());
137 EXPECT_EQ(1U, infobar_service->infobar_count());
138 EXPECT_TRUE(infobar_tab_helper->displayed_preview_infobar());
139
140 // Navigate to reset the displayed state.
141 content::WebContentsTester::For(web_contents())
142 ->NavigateAndCommit(GURL(kTestUrl));
143
144 EXPECT_FALSE(infobar_tab_helper->displayed_preview_infobar());
145 }
146 #endif // BUILDFLAG(ANDROID_JAVA_UI)
OLDNEW
« no previous file with comments | « chrome/browser/previews/previews_infobar_tab_helper.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698