OLD | NEW |
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/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
13 #include "chrome/browser/infobars/infobar_service.h" | 13 #include "chrome/browser/infobars/infobar_service.h" |
14 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" | 14 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" |
15 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact
ory.h" | 15 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact
ory.h" |
16 #include "chrome/browser/previews/previews_infobar_tab_helper.h" | 16 #include "chrome/browser/previews/previews_infobar_tab_helper.h" |
17 #include "chrome/common/features.h" | |
18 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 17 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
19 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test
_utils.h" | 18 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test
_utils.h" |
20 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade
rs.h" | 19 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade
rs.h" |
21 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_
names.h" | 20 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_
names.h" |
22 #include "components/offline_pages/core/offline_page_item.h" | 21 #include "components/offline_pages/core/offline_page_item.h" |
23 #include "components/offline_pages/core/request_header/offline_page_header.h" | 22 #include "components/offline_pages/core/request_header/offline_page_header.h" |
24 #include "components/prefs/pref_registry_simple.h" | 23 #include "components/prefs/pref_registry_simple.h" |
25 #include "components/proxy_config/proxy_config_pref_names.h" | 24 #include "components/proxy_config/proxy_config_pref_names.h" |
26 #include "content/public/browser/navigation_handle.h" | 25 #include "content/public/browser/navigation_handle.h" |
27 #include "content/public/test/web_contents_tester.h" | 26 #include "content/public/test/web_contents_tester.h" |
28 #include "net/http/http_util.h" | 27 #include "net/http/http_util.h" |
29 | 28 |
30 #if BUILDFLAG(ANDROID_JAVA_UI) | 29 #if defined(OS_ANDROID) |
31 #include "chrome/browser/android/offline_pages/offline_page_tab_helper.h" | 30 #include "chrome/browser/android/offline_pages/offline_page_tab_helper.h" |
32 #endif // BUILDFLAG(ANDROID_JAVA_UI) | 31 #endif // defined(OS_ANDROID) |
33 | 32 |
34 namespace { | 33 namespace { |
35 const char kTestUrl[] = "http://www.test.com/"; | 34 const char kTestUrl[] = "http://www.test.com/"; |
36 } | 35 } |
37 | 36 |
38 class PreviewsInfoBarTabHelperUnitTest | 37 class PreviewsInfoBarTabHelperUnitTest |
39 : public ChromeRenderViewHostTestHarness { | 38 : public ChromeRenderViewHostTestHarness { |
40 protected: | 39 protected: |
41 void SetUp() override { | 40 void SetUp() override { |
42 ChromeRenderViewHostTestHarness::SetUp(); | 41 ChromeRenderViewHostTestHarness::SetUp(); |
43 // Insert an OfflinePageTabHelper before PreviewsInfoBarTabHelper. | 42 // Insert an OfflinePageTabHelper before PreviewsInfoBarTabHelper. |
44 #if BUILDFLAG(ANDROID_JAVA_UI) | 43 #if defined(OS_ANDROID) |
45 offline_pages::OfflinePageTabHelper::CreateForWebContents(web_contents()); | 44 offline_pages::OfflinePageTabHelper::CreateForWebContents(web_contents()); |
46 #endif // BUILDFLAG(ANDROID_JAVA_UI) | 45 #endif // defined(OS_ANDROID) |
47 InfoBarService::CreateForWebContents(web_contents()); | 46 InfoBarService::CreateForWebContents(web_contents()); |
48 PreviewsInfoBarTabHelper::CreateForWebContents(web_contents()); | 47 PreviewsInfoBarTabHelper::CreateForWebContents(web_contents()); |
49 test_handle_ = content::NavigationHandle::CreateNavigationHandleForTesting( | 48 test_handle_ = content::NavigationHandle::CreateNavigationHandleForTesting( |
50 GURL(kTestUrl), main_rfh()); | 49 GURL(kTestUrl), main_rfh()); |
51 content::RenderFrameHostTester::For(main_rfh()) | 50 content::RenderFrameHostTester::For(main_rfh()) |
52 ->InitializeRenderFrameIfNeeded(); | 51 ->InitializeRenderFrameIfNeeded(); |
53 | 52 |
54 drp_test_context_ = | 53 drp_test_context_ = |
55 data_reduction_proxy::DataReductionProxyTestContext::Builder() | 54 data_reduction_proxy::DataReductionProxyTestContext::Builder() |
56 .WithMockConfig() | 55 .WithMockConfig() |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 EXPECT_EQ(1U, infobar_service->infobar_count()); | 115 EXPECT_EQ(1U, infobar_service->infobar_count()); |
117 EXPECT_TRUE(infobar_tab_helper->displayed_preview_infobar()); | 116 EXPECT_TRUE(infobar_tab_helper->displayed_preview_infobar()); |
118 | 117 |
119 // Navigate to reset the displayed state. | 118 // Navigate to reset the displayed state. |
120 content::WebContentsTester::For(web_contents()) | 119 content::WebContentsTester::For(web_contents()) |
121 ->NavigateAndCommit(GURL(kTestUrl)); | 120 ->NavigateAndCommit(GURL(kTestUrl)); |
122 | 121 |
123 EXPECT_FALSE(infobar_tab_helper->displayed_preview_infobar()); | 122 EXPECT_FALSE(infobar_tab_helper->displayed_preview_infobar()); |
124 } | 123 } |
125 | 124 |
126 #if BUILDFLAG(ANDROID_JAVA_UI) | 125 #if defined(OS_ANDROID) |
127 TEST_F(PreviewsInfoBarTabHelperUnitTest, CreateOfflineInfoBar) { | 126 TEST_F(PreviewsInfoBarTabHelperUnitTest, CreateOfflineInfoBar) { |
128 PreviewsInfoBarTabHelper* infobar_tab_helper = | 127 PreviewsInfoBarTabHelper* infobar_tab_helper = |
129 PreviewsInfoBarTabHelper::FromWebContents(web_contents()); | 128 PreviewsInfoBarTabHelper::FromWebContents(web_contents()); |
130 EXPECT_FALSE(infobar_tab_helper->displayed_preview_infobar()); | 129 EXPECT_FALSE(infobar_tab_helper->displayed_preview_infobar()); |
131 | 130 |
132 SimulateCommit(); | 131 SimulateCommit(); |
133 offline_pages::OfflinePageItem item; | 132 offline_pages::OfflinePageItem item; |
134 item.url = GURL(kTestUrl); | 133 item.url = GURL(kTestUrl); |
135 offline_pages::OfflinePageHeader header; | 134 offline_pages::OfflinePageHeader header; |
136 offline_pages::OfflinePageTabHelper::FromWebContents(web_contents()) | 135 offline_pages::OfflinePageTabHelper::FromWebContents(web_contents()) |
137 ->SetOfflinePage(item, header, true); | 136 ->SetOfflinePage(item, header, true); |
138 CallDidFinishNavigation(); | 137 CallDidFinishNavigation(); |
139 | 138 |
140 InfoBarService* infobar_service = | 139 InfoBarService* infobar_service = |
141 InfoBarService::FromWebContents(web_contents()); | 140 InfoBarService::FromWebContents(web_contents()); |
142 EXPECT_EQ(1U, infobar_service->infobar_count()); | 141 EXPECT_EQ(1U, infobar_service->infobar_count()); |
143 EXPECT_TRUE(infobar_tab_helper->displayed_preview_infobar()); | 142 EXPECT_TRUE(infobar_tab_helper->displayed_preview_infobar()); |
144 | 143 |
145 // Navigate to reset the displayed state. | 144 // Navigate to reset the displayed state. |
146 content::WebContentsTester::For(web_contents()) | 145 content::WebContentsTester::For(web_contents()) |
147 ->NavigateAndCommit(GURL(kTestUrl)); | 146 ->NavigateAndCommit(GURL(kTestUrl)); |
148 | 147 |
149 EXPECT_FALSE(infobar_tab_helper->displayed_preview_infobar()); | 148 EXPECT_FALSE(infobar_tab_helper->displayed_preview_infobar()); |
150 } | 149 } |
151 #endif // BUILDFLAG(ANDROID_JAVA_UI) | 150 #endif // defined(OS_ANDROID) |
OLD | NEW |