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

Side by Side Diff: third_party/WebKit/Source/modules/push_messaging/PushManagerTest.cpp

Issue 1816123002: Add testing for subscription from service workers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix asan errors Created 4 years, 8 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
« no previous file with comments | « third_party/WebKit/Source/modules/push_messaging/PushManager.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "modules/push_messaging/PushManager.h" 5 #include "modules/push_messaging/PushManager.h"
6 6
7 #include "bindings/modules/v8/UnionTypesModules.h" 7 #include "bindings/modules/v8/UnionTypesModules.h"
8 #include "core/dom/DOMArrayBuffer.h" 8 #include "core/dom/DOMArrayBuffer.h"
9 #include "modules/push_messaging/PushSubscriptionOptions.h" 9 #include "modules/push_messaging/PushSubscriptionOptions.h"
10 #include "public/platform/WebString.h" 10 #include "public/platform/WebString.h"
11 #include "public/platform/modules/push_messaging/WebPushSubscriptionOptions.h" 11 #include "public/platform/modules/push_messaging/WebPushSubscriptionOptions.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 namespace blink { 14 namespace blink {
15 namespace { 15 namespace {
16 16
17 const char kValidKeyMarker = 0x04; 17 const char kValidKeyMarker = 0x04;
18 const unsigned kValidKeyLength = 65; 18 const unsigned kValidKeyLength = 65;
19 19
20 // NIST P-256 public key made available to tests. Must be an uncompressed
21 // point in accordance with SEC1 2.3.3.
22 const uint8_t kApplicationServerKey[65] = {
23 0x04, 0x55, 0x52, 0x6A, 0xA5, 0x6E, 0x8E, 0xAA, 0x47, 0x97, 0x36, 0x10, 0xC1 ,
24 0x66, 0x3C, 0x1E, 0x65, 0xBF, 0xA1, 0x7B, 0xEE, 0x48, 0xC9, 0xC6, 0xBB, 0xBF ,
25 0x02, 0x18, 0x53, 0x72, 0x1D, 0x0C, 0x7B, 0xA9, 0xE3, 0x11, 0xB7, 0x03, 0x52 ,
26 0x21, 0xD3, 0x71, 0x90, 0x13, 0xA8, 0xC1, 0xCF, 0xED, 0x20, 0xF7, 0x1F, 0xD1 ,
27 0x7F, 0xF2, 0x76, 0xB6, 0x01, 0x20, 0xD8, 0x35, 0xA5, 0xD9, 0x3C, 0x43, 0xDF
28 };
29
20 TEST(PushManagerTest, ValidSenderKey) 30 TEST(PushManagerTest, ValidSenderKey)
21 { 31 {
22 uint8_t senderKey[kValidKeyLength];
23 memset(senderKey, 0, sizeof(senderKey));
24 senderKey[0] = kValidKeyMarker;
25 PushSubscriptionOptions options; 32 PushSubscriptionOptions options;
26 options.setApplicationServerKey( 33 options.setApplicationServerKey(
27 ArrayBufferOrArrayBufferView::fromArrayBuffer( 34 ArrayBufferOrArrayBufferView::fromArrayBuffer(
28 DOMArrayBuffer::create(senderKey, kValidKeyLength))); 35 DOMArrayBuffer::create(kApplicationServerKey, kValidKeyLength)));
29 36
30 TrackExceptionState exceptionState; 37 TrackExceptionState exceptionState;
31 WebPushSubscriptionOptions output = PushManager::toWebPushSubscriptionOption s(options, exceptionState); 38 WebPushSubscriptionOptions output = PushManager::toWebPushSubscriptionOption s(options, exceptionState);
32 EXPECT_FALSE(exceptionState.hadException()); 39 EXPECT_FALSE(exceptionState.hadException());
33 EXPECT_EQ(output.applicationServerKey.length(), kValidKeyLength); 40 EXPECT_EQ(output.applicationServerKey.length(), kValidKeyLength);
34 EXPECT_EQ(output.applicationServerKey, WebString::fromUTF8(reinterpret_cast< const char*>(senderKey), kValidKeyLength)); 41
42 // Copy the key into a size+1 buffer so that it can be treated as a null
43 // terminated string for the purposes of EXPECT_EQ.
44 uint8_t senderKey[kValidKeyLength+1];
45 for (unsigned i = 0; i < kValidKeyLength; i++)
46 senderKey[i] = kApplicationServerKey[i];
47 senderKey[kValidKeyLength] = 0x0;
48 EXPECT_EQ(reinterpret_cast<const char*>(senderKey), output.applicationServer Key.latin1());
49 EXPECT_FALSE(output.applicationServerKey.isEmpty());
35 } 50 }
36 51
37 TEST(PushManagerTest, InvalidSenderKeyMarker) 52 TEST(PushManagerTest, InvalidSenderKeyMarker)
38 { 53 {
39 uint8_t senderKey[kValidKeyLength]; 54 uint8_t senderKey[kValidKeyLength];
40 memset(senderKey, 0, sizeof(senderKey)); 55 memset(senderKey, 0, sizeof(senderKey));
41 senderKey[0] = 0x05; 56 senderKey[0] = 0x05;
42 PushSubscriptionOptions options; 57 PushSubscriptionOptions options;
43 options.setApplicationServerKey( 58 options.setApplicationServerKey(
44 ArrayBufferOrArrayBufferView::fromArrayBuffer( 59 ArrayBufferOrArrayBufferView::fromArrayBuffer(
(...skipping 14 matching lines...) Expand all
59 ArrayBufferOrArrayBufferView::fromArrayBuffer( 74 ArrayBufferOrArrayBufferView::fromArrayBuffer(
60 DOMArrayBuffer::create(senderKey, kValidKeyLength - 1))); 75 DOMArrayBuffer::create(senderKey, kValidKeyLength - 1)));
61 76
62 TrackExceptionState exceptionState; 77 TrackExceptionState exceptionState;
63 WebPushSubscriptionOptions output = PushManager::toWebPushSubscriptionOption s(options, exceptionState); 78 WebPushSubscriptionOptions output = PushManager::toWebPushSubscriptionOption s(options, exceptionState);
64 EXPECT_TRUE(exceptionState.hadException()); 79 EXPECT_TRUE(exceptionState.hadException());
65 } 80 }
66 81
67 } // namespace 82 } // namespace
68 } // namespace blink 83 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/push_messaging/PushManager.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698