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

Unified Diff: content/browser/background_fetch/background_fetch_registration_id_unittest.cc

Issue 2777063008: Connect BackgroundFetch to the OfflineItemCollection
Patch Set: Added BackgroundFetchClientProxy to proxy calls to and from the Context. Created 3 years, 9 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/background_fetch/background_fetch_registration_id_unittest.cc
diff --git a/content/browser/background_fetch/background_fetch_registration_id_unittest.cc b/content/browser/background_fetch/background_fetch_registration_id_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..75ab4711167bb26b3368b96cb1100a99eea0b5d2
--- /dev/null
+++ b/content/browser/background_fetch/background_fetch_registration_id_unittest.cc
@@ -0,0 +1,83 @@
+// Copyright 2017 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/background_fetch/background_fetch_registration_id.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+#include "url/gurl.h"
+#include "url/origin.h"
+
+namespace content {
+
+namespace {
+
+const char kTestOrigin[] = "https://www.example.com";
+const int64_t kTestServiceWorkerRegistrationId = 9001;
Peter Beverloo 2017/03/31 01:32:24 Can we try this with a >32 bit value too?
harkness 2017/03/31 10:11:44 Done.
+const char kTestTag[] = "test_tag";
+const char kExpectedSerialized[] = "0#9001#https://www.example.com#test_tag";
+
+} // anonymous namespace
+
+class BackgroundFetchRegistrationIdTest : public ::testing::Test {};
Peter Beverloo 2017/03/31 01:32:24 Since the test fixture doesn't do anything, you ca
harkness 2017/03/31 10:11:44 Done.
+
+TEST_F(BackgroundFetchRegistrationIdTest, SerializeTest) {
+ BackgroundFetchRegistrationId registration_id(
+ kTestServiceWorkerRegistrationId, url::Origin(GURL(kTestOrigin)),
+ kTestTag);
+ std::string serialized_id = registration_id.Serialize();
+ EXPECT_EQ(kExpectedSerialized, serialized_id);
+}
+
+TEST_F(BackgroundFetchRegistrationIdTest, DeserializeSuccessTest) {
+ BackgroundFetchRegistrationId registration_id;
+ ASSERT_TRUE(BackgroundFetchRegistrationId::Deserialize(kExpectedSerialized,
+ registration_id));
+
+ EXPECT_EQ(kTestOrigin, registration_id.origin().Serialize());
+ EXPECT_EQ(kTestServiceWorkerRegistrationId,
+ registration_id.service_worker_registration_id());
+ EXPECT_EQ(kTestTag, registration_id.tag());
+}
+
+TEST_F(BackgroundFetchRegistrationIdTest, DeserializeComplexTagTest) {
+ BackgroundFetchRegistrationId registration_id;
+ std::string silly_tag("0#9001#https://www.example.com#this#is#a#stupid#tag");
+ ASSERT_TRUE(
+ BackgroundFetchRegistrationId::Deserialize(silly_tag, registration_id));
+
+ EXPECT_EQ(kTestOrigin, registration_id.origin().Serialize());
+ EXPECT_EQ(kTestServiceWorkerRegistrationId,
+ registration_id.service_worker_registration_id());
+ EXPECT_EQ("this#is#a#stupid#tag", registration_id.tag());
+}
+
+TEST_F(BackgroundFetchRegistrationIdTest, DeserializeFailureTest) {
+ BackgroundFetchRegistrationId registration_id;
+
+ // Should fail: Invalid version.
+ EXPECT_FALSE(BackgroundFetchRegistrationId::Deserialize(
+ "1#1#https://www.example.com#tag", registration_id));
+
+ // Should fail: Invalid service worker registration id.
+ EXPECT_FALSE(BackgroundFetchRegistrationId::Deserialize(
+ "0#abc#https://www.example.com#tag", registration_id));
+
+ // Should fail: Invalid origin.
+ EXPECT_FALSE(BackgroundFetchRegistrationId::Deserialize(
+ "0#1#www.example.com#tag", registration_id));
+
+ // Should fail: Empty origin.
+ EXPECT_FALSE(
+ BackgroundFetchRegistrationId::Deserialize("0#1##tag", registration_id));
+
+ // Should fail: Not enough fields.
+ EXPECT_FALSE(BackgroundFetchRegistrationId::Deserialize(
+ "0#1#https://www.example.com", registration_id));
+
+ // Should fail: Invalid tag
+ EXPECT_FALSE(BackgroundFetchRegistrationId::Deserialize(
+ "0#1#https://www.example.com#", registration_id));
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698