Chromium Code Reviews| 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; | |
|
Peter Beverloo
2016/02/26 16:02:33
Please do not indent code in namespaces.
harkness
2016/02/26 17:12:04
gah, evil git cl format!
| |
| 18 const int kValidKeyLength = 65; | |
| 19 | |
| 20 TEST(PushManagerTest, ValidSenderKey) | |
| 21 { | |
| 22 uint8_t senderKey[kValidKeyLength]; | |
| 23 std::memset(senderKey, 0, sizeof(senderKey)); | |
|
Peter Beverloo
2016/02/26 16:02:33
nit: no std::
harkness
2016/02/26 17:12:04
Done.
| |
| 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::toWebPushSubscriptionOp tions(options, exceptionState); | |
| 32 EXPECT_FALSE(exceptionState.hadException()); | |
| 33 EXPECT_EQ(0, std::memcmp(output.applicationServerKey.utf8().c_str(), sen derKey, kValidKeyLength)); | |
|
Peter Beverloo
2016/02/26 16:02:33
STL is not yet allowed in these parts of Blink, un
Peter Beverloo
2016/02/26 16:02:33
ASSERT_EQ on the length to make sure we don't acce
harkness
2016/02/26 17:12:04
Done.
harkness
2016/02/26 17:12:04
Done.
| |
| 34 } | |
| 35 | |
| 36 TEST(PushManagerTest, InvalidSenderKeyMarker) | |
| 37 { | |
| 38 uint8_t senderKey[kValidKeyLength]; | |
| 39 senderKey[0] = 0x05; | |
| 40 for (int i = 1; i < kValidKeyLength; i++) | |
| 41 senderKey[i] = 0x0; | |
| 42 PushSubscriptionOptions options; | |
| 43 options.setApplicationServerKey( | |
| 44 ArrayBufferOrArrayBufferView::fromArrayBuffer( | |
| 45 DOMArrayBuffer::create(senderKey, kValidKeyLength))); | |
| 46 | |
| 47 TrackExceptionState exceptionState; | |
| 48 WebPushSubscriptionOptions output = PushManager::toWebPushSubscriptionOp tions(options, exceptionState); | |
| 49 EXPECT_TRUE(exceptionState.hadException()); | |
| 50 } | |
| 51 | |
| 52 TEST(PushManagerTest, InvalidSenderKeyLength) | |
| 53 { | |
| 54 uint8_t senderKey[kValidKeyLength - 1]; | |
| 55 senderKey[0] = kValidKeyMarker; | |
| 56 for (int i = 1; i < kValidKeyLength - 1; i++) | |
| 57 senderKey[i] = 0x0; | |
| 58 PushSubscriptionOptions options; | |
| 59 options.setApplicationServerKey( | |
| 60 ArrayBufferOrArrayBufferView::fromArrayBuffer( | |
| 61 DOMArrayBuffer::create(senderKey, kValidKeyLength - 1))); | |
| 62 | |
| 63 TrackExceptionState exceptionState; | |
| 64 WebPushSubscriptionOptions output = PushManager::toWebPushSubscriptionOp tions(options, exceptionState); | |
| 65 EXPECT_TRUE(exceptionState.hadException()); | |
| 66 } | |
| 67 | |
| 68 } // anonymous namespace | |
|
Peter Beverloo
2016/02/26 16:02:33
micro nit: we usually just use "// namespace"
harkness
2016/02/26 17:12:04
Done.
| |
| 69 } // namespace blink | |
| OLD | NEW |