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

Unified Diff: content/browser/renderer_host/routing_id_issuer_unittest.cc

Issue 643733002: Add RoutingIDIssuer to ensure the correctness of ID to be routed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Nasko's points. Created 6 years, 2 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: content/browser/renderer_host/routing_id_issuer_unittest.cc
diff --git a/content/browser/renderer_host/routing_id_issuer_unittest.cc b/content/browser/renderer_host/routing_id_issuer_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..da1e528d6ad2d15879d94f219b4482f518aa0e8d
--- /dev/null
+++ b/content/browser/renderer_host/routing_id_issuer_unittest.cc
@@ -0,0 +1,41 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/renderer_host/routing_id_issuer.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace content {
+namespace {
+
+const int kMangler = 5;
+
+class RoutingIDIssuerTest : public testing::Test {};
+
+TEST_F(RoutingIDIssuerTest, IssueNext) {
+ scoped_ptr<RoutingIDIssuer> target =
+ RoutingIDIssuer::CreateWithMangler(kMangler);
+ int id0 = target->IssueNext();
+ int id1 = target->IssueNext();
+ EXPECT_EQ(id0 + 1, id1);
+}
+
+TEST_F(RoutingIDIssuerTest, IsProbablyValid) {
+ scoped_ptr<RoutingIDIssuer> proper =
+ RoutingIDIssuer::CreateWithMangler(kMangler);
+ scoped_ptr<RoutingIDIssuer> foreign =
+ RoutingIDIssuer::CreateWithMangler(kMangler + 1);
+
+ EXPECT_FALSE(proper->IsProbablyValid(kMangler));
+
+ int proper_id = proper->IssueNext();
+ int foreign_id = foreign->IssueNext();
+ EXPECT_TRUE(proper->IsProbablyValid(proper_id));
+ EXPECT_TRUE(foreign->IsProbablyValid(foreign_id));
+ EXPECT_FALSE(proper->IsProbablyValid(foreign_id));
+ EXPECT_FALSE(foreign->IsProbablyValid(proper_id));
+}
+
+} // namespace
+} // namespace contnet

Powered by Google App Engine
This is Rietveld 408576698