Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: chrome/browser/extensions/blacklist_check_unittest.cc

Issue 2693373003: PreloadCheck class for extension pre-install checks (Closed)
Patch Set: don't break enable_extensions=false Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/extensions/blacklist_check.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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_;
39 PreloadCheckRunner runner_;
40
41 private:
42 content::TestBrowserThreadBundle browser_thread_bundle_;
43 TestExtensionPrefs test_prefs_;
44 Blacklist blacklist_;
45 TestBlacklist test_blacklist_;
46 };
47
48 } // namespace
49
50 // Tests that the blacklist check identifies a blacklisted extension.
51 TEST_F(BlacklistCheckTest, BlacklistedMalware) {
52 SetBlacklistState(BLACKLISTED_MALWARE);
53
54 BlacklistCheck check(blacklist(), extension_);
55 runner_.RunUntilComplete(&check);
56
57 EXPECT_THAT(runner_.errors(),
58 testing::UnorderedElementsAre(PreloadCheck::BLACKLISTED_ID));
59 EXPECT_TRUE(check.GetErrorMessage().empty());
60 }
61
62 // Tests that the blacklist check ignores a non-blacklisted extension.
63 TEST_F(BlacklistCheckTest, Pass) {
64 SetBlacklistState(NOT_BLACKLISTED);
65
66 BlacklistCheck check(blacklist(), extension_);
67 runner_.RunUntilComplete(&check);
68
69 EXPECT_EQ(0u, runner_.errors().size());
70 EXPECT_TRUE(check.GetErrorMessage().empty());
71 }
72
73 // Tests that destroying the check after starting it does not cause errors.
74 TEST_F(BlacklistCheckTest, ResetCheck) {
75 SetBlacklistState(BLACKLISTED_MALWARE);
76
77 {
78 BlacklistCheck check(blacklist(), extension_);
79 runner_.Run(&check);
80 }
81
82 runner_.WaitForIdle();
83 EXPECT_FALSE(runner_.called());
84 }
85
86 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/blacklist_check.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698