Chromium Code Reviews| Index: chrome/browser/extensions/blacklist_check_unittest.cc |
| diff --git a/chrome/browser/extensions/blacklist_check_unittest.cc b/chrome/browser/extensions/blacklist_check_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..30c4fa83ecab147c357ff8235022e7da06867597 |
| --- /dev/null |
| +++ b/chrome/browser/extensions/blacklist_check_unittest.cc |
| @@ -0,0 +1,88 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/extensions/blacklist_check.h" |
| + |
| +#include "base/threading/thread_task_runner_handle.h" |
| +#include "chrome/browser/extensions/blacklist.h" |
| +#include "chrome/browser/extensions/test_blacklist.h" |
| +#include "chrome/browser/extensions/test_extension_prefs.h" |
| +#include "content/public/test/test_browser_thread_bundle.h" |
| +#include "extensions/browser/extension_prefs.h" |
| +#include "extensions/browser/preload_check.h" |
| +#include "extensions/browser/preload_check_test_util.h" |
| +#include "testing/gmock/include/gmock/gmock.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace extensions { |
| +namespace { |
| + |
| +class BlacklistCheckTest : public testing::Test { |
| + public: |
| + BlacklistCheckTest() |
| + : test_prefs_(base::ThreadTaskRunnerHandle::Get()), |
| + blacklist_(test_prefs_.prefs()) {} |
| + |
| + protected: |
| + void SetUp() override { |
| + test_blacklist_.Attach(&blacklist_); |
| + extension_ = test_prefs_.AddExtension("foo"); |
| + } |
| + |
| + void SetBlacklistState(BlacklistState state) { |
| + test_blacklist_.SetBlacklistState(extension_->id(), state, /*notify=*/true); |
| + } |
| + |
| + Blacklist* blacklist() { return &blacklist_; } |
| + scoped_refptr<Extension> extension() { return extension_; } |
| + |
| + protected: |
| + 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
|
| + |
| + private: |
| + content::TestBrowserThreadBundle browser_thread_bundle_; |
| + TestExtensionPrefs test_prefs_; |
| + Blacklist blacklist_; |
| + TestBlacklist test_blacklist_; |
| + scoped_refptr<Extension> extension_; |
| +}; |
| + |
| +} // namespace |
| + |
| +// Tests that the blacklist check identifies a blacklisted extension. |
| +TEST_F(BlacklistCheckTest, BlacklistedMalware) { |
| + SetBlacklistState(BLACKLISTED_MALWARE); |
| + |
| + BlacklistCheck check(blacklist(), extension()); |
| + runner_.RunUntilComplete(&check); |
| + |
| + EXPECT_THAT(runner_.errors(), |
| + testing::UnorderedElementsAre(PreloadCheck::BLACKLISTED_ID)); |
| + EXPECT_TRUE(check.GetErrorMessage().empty()); |
| +} |
| + |
| +// Tests that the blacklist check ignores a non-blacklisted extension. |
| +TEST_F(BlacklistCheckTest, Pass) { |
| + SetBlacklistState(NOT_BLACKLISTED); |
| + |
| + BlacklistCheck check(blacklist(), extension()); |
| + runner_.RunUntilComplete(&check); |
| + |
| + EXPECT_EQ(0u, runner_.errors().size()); |
| + EXPECT_TRUE(check.GetErrorMessage().empty()); |
| +} |
| + |
| +// Tests that destroying the check after starting it does not cause errors. |
| +TEST_F(BlacklistCheckTest, ResetCheck) { |
| + SetBlacklistState(BLACKLISTED_MALWARE); |
| + |
| + { |
| + BlacklistCheck check(blacklist(), extension()); |
| + check.Start(runner_.GetCallback()); |
| + } |
| + runner_.Wait(); |
| + EXPECT_FALSE(runner_.called()); |
| +} |
| + |
| +} // namespace extensions |