OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #ifndef CHROME_BROWSER_EXTENSIONS_TEST_BLACKLIST_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_TEST_BLACKLIST_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_TEST_BLACKLIST_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_TEST_BLACKLIST_H_ |
7 | 7 |
| 8 #include <map> |
8 #include <string> | 9 #include <string> |
9 | 10 |
10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
11 #include "chrome/browser/extensions/blacklist.h" | 12 #include "chrome/browser/extensions/blacklist.h" |
| 13 #include "chrome/browser/extensions/blacklist_state_fetcher.h" |
12 | 14 |
13 namespace extensions { | 15 namespace extensions { |
14 | 16 |
| 17 class FakeSafeBrowsingDatabaseManager; |
| 18 |
| 19 // Replace BlacklistStateFetcher for testing of the Blacklist class. |
| 20 class BlacklistStateFetcherMock : public BlacklistStateFetcher { |
| 21 public: |
| 22 BlacklistStateFetcherMock(); |
| 23 |
| 24 virtual ~BlacklistStateFetcherMock(); |
| 25 |
| 26 virtual void Request(const std::string& id, |
| 27 const RequestCallback& callback) OVERRIDE; |
| 28 |
| 29 void SetState(const std::string& id, BlacklistState state); |
| 30 |
| 31 void Clear(); |
| 32 |
| 33 int request_count() const { return request_count_; } |
| 34 |
| 35 private: |
| 36 std::map<std::string, BlacklistState> states_; |
| 37 int request_count_; |
| 38 }; |
| 39 |
| 40 |
15 // A wrapper for an extensions::Blacklist that provides functionality for | 41 // A wrapper for an extensions::Blacklist that provides functionality for |
16 // testing. | 42 // testing. It sets up mocks for SafeBrowsing database and BlacklistFetcher, |
| 43 // that are used by blacklist to retrieve respectively the set of blacklisted |
| 44 // extensions and their blacklist states. |
17 class TestBlacklist { | 45 class TestBlacklist { |
18 public: | 46 public: |
| 47 // Use this if the SafeBrowsing and/or StateFetcher mocks should be created |
| 48 // before initializing the Blacklist. |
| 49 explicit TestBlacklist(); |
| 50 |
19 explicit TestBlacklist(Blacklist* blacklist); | 51 explicit TestBlacklist(Blacklist* blacklist); |
20 | 52 |
| 53 ~TestBlacklist(); |
| 54 |
| 55 void Attach(Blacklist* blacklist); |
| 56 |
| 57 // Only call this if Blacklist is destroyed before TestBlacklist, otherwise |
| 58 // it will be performed from the destructor. |
| 59 void Detach(); |
| 60 |
21 Blacklist* blacklist() { return blacklist_; } | 61 Blacklist* blacklist() { return blacklist_; } |
22 | 62 |
| 63 // Set the extension state in SafeBrowsingDatabaseManager and |
| 64 // BlacklistFetcher. |
| 65 void SetBlacklistState(const std::string& extension_id, |
| 66 BlacklistState state, |
| 67 bool notify); |
| 68 |
23 BlacklistState GetBlacklistState(const std::string& extension_id); | 69 BlacklistState GetBlacklistState(const std::string& extension_id); |
24 | 70 |
| 71 void Clear(bool notify); |
| 72 |
| 73 void DisableSafeBrowsing(); |
| 74 |
| 75 void EnableSafeBrowsing(); |
| 76 |
| 77 void NotifyUpdate(); |
| 78 |
| 79 const BlacklistStateFetcherMock* fetcher() { return &state_fetcher_mock_; } |
| 80 |
25 private: | 81 private: |
26 Blacklist* blacklist_; | 82 Blacklist* blacklist_; |
27 | 83 |
| 84 // The BlacklistStateFetcher object is normally managed by Blacklist. Because |
| 85 // of this, we need to prevent this object from being deleted with Blacklist. |
| 86 // For this, Detach() should be called before blacklist_ is deleted. |
| 87 BlacklistStateFetcherMock state_fetcher_mock_; |
| 88 |
| 89 scoped_refptr<FakeSafeBrowsingDatabaseManager> blacklist_db_; |
| 90 |
| 91 Blacklist::ScopedDatabaseManagerForTest scoped_blacklist_db_; |
| 92 |
28 DISALLOW_COPY_AND_ASSIGN(TestBlacklist); | 93 DISALLOW_COPY_AND_ASSIGN(TestBlacklist); |
29 }; | 94 }; |
30 | 95 |
31 } // namespace extensions | 96 } // namespace extensions |
32 | 97 |
33 #endif // CHROME_BROWSER_EXTENSIONS_TEST_BLACKLIST_H_ | 98 #endif // CHROME_BROWSER_EXTENSIONS_TEST_BLACKLIST_H_ |
OLD | NEW |