| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/notifications/NotificationData.h" | 5 #include "modules/notifications/NotificationData.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
| 8 #include "core/testing/NullExecutionContext.h" | 8 #include "core/testing/NullExecutionContext.h" |
| 9 #include "modules/notifications/Notification.h" | 9 #include "modules/notifications/Notification.h" |
| 10 #include "modules/notifications/NotificationOptions.h" | 10 #include "modules/notifications/NotificationOptions.h" |
| 11 #include "platform/weborigin/KURL.h" | 11 #include "platform/weborigin/KURL.h" |
| 12 #include "platform/wtf/CurrentTime.h" | 12 #include "platform/wtf/CurrentTime.h" |
| 13 #include "platform/wtf/HashMap.h" | 13 #include "platform/wtf/HashMap.h" |
| 14 #include "platform/wtf/Vector.h" | 14 #include "platform/wtf/Vector.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 16 |
| 17 namespace blink { | 17 namespace blink { |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 const char kBaseUrl[] = "https://example.com/directory/"; | 20 const char kNotificationBaseUrl[] = "https://example.com/directory/"; |
| 21 const char kNotificationTitle[] = "My Notification"; | 21 const char kNotificationTitle[] = "My Notification"; |
| 22 | 22 |
| 23 const char kNotificationDir[] = "rtl"; | 23 const char kNotificationDir[] = "rtl"; |
| 24 const char kNotificationLang[] = "nl"; | 24 const char kNotificationLang[] = "nl"; |
| 25 const char kNotificationBody[] = "Hello, world"; | 25 const char kNotificationBody[] = "Hello, world"; |
| 26 const char kNotificationTag[] = "my_tag"; | 26 const char kNotificationTag[] = "my_tag"; |
| 27 const char kNotificationEmptyTag[] = ""; | 27 const char kNotificationEmptyTag[] = ""; |
| 28 const char kNotificationImage[] = "https://example.com/image.jpg"; | 28 const char kNotificationImage[] = "https://example.com/image.jpg"; |
| 29 const char kNotificationIcon[] = "/icon.png"; | 29 const char kNotificationIcon[] = "/icon.png"; |
| 30 const char kNotificationIconInvalid[] = "https://invalid:icon:url"; | 30 const char kNotificationIconInvalid[] = "https://invalid:icon:url"; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 60 return KURL(base_, url); | 60 return KURL(base_, url); |
| 61 } | 61 } |
| 62 | 62 |
| 63 private: | 63 private: |
| 64 KURL base_; | 64 KURL base_; |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 class NotificationDataTest : public ::testing::Test { | 67 class NotificationDataTest : public ::testing::Test { |
| 68 public: | 68 public: |
| 69 void SetUp() override { | 69 void SetUp() override { |
| 70 execution_context_ = new CompleteUrlExecutionContext(kBaseUrl); | 70 execution_context_ = new CompleteUrlExecutionContext(kNotificationBaseUrl); |
| 71 } | 71 } |
| 72 | 72 |
| 73 ExecutionContext* GetExecutionContext() { return execution_context_.Get(); } | 73 ExecutionContext* GetExecutionContext() { return execution_context_.Get(); } |
| 74 | 74 |
| 75 private: | 75 private: |
| 76 Persistent<ExecutionContext> execution_context_; | 76 Persistent<ExecutionContext> execution_context_; |
| 77 }; | 77 }; |
| 78 | 78 |
| 79 TEST_F(NotificationDataTest, ReflectProperties) { | 79 TEST_F(NotificationDataTest, ReflectProperties) { |
| 80 Vector<unsigned> vibration_pattern; | 80 Vector<unsigned> vibration_pattern; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 ASSERT_FALSE(exception_state.HadException()); | 119 ASSERT_FALSE(exception_state.HadException()); |
| 120 | 120 |
| 121 EXPECT_EQ(kNotificationTitle, notification_data.title); | 121 EXPECT_EQ(kNotificationTitle, notification_data.title); |
| 122 | 122 |
| 123 EXPECT_EQ(WebNotificationData::kDirectionRightToLeft, | 123 EXPECT_EQ(WebNotificationData::kDirectionRightToLeft, |
| 124 notification_data.direction); | 124 notification_data.direction); |
| 125 EXPECT_EQ(kNotificationLang, notification_data.lang); | 125 EXPECT_EQ(kNotificationLang, notification_data.lang); |
| 126 EXPECT_EQ(kNotificationBody, notification_data.body); | 126 EXPECT_EQ(kNotificationBody, notification_data.body); |
| 127 EXPECT_EQ(kNotificationTag, notification_data.tag); | 127 EXPECT_EQ(kNotificationTag, notification_data.tag); |
| 128 | 128 |
| 129 KURL base(kParsedURLString, kBaseUrl); | 129 KURL base(kParsedURLString, kNotificationBaseUrl); |
| 130 | 130 |
| 131 // URLs should be resolved against the base URL of the execution context. | 131 // URLs should be resolved against the base URL of the execution context. |
| 132 EXPECT_EQ(WebURL(KURL(base, kNotificationImage)), notification_data.image); | 132 EXPECT_EQ(WebURL(KURL(base, kNotificationImage)), notification_data.image); |
| 133 EXPECT_EQ(WebURL(KURL(base, kNotificationIcon)), notification_data.icon); | 133 EXPECT_EQ(WebURL(KURL(base, kNotificationIcon)), notification_data.icon); |
| 134 EXPECT_EQ(WebURL(KURL(base, kNotificationBadge)), notification_data.badge); | 134 EXPECT_EQ(WebURL(KURL(base, kNotificationBadge)), notification_data.badge); |
| 135 | 135 |
| 136 ASSERT_EQ(vibration_pattern.size(), notification_data.vibrate.size()); | 136 ASSERT_EQ(vibration_pattern.size(), notification_data.vibrate.size()); |
| 137 for (size_t i = 0; i < vibration_pattern.size(); ++i) | 137 for (size_t i = 0; i < vibration_pattern.size(); ++i) |
| 138 EXPECT_EQ(vibration_pattern[i], | 138 EXPECT_EQ(vibration_pattern[i], |
| 139 static_cast<unsigned>(notification_data.vibrate[i])); | 139 static_cast<unsigned>(notification_data.vibrate[i])); |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 ASSERT_EQ(Notification::maxActions(), notification_data.actions.size()); | 320 ASSERT_EQ(Notification::maxActions(), notification_data.actions.size()); |
| 321 | 321 |
| 322 for (size_t i = 0; i < Notification::maxActions(); ++i) { | 322 for (size_t i = 0; i < Notification::maxActions(); ++i) { |
| 323 WebString expected_action = String::Number(i); | 323 WebString expected_action = String::Number(i); |
| 324 EXPECT_EQ(expected_action, notification_data.actions[i].action); | 324 EXPECT_EQ(expected_action, notification_data.actions[i].action); |
| 325 } | 325 } |
| 326 } | 326 } |
| 327 | 327 |
| 328 } // namespace | 328 } // namespace |
| 329 } // namespace blink | 329 } // namespace blink |
| OLD | NEW |