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/run_loop.h" |
11 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
12 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
13 #include "chrome/browser/infobars/infobar_service.h" | 14 #include "chrome/browser/infobars/infobar_service.h" |
14 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" | 15 #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" | 16 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact
ory.h" |
16 #include "chrome/browser/previews/previews_infobar_tab_helper.h" | 17 #include "chrome/browser/previews/previews_infobar_tab_helper.h" |
17 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 18 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 19 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_ping
back_client.h" |
| 20 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv
ice.h" |
| 21 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett
ings.h" |
18 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test
_utils.h" | 22 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test
_utils.h" |
19 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade
rs.h" | 23 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade
rs.h" |
20 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_
names.h" | 24 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_
names.h" |
21 #include "components/offline_pages/core/offline_page_item.h" | 25 #include "components/offline_pages/core/offline_page_item.h" |
22 #include "components/offline_pages/core/request_header/offline_page_header.h" | 26 #include "components/offline_pages/core/request_header/offline_page_header.h" |
23 #include "components/prefs/pref_registry_simple.h" | 27 #include "components/prefs/pref_registry_simple.h" |
24 #include "components/proxy_config/proxy_config_pref_names.h" | 28 #include "components/proxy_config/proxy_config_pref_names.h" |
25 #include "content/public/browser/navigation_handle.h" | 29 #include "content/public/browser/navigation_handle.h" |
26 #include "content/public/test/web_contents_tester.h" | 30 #include "content/public/test/web_contents_tester.h" |
27 #include "net/http/http_util.h" | 31 #include "net/http/http_util.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 EXPECT_EQ(1U, infobar_service->infobar_count()); | 119 EXPECT_EQ(1U, infobar_service->infobar_count()); |
116 EXPECT_TRUE(infobar_tab_helper->displayed_preview_infobar()); | 120 EXPECT_TRUE(infobar_tab_helper->displayed_preview_infobar()); |
117 | 121 |
118 // Navigate to reset the displayed state. | 122 // Navigate to reset the displayed state. |
119 content::WebContentsTester::For(web_contents()) | 123 content::WebContentsTester::For(web_contents()) |
120 ->NavigateAndCommit(GURL(kTestUrl)); | 124 ->NavigateAndCommit(GURL(kTestUrl)); |
121 | 125 |
122 EXPECT_FALSE(infobar_tab_helper->displayed_preview_infobar()); | 126 EXPECT_FALSE(infobar_tab_helper->displayed_preview_infobar()); |
123 } | 127 } |
124 | 128 |
| 129 TEST_F(PreviewsInfoBarTabHelperUnitTest, PingbackClientCleared) { |
| 130 auto* data_reduction_proxy_settings = |
| 131 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
| 132 web_contents()->GetBrowserContext()); |
| 133 |
| 134 EXPECT_EQ(0u, data_reduction_proxy_settings->data_reduction_proxy_service() |
| 135 ->pingback_client() |
| 136 ->PendingTabLoadsForTesting()); |
| 137 |
| 138 data_reduction_proxy_settings->data_reduction_proxy_service() |
| 139 ->pingback_client() |
| 140 ->AddOptOut(web_contents(), 0u); |
| 141 |
| 142 EXPECT_EQ(1u, data_reduction_proxy_settings->data_reduction_proxy_service() |
| 143 ->pingback_client() |
| 144 ->PendingTabLoadsForTesting()); |
| 145 CallDidFinishNavigation(); |
| 146 SetContents(nullptr); |
| 147 |
| 148 EXPECT_EQ(1u, data_reduction_proxy_settings->data_reduction_proxy_service() |
| 149 ->pingback_client() |
| 150 ->PendingTabLoadsForTesting()); |
| 151 |
| 152 base::RunLoop().RunUntilIdle(); |
| 153 |
| 154 EXPECT_EQ(0u, data_reduction_proxy_settings->data_reduction_proxy_service() |
| 155 ->pingback_client() |
| 156 ->PendingTabLoadsForTesting()); |
| 157 } |
| 158 |
125 #if defined(OS_ANDROID) | 159 #if defined(OS_ANDROID) |
126 TEST_F(PreviewsInfoBarTabHelperUnitTest, CreateOfflineInfoBar) { | 160 TEST_F(PreviewsInfoBarTabHelperUnitTest, CreateOfflineInfoBar) { |
127 PreviewsInfoBarTabHelper* infobar_tab_helper = | 161 PreviewsInfoBarTabHelper* infobar_tab_helper = |
128 PreviewsInfoBarTabHelper::FromWebContents(web_contents()); | 162 PreviewsInfoBarTabHelper::FromWebContents(web_contents()); |
129 EXPECT_FALSE(infobar_tab_helper->displayed_preview_infobar()); | 163 EXPECT_FALSE(infobar_tab_helper->displayed_preview_infobar()); |
130 | 164 |
131 SimulateCommit(); | 165 SimulateCommit(); |
132 offline_pages::OfflinePageItem item; | 166 offline_pages::OfflinePageItem item; |
133 item.url = GURL(kTestUrl); | 167 item.url = GURL(kTestUrl); |
134 offline_pages::OfflinePageHeader header; | 168 offline_pages::OfflinePageHeader header; |
135 offline_pages::OfflinePageTabHelper::FromWebContents(web_contents()) | 169 offline_pages::OfflinePageTabHelper::FromWebContents(web_contents()) |
136 ->SetOfflinePage(item, header, true); | 170 ->SetOfflinePage(item, header, true); |
137 CallDidFinishNavigation(); | 171 CallDidFinishNavigation(); |
138 | 172 |
139 InfoBarService* infobar_service = | 173 InfoBarService* infobar_service = |
140 InfoBarService::FromWebContents(web_contents()); | 174 InfoBarService::FromWebContents(web_contents()); |
141 EXPECT_EQ(1U, infobar_service->infobar_count()); | 175 EXPECT_EQ(1U, infobar_service->infobar_count()); |
142 EXPECT_TRUE(infobar_tab_helper->displayed_preview_infobar()); | 176 EXPECT_TRUE(infobar_tab_helper->displayed_preview_infobar()); |
143 | 177 |
144 // Navigate to reset the displayed state. | 178 // Navigate to reset the displayed state. |
145 content::WebContentsTester::For(web_contents()) | 179 content::WebContentsTester::For(web_contents()) |
146 ->NavigateAndCommit(GURL(kTestUrl)); | 180 ->NavigateAndCommit(GURL(kTestUrl)); |
147 | 181 |
148 EXPECT_FALSE(infobar_tab_helper->displayed_preview_infobar()); | 182 EXPECT_FALSE(infobar_tab_helper->displayed_preview_infobar()); |
149 } | 183 } |
150 #endif // defined(OS_ANDROID) | 184 #endif // defined(OS_ANDROID) |
OLD | NEW |