| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 #include "public/web/WebFrame.h" | 43 #include "public/web/WebFrame.h" |
| 44 #include "public/web/WebView.h" | 44 #include "public/web/WebView.h" |
| 45 #include "v8.h" | 45 #include "v8.h" |
| 46 #include "web/WebLocalFrameImpl.h" | 46 #include "web/WebLocalFrameImpl.h" |
| 47 #include "web/WebViewImpl.h" | 47 #include "web/WebViewImpl.h" |
| 48 #include "web/tests/FrameTestHelpers.h" | 48 #include "web/tests/FrameTestHelpers.h" |
| 49 #include <gtest/gtest.h> | 49 #include <gtest/gtest.h> |
| 50 | 50 |
| 51 namespace blink { | 51 namespace blink { |
| 52 | 52 |
| 53 class TestListener : public V8AbstractEventListener { | 53 class TestListener final : public V8AbstractEventListener { |
| 54 public: | 54 public: |
| 55 bool operator==(const EventListener&) override | 55 bool operator==(const EventListener&) override |
| 56 { | 56 { |
| 57 return true; | 57 return true; |
| 58 } | 58 } |
| 59 | 59 |
| 60 void handleEvent(ScriptState* scriptState, Event* event) override | 60 void handleEvent(ScriptState* scriptState, Event* event) override |
| 61 { | 61 { |
| 62 EXPECT_EQ(event->type(), "blah"); | 62 EXPECT_EQ(event->type(), "blah"); |
| 63 | 63 |
| 64 ScriptState::Scope scope(scriptState); | 64 ScriptState::Scope scope(scriptState); |
| 65 v8::Local<v8::Context> context = scriptState->context(); | 65 v8::Local<v8::Context> context = scriptState->context(); |
| 66 v8::Local<v8::Value> jsEvent = toV8(event, context->Global(), isolate())
; | 66 v8::Local<v8::Value> jsEvent = toV8(event, context->Global(), isolate())
; |
| 67 | 67 |
| 68 EXPECT_EQ(jsEvent->ToObject(context).ToLocalChecked()->Get(context, v8At
omicString(isolate(), "detail")).ToLocalChecked(), v8::Boolean::New(isolate(), t
rue)); | 68 EXPECT_EQ(jsEvent->ToObject(context).ToLocalChecked()->Get(context, v8At
omicString(isolate(), "detail")).ToLocalChecked(), v8::Boolean::New(isolate(), t
rue)); |
| 69 } | 69 } |
| 70 | 70 |
| 71 static PassRefPtr<TestListener> create(ScriptState* scriptState) | 71 static PassRefPtrWillBeRawPtr<TestListener> create(ScriptState* scriptState) |
| 72 { | 72 { |
| 73 return adoptRef(new TestListener(scriptState)); | 73 return adoptRefWillBeNoop(new TestListener(scriptState)); |
| 74 } | 74 } |
| 75 | 75 |
| 76 private: | 76 private: |
| 77 TestListener(ScriptState* scriptState) | 77 explicit TestListener(ScriptState* scriptState) |
| 78 : V8AbstractEventListener(false, scriptState->world(), scriptState->isol
ate()) | 78 : V8AbstractEventListener(false, scriptState->world(), scriptState->isol
ate()) |
| 79 { | 79 { |
| 80 } | 80 } |
| 81 | 81 |
| 82 v8::Local<v8::Value> callListenerFunction(ScriptState*, v8::Local<v8::Value>
, Event*) override | 82 v8::Local<v8::Value> callListenerFunction(ScriptState*, v8::Local<v8::Value>
, Event*) override |
| 83 { | 83 { |
| 84 ASSERT_NOT_REACHED(); | 84 ASSERT_NOT_REACHED(); |
| 85 return v8::Local<v8::Value>(); | 85 return v8::Local<v8::Value>(); |
| 86 } | 86 } |
| 87 }; | 87 }; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 99 | 99 |
| 100 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(baseURL.c_s
tr()), WebString::fromUTF8(path.c_str())); | 100 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(baseURL.c_s
tr()), WebString::fromUTF8(path.c_str())); |
| 101 FrameTestHelpers::WebViewHelper webViewHelper; | 101 FrameTestHelpers::WebViewHelper webViewHelper; |
| 102 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webViewHelper.initializeAndLo
ad(baseURL + path)->mainFrame()); | 102 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webViewHelper.initializeAndLo
ad(baseURL + path)->mainFrame()); |
| 103 WebDOMEvent event = frame->frame()->document()->createEvent("CustomEvent", I
GNORE_EXCEPTION); | 103 WebDOMEvent event = frame->frame()->document()->createEvent("CustomEvent", I
GNORE_EXCEPTION); |
| 104 WebDOMCustomEvent customEvent = event.to<WebDOMCustomEvent>(); | 104 WebDOMCustomEvent customEvent = event.to<WebDOMCustomEvent>(); |
| 105 | 105 |
| 106 v8::Isolate* isolate = toIsolate(frame->frame()); | 106 v8::Isolate* isolate = toIsolate(frame->frame()); |
| 107 V8TestingScope scope(isolate); | 107 V8TestingScope scope(isolate); |
| 108 customEvent.initCustomEvent("blah", false, false, WebSerializedScriptValue::
serialize(v8::Boolean::New(isolate, true))); | 108 customEvent.initCustomEvent("blah", false, false, WebSerializedScriptValue::
serialize(v8::Boolean::New(isolate, true))); |
| 109 RefPtr<EventListener> listener = TestListener::create(scope.scriptState()); | 109 RefPtrWillBeRawPtr<EventListener> listener = TestListener::create(scope.scri
ptState()); |
| 110 frame->frame()->document()->addEventListener("blah", listener, false); | 110 frame->frame()->document()->addEventListener("blah", listener, false); |
| 111 frame->frame()->document()->dispatchEvent(event); | 111 frame->frame()->document()->dispatchEvent(event); |
| 112 | 112 |
| 113 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); | 113 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); |
| 114 } | 114 } |
| 115 | 115 |
| 116 } // namespace blink | 116 } // namespace blink |
| OLD | NEW |