OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/safe_search_api/safe_search_url_checker.h" | 5 #include "chrome/browser/safe_search_api/safe_search_url_checker.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/json/json_writer.h" | 14 #include "base/json/json_writer.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ptr_util.h" |
16 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
17 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/thread_task_runner_handle.h" |
18 #include "base/values.h" | 19 #include "base/values.h" |
19 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
20 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" | 21 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
21 #include "net/url_request/test_url_fetcher_factory.h" | 22 #include "net/url_request/test_url_fetcher_factory.h" |
22 #include "net/url_request/url_request_test_util.h" | 23 #include "net/url_request/url_request_test_util.h" |
23 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
25 #include "url/gurl.h" | 26 #include "url/gurl.h" |
(...skipping 18 matching lines...) Expand all Loading... |
44 "http://www.randomsite8.com", | 45 "http://www.randomsite8.com", |
45 "http://www.randomsite9.com", | 46 "http://www.randomsite9.com", |
46 }; | 47 }; |
47 | 48 |
48 std::string BuildResponse(bool is_porn) { | 49 std::string BuildResponse(bool is_porn) { |
49 base::DictionaryValue dict; | 50 base::DictionaryValue dict; |
50 std::unique_ptr<base::DictionaryValue> classification_dict( | 51 std::unique_ptr<base::DictionaryValue> classification_dict( |
51 new base::DictionaryValue); | 52 new base::DictionaryValue); |
52 if (is_porn) | 53 if (is_porn) |
53 classification_dict->SetBoolean("pornography", is_porn); | 54 classification_dict->SetBoolean("pornography", is_porn); |
54 base::ListValue* classifications_list = new base::ListValue; | 55 auto classifications_list = base::MakeUnique<base::ListValue>(); |
55 classifications_list->Append(std::move(classification_dict)); | 56 classifications_list->Append(std::move(classification_dict)); |
56 dict.SetWithoutPathExpansion("classifications", classifications_list); | 57 dict.SetWithoutPathExpansion("classifications", |
| 58 std::move(classifications_list)); |
57 std::string result; | 59 std::string result; |
58 base::JSONWriter::Write(dict, &result); | 60 base::JSONWriter::Write(dict, &result); |
59 return result; | 61 return result; |
60 } | 62 } |
61 | 63 |
62 } // namespace | 64 } // namespace |
63 | 65 |
64 class SafeSearchURLCheckerTest : public testing::Test { | 66 class SafeSearchURLCheckerTest : public testing::Test { |
65 public: | 67 public: |
66 SafeSearchURLCheckerTest() | 68 SafeSearchURLCheckerTest() |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 ASSERT_FALSE(CheckURL(url)); | 189 ASSERT_FALSE(CheckURL(url)); |
188 EXPECT_CALL(*this, OnCheckDone(url, Classification::SAFE, false)); | 190 EXPECT_CALL(*this, OnCheckDone(url, Classification::SAFE, false)); |
189 SendValidResponse(false); | 191 SendValidResponse(false); |
190 | 192 |
191 // Since the cache timeout is zero, the cache entry should be invalidated | 193 // Since the cache timeout is zero, the cache entry should be invalidated |
192 // immediately. | 194 // immediately. |
193 ASSERT_FALSE(CheckURL(url)); | 195 ASSERT_FALSE(CheckURL(url)); |
194 EXPECT_CALL(*this, OnCheckDone(url, Classification::UNSAFE, false)); | 196 EXPECT_CALL(*this, OnCheckDone(url, Classification::UNSAFE, false)); |
195 SendValidResponse(true); | 197 SendValidResponse(true); |
196 } | 198 } |
OLD | NEW |