OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 9 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
10 #include "chrome/browser/browsing_data/browsing_data_remover.h" | 10 #include "chrome/browser/browsing_data/browsing_data_remover.h" |
11 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" | 11 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" |
12 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h" | 12 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h" |
13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
18 #include "chrome/test/base/in_process_browser_test.h" | 18 #include "chrome/test/base/in_process_browser_test.h" |
19 #include "chrome/test/base/ui_test_utils.h" | 19 #include "chrome/test/base/ui_test_utils.h" |
20 #include "components/prefs/pref_service.h" | 20 #include "components/prefs/pref_service.h" |
21 #include "content/public/browser/browser_context.h" | 21 #include "content/public/browser/browser_context.h" |
22 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
23 #include "content/public/browser/download_manager.h" | 23 #include "content/public/browser/download_manager.h" |
24 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
25 #include "content/public/common/content_paths.h" | 25 #include "content/public/common/content_paths.h" |
26 #include "content/public/test/browser_test_utils.h" | 26 #include "content/public/test/browser_test_utils.h" |
27 #include "content/public/test/download_test_observer.h" | 27 #include "content/public/test/download_test_observer.h" |
| 28 #include "net/http/transport_security_state.h" |
28 #include "net/test/url_request/url_request_mock_http_job.h" | 29 #include "net/test/url_request/url_request_mock_http_job.h" |
| 30 #include "net/url_request/url_request_context.h" |
| 31 #include "net/url_request/url_request_context_getter.h" |
29 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
30 | 33 |
31 using content::BrowserThread; | 34 using content::BrowserThread; |
32 | 35 |
33 namespace { | 36 namespace { |
34 void SetUrlRequestMock(const base::FilePath& path) { | 37 void SetUrlRequestMock(const base::FilePath& path) { |
35 net::URLRequestMockHTTPJob::AddUrlHandlers(path, | 38 net::URLRequestMockHTTPJob::AddUrlHandlers(path, |
36 BrowserThread::GetBlockingPool()); | 39 BrowserThread::GetBlockingPool()); |
37 } | 40 } |
38 } | 41 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 void RemoveAndWait(int remove_mask) { | 93 void RemoveAndWait(int remove_mask) { |
91 BrowsingDataRemover* remover = | 94 BrowsingDataRemover* remover = |
92 BrowsingDataRemoverFactory::GetForBrowserContext(browser()->profile()); | 95 BrowsingDataRemoverFactory::GetForBrowserContext(browser()->profile()); |
93 BrowsingDataRemoverCompletionObserver completion_observer(remover); | 96 BrowsingDataRemoverCompletionObserver completion_observer(remover); |
94 remover->Remove(BrowsingDataRemover::Period(BrowsingDataRemover::LAST_HOUR), | 97 remover->Remove(BrowsingDataRemover::Period(BrowsingDataRemover::LAST_HOUR), |
95 remove_mask, BrowsingDataHelper::UNPROTECTED_WEB); | 98 remove_mask, BrowsingDataHelper::UNPROTECTED_WEB); |
96 completion_observer.BlockUntilCompletion(); | 99 completion_observer.BlockUntilCompletion(); |
97 } | 100 } |
98 }; | 101 }; |
99 | 102 |
| 103 class BrowsingDataRemoverTransportSecurityStateBrowserTest |
| 104 : public BrowsingDataRemoverBrowserTest { |
| 105 public: |
| 106 BrowsingDataRemoverTransportSecurityStateBrowserTest() {} |
| 107 |
| 108 void SetUpOnMainThread() override { |
| 109 BrowserThread::PostTask( |
| 110 BrowserThread::IO, FROM_HERE, |
| 111 base::Bind(&BrowsingDataRemoverTransportSecurityStateBrowserTest:: |
| 112 SetUpTransportSecurityState, |
| 113 this, base::RetainedRef( |
| 114 browser()->profile()->GetRequestContext()))); |
| 115 } |
| 116 |
| 117 void CheckTransportSecurityState( |
| 118 scoped_refptr<net::URLRequestContextGetter> context_getter, |
| 119 bool should_be_cleared) { |
| 120 net::TransportSecurityState* state = |
| 121 context_getter->GetURLRequestContext()->transport_security_state(); |
| 122 if (should_be_cleared) |
| 123 EXPECT_FALSE(state->ShouldUpgradeToSSL("example.test")); |
| 124 else |
| 125 EXPECT_TRUE(state->ShouldUpgradeToSSL("example.test")); |
| 126 } |
| 127 |
| 128 protected: |
| 129 void SetUpTransportSecurityState( |
| 130 scoped_refptr<net::URLRequestContextGetter> context_getter) { |
| 131 net::TransportSecurityState* state = |
| 132 context_getter->GetURLRequestContext()->transport_security_state(); |
| 133 base::Time expiry = base::Time::Now() + base::TimeDelta::FromDays(1000); |
| 134 EXPECT_FALSE(state->ShouldUpgradeToSSL("example.test")); |
| 135 state->AddHSTS("example.test", expiry, false); |
| 136 EXPECT_TRUE(state->ShouldUpgradeToSSL("example.test")); |
| 137 } |
| 138 }; |
| 139 |
100 // Test BrowsingDataRemover for downloads. | 140 // Test BrowsingDataRemover for downloads. |
101 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, Download) { | 141 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, Download) { |
102 DownloadAnItem(); | 142 DownloadAnItem(); |
103 RemoveAndWait(BrowsingDataRemover::REMOVE_DOWNLOADS); | 143 RemoveAndWait(BrowsingDataRemover::REMOVE_DOWNLOADS); |
104 VerifyDownloadCount(0u); | 144 VerifyDownloadCount(0u); |
105 } | 145 } |
106 | 146 |
107 // The call to Remove() should crash in debug (DCHECK), but the browser-test | 147 // The call to Remove() should crash in debug (DCHECK), but the browser-test |
108 // process model prevents using a death test. | 148 // process model prevents using a death test. |
109 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) | 149 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) |
(...skipping 19 matching lines...) Expand all Loading... |
129 RunScriptAndCheckResult("getRecords()", "text"); | 169 RunScriptAndCheckResult("getRecords()", "text"); |
130 | 170 |
131 RemoveAndWait(BrowsingDataRemover::REMOVE_SITE_DATA); | 171 RemoveAndWait(BrowsingDataRemover::REMOVE_SITE_DATA); |
132 | 172 |
133 ui_test_utils::NavigateToURL(browser(), url); | 173 ui_test_utils::NavigateToURL(browser(), url); |
134 RunScriptAndCheckResult("createTable()", "done"); | 174 RunScriptAndCheckResult("createTable()", "done"); |
135 RunScriptAndCheckResult("insertRecord('text2')", "done"); | 175 RunScriptAndCheckResult("insertRecord('text2')", "done"); |
136 RunScriptAndCheckResult("getRecords()", "text2"); | 176 RunScriptAndCheckResult("getRecords()", "text2"); |
137 } | 177 } |
138 | 178 |
139 // Profile::ClearNetworkingHistorySince should be exercised here too see whether | 179 // Verify that TransportSecurityState data is cleared for REMOVE_CACHE. |
140 // the call gets delegated through ProfileIO[Impl]Data properly, which is hard | 180 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverTransportSecurityStateBrowserTest, |
141 // to write unit-tests for. Currently this is done by both of the above tests. | 181 ClearTransportSecurityState) { |
142 // Add standalone test if this changes. | 182 RemoveAndWait(BrowsingDataRemover::REMOVE_CACHE); |
| 183 base::RunLoop run_loop; |
| 184 BrowserThread::PostTaskAndReply( |
| 185 BrowserThread::IO, FROM_HERE, |
| 186 base::Bind(&BrowsingDataRemoverTransportSecurityStateBrowserTest:: |
| 187 CheckTransportSecurityState, |
| 188 this, |
| 189 base::RetainedRef(browser()->profile()->GetRequestContext()), |
| 190 true /* should be cleared */), |
| 191 run_loop.QuitClosure()); |
| 192 } |
| 193 |
| 194 // Verify that TransportSecurityState data is not cleared if REMOVE_CACHE is not |
| 195 // set. |
| 196 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverTransportSecurityStateBrowserTest, |
| 197 PreserveTransportSecurityState) { |
| 198 RemoveAndWait(BrowsingDataRemover::REMOVE_SITE_DATA); |
| 199 base::RunLoop run_loop; |
| 200 BrowserThread::PostTaskAndReply( |
| 201 BrowserThread::IO, FROM_HERE, |
| 202 base::Bind(&BrowsingDataRemoverTransportSecurityStateBrowserTest:: |
| 203 CheckTransportSecurityState, |
| 204 this, |
| 205 base::RetainedRef(browser()->profile()->GetRequestContext()), |
| 206 false /* should not be cleared */), |
| 207 run_loop.QuitClosure()); |
| 208 } |
OLD | NEW |