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

Unified Diff: content/browser/push_messaging_application_id_unittest.cc

Issue 404353003: Define PushMessagingApplicationId and replace ad-hoc code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address John's comments. Created 6 years, 5 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/push_messaging_application_id_unittest.cc
diff --git a/content/browser/push_messaging_application_id_unittest.cc b/content/browser/push_messaging_application_id_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8785eab38fa861241f7563e7f02f50433b3f73c2
--- /dev/null
+++ b/content/browser/push_messaging_application_id_unittest.cc
@@ -0,0 +1,54 @@
+// 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/public/browser/push_messaging_application_id.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace content {
+
+TEST(PushMessagingApplicationIdTest, ConstructorValidity) {
+ EXPECT_TRUE(PushMessagingApplicationId(GURL("https://www.example.com/"), 1)
+ .IsValid());
+ EXPECT_TRUE(
+ PushMessagingApplicationId(GURL("https://www.example.com"), 1).IsValid());
+ EXPECT_FALSE(PushMessagingApplicationId(GURL(""), 1).IsValid());
+ EXPECT_FALSE(PushMessagingApplicationId(GURL("foo"), 1).IsValid());
+ EXPECT_FALSE(PushMessagingApplicationId(GURL("https://www.example.com/foo"),
+ 1).IsValid());
+ EXPECT_FALSE(PushMessagingApplicationId(GURL("https://www.example.com/#foo"),
+ 1).IsValid());
+ EXPECT_FALSE(PushMessagingApplicationId(GURL("https://www.example.com/"), -1)
+ .IsValid());
+ EXPECT_FALSE(PushMessagingApplicationId().IsValid());
+}
+
+TEST(PushMessagingApplicationIdTest, ToString) {
+ EXPECT_EQ(PushMessagingApplicationId(GURL("https://www.example.com/"), 1)
+ .ToString(),
+ "push#https://www.example.com/#1");
+ EXPECT_EQ(
+ PushMessagingApplicationId(GURL("https://www.example.com"), 1).ToString(),
+ "push#https://www.example.com/#1");
+}
+
+TEST(PushMessagingApplicationIdTest, ParseValidity) {
+ EXPECT_TRUE(PushMessagingApplicationId::Parse(
+ "push#https://www.example.com/#1").IsValid());
+ EXPECT_FALSE(PushMessagingApplicationId::Parse("").IsValid());
+ EXPECT_FALSE(PushMessagingApplicationId::Parse(
+ "sync#https://www.example.com/#1").IsValid());
+ EXPECT_FALSE(PushMessagingApplicationId::Parse("push#foo#1").IsValid());
+ EXPECT_FALSE(PushMessagingApplicationId::Parse(
+ "push#https://www.example.com/foo#1").IsValid());
+ EXPECT_FALSE(PushMessagingApplicationId::Parse(
+ "push#https://www.example.com/#one").IsValid());
+ EXPECT_FALSE(PushMessagingApplicationId::Parse(
+ "push#https://www.example.com/#foo#1").IsValid());
+ EXPECT_FALSE(PushMessagingApplicationId::Parse(
+ "push#https://www.example.com/#1#1").IsValid());
+ EXPECT_FALSE(PushMessagingApplicationId::Parse(
+ "push#https://www.example.com/#-1").IsValid());
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698