Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Unified Diff: chrome/browser/safe_browsing/malware_details_unittest.cc

Issue 6208003: Add a Node message in the malware details protocol buffer. This allows us to ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/safe_browsing/malware_details_unittest.cc
===================================================================
--- chrome/browser/safe_browsing/malware_details_unittest.cc (revision 71096)
+++ 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,11 +32,17 @@
}
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();
}
+ static bool NodeLessThan(
+ const ClientMalwareReportRequest::Node* lhs,
+ const ClientMalwareReportRequest::Node* rhs) {
+ return lhs->id() < rhs->id();
+ }
+
protected:
void InitResource(SafeBrowsingService::UnsafeResource* resource,
ResourceType::Type resource_type,
@@ -47,39 +55,58 @@
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 and nodes, 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());
}
+
+ ASSERT_EQ(expected_pb.nodes_size(), report_pb.nodes_size());
+ // Sort the nodes, to make the test deterministic
+ std::vector<const ClientMalwareReportRequest::Node*> nodes;
+ for (int i = 0; i < report_pb.nodes_size(); ++i) {
+ const ClientMalwareReportRequest::Node& node = report_pb.nodes(i);
+ nodes.push_back(&node);
+ }
+ std::sort(nodes.begin(), nodes.end(), &MalwareDetailsTest::NodeLessThan);
+
+ std::vector<const ClientMalwareReportRequest::Node*> expected_nodes;
+ for (int i = 0; i < report_pb.nodes_size(); ++i) {
+ const ClientMalwareReportRequest::Node& node = expected_pb.nodes(i);
+ expected_nodes.push_back(&node);
+ }
+ std::sort(expected_nodes.begin(), expected_nodes.end(),
+ &MalwareDetailsTest::NodeLessThan);
+
+ for (uint32 i = 0; i < expected_nodes.size(); ++i) {
+ EXPECT_EQ(expected_nodes[i]->id(), nodes[i]->id());
+ EXPECT_EQ(expected_nodes[i]->parent_id(), nodes[i]->parent_id());
+ }
}
BrowserThread ui_thread_;
@@ -98,19 +125,25 @@
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);
+ pb_resource = expected.add_resources();
+ pb_resource->set_id(1);
+ pb_resource->set_url(kMalwareURL);
+
+ ClientMalwareReportRequest::Node* node = expected.add_nodes();
+ node->set_id(0);
node = expected.add_nodes();
- node->set_url(kMalwareURL);
+ node->set_id(1);
VerifyResults(actual, expected);
}
@@ -128,25 +161,35 @@
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);
+ pb_resource = expected.add_resources();
+ pb_resource->set_id(2);
+ pb_resource->set_url(kMalwareURL);
+
+ ClientMalwareReportRequest::Node* node = expected.add_nodes();
+ node->set_id(0);
node = expected.add_nodes();
- node->set_url(kOriginalLandingURL);
+ node->set_id(1);
+ // The Node for kMmalwareUrl (with id 2) should have the Node for
+ // kOriginalLandingURL (with id 1) as parent.
+ node = expected.add_nodes();
+ node->set_id(2);
+ node->set_parent_id(1);
VerifyResults(actual, expected);
}
@@ -160,16 +203,18 @@
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
+ ClientMalwareReportRequest::Node* node = expected.add_nodes();
+ node->set_id(0);
+
VerifyResults(actual, expected);
}

Powered by Google App Engine
This is Rietveld 408576698