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

Side by Side 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, 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "modules/push_messaging/PushManager.h"
6
7 #include "bindings/modules/v8/UnionTypesModules.h"
8 #include "core/dom/DOMArrayBuffer.h"
9 #include "modules/push_messaging/PushSubscriptionOptions.h"
10 #include "public/platform/WebString.h"
11 #include "public/platform/modules/push_messaging/WebPushSubscriptionOptions.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 namespace blink {
15 namespace {
16
17 const char kValidKeyMarker = 0x04;
18 const unsigned kValidKeyLength = 65;
19
20 TEST(PushManagerTest, ValidSenderKey)
21 {
22 uint8_t senderKey[kValidKeyLength];
23 memset(senderKey, 0, sizeof(senderKey));
24 senderKey[0] = kValidKeyMarker;
25 PushSubscriptionOptions options;
26 options.setApplicationServerKey(
27 ArrayBufferOrArrayBufferView::fromArrayBuffer(
28 DOMArrayBuffer::create(senderKey, kValidKeyLength)));
29
30 TrackExceptionState exceptionState;
31 WebPushSubscriptionOptions output = PushManager::toWebPushSubscriptionOption s(options, exceptionState);
32 EXPECT_FALSE(exceptionState.hadException());
33 EXPECT_EQ(output.applicationServerKey.length(), kValidKeyLength);
34 EXPECT_EQ(output.applicationServerKey, WebString::fromUTF8(reinterpret_cast< const char*>(senderKey), kValidKeyLength));
35 }
36
37 TEST(PushManagerTest, InvalidSenderKeyMarker)
38 {
39 uint8_t senderKey[kValidKeyLength];
40 memset(senderKey, 0, sizeof(senderKey));
41 senderKey[0] = 0x05;
42 PushSubscriptionOptions options;
43 options.setApplicationServerKey(
44 ArrayBufferOrArrayBufferView::fromArrayBuffer(
45 DOMArrayBuffer::create(senderKey, kValidKeyLength)));
46
47 TrackExceptionState exceptionState;
48 WebPushSubscriptionOptions output = PushManager::toWebPushSubscriptionOption s(options, exceptionState);
49 EXPECT_TRUE(exceptionState.hadException());
50 }
51
52 TEST(PushManagerTest, InvalidSenderKeyLength)
53 {
54 uint8_t senderKey[kValidKeyLength - 1];
55 memset(senderKey, 0, sizeof(senderKey));
56 senderKey[0] = kValidKeyMarker;
57 PushSubscriptionOptions options;
58 options.setApplicationServerKey(
59 ArrayBufferOrArrayBufferView::fromArrayBuffer(
60 DOMArrayBuffer::create(senderKey, kValidKeyLength - 1)));
61
62 TrackExceptionState exceptionState;
63 WebPushSubscriptionOptions output = PushManager::toWebPushSubscriptionOption s(options, exceptionState);
64 EXPECT_TRUE(exceptionState.hadException());
65 }
66
67 } // namespace
68 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698