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

Unified Diff: third_party/WebKit/Source/modules/push_messaging/PushManagerTest.cpp

Issue 1701313002: Partial implementation of subscription restrictions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix module export build issue Created 4 years, 10 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: third_party/WebKit/Source/modules/push_messaging/PushManagerTest.cpp
diff --git a/third_party/WebKit/Source/modules/push_messaging/PushManagerTest.cpp b/third_party/WebKit/Source/modules/push_messaging/PushManagerTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..e5e7f8f53dd9f1c46f236c152d0e85b136930678
--- /dev/null
+++ b/third_party/WebKit/Source/modules/push_messaging/PushManagerTest.cpp
@@ -0,0 +1,68 @@
+// Copyright 2016 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 "modules/push_messaging/PushManager.h"
+
+#include "bindings/modules/v8/UnionTypesModules.h"
+#include "core/dom/DOMArrayBuffer.h"
+#include "modules/push_messaging/PushSubscriptionOptions.h"
+#include "public/platform/WebString.h"
+#include "public/platform/modules/push_messaging/WebPushSubscriptionOptions.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace blink {
+namespace {
+
+const char kValidKeyMarker = 0x04;
+const unsigned kValidKeyLength = 65;
+
+TEST(PushManagerTest, ValidSenderKey)
+{
+ uint8_t senderKey[kValidKeyLength];
+ memset(senderKey, 0, sizeof(senderKey));
+ senderKey[0] = kValidKeyMarker;
+ PushSubscriptionOptions options;
+ options.setApplicationServerKey(
+ ArrayBufferOrArrayBufferView::fromArrayBuffer(
+ DOMArrayBuffer::create(senderKey, kValidKeyLength)));
+
+ TrackExceptionState exceptionState;
+ WebPushSubscriptionOptions output = PushManager::toWebPushSubscriptionOptions(options, exceptionState);
+ EXPECT_FALSE(exceptionState.hadException());
+ EXPECT_EQ(output.applicationServerKey.length(), kValidKeyLength);
+ EXPECT_EQ(output.applicationServerKey, WebString::fromUTF8(reinterpret_cast<const char*>(senderKey), kValidKeyLength));
+}
+
+TEST(PushManagerTest, InvalidSenderKeyMarker)
+{
+ uint8_t senderKey[kValidKeyLength];
+ memset(senderKey, 0, sizeof(senderKey));
+ senderKey[0] = 0x05;
+ PushSubscriptionOptions options;
+ options.setApplicationServerKey(
+ ArrayBufferOrArrayBufferView::fromArrayBuffer(
+ DOMArrayBuffer::create(senderKey, kValidKeyLength)));
+
+ TrackExceptionState exceptionState;
+ WebPushSubscriptionOptions output = PushManager::toWebPushSubscriptionOptions(options, exceptionState);
+ EXPECT_TRUE(exceptionState.hadException());
+}
+
+TEST(PushManagerTest, InvalidSenderKeyLength)
+{
+ uint8_t senderKey[kValidKeyLength - 1];
+ memset(senderKey, 0, sizeof(senderKey));
+ senderKey[0] = kValidKeyMarker;
+ PushSubscriptionOptions options;
+ options.setApplicationServerKey(
+ ArrayBufferOrArrayBufferView::fromArrayBuffer(
+ DOMArrayBuffer::create(senderKey, kValidKeyLength - 1)));
+
+ TrackExceptionState exceptionState;
+ WebPushSubscriptionOptions output = PushManager::toWebPushSubscriptionOptions(options, exceptionState);
+ EXPECT_TRUE(exceptionState.hadException());
+}
+
+} // namespace
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698