OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 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 #include "chrome/browser/extensions/blacklist_check.h" | |
6 | |
7 #include "base/threading/thread_task_runner_handle.h" | |
8 #include "chrome/browser/extensions/blacklist.h" | |
9 #include "chrome/browser/extensions/test_blacklist.h" | |
10 #include "chrome/browser/extensions/test_extension_prefs.h" | |
11 #include "content/public/test/test_browser_thread_bundle.h" | |
12 #include "extensions/browser/extension_prefs.h" | |
13 #include "extensions/browser/preload_check.h" | |
14 #include "extensions/browser/preload_check_test_util.h" | |
15 #include "testing/gmock/include/gmock/gmock.h" | |
16 #include "testing/gtest/include/gtest/gtest.h" | |
17 | |
18 namespace extensions { | |
19 namespace { | |
20 | |
21 class BlacklistCheckTest : public testing::Test { | |
22 public: | |
23 BlacklistCheckTest() | |
24 : test_prefs_(base::ThreadTaskRunnerHandle::Get()), | |
25 blacklist_(test_prefs_.prefs()) {} | |
26 | |
27 protected: | |
28 void SetUp() override { | |
29 test_blacklist_.Attach(&blacklist_); | |
30 extension_ = test_prefs_.AddExtension("foo"); | |
31 } | |
32 | |
33 void SetBlacklistState(BlacklistState state) { | |
34 test_blacklist_.SetBlacklistState(extension_->id(), state, /*notify=*/true); | |
35 } | |
36 | |
37 Blacklist* blacklist() { return &blacklist_; } | |
38 scoped_refptr<Extension> extension() { return extension_; } | |
39 | |
40 protected: | |
41 PreloadCheckRunner runner_; | |
Devlin
2017/03/16 01:42:44
nit: it'd be my preference to expose this through
michaelpg
2017/03/17 02:34:26
I don't see value in that. Unlike, say, browser_th
| |
42 | |
43 private: | |
44 content::TestBrowserThreadBundle browser_thread_bundle_; | |
45 TestExtensionPrefs test_prefs_; | |
46 Blacklist blacklist_; | |
47 TestBlacklist test_blacklist_; | |
48 scoped_refptr<Extension> extension_; | |
49 }; | |
50 | |
51 } // namespace | |
52 | |
53 // Tests that the blacklist check identifies a blacklisted extension. | |
54 TEST_F(BlacklistCheckTest, BlacklistedMalware) { | |
55 SetBlacklistState(BLACKLISTED_MALWARE); | |
56 | |
57 BlacklistCheck check(blacklist(), extension()); | |
58 runner_.RunUntilComplete(&check); | |
59 | |
60 EXPECT_THAT(runner_.errors(), | |
61 testing::UnorderedElementsAre(PreloadCheck::BLACKLISTED_ID)); | |
62 EXPECT_TRUE(check.GetErrorMessage().empty()); | |
63 } | |
64 | |
65 // Tests that the blacklist check ignores a non-blacklisted extension. | |
66 TEST_F(BlacklistCheckTest, Pass) { | |
67 SetBlacklistState(NOT_BLACKLISTED); | |
68 | |
69 BlacklistCheck check(blacklist(), extension()); | |
70 runner_.RunUntilComplete(&check); | |
71 | |
72 EXPECT_EQ(0u, runner_.errors().size()); | |
73 EXPECT_TRUE(check.GetErrorMessage().empty()); | |
74 } | |
75 | |
76 // Tests that destroying the check after starting it does not cause errors. | |
77 TEST_F(BlacklistCheckTest, ResetCheck) { | |
78 SetBlacklistState(BLACKLISTED_MALWARE); | |
79 | |
80 { | |
81 BlacklistCheck check(blacklist(), extension()); | |
82 check.Start(runner_.GetCallback()); | |
83 } | |
84 runner_.Wait(); | |
85 EXPECT_FALSE(runner_.called()); | |
86 } | |
87 | |
88 } // namespace extensions | |
OLD | NEW |