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

Side by Side Diff: Source/web/tests/CustomEventTest.cpp

Issue 1174283002: Fix unit test style in Source/web/. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: remove static Created 5 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 28 matching lines...) Expand all
39 #include "platform/testing/URLTestHelpers.h" 39 #include "platform/testing/URLTestHelpers.h"
40 #include "public/platform/Platform.h" 40 #include "public/platform/Platform.h"
41 #include "public/platform/WebUnitTestSupport.h" 41 #include "public/platform/WebUnitTestSupport.h"
42 #include "public/web/WebDOMCustomEvent.h" 42 #include "public/web/WebDOMCustomEvent.h"
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
50 #include <gtest/gtest.h> 49 #include <gtest/gtest.h>
51 50
52 using namespace blink; 51 namespace blink {
53
54 namespace {
55 52
56 class TestListener : public V8AbstractEventListener { 53 class TestListener : public V8AbstractEventListener {
57 public: 54 public:
58 virtual bool operator==(const EventListener&) 55 bool operator==(const EventListener&) override
59 { 56 {
60 return true; 57 return true;
61 } 58 }
62 59
63 virtual void handleEvent(ScriptState* scriptState, Event* event) 60 void handleEvent(ScriptState* scriptState, Event* event) override
64 { 61 {
65 EXPECT_EQ(event->type(), "blah"); 62 EXPECT_EQ(event->type(), "blah");
66 63
67 ScriptState::Scope scope(scriptState); 64 ScriptState::Scope scope(scriptState);
68 v8::Local<v8::Context> context = scriptState->context(); 65 v8::Local<v8::Context> context = scriptState->context();
69 v8::Local<v8::Value> jsEvent = toV8(event, context->Global(), isolate()) ; 66 v8::Local<v8::Value> jsEvent = toV8(event, context->Global(), isolate()) ;
70 67
71 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));
72 } 69 }
73 70
74 static PassRefPtr<TestListener> create(ScriptState* scriptState) 71 static PassRefPtr<TestListener> create(ScriptState* scriptState)
75 { 72 {
76 return adoptRef(new TestListener(scriptState)); 73 return adoptRef(new TestListener(scriptState));
77 } 74 }
78 75
79 private: 76 private:
80 TestListener(ScriptState* scriptState) 77 TestListener(ScriptState* scriptState)
81 : V8AbstractEventListener(false, scriptState->world(), scriptState->isol ate()) 78 : V8AbstractEventListener(false, scriptState->world(), scriptState->isol ate())
82 { 79 {
83 } 80 }
84 81
85 virtual v8::Local<v8::Value> callListenerFunction(ScriptState*, v8::Local<v8 ::Value>, Event*) 82 v8::Local<v8::Value> callListenerFunction(ScriptState*, v8::Local<v8::Value> , Event*) override
86 { 83 {
87 ASSERT_NOT_REACHED(); 84 ASSERT_NOT_REACHED();
88 return v8::Local<v8::Value>(); 85 return v8::Local<v8::Value>();
89 } 86 }
90 }; 87 };
91 88
92 // Tests that a CustomEvent can be initialized with a 'detail' value that is a 89 // Tests that a CustomEvent can be initialized with a 'detail' value that is a
93 // SerializedScriptValue, and that this value can be retrieved and read in an 90 // SerializedScriptValue, and that this value can be retrieved and read in an
94 // event listener. Initialization of a CustomEvent with a SerializedScriptValue 91 // event listener. Initialization of a CustomEvent with a SerializedScriptValue
95 // is an internal API, so it cannot be tested with a LayoutTest. 92 // is an internal API, so it cannot be tested with a LayoutTest.
(...skipping 13 matching lines...) Expand all
109 v8::Isolate* isolate = toIsolate(frame->frame()); 106 v8::Isolate* isolate = toIsolate(frame->frame());
110 V8TestingScope scope(isolate); 107 V8TestingScope scope(isolate);
111 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)));
112 RefPtr<EventListener> listener = TestListener::create(scope.scriptState()); 109 RefPtr<EventListener> listener = TestListener::create(scope.scriptState());
113 frame->frame()->document()->addEventListener("blah", listener, false); 110 frame->frame()->document()->addEventListener("blah", listener, false);
114 frame->frame()->document()->dispatchEvent(event); 111 frame->frame()->document()->dispatchEvent(event);
115 112
116 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); 113 Platform::current()->unitTestSupport()->unregisterAllMockedURLs();
117 } 114 }
118 115
119 } 116 } // namespace blink
OLDNEW
« no previous file with comments | « Source/web/tests/ChromeClientImplTest.cpp ('k') | Source/web/tests/FrameLoaderClientImplTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698