| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 namespace blink { | 44 namespace blink { |
| 45 namespace { | 45 namespace { |
| 46 | 46 |
| 47 class IDBTransactionTest : public testing::Test { | 47 class IDBTransactionTest : public testing::Test { |
| 48 public: | 48 public: |
| 49 IDBTransactionTest() | 49 IDBTransactionTest() |
| 50 : m_scope(v8::Isolate::GetCurrent()) | 50 : m_scope(v8::Isolate::GetCurrent()) |
| 51 { | 51 { |
| 52 } | 52 } |
| 53 | 53 |
| 54 virtual void SetUp() override | 54 void SetUp() override |
| 55 { | 55 { |
| 56 m_executionContext = Document::create(); | 56 m_executionContext = Document::create(); |
| 57 m_scope.scriptState()->setExecutionContext(m_executionContext.get()); | 57 m_scope.scriptState()->setExecutionContext(m_executionContext.get()); |
| 58 } | 58 } |
| 59 | 59 |
| 60 virtual void TearDown() override | 60 void TearDown() override |
| 61 { | 61 { |
| 62 m_executionContext->notifyContextDestroyed(); | 62 m_executionContext->notifyContextDestroyed(); |
| 63 m_scope.scriptState()->setExecutionContext(nullptr); | 63 m_scope.scriptState()->setExecutionContext(nullptr); |
| 64 } | 64 } |
| 65 | 65 |
| 66 v8::Isolate* isolate() const { return m_scope.isolate(); } | 66 v8::Isolate* isolate() const { return m_scope.isolate(); } |
| 67 ScriptState* scriptState() const { return m_scope.scriptState(); } | 67 ScriptState* scriptState() const { return m_scope.scriptState(); } |
| 68 ExecutionContext* executionContext() { return m_scope.scriptState()->executi
onContext(); } | 68 ExecutionContext* executionContext() { return m_scope.scriptState()->executi
onContext(); } |
| 69 | 69 |
| 70 void deactivateNewTransactions() | 70 void deactivateNewTransactions() |
| 71 { | 71 { |
| 72 V8PerIsolateData::from(isolate())->runEndOfScopeTasks(); | 72 V8PerIsolateData::from(isolate())->runEndOfScopeTasks(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 private: | 75 private: |
| 76 V8TestingScope m_scope; | 76 V8TestingScope m_scope; |
| 77 RefPtrWillBePersistent<ExecutionContext> m_executionContext; | 77 RefPtrWillBePersistent<ExecutionContext> m_executionContext; |
| 78 }; | 78 }; |
| 79 | 79 |
| 80 class FakeWebIDBDatabase final : public WebIDBDatabase { | 80 class FakeWebIDBDatabase final : public WebIDBDatabase { |
| 81 public: | 81 public: |
| 82 static PassOwnPtr<FakeWebIDBDatabase> create() { return adoptPtr(new FakeWeb
IDBDatabase()); } | 82 static PassOwnPtr<FakeWebIDBDatabase> create() { return adoptPtr(new FakeWeb
IDBDatabase()); } |
| 83 | 83 |
| 84 virtual void commit(long long transactionId) override { } | 84 void commit(long long transactionId) override { } |
| 85 virtual void abort(long long transactionId) override { } | 85 void abort(long long transactionId) override { } |
| 86 virtual void close() override { } | 86 void close() override { } |
| 87 | 87 |
| 88 private: | 88 private: |
| 89 FakeWebIDBDatabase() { } | 89 FakeWebIDBDatabase() { } |
| 90 }; | 90 }; |
| 91 | 91 |
| 92 class FakeIDBDatabaseCallbacks final : public IDBDatabaseCallbacks { | 92 class FakeIDBDatabaseCallbacks final : public IDBDatabaseCallbacks { |
| 93 public: | 93 public: |
| 94 static FakeIDBDatabaseCallbacks* create() { return new FakeIDBDatabaseCallba
cks(); } | 94 static FakeIDBDatabaseCallbacks* create() { return new FakeIDBDatabaseCallba
cks(); } |
| 95 virtual void onVersionChange(int64_t oldVersion, int64_t newVersion) overrid
e { } | 95 void onVersionChange(int64_t oldVersion, int64_t newVersion) override { } |
| 96 virtual void onForcedClose() override { } | 96 void onForcedClose() override { } |
| 97 virtual void onAbort(int64_t transactionId, DOMError* error) override { } | 97 void onAbort(int64_t transactionId, DOMError* error) override { } |
| 98 virtual void onComplete(int64_t transactionId) override { } | 98 void onComplete(int64_t transactionId) override { } |
| 99 private: | 99 private: |
| 100 FakeIDBDatabaseCallbacks() { } | 100 FakeIDBDatabaseCallbacks() { } |
| 101 }; | 101 }; |
| 102 | 102 |
| 103 TEST_F(IDBTransactionTest, EnsureLifetime) | 103 TEST_F(IDBTransactionTest, EnsureLifetime) |
| 104 { | 104 { |
| 105 OwnPtr<FakeWebIDBDatabase> backend = FakeWebIDBDatabase::create(); | 105 OwnPtr<FakeWebIDBDatabase> backend = FakeWebIDBDatabase::create(); |
| 106 Persistent<IDBDatabase> db = IDBDatabase::create(executionContext(), backend
.release(), FakeIDBDatabaseCallbacks::create()); | 106 Persistent<IDBDatabase> db = IDBDatabase::create(executionContext(), backend
.release(), FakeIDBDatabaseCallbacks::create()); |
| 107 | 107 |
| 108 const int64_t transactionId = 1234; | 108 const int64_t transactionId = 1234; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 // will not fail if it is, but ASAN would notice the error. | 161 // will not fail if it is, but ASAN would notice the error. |
| 162 db->onAbort(transactionId, DOMError::create(AbortError, "Aborted")); | 162 db->onAbort(transactionId, DOMError::create(AbortError, "Aborted")); |
| 163 | 163 |
| 164 // onAbort() should have cleared the transaction's reference to the database
. | 164 // onAbort() should have cleared the transaction's reference to the database
. |
| 165 Heap::collectAllGarbage(); | 165 Heap::collectAllGarbage(); |
| 166 EXPECT_EQ(0u, set.size()); | 166 EXPECT_EQ(0u, set.size()); |
| 167 } | 167 } |
| 168 | 168 |
| 169 } // namespace | 169 } // namespace |
| 170 } // namespace blink | 170 } // namespace blink |
| OLD | NEW |