OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 EXPECT_EQ(expected_pb.referrer_url(), report_pb.referrer_url()); | 260 EXPECT_EQ(expected_pb.referrer_url(), report_pb.referrer_url()); |
261 EXPECT_EQ(expected_pb.did_proceed(), report_pb.did_proceed()); | 261 EXPECT_EQ(expected_pb.did_proceed(), report_pb.did_proceed()); |
262 EXPECT_EQ(expected_pb.has_repeat_visit(), report_pb.has_repeat_visit()); | 262 EXPECT_EQ(expected_pb.has_repeat_visit(), report_pb.has_repeat_visit()); |
263 if (expected_pb.has_repeat_visit() && report_pb.has_repeat_visit()) { | 263 if (expected_pb.has_repeat_visit() && report_pb.has_repeat_visit()) { |
264 EXPECT_EQ(expected_pb.repeat_visit(), report_pb.repeat_visit()); | 264 EXPECT_EQ(expected_pb.repeat_visit(), report_pb.repeat_visit()); |
265 } | 265 } |
266 | 266 |
267 ASSERT_EQ(expected_pb.resources_size(), report_pb.resources_size()); | 267 ASSERT_EQ(expected_pb.resources_size(), report_pb.resources_size()); |
268 // Put the actual resources in a map, then iterate over the expected | 268 // Put the actual resources in a map, then iterate over the expected |
269 // resources, making sure each exists and is equal. | 269 // resources, making sure each exists and is equal. |
270 base::hash_map<int, const ClientSafeBrowsingReportRequest::Resource*> | 270 std::map<int, const ClientSafeBrowsingReportRequest::Resource*> |
271 actual_resource_map; | 271 actual_resource_map; |
272 for (const ClientSafeBrowsingReportRequest::Resource& resource : | 272 for (const ClientSafeBrowsingReportRequest::Resource& resource : |
273 report_pb.resources()) { | 273 report_pb.resources()) { |
274 actual_resource_map[resource.id()] = &resource; | 274 actual_resource_map[resource.id()] = &resource; |
275 } | 275 } |
276 // Make sure no resources disappeared when moving them to a map (IDs should | 276 // Make sure no resources disappeared when moving them to a map (IDs should |
277 // be unique). | 277 // be unique). |
278 ASSERT_EQ(expected_pb.resources_size(), | 278 ASSERT_EQ(expected_pb.resources_size(), |
279 static_cast<int>(actual_resource_map.size())); | 279 static_cast<int>(actual_resource_map.size())); |
280 for (const ClientSafeBrowsingReportRequest::Resource& expected_resource : | 280 for (const ClientSafeBrowsingReportRequest::Resource& expected_resource : |
281 expected_pb.resources()) { | 281 expected_pb.resources()) { |
282 ASSERT_TRUE(actual_resource_map.count(expected_resource.id()) > 0); | 282 ASSERT_TRUE(actual_resource_map.count(expected_resource.id()) > 0); |
283 VerifyResource(*actual_resource_map[expected_resource.id()], | 283 VerifyResource(*actual_resource_map[expected_resource.id()], |
284 expected_resource); | 284 expected_resource); |
285 } | 285 } |
286 | 286 |
287 ASSERT_EQ(expected_pb.dom_size(), report_pb.dom_size()); | 287 ASSERT_EQ(expected_pb.dom_size(), report_pb.dom_size()); |
288 // Put the actual elements in a map, then iterate over the expected | 288 // Put the actual elements in a map, then iterate over the expected |
289 // elements, making sure each exists and is equal. | 289 // elements, making sure each exists and is equal. |
290 base::hash_map<int, const HTMLElement*> actual_dom_map; | 290 std::map<int, const HTMLElement*> actual_dom_map; |
291 for (const HTMLElement& element : report_pb.dom()) { | 291 for (const HTMLElement& element : report_pb.dom()) { |
292 actual_dom_map[element.id()] = &element; | 292 actual_dom_map[element.id()] = &element; |
293 } | 293 } |
294 // Make sure no elements disappeared when moving them to a map (IDs should | 294 // Make sure no elements disappeared when moving them to a map (IDs should |
295 // be unique). | 295 // be unique). |
296 ASSERT_EQ(expected_pb.dom_size(), static_cast<int>(actual_dom_map.size())); | 296 ASSERT_EQ(expected_pb.dom_size(), static_cast<int>(actual_dom_map.size())); |
297 for (const HTMLElement& expected_element : expected_pb.dom()) { | 297 for (const HTMLElement& expected_element : expected_pb.dom()) { |
298 ASSERT_TRUE(actual_dom_map.count(expected_element.id()) > 0); | 298 ASSERT_TRUE(actual_dom_map.count(expected_element.id()) > 0); |
299 VerifyElement(*actual_dom_map[expected_element.id()], expected_element); | 299 VerifyElement(*actual_dom_map[expected_element.id()], expected_element); |
300 } | 300 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 EXPECT_EQ(expected.response().remote_ip(), resource.response().remote_ip()); | 339 EXPECT_EQ(expected.response().remote_ip(), resource.response().remote_ip()); |
340 } | 340 } |
341 | 341 |
342 void VerifyElement(const HTMLElement& element, const HTMLElement& expected) { | 342 void VerifyElement(const HTMLElement& element, const HTMLElement& expected) { |
343 EXPECT_EQ(expected.id(), element.id()); | 343 EXPECT_EQ(expected.id(), element.id()); |
344 EXPECT_EQ(expected.tag(), element.tag()); | 344 EXPECT_EQ(expected.tag(), element.tag()); |
345 EXPECT_EQ(expected.resource_id(), element.resource_id()); | 345 EXPECT_EQ(expected.resource_id(), element.resource_id()); |
346 EXPECT_THAT(element.child_ids(), | 346 EXPECT_THAT(element.child_ids(), |
347 UnorderedPointwise(Eq(), expected.child_ids())); | 347 UnorderedPointwise(Eq(), expected.child_ids())); |
348 ASSERT_EQ(expected.attribute_size(), element.attribute_size()); | 348 ASSERT_EQ(expected.attribute_size(), element.attribute_size()); |
349 base::hash_map<std::string, std::string> actual_attributes_map; | 349 std::map<std::string, std::string> actual_attributes_map; |
350 for (const HTMLElement::Attribute& attribute : element.attribute()) { | 350 for (const HTMLElement::Attribute& attribute : element.attribute()) { |
351 actual_attributes_map[attribute.name()] = attribute.value(); | 351 actual_attributes_map[attribute.name()] = attribute.value(); |
352 } | 352 } |
353 ASSERT_EQ(expected.attribute_size(), | 353 ASSERT_EQ(expected.attribute_size(), |
354 static_cast<int>(actual_attributes_map.size())); | 354 static_cast<int>(actual_attributes_map.size())); |
355 for (const HTMLElement::Attribute& expected_attribute : | 355 for (const HTMLElement::Attribute& expected_attribute : |
356 expected.attribute()) { | 356 expected.attribute()) { |
357 ASSERT_TRUE(actual_attributes_map.count(expected_attribute.name()) > 0); | 357 ASSERT_TRUE(actual_attributes_map.count(expected_attribute.name()) > 0); |
358 EXPECT_EQ(expected_attribute.value(), | 358 EXPECT_EQ(expected_attribute.value(), |
359 actual_attributes_map[expected_attribute.name()]); | 359 actual_attributes_map[expected_attribute.name()]); |
(...skipping 969 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1329 pb_resource->set_parent_id(3); | 1329 pb_resource->set_parent_id(3); |
1330 pb_resource->set_url(kSecondRedirectURL); | 1330 pb_resource->set_url(kSecondRedirectURL); |
1331 pb_resource = expected.add_resources(); | 1331 pb_resource = expected.add_resources(); |
1332 pb_resource->set_id(3); | 1332 pb_resource->set_id(3); |
1333 pb_resource->set_url(kFirstRedirectURL); | 1333 pb_resource->set_url(kFirstRedirectURL); |
1334 | 1334 |
1335 VerifyResults(actual, expected); | 1335 VerifyResults(actual, expected); |
1336 } | 1336 } |
1337 | 1337 |
1338 } // namespace safe_browsing | 1338 } // namespace safe_browsing |
OLD | NEW |