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

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: Added exception failure return and updated more tests 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..273ea38276b50a1147f4973ae82aba4104101d59
--- /dev/null
+++ b/third_party/WebKit/Source/modules/push_messaging/PushManagerTest.cpp
@@ -0,0 +1,69 @@
+// 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;
Peter Beverloo 2016/02/26 16:02:33 Please do not indent code in namespaces.
harkness 2016/02/26 17:12:04 gah, evil git cl format!
+ const int kValidKeyLength = 65;
+
+ TEST(PushManagerTest, ValidSenderKey)
+ {
+ uint8_t senderKey[kValidKeyLength];
+ std::memset(senderKey, 0, sizeof(senderKey));
Peter Beverloo 2016/02/26 16:02:33 nit: no std::
harkness 2016/02/26 17:12:04 Done.
+ 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(0, std::memcmp(output.applicationServerKey.utf8().c_str(), senderKey, kValidKeyLength));
Peter Beverloo 2016/02/26 16:02:33 STL is not yet allowed in these parts of Blink, un
Peter Beverloo 2016/02/26 16:02:33 ASSERT_EQ on the length to make sure we don't acce
harkness 2016/02/26 17:12:04 Done.
harkness 2016/02/26 17:12:04 Done.
+ }
+
+ TEST(PushManagerTest, InvalidSenderKeyMarker)
+ {
+ uint8_t senderKey[kValidKeyLength];
+ senderKey[0] = 0x05;
+ for (int i = 1; i < kValidKeyLength; i++)
+ senderKey[i] = 0x0;
+ 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];
+ senderKey[0] = kValidKeyMarker;
+ for (int i = 1; i < kValidKeyLength - 1; i++)
+ senderKey[i] = 0x0;
+ PushSubscriptionOptions options;
+ options.setApplicationServerKey(
+ ArrayBufferOrArrayBufferView::fromArrayBuffer(
+ DOMArrayBuffer::create(senderKey, kValidKeyLength - 1)));
+
+ TrackExceptionState exceptionState;
+ WebPushSubscriptionOptions output = PushManager::toWebPushSubscriptionOptions(options, exceptionState);
+ EXPECT_TRUE(exceptionState.hadException());
+ }
+
+} // anonymous namespace
Peter Beverloo 2016/02/26 16:02:33 micro nit: we usually just use "// namespace"
harkness 2016/02/26 17:12:04 Done.
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698