| 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 "chrome/browser/safe_browsing/protocol_manager.h" | 5 #include "chrome/browser/safe_browsing/protocol_manager.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "base/test/test_simple_task_runner.h" | 12 #include "base/test/test_simple_task_runner.h" |
| 13 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "chrome/browser/safe_browsing/chunk.pb.h" | 15 #include "chrome/browser/safe_browsing/chunk.pb.h" |
| 16 #include "components/safe_browsing_db/safe_browsing_prefs.h" |
| 16 #include "components/safe_browsing_db/safebrowsing.pb.h" | 17 #include "components/safe_browsing_db/safebrowsing.pb.h" |
| 17 #include "components/safe_browsing_db/util.h" | 18 #include "components/safe_browsing_db/util.h" |
| 18 #include "content/public/test/test_browser_thread.h" | 19 #include "content/public/test/test_browser_thread.h" |
| 19 #include "google_apis/google_api_keys.h" | 20 #include "google_apis/google_api_keys.h" |
| 20 #include "net/base/escape.h" | 21 #include "net/base/escape.h" |
| 21 #include "net/base/load_flags.h" | 22 #include "net/base/load_flags.h" |
| 22 #include "net/base/net_errors.h" | 23 #include "net/base/net_errors.h" |
| 23 #include "net/url_request/test_url_fetcher_factory.h" | 24 #include "net/url_request/test_url_fetcher_factory.h" |
| 24 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
| 25 #include "testing/gmock_mutant.h" | 26 #include "testing/gmock_mutant.h" |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 } | 270 } |
| 270 | 271 |
| 271 TEST_F(SafeBrowsingProtocolManagerTest, TestGetHashUrl) { | 272 TEST_F(SafeBrowsingProtocolManagerTest, TestGetHashUrl) { |
| 272 std::unique_ptr<SafeBrowsingProtocolManager> pm( | 273 std::unique_ptr<SafeBrowsingProtocolManager> pm( |
| 273 CreateProtocolManager(nullptr)); | 274 CreateProtocolManager(nullptr)); |
| 274 | 275 |
| 275 EXPECT_EQ( | 276 EXPECT_EQ( |
| 276 "https://prefix.com/foo/gethash?client=unittest&appver=1.0&" | 277 "https://prefix.com/foo/gethash?client=unittest&appver=1.0&" |
| 277 "pver=3.0" + | 278 "pver=3.0" + |
| 278 key_param_ + "&ext=0", | 279 key_param_ + "&ext=0", |
| 279 pm->GetHashUrl(false).spec()); | 280 pm->GetHashUrl(SBER_LEVEL_OFF).spec()); |
| 280 | 281 |
| 281 pm->set_additional_query(kAdditionalQuery); | 282 pm->set_additional_query(kAdditionalQuery); |
| 282 EXPECT_EQ( | 283 EXPECT_EQ( |
| 283 "https://prefix.com/foo/gethash?client=unittest&appver=1.0&" | 284 "https://prefix.com/foo/gethash?client=unittest&appver=1.0&" |
| 284 "pver=3.0" + | 285 "pver=3.0" + |
| 285 key_param_ + "&additional_query&ext=1", | 286 key_param_ + "&additional_query&ext=1", |
| 286 pm->GetHashUrl(true).spec()); | 287 pm->GetHashUrl(SBER_LEVEL_LEGACY).spec()); |
| 288 |
| 289 EXPECT_EQ( |
| 290 "https://prefix.com/foo/gethash?client=unittest&appver=1.0&" |
| 291 "pver=3.0" + |
| 292 key_param_ + "&additional_query&ext=2", |
| 293 pm->GetHashUrl(SBER_LEVEL_SCOUT).spec()); |
| 287 } | 294 } |
| 288 | 295 |
| 289 TEST_F(SafeBrowsingProtocolManagerTest, TestUpdateUrl) { | 296 TEST_F(SafeBrowsingProtocolManagerTest, TestUpdateUrl) { |
| 290 std::unique_ptr<SafeBrowsingProtocolManager> pm( | 297 std::unique_ptr<SafeBrowsingProtocolManager> pm( |
| 291 CreateProtocolManager(nullptr)); | 298 CreateProtocolManager(nullptr)); |
| 292 | 299 |
| 293 EXPECT_EQ( | 300 EXPECT_EQ( |
| 294 "https://prefix.com/foo/downloads?client=unittest&appver=1.0&" | 301 "https://prefix.com/foo/downloads?client=unittest&appver=1.0&" |
| 295 "pver=3.0" + | 302 "pver=3.0" + |
| 296 key_param_ + "&ext=1", | 303 key_param_ + "&ext=1", |
| 297 pm->UpdateUrl(true).spec()); | 304 pm->UpdateUrl(SBER_LEVEL_LEGACY).spec()); |
| 305 |
| 306 EXPECT_EQ( |
| 307 "https://prefix.com/foo/downloads?client=unittest&appver=1.0&" |
| 308 "pver=3.0" + |
| 309 key_param_ + "&ext=2", |
| 310 pm->UpdateUrl(SBER_LEVEL_SCOUT).spec()); |
| 298 | 311 |
| 299 pm->set_additional_query(kAdditionalQuery); | 312 pm->set_additional_query(kAdditionalQuery); |
| 300 EXPECT_EQ( | 313 EXPECT_EQ( |
| 301 "https://prefix.com/foo/downloads?client=unittest&appver=1.0&" | 314 "https://prefix.com/foo/downloads?client=unittest&appver=1.0&" |
| 302 "pver=3.0" + | 315 "pver=3.0" + |
| 303 key_param_ + "&additional_query&ext=0", | 316 key_param_ + "&additional_query&ext=0", |
| 304 pm->UpdateUrl(false).spec()); | 317 pm->UpdateUrl(SBER_LEVEL_OFF).spec()); |
| 305 } | 318 } |
| 306 | 319 |
| 307 TEST_F(SafeBrowsingProtocolManagerTest, TestNextChunkUrl) { | 320 TEST_F(SafeBrowsingProtocolManagerTest, TestNextChunkUrl) { |
| 308 std::unique_ptr<SafeBrowsingProtocolManager> pm( | 321 std::unique_ptr<SafeBrowsingProtocolManager> pm( |
| 309 CreateProtocolManager(nullptr)); | 322 CreateProtocolManager(nullptr)); |
| 310 | 323 |
| 311 std::string url_partial = "localhost:1234/foo/bar?foo"; | 324 std::string url_partial = "localhost:1234/foo/bar?foo"; |
| 312 std::string url_http_full = "http://localhost:1234/foo/bar?foo"; | 325 std::string url_http_full = "http://localhost:1234/foo/bar?foo"; |
| 313 std::string url_https_full = "https://localhost:1234/foo/bar?foo"; | 326 std::string url_https_full = "https://localhost:1234/foo/bar?foo"; |
| 314 std::string url_https_no_query = "https://localhost:1234/foo/bar"; | 327 std::string url_https_no_query = "https://localhost:1234/foo/bar"; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 } | 382 } |
| 370 }; | 383 }; |
| 371 | 384 |
| 372 // |InvokeGetChunksCallback| is required because GMock's InvokeArgument action | 385 // |InvokeGetChunksCallback| is required because GMock's InvokeArgument action |
| 373 // expects to use operator(), and a Callback only provides Run(). | 386 // expects to use operator(), and a Callback only provides Run(). |
| 374 // TODO(cbentzel): Use ACTION or ACTION_TEMPLATE instead? | 387 // TODO(cbentzel): Use ACTION or ACTION_TEMPLATE instead? |
| 375 void InvokeGetChunksCallback( | 388 void InvokeGetChunksCallback( |
| 376 const std::vector<SBListChunkRanges>& ranges, | 389 const std::vector<SBListChunkRanges>& ranges, |
| 377 bool database_error, | 390 bool database_error, |
| 378 SafeBrowsingProtocolManagerDelegate::GetChunksCallback callback) { | 391 SafeBrowsingProtocolManagerDelegate::GetChunksCallback callback) { |
| 379 callback.Run(ranges, database_error, false); | 392 callback.Run(ranges, database_error, SBER_LEVEL_OFF); |
| 380 } | 393 } |
| 381 | 394 |
| 382 // |HandleAddChunks| deletes the chunks and asynchronously invokes | 395 // |HandleAddChunks| deletes the chunks and asynchronously invokes |
| 383 // |callback| since SafeBrowsingProtocolManager is not re-entrant at the time | 396 // |callback| since SafeBrowsingProtocolManager is not re-entrant at the time |
| 384 // this is called. This guarantee is part of the | 397 // this is called. This guarantee is part of the |
| 385 // SafeBrowsingProtocolManagerDelegate contract. | 398 // SafeBrowsingProtocolManagerDelegate contract. |
| 386 void HandleAddChunks( | 399 void HandleAddChunks( |
| 387 const std::string& unused_list, | 400 const std::string& unused_list, |
| 388 const std::vector<std::unique_ptr<SBChunkData>>& chunks, | 401 const std::vector<std::unique_ptr<SBChunkData>>& chunks, |
| 389 SafeBrowsingProtocolManagerDelegate::AddChunksCallback callback) { | 402 SafeBrowsingProtocolManagerDelegate::AddChunksCallback callback) { |
| (...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1099 | 1112 |
| 1100 EXPECT_FALSE(pm->IsUpdateScheduled()); | 1113 EXPECT_FALSE(pm->IsUpdateScheduled()); |
| 1101 | 1114 |
| 1102 // Invoke the AddChunksCallback to finish the update. | 1115 // Invoke the AddChunksCallback to finish the update. |
| 1103 runner_->RunPendingTasks(); | 1116 runner_->RunPendingTasks(); |
| 1104 | 1117 |
| 1105 EXPECT_TRUE(pm->IsUpdateScheduled()); | 1118 EXPECT_TRUE(pm->IsUpdateScheduled()); |
| 1106 } | 1119 } |
| 1107 | 1120 |
| 1108 } // namespace safe_browsing | 1121 } // namespace safe_browsing |
| OLD | NEW |