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

Unified Diff: chrome/browser/services/gcm/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 comments from jam and fgorski. 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: chrome/browser/services/gcm/push_messaging_application_id_unittest.cc
diff --git a/chrome/browser/services/gcm/push_messaging_application_id_unittest.cc b/chrome/browser/services/gcm/push_messaging_application_id_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3f908bc312f5d1a5497c8a20b938139de1bc64c8
--- /dev/null
+++ b/chrome/browser/services/gcm/push_messaging_application_id_unittest.cc
@@ -0,0 +1,50 @@
+// 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 "chrome/browser/services/gcm/push_messaging_application_id.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+TEST(PushMessagingApplicationIdTest, ConstructorValidity) {
+ EXPECT_TRUE(gcm::PushMessagingApplicationId(GURL("https://www.example.com/"),
+ 1).IsValid());
+ EXPECT_TRUE(gcm::PushMessagingApplicationId(GURL("https://www.example.com"),
+ 1).IsValid());
+ EXPECT_FALSE(gcm::PushMessagingApplicationId(GURL(""), 1).IsValid());
+ EXPECT_FALSE(gcm::PushMessagingApplicationId(GURL("foo"), 1).IsValid());
+ EXPECT_FALSE(gcm::PushMessagingApplicationId(
+ GURL("https://www.example.com/foo"), 1).IsValid());
+ EXPECT_FALSE(gcm::PushMessagingApplicationId(
+ GURL("https://www.example.com/#foo"), 1).IsValid());
+ EXPECT_FALSE(gcm::PushMessagingApplicationId(GURL("https://www.example.com/"),
+ -1).IsValid());
+ EXPECT_FALSE(gcm::PushMessagingApplicationId().IsValid());
+}
+
+TEST(PushMessagingApplicationIdTest, ToString) {
+ EXPECT_EQ(gcm::PushMessagingApplicationId(GURL("https://www.example.com/"), 1)
+ .ToString(),
+ "push#https://www.example.com/#1");
+ EXPECT_EQ(gcm::PushMessagingApplicationId(GURL("https://www.example.com"), 1)
+ .ToString(),
+ "push#https://www.example.com/#1");
+}
+
+TEST(PushMessagingApplicationIdTest, ParseValidity) {
+ EXPECT_TRUE(gcm::PushMessagingApplicationId::Parse(
+ "push#https://www.example.com/#1").IsValid());
+ EXPECT_FALSE(gcm::PushMessagingApplicationId::Parse("").IsValid());
+ EXPECT_FALSE(gcm::PushMessagingApplicationId::Parse(
+ "sync#https://www.example.com/#1").IsValid());
+ EXPECT_FALSE(gcm::PushMessagingApplicationId::Parse("push#foo#1").IsValid());
+ EXPECT_FALSE(gcm::PushMessagingApplicationId::Parse(
+ "push#https://www.example.com/foo#1").IsValid());
+ EXPECT_FALSE(gcm::PushMessagingApplicationId::Parse(
+ "push#https://www.example.com/#one").IsValid());
+ EXPECT_FALSE(gcm::PushMessagingApplicationId::Parse(
+ "push#https://www.example.com/#foo#1").IsValid());
+ EXPECT_FALSE(gcm::PushMessagingApplicationId::Parse(
+ "push#https://www.example.com/#1#1").IsValid());
+ EXPECT_FALSE(gcm::PushMessagingApplicationId::Parse(
+ "push#https://www.example.com/#-1").IsValid());
+}

Powered by Google App Engine
This is Rietveld 408576698