 Chromium Code Reviews
 Chromium Code Reviews Issue 1701313002:
  Partial implementation of subscription restrictions.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 1701313002:
  Partial implementation of subscription restrictions.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| Index: third_party/WebKit/Source/modules/push_messaging/PushManagerTest.cpp | 
| diff --git a/third_party/WebKit/Source/modules/push_messaging/PushManagerTest.cpp b/third_party/WebKit/Source/modules/push_messaging/PushManagerTest.cpp | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..ffc87fac84a4a1c8903d2ef7db1b48857559f0f8 | 
| --- /dev/null | 
| +++ b/third_party/WebKit/Source/modules/push_messaging/PushManagerTest.cpp | 
| @@ -0,0 +1,71 @@ | 
| +// Copyright 2016 The Chromium Authors. All rights reserved. | 
| +// Use of this source code is governed by a BSD-style license that can be | 
| +// found in the LICENSE file. | 
| + | 
| +#include "modules/push_messaging/PushManager.h" | 
| + | 
| +#include "bindings/modules/v8/UnionTypesModules.h" | 
| +#include "core/dom/DOMArrayBuffer.h" | 
| +#include "public/platform/WebString.h" | 
| +#include "testing/gtest/include/gtest/gtest.h" | 
| + | 
| +namespace blink { | 
| +namespace { | 
| + | 
| +const char kSenderId[] = "0123456789"; | 
| +const char kValidKeyMarker = 0x04; | 
| +const int kValidKeyLength = 65; | 
| + | 
| +TEST(PushManagerTest, ValidSenderId) | 
| +{ | 
| + ArrayBufferOrArrayBufferView input = | 
| + ArrayBufferOrArrayBufferView::fromArrayBuffer( | 
| + DOMArrayBuffer::create(kSenderId, sizeof(kSenderId))); | 
| + | 
| + EXPECT_EQ(PushManager::toString(input).utf8(), kSenderId); | 
| +} | 
| + | 
| +TEST(PushManagerTest, ValidSenderKey) | 
| +{ | 
| + uint8_t senderKey[kValidKeyLength]; | 
| + senderKey[0] = kValidKeyMarker; | 
| + for (int i = 1; i < kValidKeyLength; i++) | 
| + senderKey[i] = 0x0; | 
| + ArrayBufferOrArrayBufferView input = | 
| + ArrayBufferOrArrayBufferView::fromArrayBuffer( | 
| + DOMArrayBuffer::create(senderKey, kValidKeyLength)); | 
| + | 
| + WebString output = PushManager::toString(input); | 
| + EXPECT_EQ(0, std::memcmp(output.utf8().c_str(), senderKey, kValidKeyLength)); | 
| +} | 
| + | 
| +TEST(PushManagerTest, InvalidSenderKeyMarker) | 
| +{ | 
| + uint8_t senderKey[kValidKeyLength]; | 
| 
Peter Beverloo
2016/02/23 14:28:29
Perhaps rewrite it like this:
===============
uin
 
harkness
2016/02/26 11:44:26
Done.
 | 
| + senderKey[0] = 0x05; | 
| + for (int i = 1; i < kValidKeyLength; i++) | 
| + senderKey[i] = 0x0; | 
| + ArrayBufferOrArrayBufferView input = | 
| + ArrayBufferOrArrayBufferView::fromArrayBuffer( | 
| + DOMArrayBuffer::create(senderKey, kValidKeyLength)); | 
| + | 
| + WebString output = PushManager::toString(input); | 
| + EXPECT_TRUE(output.isNull()); | 
| +} | 
| + | 
| +TEST(PushManagerTest, InvalidSenderKeyLength) | 
| +{ | 
| + uint8_t senderKey[kValidKeyLength - 1]; | 
| + senderKey[0] = kValidKeyMarker; | 
| + for (int i = 1; i < kValidKeyLength - 1; i++) | 
| + senderKey[i] = 0x0; | 
| + ArrayBufferOrArrayBufferView input = | 
| + ArrayBufferOrArrayBufferView::fromArrayBuffer( | 
| + DOMArrayBuffer::create(senderKey, kValidKeyLength-1)); | 
| + | 
| + WebString output = PushManager::toString(input); | 
| + EXPECT_TRUE(output.isNull()); | 
| +} | 
| + | 
| +} // anonymous namespace | 
| +} // namespace blink |