- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / safe_browsing / safe_browsing_store_unittest_helper.h
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_STORE_UNITTEST_HELPER_H_
6 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_STORE_UNITTEST_HELPER_H_
7
8 #include "chrome/browser/safe_browsing/safe_browsing_store.h"
9
10 #include "crypto/sha2.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 // Helper code for testing that a SafeBrowsingStore implementation
14 // works to spec.
15
16 // Helper to make it easy to initialize SBFullHash constants.
17 inline const SBFullHash SBFullHashFromString(const char* str) {
18   SBFullHash h;
19   crypto::SHA256HashString(str, &h.full_hash, sizeof(h.full_hash));
20   return h;
21 }
22
23 // TODO(shess): There's an == operator defined in
24 // safe_browsing_utils.h, but using it gives me the heebie-jeebies.
25 inline bool SBFullHashEq(const SBFullHash& a, const SBFullHash& b) {
26   return !memcmp(a.full_hash, b.full_hash, sizeof(a.full_hash));
27 }
28
29 // Test that the empty store looks empty.
30 void SafeBrowsingStoreTestEmpty(SafeBrowsingStore* store);
31
32 // Write some prefix data to the store and verify that it looks like
33 // it is still there after the transaction completes.
34 void SafeBrowsingStoreTestStorePrefix(SafeBrowsingStore* store);
35
36 // Test that subs knockout adds.
37 void SafeBrowsingStoreTestSubKnockout(SafeBrowsingStore* store);
38
39 // Test that deletes delete the chunk's data.
40 void SafeBrowsingStoreTestDeleteChunks(SafeBrowsingStore* store);
41
42 // Test that deleting the store deletes the store.
43 void SafeBrowsingStoreTestDelete(SafeBrowsingStore* store,
44                                  const base::FilePath& filename);
45
46 // Wrap all the tests up for implementation subclasses.
47 // |test_fixture| is the class that would be passed to TEST_F(),
48 // |instance_name| is the name of the SafeBrowsingStore instance
49 // within the class, as a pointer, and |filename| is that store's
50 // filename, for the Delete() test.
51 #define TEST_STORE(test_fixture, instance_name, filename)        \
52   TEST_F(test_fixture, Empty) { \
53     SafeBrowsingStoreTestEmpty(instance_name); \
54   } \
55   TEST_F(test_fixture, StorePrefix) { \
56     SafeBrowsingStoreTestStorePrefix(instance_name); \
57   } \
58   TEST_F(test_fixture, SubKnockout) { \
59     SafeBrowsingStoreTestSubKnockout(instance_name); \
60   } \
61   TEST_F(test_fixture, DeleteChunks) { \
62     SafeBrowsingStoreTestDeleteChunks(instance_name); \
63   } \
64   TEST_F(test_fixture, Delete) { \
65     SafeBrowsingStoreTestDelete(instance_name, filename);        \
66   }
67
68 #endif  // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_STORE_UNITTEST_HELPER_H_