Add a webstorePrivate API to show a permission prompt for delegated bundle installs
[chromium-blink-merge.git] / chrome / browser / extensions / blacklist_state_fetcher_unittest.cc
blob793e2cf41a8e55b9066dd4d55c81870112806731
1 // Copyright 2013 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.
5 #include "base/bind.h"
6 #include "base/run_loop.h"
7 #include "chrome/browser/extensions/blacklist_state_fetcher.h"
8 #include "chrome/browser/extensions/test_blacklist_state_fetcher.h"
9 #include "chrome/common/safe_browsing/crx_info.pb.h"
10 #include "content/public/test/test_browser_thread_bundle.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 namespace extensions {
14 namespace {
16 void Assign(BlacklistState* to, BlacklistState from) {
17 *to = from;
20 } // namespace
22 class BlacklistStateFetcherTest : public testing::Test {
23 private:
24 content::TestBrowserThreadBundle browser_thread_bundle_;
27 TEST_F(BlacklistStateFetcherTest, RequestBlacklistState) {
28 BlacklistStateFetcher fetcher;
29 TestBlacklistStateFetcher tester(&fetcher);
31 tester.SetBlacklistVerdict(
32 "a", ClientCRXListInfoResponse_Verdict_SECURITY_VULNERABILITY);
34 BlacklistState result;
35 fetcher.Request("a", base::Bind(&Assign, &result));
37 EXPECT_TRUE(tester.HandleFetcher(0));
38 EXPECT_EQ(BLACKLISTED_SECURITY_VULNERABILITY, result);
41 TEST_F(BlacklistStateFetcherTest, RequestMultipleBlacklistStates) {
42 BlacklistStateFetcher fetcher;
43 TestBlacklistStateFetcher tester(&fetcher);
45 tester.SetBlacklistVerdict(
46 "a", ClientCRXListInfoResponse_Verdict_NOT_IN_BLACKLIST);
47 tester.SetBlacklistVerdict(
48 "b", ClientCRXListInfoResponse_Verdict_MALWARE);
49 tester.SetBlacklistVerdict(
50 "c", ClientCRXListInfoResponse_Verdict_SECURITY_VULNERABILITY);
51 tester.SetBlacklistVerdict(
52 "d", ClientCRXListInfoResponse_Verdict_CWS_POLICY_VIOLATION);
53 tester.SetBlacklistVerdict(
54 "e", ClientCRXListInfoResponse_Verdict_POTENTIALLY_UNWANTED);
56 BlacklistState result[9];
57 fetcher.Request("a", base::Bind(&Assign, &result[0]));
58 fetcher.Request("a", base::Bind(&Assign, &result[1]));
59 fetcher.Request("b", base::Bind(&Assign, &result[2]));
60 fetcher.Request("b", base::Bind(&Assign, &result[3]));
61 fetcher.Request("c", base::Bind(&Assign, &result[4]));
62 fetcher.Request("d", base::Bind(&Assign, &result[5]));
63 fetcher.Request("e", base::Bind(&Assign, &result[6]));
64 fetcher.Request("f", base::Bind(&Assign, &result[7]));
65 fetcher.Request("f", base::Bind(&Assign, &result[8]));
67 // 6 fetchers should be created. Sending responses in shuffled order.
68 EXPECT_TRUE(tester.HandleFetcher(4));
69 EXPECT_TRUE(tester.HandleFetcher(2));
70 EXPECT_TRUE(tester.HandleFetcher(5));
71 EXPECT_TRUE(tester.HandleFetcher(1));
72 EXPECT_TRUE(tester.HandleFetcher(0));
73 EXPECT_TRUE(tester.HandleFetcher(3));
75 EXPECT_EQ(NOT_BLACKLISTED, result[0]);
76 EXPECT_EQ(NOT_BLACKLISTED, result[1]);
77 EXPECT_EQ(BLACKLISTED_MALWARE, result[2]);
78 EXPECT_EQ(BLACKLISTED_MALWARE, result[3]);
79 EXPECT_EQ(BLACKLISTED_SECURITY_VULNERABILITY, result[4]);
80 EXPECT_EQ(BLACKLISTED_CWS_POLICY_VIOLATION, result[5]);
81 EXPECT_EQ(BLACKLISTED_POTENTIALLY_UNWANTED, result[6]);
82 EXPECT_EQ(NOT_BLACKLISTED, result[7]);
83 EXPECT_EQ(NOT_BLACKLISTED, result[8]);
86 } // namespace extensions