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

Unified 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: Fix asan errors 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/modules/push_messaging/PushManager.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
index e5e7f8f53dd9f1c46f236c152d0e85b136930678..15cca80889faf38757a54f87271901c013491ae4 100644
--- a/third_party/WebKit/Source/modules/push_messaging/PushManagerTest.cpp
+++ b/third_party/WebKit/Source/modules/push_messaging/PushManagerTest.cpp
@@ -17,21 +17,36 @@ namespace {
const char kValidKeyMarker = 0x04;
const unsigned kValidKeyLength = 65;
+// NIST P-256 public key made available to tests. Must be an uncompressed
+// point in accordance with SEC1 2.3.3.
+const uint8_t kApplicationServerKey[65] = {
+ 0x04, 0x55, 0x52, 0x6A, 0xA5, 0x6E, 0x8E, 0xAA, 0x47, 0x97, 0x36, 0x10, 0xC1,
+ 0x66, 0x3C, 0x1E, 0x65, 0xBF, 0xA1, 0x7B, 0xEE, 0x48, 0xC9, 0xC6, 0xBB, 0xBF,
+ 0x02, 0x18, 0x53, 0x72, 0x1D, 0x0C, 0x7B, 0xA9, 0xE3, 0x11, 0xB7, 0x03, 0x52,
+ 0x21, 0xD3, 0x71, 0x90, 0x13, 0xA8, 0xC1, 0xCF, 0xED, 0x20, 0xF7, 0x1F, 0xD1,
+ 0x7F, 0xF2, 0x76, 0xB6, 0x01, 0x20, 0xD8, 0x35, 0xA5, 0xD9, 0x3C, 0x43, 0xDF
+};
+
TEST(PushManagerTest, ValidSenderKey)
{
- uint8_t senderKey[kValidKeyLength];
- memset(senderKey, 0, sizeof(senderKey));
- senderKey[0] = kValidKeyMarker;
PushSubscriptionOptions options;
options.setApplicationServerKey(
ArrayBufferOrArrayBufferView::fromArrayBuffer(
- DOMArrayBuffer::create(senderKey, kValidKeyLength)));
+ DOMArrayBuffer::create(kApplicationServerKey, kValidKeyLength)));
TrackExceptionState exceptionState;
WebPushSubscriptionOptions output = PushManager::toWebPushSubscriptionOptions(options, exceptionState);
EXPECT_FALSE(exceptionState.hadException());
EXPECT_EQ(output.applicationServerKey.length(), kValidKeyLength);
- EXPECT_EQ(output.applicationServerKey, WebString::fromUTF8(reinterpret_cast<const char*>(senderKey), kValidKeyLength));
+
+ // Copy the key into a size+1 buffer so that it can be treated as a null
+ // terminated string for the purposes of EXPECT_EQ.
+ uint8_t senderKey[kValidKeyLength+1];
+ for (unsigned i = 0; i < kValidKeyLength; i++)
+ senderKey[i] = kApplicationServerKey[i];
+ senderKey[kValidKeyLength] = 0x0;
+ EXPECT_EQ(reinterpret_cast<const char*>(senderKey), output.applicationServerKey.latin1());
+ EXPECT_FALSE(output.applicationServerKey.isEmpty());
}
TEST(PushManagerTest, InvalidSenderKeyMarker)
« no previous file with comments | « third_party/WebKit/Source/modules/push_messaging/PushManager.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698