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

Side by Side Diff: third_party/WebKit/Source/core/testing/Internals.cpp

Issue 2680423006: UseCounter: Introduce UseCounter::Observer for layout tests (Closed)
Patch Set: instance method Created 3 years, 10 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * Copyright (C) 2013 Apple Inc. All rights reserved. 3 * Copyright (C) 2013 Apple Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 #include "wtf/Optional.h" 150 #include "wtf/Optional.h"
151 #include "wtf/PtrUtil.h" 151 #include "wtf/PtrUtil.h"
152 #include "wtf/dtoa.h" 152 #include "wtf/dtoa.h"
153 #include "wtf/text/StringBuffer.h" 153 #include "wtf/text/StringBuffer.h"
154 #include <deque> 154 #include <deque>
155 #include <memory> 155 #include <memory>
156 #include <v8.h> 156 #include <v8.h>
157 157
158 namespace blink { 158 namespace blink {
159 159
160 namespace {
161
162 class UseCounterObserverImpl final : public UseCounter::Observer {
163 WTF_MAKE_NONCOPYABLE(UseCounterObserverImpl);
164
165 public:
166 UseCounterObserverImpl(ScriptPromiseResolver* resolver,
167 UseCounter::Feature feature)
168 : m_resolver(resolver), m_feature(feature) {}
169
170 bool onCountFeature(UseCounter::Feature feature) final {
171 if (m_feature != feature)
172 return false;
173 m_resolver->resolve(feature);
174 return true;
175 }
176
177 DEFINE_INLINE_VIRTUAL_TRACE() {
178 UseCounter::Observer::trace(visitor);
179 visitor->trace(m_resolver);
180 }
181
182 private:
183 Member<ScriptPromiseResolver> m_resolver;
184 UseCounter::Feature m_feature;
185 };
186
187 } // namespace
188
160 static WTF::Optional<DocumentMarker::MarkerType> markerTypeFrom( 189 static WTF::Optional<DocumentMarker::MarkerType> markerTypeFrom(
161 const String& markerType) { 190 const String& markerType) {
162 if (equalIgnoringCase(markerType, "Spelling")) 191 if (equalIgnoringCase(markerType, "Spelling"))
163 return DocumentMarker::Spelling; 192 return DocumentMarker::Spelling;
164 if (equalIgnoringCase(markerType, "Grammar")) 193 if (equalIgnoringCase(markerType, "Grammar"))
165 return DocumentMarker::Grammar; 194 return DocumentMarker::Grammar;
166 if (equalIgnoringCase(markerType, "TextMatch")) 195 if (equalIgnoringCase(markerType, "TextMatch"))
167 return DocumentMarker::TextMatch; 196 return DocumentMarker::TextMatch;
168 return WTF::nullopt; 197 return WTF::nullopt;
169 } 198 }
(...skipping 2809 matching lines...) Expand 10 before | Expand all | Expand 10 after
2979 return false; 3008 return false;
2980 return UseCounter::isCounted(*document, 3009 return UseCounter::isCounted(*document,
2981 static_cast<UseCounter::Feature>(feature)); 3010 static_cast<UseCounter::Feature>(feature));
2982 } 3011 }
2983 3012
2984 bool Internals::isCSSPropertyUseCounted(Document* document, 3013 bool Internals::isCSSPropertyUseCounted(Document* document,
2985 const String& propertyName) { 3014 const String& propertyName) {
2986 return UseCounter::isCounted(*document, propertyName); 3015 return UseCounter::isCounted(*document, propertyName);
2987 } 3016 }
2988 3017
3018 ScriptPromise Internals::observeUseCounter(ScriptState* scriptState,
3019 Document* document,
3020 uint32_t feature) {
3021 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
3022 ScriptPromise promise = resolver->promise();
3023 if (feature >= UseCounter::NumberOfFeatures) {
3024 resolver->reject();
3025 return promise;
3026 }
3027
3028 UseCounter::Feature useCounterFeature =
3029 static_cast<UseCounter::Feature>(feature);
3030 if (UseCounter::isCounted(*document, useCounterFeature)) {
3031 resolver->resolve();
3032 return promise;
3033 }
3034
3035 Frame* frame = document->frame();
3036 if (!frame || !frame->host()) {
3037 resolver->reject();
3038 return promise;
3039 }
3040
3041 frame->host()->useCounter().addObserver(
3042 new UseCounterObserverImpl(resolver, useCounterFeature));
3043 return promise;
3044 }
3045
2989 String Internals::unscopableAttribute() { 3046 String Internals::unscopableAttribute() {
2990 return "unscopableAttribute"; 3047 return "unscopableAttribute";
2991 } 3048 }
2992 3049
2993 String Internals::unscopableMethod() { 3050 String Internals::unscopableMethod() {
2994 return "unscopableMethod"; 3051 return "unscopableMethod";
2995 } 3052 }
2996 3053
2997 ClientRectList* Internals::focusRingRects(Element* element) { 3054 ClientRectList* Internals::focusRingRects(Element* element) {
2998 Vector<LayoutRect> rects; 3055 Vector<LayoutRect> rects;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
3062 3119
3063 void Internals::crash() { 3120 void Internals::crash() {
3064 CHECK(false) << "Intentional crash"; 3121 CHECK(false) << "Intentional crash";
3065 } 3122 }
3066 3123
3067 void Internals::setIsLowEndDevice(bool isLowEndDevice) { 3124 void Internals::setIsLowEndDevice(bool isLowEndDevice) {
3068 MemoryCoordinator::setIsLowEndDeviceForTesting(isLowEndDevice); 3125 MemoryCoordinator::setIsLowEndDeviceForTesting(isLowEndDevice);
3069 } 3126 }
3070 3127
3071 } // namespace blink 3128 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/testing/Internals.h ('k') | third_party/WebKit/Source/core/testing/Internals.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698