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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 | 48 |
49 #include <gtest/gtest.h> | 49 #include <gtest/gtest.h> |
50 | 50 |
51 using namespace WebCore; | 51 using namespace WebCore; |
52 using namespace blink; | 52 using namespace blink; |
53 | 53 |
54 namespace { | 54 namespace { |
55 | 55 |
56 class TestListener : public V8AbstractEventListener { | 56 class TestListener : public V8AbstractEventListener { |
57 public: | 57 public: |
58 virtual bool operator==(const EventListener& listener) | 58 virtual bool operator==(const EventListener&) |
59 { | 59 { |
60 return true; | 60 return true; |
61 } | 61 } |
62 | 62 |
63 virtual void handleEvent(ExecutionContext* context, Event* event) | 63 virtual void handleEvent(ExecutionContext* context, Event* event) |
64 { | 64 { |
65 EXPECT_EQ(event->type(), "blah"); | 65 EXPECT_EQ(event->type(), "blah"); |
66 | 66 |
67 v8::Local<v8::Context> v8Context = WebCore::toV8Context(context, DOMWrap
perWorld::mainWorld()); | 67 ScriptState::Scope scope(scriptState()); |
68 v8::Isolate* isolate = v8Context->GetIsolate(); | 68 v8::Handle<v8::Value> jsEvent = toV8(event, scriptState()->context()->Gl
obal(), isolate()); |
69 v8::Context::Scope scope(v8Context); | |
70 v8::Handle<v8::Value> jsEvent = toV8(event, v8::Handle<v8::Object>(), is
olate); | |
71 | 69 |
72 EXPECT_EQ(jsEvent->ToObject()->Get(v8::String::NewFromUtf8(isolate, "det
ail")), v8::Boolean::New(isolate, true)); | 70 EXPECT_EQ(jsEvent->ToObject()->Get(v8::String::NewFromUtf8(scriptState()
->isolate(), "detail")), v8::Boolean::New(scriptState()->isolate(), true)); |
73 } | 71 } |
74 | 72 |
75 static PassRefPtr<TestListener> create(v8::Isolate* isolate, DOMWrapperWorld
& world) | 73 static PassRefPtr<TestListener> create(ScriptState* scriptState) |
76 { | 74 { |
77 return adoptRef(new TestListener(isolate, world)); | 75 return adoptRef(new TestListener(scriptState)); |
78 } | 76 } |
79 | 77 |
80 private: | 78 private: |
81 TestListener(v8::Isolate* isolate, DOMWrapperWorld& world) | 79 TestListener(ScriptState* scriptState) |
82 : V8AbstractEventListener(false, world, isolate) | 80 : V8AbstractEventListener(false, scriptState) |
83 { | 81 { |
84 } | 82 } |
85 | 83 |
86 virtual v8::Local<v8::Value> callListenerFunction(ExecutionContext*, v8::Han
dle<v8::Value> jsevent, Event*) | 84 virtual v8::Local<v8::Value> callListenerFunction(ExecutionContext*, v8::Han
dle<v8::Value> jsevent, Event*) |
87 { | 85 { |
88 ASSERT_NOT_REACHED(); | 86 ASSERT_NOT_REACHED(); |
89 return v8::Local<v8::Value>(); | 87 return v8::Local<v8::Value>(); |
90 } | 88 } |
91 }; | 89 }; |
92 | 90 |
(...skipping 10 matching lines...) Expand all Loading... |
103 | 101 |
104 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(baseURL.c_s
tr()), WebString::fromUTF8(path.c_str())); | 102 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(baseURL.c_s
tr()), WebString::fromUTF8(path.c_str())); |
105 FrameTestHelpers::WebViewHelper webViewHelper; | 103 FrameTestHelpers::WebViewHelper webViewHelper; |
106 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webViewHelper.initializeAndLo
ad(baseURL + path)->mainFrame()); | 104 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webViewHelper.initializeAndLo
ad(baseURL + path)->mainFrame()); |
107 WebDOMEvent event = frame->frame()->document()->createEvent("CustomEvent", I
GNORE_EXCEPTION); | 105 WebDOMEvent event = frame->frame()->document()->createEvent("CustomEvent", I
GNORE_EXCEPTION); |
108 WebDOMCustomEvent customEvent = event.to<WebDOMCustomEvent>(); | 106 WebDOMCustomEvent customEvent = event.to<WebDOMCustomEvent>(); |
109 | 107 |
110 v8::Isolate* isolate = toIsolate(frame->frame()); | 108 v8::Isolate* isolate = toIsolate(frame->frame()); |
111 V8TestingScope scope(isolate); | 109 V8TestingScope scope(isolate); |
112 customEvent.initCustomEvent("blah", false, false, WebSerializedScriptValue::
serialize(v8::Boolean::New(isolate, true))); | 110 customEvent.initCustomEvent("blah", false, false, WebSerializedScriptValue::
serialize(v8::Boolean::New(isolate, true))); |
113 RefPtr<DOMWrapperWorld> world = DOMWrapperWorld::create(); | 111 RefPtr<EventListener> listener = TestListener::create(ScriptState::current(i
solate)); |
114 RefPtr<EventListener> listener = TestListener::create(isolate, *world); | |
115 frame->frame()->document()->addEventListener("blah", listener, false); | 112 frame->frame()->document()->addEventListener("blah", listener, false); |
116 frame->frame()->document()->dispatchEvent(event); | 113 frame->frame()->document()->dispatchEvent(event); |
117 | 114 |
118 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); | 115 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); |
119 } | 116 } |
120 | 117 |
121 } | 118 } |
OLD | NEW |