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

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: Code review comments incorporated and all tests working 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
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, 0xFD
28 };
29
20 TEST(PushManagerTest, ValidSenderKey) 30 TEST(PushManagerTest, ValidSenderKey)
21 { 31 {
22 uint8_t senderKey[kValidKeyLength]; 32 uint8_t senderKey[kValidKeyLength];
Michael van Ouwerkerk 2016/03/30 09:50:04 This is unused now.
harkness 2016/03/30 10:51:49 Done.
23 memset(senderKey, 0, sizeof(senderKey)); 33 memset(senderKey, 0, sizeof(senderKey));
24 senderKey[0] = kValidKeyMarker; 34 senderKey[0] = kValidKeyMarker;
25 PushSubscriptionOptions options; 35 PushSubscriptionOptions options;
26 options.setApplicationServerKey( 36 options.setApplicationServerKey(
27 ArrayBufferOrArrayBufferView::fromArrayBuffer( 37 ArrayBufferOrArrayBufferView::fromArrayBuffer(
28 DOMArrayBuffer::create(senderKey, kValidKeyLength))); 38 DOMArrayBuffer::create(kApplicationServerKey, kValidKeyLength)));
29 39
30 TrackExceptionState exceptionState; 40 TrackExceptionState exceptionState;
31 WebPushSubscriptionOptions output = PushManager::toWebPushSubscriptionOption s(options, exceptionState); 41 WebPushSubscriptionOptions output = PushManager::toWebPushSubscriptionOption s(options, exceptionState);
32 EXPECT_FALSE(exceptionState.hadException()); 42 EXPECT_FALSE(exceptionState.hadException());
33 EXPECT_EQ(output.applicationServerKey.length(), kValidKeyLength); 43 EXPECT_EQ(output.applicationServerKey.length(), kValidKeyLength);
34 EXPECT_EQ(output.applicationServerKey, WebString::fromUTF8(reinterpret_cast< const char*>(senderKey), kValidKeyLength)); 44 EXPECT_EQ(output.applicationServerKey.latin1(), reinterpret_cast<const char* >(kApplicationServerKey));
45 EXPECT_FALSE(output.applicationServerKey.isEmpty());
35 } 46 }
36 47
37 TEST(PushManagerTest, InvalidSenderKeyMarker) 48 TEST(PushManagerTest, InvalidSenderKeyMarker)
38 { 49 {
39 uint8_t senderKey[kValidKeyLength]; 50 uint8_t senderKey[kValidKeyLength];
40 memset(senderKey, 0, sizeof(senderKey)); 51 memset(senderKey, 0, sizeof(senderKey));
41 senderKey[0] = 0x05; 52 senderKey[0] = 0x05;
42 PushSubscriptionOptions options; 53 PushSubscriptionOptions options;
43 options.setApplicationServerKey( 54 options.setApplicationServerKey(
44 ArrayBufferOrArrayBufferView::fromArrayBuffer( 55 ArrayBufferOrArrayBufferView::fromArrayBuffer(
(...skipping 14 matching lines...) Expand all
59 ArrayBufferOrArrayBufferView::fromArrayBuffer( 70 ArrayBufferOrArrayBufferView::fromArrayBuffer(
60 DOMArrayBuffer::create(senderKey, kValidKeyLength - 1))); 71 DOMArrayBuffer::create(senderKey, kValidKeyLength - 1)));
61 72
62 TrackExceptionState exceptionState; 73 TrackExceptionState exceptionState;
63 WebPushSubscriptionOptions output = PushManager::toWebPushSubscriptionOption s(options, exceptionState); 74 WebPushSubscriptionOptions output = PushManager::toWebPushSubscriptionOption s(options, exceptionState);
64 EXPECT_TRUE(exceptionState.hadException()); 75 EXPECT_TRUE(exceptionState.hadException());
65 } 76 }
66 77
67 } // namespace 78 } // namespace
68 } // namespace blink 79 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698