Home | History | Annotate | Download | only in safe_browsing
      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 #pragma once
      8 
      9 #include "chrome/browser/safe_browsing/safe_browsing_store.h"
     10 
     11 #include "crypto/sha2.h"
     12 #include "testing/gtest/include/gtest/gtest.h"
     13 
     14 // Helper code for testing that a SafeBrowsingStore implementation
     15 // works to spec.
     16 
     17 // Helper to make it easy to initialize SBFullHash constants.
     18 inline const SBFullHash SBFullHashFromString(const char* str) {
     19   SBFullHash h;
     20   crypto::SHA256HashString(str, &h.full_hash, sizeof(h.full_hash));
     21   return h;
     22 }
     23 
     24 // TODO(shess): There's an == operator defined in
     25 // safe_browsing_utils.h, but using it gives me the heebie-jeebies.
     26 inline bool SBFullHashEq(const SBFullHash& a, const SBFullHash& b) {
     27   return !memcmp(a.full_hash, b.full_hash, sizeof(a.full_hash));
     28 }
     29 
     30 // Test that the empty store looks empty.
     31 void SafeBrowsingStoreTestEmpty(SafeBrowsingStore* store);
     32 
     33 // Write some prefix data to the store and verify that it looks like
     34 // it is still there after the transaction completes.
     35 void SafeBrowsingStoreTestStorePrefix(SafeBrowsingStore* store);
     36 
     37 // Test that subs knockout adds.
     38 void SafeBrowsingStoreTestSubKnockout(SafeBrowsingStore* store);
     39 
     40 // Test that deletes delete the chunk's data.
     41 void SafeBrowsingStoreTestDeleteChunks(SafeBrowsingStore* store);
     42 
     43 // Test that deleting the store deletes the store.
     44 void SafeBrowsingStoreTestDelete(SafeBrowsingStore* store,
     45                                  const FilePath& filename);
     46 
     47 // Wrap all the tests up for implementation subclasses.
     48 // |test_fixture| is the class that would be passed to TEST_F(),
     49 // |instance_name| is the name of the SafeBrowsingStore instance
     50 // within the class, as a pointer, and |filename| is that store's
     51 // filename, for the Delete() test.
     52 #define TEST_STORE(test_fixture, instance_name, filename)        \
     53   TEST_F(test_fixture, Empty) { \
     54     SafeBrowsingStoreTestEmpty(instance_name); \
     55   } \
     56   TEST_F(test_fixture, StorePrefix) { \
     57     SafeBrowsingStoreTestStorePrefix(instance_name); \
     58   } \
     59   TEST_F(test_fixture, SubKnockout) { \
     60     SafeBrowsingStoreTestSubKnockout(instance_name); \
     61   } \
     62   TEST_F(test_fixture, DeleteChunks) { \
     63     SafeBrowsingStoreTestDeleteChunks(instance_name); \
     64   } \
     65   TEST_F(test_fixture, Delete) { \
     66     SafeBrowsingStoreTestDelete(instance_name, filename);        \
     67   }
     68 
     69 #endif  // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_STORE_UNITTEST_HELPER_H_
     70