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

Side by Side Diff: Source/bindings/v8/ScriptPromiseTest.cpp

Issue 181173002: ScriptPromise should check the constructor paraemter. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebase Created 6 years, 9 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) 2014 Google Inc. All rights reserved. 2 * Copyright (C) 2014 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 25 matching lines...) Expand all
36 #include "bindings/v8/V8Binding.h" 36 #include "bindings/v8/V8Binding.h"
37 #include "bindings/v8/custom/V8PromiseCustom.h" 37 #include "bindings/v8/custom/V8PromiseCustom.h"
38 38
39 #include <gtest/gtest.h> 39 #include <gtest/gtest.h>
40 #include <v8.h> 40 #include <v8.h>
41 41
42 namespace WebCore { 42 namespace WebCore {
43 43
44 namespace { 44 namespace {
45 45
46 void callback(const v8::FunctionCallbackInfo<v8::Value>& info) { }
47
46 class ScriptPromiseTest : public testing::Test { 48 class ScriptPromiseTest : public testing::Test {
47 public: 49 public:
48 ScriptPromiseTest() 50 ScriptPromiseTest()
49 : m_isolate(v8::Isolate::GetCurrent()) 51 : m_isolate(v8::Isolate::GetCurrent())
50 { 52 {
51 }
52
53 void SetUp()
54 {
55 m_scope = V8BindingTestScope::create(m_isolate); 53 m_scope = V8BindingTestScope::create(m_isolate);
56 } 54 }
57 55
58 void TearDown() 56 ~ScriptPromiseTest()
59 { 57 {
60 m_scope.clear(); 58 // FIXME: We put this statement here to clear an exception from the isol ate.
59 createClosure(callback, v8::Undefined(m_isolate), m_isolate);
61 } 60 }
62 61
63 V8PromiseCustom::PromiseState state(ScriptPromise promise) 62 V8PromiseCustom::PromiseState state(ScriptPromise promise)
64 { 63 {
65 return V8PromiseCustom::getState(V8PromiseCustom::getInternal(promise.v8 Value().As<v8::Object>())); 64 return V8PromiseCustom::getState(V8PromiseCustom::getInternal(promise.v8 Value().As<v8::Object>()));
66 } 65 }
67 66
68 protected: 67 protected:
69 v8::Isolate* m_isolate; 68 v8::Isolate* m_isolate;
70 69
71 private: 70 private:
72 OwnPtr<V8BindingTestScope> m_scope; 71 OwnPtr<V8BindingTestScope> m_scope;
73 }; 72 };
74 73
74 TEST_F(ScriptPromiseTest, constructFromNonPromise)
75 {
76 v8::TryCatch trycatch;
77 ScriptPromise promise(v8::Undefined(m_isolate), m_isolate);
78 ASSERT_TRUE(trycatch.HasCaught());
79 ASSERT_TRUE(promise.hasNoValue());
80 }
81
75 TEST_F(ScriptPromiseTest, castPromise) 82 TEST_F(ScriptPromiseTest, castPromise)
76 { 83 {
77 ScriptPromise promise = ScriptPromise::createPending(); 84 ScriptPromise promise = ScriptPromise::createPending();
78 ScriptPromise newPromise(ScriptValue(promise.v8Value(), m_isolate)); 85 ScriptPromise newPromise = ScriptPromise::cast(ScriptValue(promise.v8Value() , m_isolate));
79 86
80 ASSERT_FALSE(promise.hasNoValue()); 87 ASSERT_FALSE(promise.hasNoValue());
81 EXPECT_EQ(V8PromiseCustom::Pending, state(promise)); 88 EXPECT_EQ(V8PromiseCustom::Pending, state(promise));
82 EXPECT_EQ(promise.v8Value(), newPromise.v8Value()); 89 EXPECT_EQ(promise.v8Value(), newPromise.v8Value());
83 } 90 }
84 91
85 TEST_F(ScriptPromiseTest, castNonPromise) 92 TEST_F(ScriptPromiseTest, castNonPromise)
86 { 93 {
87 ScriptValue value = ScriptValue(v8String(m_isolate, "hello"), m_isolate); 94 ScriptValue value = ScriptValue(v8String(m_isolate, "hello"), m_isolate);
88 ScriptPromise promise1(ScriptValue(value.v8Value(), m_isolate)); 95 ScriptPromise promise1 = ScriptPromise::cast(ScriptValue(value.v8Value(), m_ isolate));
89 ScriptPromise promise2(ScriptValue(value.v8Value(), m_isolate)); 96 ScriptPromise promise2 = ScriptPromise::cast(ScriptValue(value.v8Value(), m_ isolate));
90 97
91 ASSERT_FALSE(promise1.hasNoValue()); 98 ASSERT_FALSE(promise1.hasNoValue());
92 ASSERT_FALSE(promise2.hasNoValue()); 99 ASSERT_FALSE(promise2.hasNoValue());
93 100
94 ASSERT_TRUE(V8PromiseCustom::isPromise(promise1.v8Value(), m_isolate)); 101 ASSERT_TRUE(V8PromiseCustom::isPromise(promise1.v8Value(), m_isolate));
95 ASSERT_TRUE(V8PromiseCustom::isPromise(promise2.v8Value(), m_isolate)); 102 ASSERT_TRUE(V8PromiseCustom::isPromise(promise2.v8Value(), m_isolate));
96 103
97 EXPECT_EQ(V8PromiseCustom::Fulfilled, state(promise1)); 104 EXPECT_EQ(V8PromiseCustom::Fulfilled, state(promise1));
98 EXPECT_EQ(V8PromiseCustom::Fulfilled, state(promise2)); 105 EXPECT_EQ(V8PromiseCustom::Fulfilled, state(promise2));
99 EXPECT_NE(promise1.v8Value(), promise2.v8Value()); 106 EXPECT_NE(promise1.v8Value(), promise2.v8Value());
100 } 107 }
101 108
102 } // namespace 109 } // namespace
103 110
104 } // namespace WebCore 111 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/bindings/v8/ScriptPromise.cpp ('k') | Source/modules/serviceworkers/RespondWithObserver.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698