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

Side by Side Diff: media/blink/multibuffer_data_source_unittest.cc

Issue 1984083003: Avoid using vtable of destroyed object in MultiBuffer unit test. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 47
48 class TestMultiBufferDataProvider : public ResourceMultiBufferDataProvider { 48 class TestMultiBufferDataProvider : public ResourceMultiBufferDataProvider {
49 public: 49 public:
50 TestMultiBufferDataProvider(UrlData* url_data, MultiBuffer::BlockId pos) 50 TestMultiBufferDataProvider(UrlData* url_data, MultiBuffer::BlockId pos)
51 : ResourceMultiBufferDataProvider(url_data, pos), loading_(false) { 51 : ResourceMultiBufferDataProvider(url_data, pos), loading_(false) {
52 CHECK(test_data_providers.insert(this).second); 52 CHECK(test_data_providers.insert(this).second);
53 } 53 }
54 ~TestMultiBufferDataProvider() override { 54 ~TestMultiBufferDataProvider() override {
55 CHECK_EQ(static_cast<size_t>(1), test_data_providers.erase(this)); 55 CHECK_EQ(static_cast<size_t>(1), test_data_providers.erase(this));
56 } 56 }
57 void SetLoadingToFalse() {
58 // Check that we have not been destroyed first.
59 if (test_data_providers.find(this) != test_data_providers.end()) {
60 loading_ = false;
61 }
62 }
63 void Start() override { 57 void Start() override {
64 // Create a mock active loader. 58 // Create a mock active loader.
65 // Keep track of active loading state via loadAsynchronously() and cancel(). 59 // Keep track of active loading state via loadAsynchronously() and cancel().
66 NiceMock<MockWebURLLoader>* url_loader = new NiceMock<MockWebURLLoader>(); 60 NiceMock<MockWebURLLoader>* url_loader = new NiceMock<MockWebURLLoader>();
67 ON_CALL(*url_loader, cancel()) 61 ON_CALL(*url_loader, cancel())
68 .WillByDefault( 62 .WillByDefault(Invoke([this]() {
69 Invoke(this, &TestMultiBufferDataProvider::SetLoadingToFalse)); 63 // Check that we have not been destroyed first.
64 if (test_data_providers.find(this) != test_data_providers.end()) {
65 this->loading_ = false;
66 }
67 }));
70 loading_ = true; 68 loading_ = true;
71 active_loader_.reset( 69 active_loader_.reset(
72 new ActiveLoader(std::unique_ptr<WebURLLoader>(url_loader))); 70 new ActiveLoader(std::unique_ptr<WebURLLoader>(url_loader)));
73 if (!on_start_.is_null()) { 71 if (!on_start_.is_null()) {
74 on_start_.Run(); 72 on_start_.Run();
75 } 73 }
76 } 74 }
77 75
78 bool loading() const { return loading_; } 76 bool loading() const { return loading_; }
79 void RunOnStart(base::Closure cb) { on_start_ = cb; } 77 void RunOnStart(base::Closure cb) { on_start_ = cb; }
(...skipping 1292 matching lines...) Expand 10 before | Expand all | Expand 10 after
1372 ReceiveData(kDataSize); 1370 ReceiveData(kDataSize);
1373 1371
1374 EXPECT_FALSE(data_source_->IsStreaming()); 1372 EXPECT_FALSE(data_source_->IsStreaming());
1375 1373
1376 FinishLoading(); 1374 FinishLoading();
1377 EXPECT_FALSE(loading()); 1375 EXPECT_FALSE(loading());
1378 Stop(); 1376 Stop();
1379 } 1377 }
1380 1378
1381 } // namespace media 1379 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698