summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/modules/notifications/notification_data_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/blink/renderer/modules/notifications/notification_data_test.cc')
-rw-r--r--chromium/third_party/blink/renderer/modules/notifications/notification_data_test.cc172
1 files changed, 83 insertions, 89 deletions
diff --git a/chromium/third_party/blink/renderer/modules/notifications/notification_data_test.cc b/chromium/third_party/blink/renderer/modules/notifications/notification_data_test.cc
index 8266bed7d98..b5680a964ca 100644
--- a/chromium/third_party/blink/renderer/modules/notifications/notification_data_test.cc
+++ b/chromium/third_party/blink/renderer/modules/notifications/notification_data_test.cc
@@ -7,9 +7,9 @@
#include "base/stl_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/notifications/notification_constants.h"
+#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_testing.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_notification_action.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_notification_options.h"
-#include "third_party/blink/renderer/core/testing/null_execution_context.h"
#include "third_party/blink/renderer/modules/notifications/notification.h"
#include "third_party/blink/renderer/modules/notifications/timestamp_trigger.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
@@ -49,37 +49,10 @@ const char kNotificationActionPlaceholder[] = "Placeholder...";
const unsigned kNotificationVibrationUnnormalized[] = {10, 1000000, 50, 42};
const int kNotificationVibrationNormalized[] = {10, 10000, 50};
-// Execution context that implements the CompleteURL method to complete
-// URLs that are assumed to be relative against a given base URL.
-class CompleteUrlExecutionContext final : public NullExecutionContext {
- public:
- explicit CompleteUrlExecutionContext(const String& base) : base_(base) {}
+TEST(NotificationDataTest, ReflectProperties) {
+ const KURL base_url(kNotificationBaseUrl);
+ V8TestingScope scope(base_url);
- protected:
- ~CompleteUrlExecutionContext() final = default;
-
- KURL CompleteURL(const String& url) const override {
- return KURL(base_, url);
- }
-
- private:
- KURL base_;
-};
-
-class NotificationDataTest : public testing::Test {
- public:
- void SetUp() override {
- execution_context_ =
- MakeGarbageCollected<CompleteUrlExecutionContext>(kNotificationBaseUrl);
- }
-
- ExecutionContext* GetExecutionContext() { return execution_context_.Get(); }
-
- private:
- Persistent<ExecutionContext> execution_context_;
-};
-
-TEST_F(NotificationDataTest, ReflectProperties) {
Vector<unsigned> vibration_pattern;
for (size_t i = 0; i < base::size(kNotificationVibration); ++i)
vibration_pattern.push_back(kNotificationVibration[i]);
@@ -89,8 +62,7 @@ TEST_F(NotificationDataTest, ReflectProperties) {
HeapVector<Member<NotificationAction>> actions;
for (size_t i = 0; i < Notification::maxActions(); ++i) {
- NotificationAction* action =
- NotificationAction::Create(GetExecutionContext()->GetIsolate());
+ NotificationAction* action = NotificationAction::Create(scope.GetIsolate());
action->setType(kNotificationActionType);
action->setAction(kNotificationActionAction);
action->setTitle(kNotificationActionTitle);
@@ -104,7 +76,7 @@ TEST_F(NotificationDataTest, ReflectProperties) {
TimestampTrigger* showTrigger = TimestampTrigger::Create(showTimestamp);
NotificationOptions* options =
- NotificationOptions::Create(GetExecutionContext()->GetIsolate());
+ NotificationOptions::Create(scope.GetIsolate());
options->setDir(kNotificationDir);
options->setLang(kNotificationLang);
options->setBody(kNotificationBody);
@@ -122,9 +94,10 @@ TEST_F(NotificationDataTest, ReflectProperties) {
// TODO(peter): Test |options.data| and |notificationData.data|.
- DummyExceptionStateForTesting exception_state;
- mojom::blink::NotificationDataPtr notification_data = CreateNotificationData(
- GetExecutionContext(), kNotificationTitle, options, exception_state);
+ ExceptionState& exception_state = scope.GetExceptionState();
+ mojom::blink::NotificationDataPtr notification_data =
+ CreateNotificationData(scope.GetExecutionContext(), kNotificationTitle,
+ options, exception_state);
ASSERT_FALSE(exception_state.HadException());
EXPECT_EQ(kNotificationTitle, notification_data->title);
@@ -137,12 +110,10 @@ TEST_F(NotificationDataTest, ReflectProperties) {
EXPECT_EQ(base::Time::FromJsTime(showTimestamp),
notification_data->show_trigger_timestamp);
- KURL base(kNotificationBaseUrl);
-
// URLs should be resolved against the base URL of the execution context.
- EXPECT_EQ(KURL(base, kNotificationImage), notification_data->image);
- EXPECT_EQ(KURL(base, kNotificationIcon), notification_data->icon);
- EXPECT_EQ(KURL(base, kNotificationBadge), notification_data->badge);
+ EXPECT_EQ(KURL(base_url, kNotificationImage), notification_data->image);
+ EXPECT_EQ(KURL(base_url, kNotificationIcon), notification_data->icon);
+ EXPECT_EQ(KURL(base_url, kNotificationBadge), notification_data->badge);
ASSERT_EQ(vibration_pattern.size(),
notification_data->vibration_pattern->size());
@@ -166,7 +137,9 @@ TEST_F(NotificationDataTest, ReflectProperties) {
}
}
-TEST_F(NotificationDataTest, SilentNotificationWithVibration) {
+TEST(NotificationDataTest, SilentNotificationWithVibration) {
+ V8TestingScope scope;
+
Vector<unsigned> vibration_pattern;
for (size_t i = 0; i < base::size(kNotificationVibration); ++i)
vibration_pattern.push_back(kNotificationVibration[i]);
@@ -175,20 +148,23 @@ TEST_F(NotificationDataTest, SilentNotificationWithVibration) {
vibration_sequence.SetUnsignedLongSequence(vibration_pattern);
NotificationOptions* options =
- NotificationOptions::Create(GetExecutionContext()->GetIsolate());
+ NotificationOptions::Create(scope.GetIsolate());
options->setVibrate(vibration_sequence);
options->setSilent(true);
- DummyExceptionStateForTesting exception_state;
- mojom::blink::NotificationDataPtr notification_data = CreateNotificationData(
- GetExecutionContext(), kNotificationTitle, options, exception_state);
+ ExceptionState& exception_state = scope.GetExceptionState();
+ mojom::blink::NotificationDataPtr notification_data =
+ CreateNotificationData(scope.GetExecutionContext(), kNotificationTitle,
+ options, exception_state);
ASSERT_TRUE(exception_state.HadException());
EXPECT_EQ("Silent notifications must not specify vibration patterns.",
exception_state.Message());
}
-TEST_F(NotificationDataTest, ActionTypeButtonWithPlaceholder) {
+TEST(NotificationDataTest, ActionTypeButtonWithPlaceholder) {
+ V8TestingScope scope;
+
HeapVector<Member<NotificationAction>> actions;
NotificationAction* action = NotificationAction::Create();
action->setType("button");
@@ -196,27 +172,31 @@ TEST_F(NotificationDataTest, ActionTypeButtonWithPlaceholder) {
actions.push_back(action);
NotificationOptions* options =
- NotificationOptions::Create(GetExecutionContext()->GetIsolate());
+ NotificationOptions::Create(scope.GetIsolate());
options->setActions(actions);
- DummyExceptionStateForTesting exception_state;
- mojom::blink::NotificationDataPtr notification_data = CreateNotificationData(
- GetExecutionContext(), kNotificationTitle, options, exception_state);
+ ExceptionState& exception_state = scope.GetExceptionState();
+ mojom::blink::NotificationDataPtr notification_data =
+ CreateNotificationData(scope.GetExecutionContext(), kNotificationTitle,
+ options, exception_state);
ASSERT_TRUE(exception_state.HadException());
EXPECT_EQ("Notifications of type \"button\" cannot specify a placeholder.",
exception_state.Message());
}
-TEST_F(NotificationDataTest, RenotifyWithEmptyTag) {
+TEST(NotificationDataTest, RenotifyWithEmptyTag) {
+ V8TestingScope scope;
+
NotificationOptions* options =
- NotificationOptions::Create(GetExecutionContext()->GetIsolate());
+ NotificationOptions::Create(scope.GetIsolate());
options->setTag(kNotificationEmptyTag);
options->setRenotify(true);
- DummyExceptionStateForTesting exception_state;
- mojom::blink::NotificationDataPtr notification_data = CreateNotificationData(
- GetExecutionContext(), kNotificationTitle, options, exception_state);
+ ExceptionState& exception_state = scope.GetExceptionState();
+ mojom::blink::NotificationDataPtr notification_data =
+ CreateNotificationData(scope.GetExecutionContext(), kNotificationTitle,
+ options, exception_state);
ASSERT_TRUE(exception_state.HadException());
EXPECT_EQ(
@@ -224,7 +204,9 @@ TEST_F(NotificationDataTest, RenotifyWithEmptyTag) {
exception_state.Message());
}
-TEST_F(NotificationDataTest, InvalidIconUrls) {
+TEST(NotificationDataTest, InvalidIconUrls) {
+ V8TestingScope scope;
+
HeapVector<Member<NotificationAction>> actions;
for (size_t i = 0; i < Notification::maxActions(); ++i) {
NotificationAction* action = NotificationAction::Create();
@@ -235,15 +217,16 @@ TEST_F(NotificationDataTest, InvalidIconUrls) {
}
NotificationOptions* options =
- NotificationOptions::Create(GetExecutionContext()->GetIsolate());
+ NotificationOptions::Create(scope.GetIsolate());
options->setImage(kNotificationIconInvalid);
options->setIcon(kNotificationIconInvalid);
options->setBadge(kNotificationIconInvalid);
options->setActions(actions);
- DummyExceptionStateForTesting exception_state;
- mojom::blink::NotificationDataPtr notification_data = CreateNotificationData(
- GetExecutionContext(), kNotificationTitle, options, exception_state);
+ ExceptionState& exception_state = scope.GetExceptionState();
+ mojom::blink::NotificationDataPtr notification_data =
+ CreateNotificationData(scope.GetExecutionContext(), kNotificationTitle,
+ options, exception_state);
ASSERT_FALSE(exception_state.HadException());
EXPECT_TRUE(notification_data->image.IsEmpty());
@@ -253,7 +236,9 @@ TEST_F(NotificationDataTest, InvalidIconUrls) {
EXPECT_TRUE(action->icon.IsEmpty());
}
-TEST_F(NotificationDataTest, VibrationNormalization) {
+TEST(NotificationDataTest, VibrationNormalization) {
+ V8TestingScope scope;
+
Vector<unsigned> unnormalized_pattern;
for (size_t i = 0; i < base::size(kNotificationVibrationUnnormalized); ++i)
unnormalized_pattern.push_back(kNotificationVibrationUnnormalized[i]);
@@ -262,12 +247,13 @@ TEST_F(NotificationDataTest, VibrationNormalization) {
vibration_sequence.SetUnsignedLongSequence(unnormalized_pattern);
NotificationOptions* options =
- NotificationOptions::Create(GetExecutionContext()->GetIsolate());
+ NotificationOptions::Create(scope.GetIsolate());
options->setVibrate(vibration_sequence);
- DummyExceptionStateForTesting exception_state;
- mojom::blink::NotificationDataPtr notification_data = CreateNotificationData(
- GetExecutionContext(), kNotificationTitle, options, exception_state);
+ ExceptionState& exception_state = scope.GetExceptionState();
+ mojom::blink::NotificationDataPtr notification_data =
+ CreateNotificationData(scope.GetExecutionContext(), kNotificationTitle,
+ options, exception_state);
EXPECT_FALSE(exception_state.HadException());
Vector<int> normalized_pattern;
@@ -282,13 +268,16 @@ TEST_F(NotificationDataTest, VibrationNormalization) {
}
}
-TEST_F(NotificationDataTest, DefaultTimestampValue) {
+TEST(NotificationDataTest, DefaultTimestampValue) {
+ V8TestingScope scope;
+
NotificationOptions* options =
- NotificationOptions::Create(GetExecutionContext()->GetIsolate());
+ NotificationOptions::Create(scope.GetIsolate());
- DummyExceptionStateForTesting exception_state;
- mojom::blink::NotificationDataPtr notification_data = CreateNotificationData(
- GetExecutionContext(), kNotificationTitle, options, exception_state);
+ ExceptionState& exception_state = scope.GetExceptionState();
+ mojom::blink::NotificationDataPtr notification_data =
+ CreateNotificationData(scope.GetExecutionContext(), kNotificationTitle,
+ options, exception_state);
EXPECT_FALSE(exception_state.HadException());
// The timestamp should be set to the current time since the epoch if it
@@ -298,23 +287,22 @@ TEST_F(NotificationDataTest, DefaultTimestampValue) {
base::Time::Now().ToDoubleT() * 1000.0, 32);
}
-TEST_F(NotificationDataTest, DirectionValues) {
+TEST(NotificationDataTest, DirectionValues) {
+ V8TestingScope scope;
+
WTF::HashMap<String, mojom::blink::NotificationDirection> mappings;
mappings.insert("ltr", mojom::blink::NotificationDirection::LEFT_TO_RIGHT);
mappings.insert("rtl", mojom::blink::NotificationDirection::RIGHT_TO_LEFT);
mappings.insert("auto", mojom::blink::NotificationDirection::AUTO);
- // Invalid values should default to "auto".
- mappings.insert("peter", mojom::blink::NotificationDirection::AUTO);
-
for (const String& direction : mappings.Keys()) {
NotificationOptions* options =
- NotificationOptions::Create(GetExecutionContext()->GetIsolate());
+ NotificationOptions::Create(scope.GetIsolate());
options->setDir(direction);
- DummyExceptionStateForTesting exception_state;
+ ExceptionState& exception_state = scope.GetExceptionState();
mojom::blink::NotificationDataPtr notification_data =
- CreateNotificationData(GetExecutionContext(), kNotificationTitle,
+ CreateNotificationData(scope.GetExecutionContext(), kNotificationTitle,
options, exception_state);
ASSERT_FALSE(exception_state.HadException());
@@ -322,7 +310,9 @@ TEST_F(NotificationDataTest, DirectionValues) {
}
}
-TEST_F(NotificationDataTest, MaximumActionCount) {
+TEST(NotificationDataTest, MaximumActionCount) {
+ V8TestingScope scope;
+
HeapVector<Member<NotificationAction>> actions;
for (size_t i = 0; i < Notification::maxActions() + 2; ++i) {
NotificationAction* action = NotificationAction::Create();
@@ -333,12 +323,13 @@ TEST_F(NotificationDataTest, MaximumActionCount) {
}
NotificationOptions* options =
- NotificationOptions::Create(GetExecutionContext()->GetIsolate());
+ NotificationOptions::Create(scope.GetIsolate());
options->setActions(actions);
- DummyExceptionStateForTesting exception_state;
- mojom::blink::NotificationDataPtr notification_data = CreateNotificationData(
- GetExecutionContext(), kNotificationTitle, options, exception_state);
+ ExceptionState& exception_state = scope.GetExceptionState();
+ mojom::blink::NotificationDataPtr notification_data =
+ CreateNotificationData(scope.GetExecutionContext(), kNotificationTitle,
+ options, exception_state);
ASSERT_FALSE(exception_state.HadException());
// The stored actions will be capped to |maxActions| entries.
@@ -350,7 +341,9 @@ TEST_F(NotificationDataTest, MaximumActionCount) {
}
}
-TEST_F(NotificationDataTest, RejectsTriggerTimestampOverAYear) {
+TEST(NotificationDataTest, RejectsTriggerTimestampOverAYear) {
+ V8TestingScope scope;
+
base::Time show_timestamp = base::Time::Now() +
kMaxNotificationShowTriggerDelay +
base::TimeDelta::FromDays(1);
@@ -358,12 +351,13 @@ TEST_F(NotificationDataTest, RejectsTriggerTimestampOverAYear) {
TimestampTrigger::Create(show_timestamp.ToJsTime());
NotificationOptions* options =
- NotificationOptions::Create(GetExecutionContext()->GetIsolate());
+ NotificationOptions::Create(scope.GetIsolate());
options->setShowTrigger(show_trigger);
- DummyExceptionStateForTesting exception_state;
- mojom::blink::NotificationDataPtr notification_data = CreateNotificationData(
- GetExecutionContext(), kNotificationTitle, options, exception_state);
+ ExceptionState& exception_state = scope.GetExceptionState();
+ mojom::blink::NotificationDataPtr notification_data =
+ CreateNotificationData(scope.GetExecutionContext(), kNotificationTitle,
+ options, exception_state);
ASSERT_TRUE(exception_state.HadException());
EXPECT_EQ("Notification trigger timestamp too far ahead in the future.",