| OLD | NEW | 
|---|
|  | (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 |  | 
| OLD | NEW | 
|---|