| Index: chrome/browser/safe_browsing/malware_details_unittest.cc
|
| ===================================================================
|
| --- chrome/browser/safe_browsing/malware_details_unittest.cc (revision 71243)
|
| +++ chrome/browser/safe_browsing/malware_details_unittest.cc (working copy)
|
| @@ -18,6 +18,8 @@
|
| static const char* kMalwareURL = "http://www.malware.com/";
|
| static const char* kHttpsURL = "https://www.url.com/";
|
|
|
| +using safe_browsing::ClientMalwareReportRequest;
|
| +
|
| class MalwareDetailsTest : public RenderViewHostTestHarness {
|
| public:
|
| MalwareDetailsTest()
|
| @@ -30,9 +32,9 @@
|
| }
|
|
|
| static bool ResourceLessThan(
|
| - const safe_browsing::ClientMalwareReportRequest::Resource* lhs,
|
| - const safe_browsing::ClientMalwareReportRequest::Resource* rhs) {
|
| - return lhs->url() < rhs->url();
|
| + const ClientMalwareReportRequest::Resource* lhs,
|
| + const ClientMalwareReportRequest::Resource* rhs) {
|
| + return lhs->id() < rhs->id();
|
| }
|
|
|
| protected:
|
| @@ -47,38 +49,36 @@
|
| resource->render_view_id = contents_->render_view_host()->routing_id();
|
| }
|
|
|
| - void VerifyResults(
|
| - const safe_browsing::ClientMalwareReportRequest& report_pb,
|
| - const safe_browsing::ClientMalwareReportRequest& expected_pb) {
|
| + void VerifyResults(const ClientMalwareReportRequest& report_pb,
|
| + const ClientMalwareReportRequest& expected_pb) {
|
| EXPECT_EQ(expected_pb.malware_url(), report_pb.malware_url());
|
| EXPECT_EQ(expected_pb.page_url(), report_pb.page_url());
|
| EXPECT_EQ(expected_pb.referrer_url(), report_pb.referrer_url());
|
|
|
| - ASSERT_EQ(expected_pb.nodes_size(), report_pb.nodes_size());
|
| - // Sort the nodes, to make the test deterministic
|
| - std::vector<const safe_browsing::ClientMalwareReportRequest::Resource*>
|
| - nodes;
|
| - for (int i = 0; i < report_pb.nodes_size(); ++i) {
|
| - const safe_browsing::ClientMalwareReportRequest::Resource& resource =
|
| - report_pb.nodes(i);
|
| - nodes.push_back(&resource);
|
| + ASSERT_EQ(expected_pb.resources_size(), report_pb.resources_size());
|
| + // Sort the resources, to make the test deterministic
|
| + std::vector<const ClientMalwareReportRequest::Resource*> resources;
|
| + for (int i = 0; i < report_pb.resources_size(); ++i) {
|
| + const ClientMalwareReportRequest::Resource& resource =
|
| + report_pb.resources(i);
|
| + resources.push_back(&resource);
|
| }
|
| - std::sort(nodes.begin(), nodes.end(),
|
| + std::sort(resources.begin(), resources.end(),
|
| &MalwareDetailsTest::ResourceLessThan);
|
|
|
| - std::vector<const safe_browsing::ClientMalwareReportRequest::Resource*>
|
| - expected;
|
| - for (int i = 0; i < report_pb.nodes_size(); ++i) {
|
| - const safe_browsing::ClientMalwareReportRequest::Resource& resource =
|
| - expected_pb.nodes(i);
|
| + std::vector<const ClientMalwareReportRequest::Resource*> expected;
|
| + for (int i = 0; i < report_pb.resources_size(); ++i) {
|
| + const ClientMalwareReportRequest::Resource& resource =
|
| + expected_pb.resources(i);
|
| expected.push_back(&resource);
|
| }
|
| std::sort(expected.begin(), expected.end(),
|
| &MalwareDetailsTest::ResourceLessThan);
|
|
|
| for (uint32 i = 0; i < expected.size(); ++i) {
|
| - EXPECT_EQ(expected[i]->url(), nodes[i]->url());
|
| - EXPECT_EQ(expected[i]->parent(), nodes[i]->parent());
|
| + EXPECT_EQ(expected[i]->id(), resources[i]->id());
|
| + EXPECT_EQ(expected[i]->url(), resources[i]->url());
|
| + EXPECT_EQ(expected[i]->parent_id(), resources[i]->parent_id());
|
| }
|
| }
|
|
|
| @@ -98,19 +98,20 @@
|
| contents(), resource);
|
|
|
| scoped_ptr<const std::string> serialized(report->GetSerializedReport());
|
| - safe_browsing::ClientMalwareReportRequest actual;
|
| + ClientMalwareReportRequest actual;
|
| actual.ParseFromString(*serialized);
|
|
|
| - safe_browsing::ClientMalwareReportRequest expected;
|
| + ClientMalwareReportRequest expected;
|
| expected.set_malware_url(kMalwareURL);
|
| expected.set_page_url(kLandingURL);
|
| expected.set_referrer_url("");
|
|
|
| - safe_browsing::ClientMalwareReportRequest::Resource* node =
|
| - expected.add_nodes();
|
| - node->set_url(kLandingURL);
|
| - node = expected.add_nodes();
|
| - node->set_url(kMalwareURL);
|
| + ClientMalwareReportRequest::Resource* pb_resource = expected.add_resources();
|
| + pb_resource->set_id(0);
|
| + pb_resource->set_url(kLandingURL);
|
| + pb_resource = expected.add_resources();
|
| + pb_resource->set_id(1);
|
| + pb_resource->set_url(kMalwareURL);
|
|
|
| VerifyResults(actual, expected);
|
| }
|
| @@ -128,25 +129,28 @@
|
| contents(), resource);
|
|
|
| scoped_ptr<const std::string> serialized(report->GetSerializedReport());
|
| - safe_browsing::ClientMalwareReportRequest actual;
|
| + ClientMalwareReportRequest actual;
|
| actual.ParseFromString(*serialized);
|
|
|
| - safe_browsing::ClientMalwareReportRequest expected;
|
| + ClientMalwareReportRequest expected;
|
| expected.set_malware_url(kMalwareURL);
|
| expected.set_page_url(kLandingURL);
|
| expected.set_referrer_url("");
|
|
|
| - safe_browsing::ClientMalwareReportRequest::Resource* node =
|
| - expected.add_nodes();
|
| - node->set_url(kLandingURL);
|
| + ClientMalwareReportRequest::Resource* pb_resource = expected.add_resources();
|
| + pb_resource->set_id(0);
|
| + pb_resource->set_url(kLandingURL);
|
|
|
| - // Malware url should have originalurl as parent.
|
| - node = expected.add_nodes();
|
| - node->set_url(kMalwareURL);
|
| - node->set_parent(kOriginalLandingURL);
|
| + pb_resource = expected.add_resources();
|
| + pb_resource->set_id(1);
|
| + pb_resource->set_url(kOriginalLandingURL);
|
|
|
| - node = expected.add_nodes();
|
| - node->set_url(kOriginalLandingURL);
|
| + pb_resource = expected.add_resources();
|
| + pb_resource->set_id(2);
|
| + pb_resource->set_url(kMalwareURL);
|
| + // The Resource for kMmalwareUrl should have the Resource for
|
| + // kOriginalLandingURL (with id 1) as parent.
|
| + pb_resource->set_parent_id(1);
|
|
|
| VerifyResults(actual, expected);
|
| }
|
| @@ -160,16 +164,15 @@
|
| contents(), resource);
|
|
|
| scoped_ptr<const std::string> serialized(report->GetSerializedReport());
|
| - safe_browsing::ClientMalwareReportRequest actual;
|
| + ClientMalwareReportRequest actual;
|
| actual.ParseFromString(*serialized);
|
|
|
| - safe_browsing::ClientMalwareReportRequest expected;
|
| + ClientMalwareReportRequest expected;
|
| expected.set_malware_url(kMalwareURL); // No page_url
|
| expected.set_referrer_url("");
|
|
|
| - safe_browsing::ClientMalwareReportRequest::Resource* node =
|
| - expected.add_nodes();
|
| - node->set_url(kMalwareURL); // Only one node
|
| + ClientMalwareReportRequest::Resource* pb_resource = expected.add_resources();
|
| + pb_resource->set_url(kMalwareURL); // Only one resource
|
|
|
| VerifyResults(actual, expected);
|
| }
|
|
|