Chromium Code Reviews| 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 "components/safe_browsing_db/database_manager.h" | 5 #include "components/safe_browsing_db/database_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ptr_util.h" | |
| 13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 14 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 15 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 16 #include "components/safe_browsing_db/test_database_manager.h" | 17 #include "components/safe_browsing_db/test_database_manager.h" |
| 17 #include "components/safe_browsing_db/v4_get_hash_protocol_manager.h" | 18 #include "components/safe_browsing_db/v4_get_hash_protocol_manager.h" |
| 18 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/test/test_browser_thread_bundle.h" | 20 #include "content/public/test/test_browser_thread_bundle.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 22 | 23 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 std::vector<std::string> blocked_permissions_; | 111 std::vector<std::string> blocked_permissions_; |
| 111 bool callback_invoked_; | 112 bool callback_invoked_; |
| 112 DISALLOW_COPY_AND_ASSIGN(TestClient); | 113 DISALLOW_COPY_AND_ASSIGN(TestClient); |
| 113 }; | 114 }; |
| 114 | 115 |
| 115 } // namespace | 116 } // namespace |
| 116 | 117 |
| 117 class SafeBrowsingDatabaseManagerTest : public testing::Test { | 118 class SafeBrowsingDatabaseManagerTest : public testing::Test { |
| 118 protected: | 119 protected: |
| 119 void SetUp() override { | 120 void SetUp() override { |
| 120 TestV4GetHashProtocolManagerFactory get_hash_pm_factory; | 121 V4GetHashProtocolManager::RegisterFactory( |
| 121 V4GetHashProtocolManager::RegisterFactory(&get_hash_pm_factory); | 122 base::WrapUnique(new TestV4GetHashProtocolManagerFactory())); |
|
mattm
2016/05/02 22:36:53
The RegisterFactory idiom is already used in a bun
Reilly Grant (use Gerrit)
2016/05/02 22:55:27
I agree in principle but this is the only place in
kcarattini
2016/05/03 01:16:32
I'm not sure I follow why passing a unique_ptr is
Reilly Grant (use Gerrit)
2016/05/03 01:18:21
It prevents you from passing a pointer to a local
| |
| 122 | 123 |
| 123 db_manager_ = new TestSafeBrowsingDatabaseManager(); | 124 db_manager_ = new TestSafeBrowsingDatabaseManager(); |
| 124 db_manager_->StartOnIOThread(NULL, V4ProtocolConfig()); | 125 db_manager_->StartOnIOThread(NULL, V4ProtocolConfig()); |
| 125 } | 126 } |
| 126 | 127 |
| 127 void TearDown() override { | 128 void TearDown() override { |
| 128 base::RunLoop().RunUntilIdle(); | 129 base::RunLoop().RunUntilIdle(); |
| 129 db_manager_->StopOnIOThread(false); | 130 db_manager_->StopOnIOThread(false); |
| 131 V4GetHashProtocolManager::RegisterFactory(nullptr); | |
| 130 } | 132 } |
| 131 | 133 |
| 132 scoped_refptr<SafeBrowsingDatabaseManager> db_manager_; | 134 scoped_refptr<SafeBrowsingDatabaseManager> db_manager_; |
| 133 | 135 |
| 134 private: | 136 private: |
| 135 content::TestBrowserThreadBundle test_browser_thread_bundle_; | 137 content::TestBrowserThreadBundle test_browser_thread_bundle_; |
| 136 }; | 138 }; |
| 137 | 139 |
| 138 TEST_F(SafeBrowsingDatabaseManagerTest, CheckApiBlacklistUrlWrongScheme) { | 140 TEST_F(SafeBrowsingDatabaseManagerTest, CheckApiBlacklistUrlWrongScheme) { |
| 139 TestClient client; | 141 TestClient client; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 EXPECT_FALSE(db_manager_->CheckApiBlacklistUrl(url, &client)); | 239 EXPECT_FALSE(db_manager_->CheckApiBlacklistUrl(url, &client)); |
| 238 EXPECT_TRUE(db_manager_->CancelApiCheck(&client)); | 240 EXPECT_TRUE(db_manager_->CancelApiCheck(&client)); |
| 239 base::RunLoop().RunUntilIdle(); | 241 base::RunLoop().RunUntilIdle(); |
| 240 | 242 |
| 241 const std::vector<std::string>& permissions = client.GetBlockedPermissions(); | 243 const std::vector<std::string>& permissions = client.GetBlockedPermissions(); |
| 242 EXPECT_EQ(0ul, permissions.size()); | 244 EXPECT_EQ(0ul, permissions.size()); |
| 243 EXPECT_FALSE(client.callback_invoked()); | 245 EXPECT_FALSE(client.callback_invoked()); |
| 244 } | 246 } |
| 245 | 247 |
| 246 } // namespace safe_browsing | 248 } // namespace safe_browsing |
| OLD | NEW |