Add a webstorePrivate API to show a permission prompt for delegated bundle installs
[chromium-blink-merge.git] / chrome / browser / extensions / test_blacklist_state_fetcher.cc
blob9e7ef4cde3899f7ee48d22c8cf9f4144f62288fd
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 "chrome/browser/extensions/test_blacklist_state_fetcher.h"
7 #include "base/stl_util.h"
8 #include "base/thread_task_runner_handle.h"
9 #include "net/url_request/url_request_test_util.h"
11 namespace extensions {
12 namespace {
14 static const char kUrlPrefix[] = "https://prefix.com/foo";
15 static const char kBackupConnectUrlPrefix[] = "https://alt1-prefix.com/foo";
16 static const char kBackupHttpUrlPrefix[] = "https://alt2-prefix.com/foo";
17 static const char kBackupNetworkUrlPrefix[] = "https://alt3-prefix.com/foo";
18 static const char kClient[] = "unittest";
19 static const char kAppVer[] = "1.0";
21 SafeBrowsingProtocolConfig CreateSafeBrowsingProtocolConfig() {
22 SafeBrowsingProtocolConfig config;
23 config.client_name = kClient;
24 config.url_prefix = kUrlPrefix;
25 config.backup_connect_error_url_prefix = kBackupConnectUrlPrefix;
26 config.backup_http_error_url_prefix = kBackupHttpUrlPrefix;
27 config.backup_network_error_url_prefix = kBackupNetworkUrlPrefix;
28 config.version = kAppVer;
29 return config;
32 } // namespace
34 TestBlacklistStateFetcher::TestBlacklistStateFetcher(
35 BlacklistStateFetcher* fetcher) : fetcher_(fetcher) {
36 fetcher_->SetSafeBrowsingConfig(CreateSafeBrowsingProtocolConfig());
37 scoped_refptr<net::TestURLRequestContextGetter> context =
38 new net::TestURLRequestContextGetter(
39 base::ThreadTaskRunnerHandle::Get());
40 fetcher_->SetURLRequestContextForTest(context.get());
43 TestBlacklistStateFetcher::~TestBlacklistStateFetcher() {
46 void TestBlacklistStateFetcher::SetBlacklistVerdict(
47 const std::string& id, ClientCRXListInfoResponse_Verdict state) {
48 verdicts_[id] = state;
51 bool TestBlacklistStateFetcher::HandleFetcher(int fetcher_id) {
52 net::TestURLFetcher* url_fetcher = url_fetcher_factory_.GetFetcherByID(
53 fetcher_id);
54 if (!url_fetcher)
55 return false;
57 const std::string& request_str = url_fetcher->upload_data();
58 ClientCRXListInfoRequest request;
59 if (!request.ParseFromString(request_str))
60 return false;
62 std::string id = request.id();
64 ClientCRXListInfoResponse response;
65 if (ContainsKey(verdicts_, id))
66 response.set_verdict(verdicts_[id]);
67 else
68 response.set_verdict(ClientCRXListInfoResponse::NOT_IN_BLACKLIST);
70 std::string response_str;
71 response.SerializeToString(&response_str);
73 url_fetcher->set_status(net::URLRequestStatus());
74 url_fetcher->set_response_code(200);
75 url_fetcher->SetResponseString(response_str);
76 url_fetcher->delegate()->OnURLFetchComplete(url_fetcher);
78 return true;
81 } // namespace extensions