OLD | NEW |
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 "core/dom/DOMArrayBuffer.h" | 7 #include "core/dom/DOMArrayBuffer.h" |
8 #include "modules/push_messaging/PushSubscriptionOptions.h" | 8 #include "modules/push_messaging/PushSubscriptionOptions.h" |
| 9 #include "modules/push_messaging/PushSubscriptionOptionsInit.h" |
9 #include "public/platform/WebString.h" | 10 #include "public/platform/WebString.h" |
10 #include "public/platform/modules/push_messaging/WebPushSubscriptionOptions.h" | 11 #include "public/platform/modules/push_messaging/WebPushSubscriptionOptions.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
12 | 13 |
13 namespace blink { | 14 namespace blink { |
14 namespace { | 15 namespace { |
15 | 16 |
16 const unsigned kMaxKeyLength = 255; | 17 const unsigned kMaxKeyLength = 255; |
17 | 18 |
18 // NIST P-256 public key made available to tests. Must be an uncompressed | 19 // NIST P-256 public key made available to tests. Must be an uncompressed |
19 // point in accordance with SEC1 2.3.3. | 20 // point in accordance with SEC1 2.3.3. |
20 const unsigned kApplicationServerKeyLength = 65; | 21 const unsigned kApplicationServerKeyLength = 65; |
21 const uint8_t kApplicationServerKey[kApplicationServerKeyLength] = { | 22 const uint8_t kApplicationServerKey[kApplicationServerKeyLength] = { |
22 0x04, 0x55, 0x52, 0x6A, 0xA5, 0x6E, 0x8E, 0xAA, 0x47, 0x97, 0x36, 0x10, 0xC1
, | 23 0x04, 0x55, 0x52, 0x6A, 0xA5, 0x6E, 0x8E, 0xAA, 0x47, 0x97, 0x36, 0x10, 0xC1
, |
23 0x66, 0x3C, 0x1E, 0x65, 0xBF, 0xA1, 0x7B, 0xEE, 0x48, 0xC9, 0xC6, 0xBB, 0xBF
, | 24 0x66, 0x3C, 0x1E, 0x65, 0xBF, 0xA1, 0x7B, 0xEE, 0x48, 0xC9, 0xC6, 0xBB, 0xBF
, |
24 0x02, 0x18, 0x53, 0x72, 0x1D, 0x0C, 0x7B, 0xA9, 0xE3, 0x11, 0xB7, 0x03, 0x52
, | 25 0x02, 0x18, 0x53, 0x72, 0x1D, 0x0C, 0x7B, 0xA9, 0xE3, 0x11, 0xB7, 0x03, 0x52
, |
25 0x21, 0xD3, 0x71, 0x90, 0x13, 0xA8, 0xC1, 0xCF, 0xED, 0x20, 0xF7, 0x1F, 0xD1
, | 26 0x21, 0xD3, 0x71, 0x90, 0x13, 0xA8, 0xC1, 0xCF, 0xED, 0x20, 0xF7, 0x1F, 0xD1
, |
26 0x7F, 0xF2, 0x76, 0xB6, 0x01, 0x20, 0xD8, 0x35, 0xA5, 0xD9, 0x3C, 0x43, 0xDF | 27 0x7F, 0xF2, 0x76, 0xB6, 0x01, 0x20, 0xD8, 0x35, 0xA5, 0xD9, 0x3C, 0x43, 0xDF |
27 }; | 28 }; |
28 | 29 |
29 TEST(PushManagerTest, ValidSenderKey) | 30 TEST(PushManagerTest, ValidSenderKey) |
30 { | 31 { |
31 PushSubscriptionOptions options; | 32 PushSubscriptionOptionsInit options; |
32 options.setApplicationServerKey( | 33 options.setApplicationServerKey( |
33 ArrayBufferOrArrayBufferView::fromArrayBuffer( | 34 ArrayBufferOrArrayBufferView::fromArrayBuffer( |
34 DOMArrayBuffer::create(kApplicationServerKey, kApplicationServerKeyL
ength))); | 35 DOMArrayBuffer::create(kApplicationServerKey, kApplicationServerKeyL
ength))); |
35 | 36 |
36 TrackExceptionState exceptionState; | 37 TrackExceptionState exceptionState; |
37 WebPushSubscriptionOptions output = PushManager::toWebPushSubscriptionOption
s(options, exceptionState); | 38 WebPushSubscriptionOptions output = PushSubscriptionOptions::toWeb(options,
exceptionState); |
38 EXPECT_FALSE(exceptionState.hadException()); | 39 EXPECT_FALSE(exceptionState.hadException()); |
39 EXPECT_EQ(output.applicationServerKey.length(), kApplicationServerKeyLength)
; | 40 EXPECT_EQ(output.applicationServerKey.length(), kApplicationServerKeyLength)
; |
40 | 41 |
41 // Copy the key into a size+1 buffer so that it can be treated as a null | 42 // Copy the key into a size+1 buffer so that it can be treated as a null |
42 // terminated string for the purposes of EXPECT_EQ. | 43 // terminated string for the purposes of EXPECT_EQ. |
43 uint8_t senderKey[kApplicationServerKeyLength+1]; | 44 uint8_t senderKey[kApplicationServerKeyLength+1]; |
44 for (unsigned i = 0; i < kApplicationServerKeyLength; i++) | 45 for (unsigned i = 0; i < kApplicationServerKeyLength; i++) |
45 senderKey[i] = kApplicationServerKey[i]; | 46 senderKey[i] = kApplicationServerKey[i]; |
46 senderKey[kApplicationServerKeyLength] = 0x0; | 47 senderKey[kApplicationServerKeyLength] = 0x0; |
47 EXPECT_EQ(reinterpret_cast<const char*>(senderKey), output.applicationServer
Key.latin1()); | 48 EXPECT_EQ(reinterpret_cast<const char*>(senderKey), output.applicationServer
Key.latin1()); |
48 EXPECT_FALSE(output.applicationServerKey.isEmpty()); | 49 EXPECT_FALSE(output.applicationServerKey.isEmpty()); |
49 } | 50 } |
50 | 51 |
51 TEST(PushManagerTest, InvalidSenderKeyLength) | 52 TEST(PushManagerTest, InvalidSenderKeyLength) |
52 { | 53 { |
53 uint8_t senderKey[kMaxKeyLength + 1]; | 54 uint8_t senderKey[kMaxKeyLength + 1]; |
54 memset(senderKey, 0, sizeof(senderKey)); | 55 memset(senderKey, 0, sizeof(senderKey)); |
55 PushSubscriptionOptions options; | 56 PushSubscriptionOptionsInit options; |
56 options.setApplicationServerKey( | 57 options.setApplicationServerKey( |
57 ArrayBufferOrArrayBufferView::fromArrayBuffer( | 58 ArrayBufferOrArrayBufferView::fromArrayBuffer( |
58 DOMArrayBuffer::create(senderKey, kMaxKeyLength + 1))); | 59 DOMArrayBuffer::create(senderKey, kMaxKeyLength + 1))); |
59 | 60 |
60 TrackExceptionState exceptionState; | 61 TrackExceptionState exceptionState; |
61 WebPushSubscriptionOptions output = PushManager::toWebPushSubscriptionOption
s(options, exceptionState); | 62 WebPushSubscriptionOptions output = PushSubscriptionOptions::toWeb(options,
exceptionState); |
62 EXPECT_TRUE(exceptionState.hadException()); | 63 EXPECT_TRUE(exceptionState.hadException()); |
63 } | 64 } |
64 | 65 |
65 } // namespace | 66 } // namespace |
66 } // namespace blink | 67 } // namespace blink |
OLD | NEW |