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

Side by Side Diff: webkit/glue/media/buffered_data_source_unittest.cc

Issue 6973051: Remove MockWebFrame in favour of MockWebFrameClient and update corresponding tests. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src
Patch Set: whitespace Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <algorithm> 5 #include <algorithm>
6 6
7 #include "base/test/test_timeouts.h" 7 #include "base/test/test_timeouts.h"
8 #include "media/base/mock_callback.h" 8 #include "media/base/mock_callback.h"
9 #include "media/base/mock_filter_host.h" 9 #include "media/base/mock_filter_host.h"
10 #include "media/base/mock_filters.h" 10 #include "media/base/mock_filters.h"
11 #include "net/base/net_errors.h" 11 #include "net/base/net_errors.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h" 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h"
14 #include "webkit/glue/media/buffered_data_source.h" 13 #include "webkit/glue/media/buffered_data_source.h"
15 #include "webkit/mocks/mock_webframe.h" 14 #include "webkit/mocks/mock_webframeclient.h"
16 15
17 using ::testing::_; 16 using ::testing::_;
18 using ::testing::Assign; 17 using ::testing::Assign;
19 using ::testing::AtLeast; 18 using ::testing::AtLeast;
20 using ::testing::DeleteArg; 19 using ::testing::DeleteArg;
21 using ::testing::DoAll; 20 using ::testing::DoAll;
22 using ::testing::InSequence; 21 using ::testing::InSequence;
23 using ::testing::Invoke; 22 using ::testing::Invoke;
24 using ::testing::InvokeWithoutArgs; 23 using ::testing::InvokeWithoutArgs;
25 using ::testing::NotNull; 24 using ::testing::NotNull;
26 using ::testing::Return; 25 using ::testing::Return;
27 using ::testing::ReturnRef; 26 using ::testing::ReturnRef;
28 using ::testing::SetArgumentPointee; 27 using ::testing::SetArgumentPointee;
29 using ::testing::StrictMock; 28 using ::testing::StrictMock;
30 using ::testing::NiceMock; 29 using ::testing::NiceMock;
31 using ::testing::WithArgs; 30 using ::testing::WithArgs;
32 31
32 using WebKit::WebFrame;
33 using WebKit::WebView;
34
33 namespace webkit_glue { 35 namespace webkit_glue {
34 36
35 static const char* kHttpUrl = "http://test"; 37 static const char* kHttpUrl = "http://test";
36 static const char* kFileUrl = "file://test"; 38 static const char* kFileUrl = "file://test";
37 static const int kDataSize = 1024; 39 static const int kDataSize = 1024;
38 40
39 enum NetworkState { 41 enum NetworkState {
40 NONE, 42 NONE,
41 LOADED, 43 LOADED,
42 LOADING 44 LOADING
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 MOCK_METHOD0(GetBufferedLastBytePosition, int64()); 85 MOCK_METHOD0(GetBufferedLastBytePosition, int64());
84 86
85 protected: 87 protected:
86 ~MockBufferedResourceLoader() {} 88 ~MockBufferedResourceLoader() {}
87 89
88 DISALLOW_COPY_AND_ASSIGN(MockBufferedResourceLoader); 90 DISALLOW_COPY_AND_ASSIGN(MockBufferedResourceLoader);
89 }; 91 };
90 92
91 class BufferedDataSourceTest : public testing::Test { 93 class BufferedDataSourceTest : public testing::Test {
92 public: 94 public:
93 BufferedDataSourceTest() { 95 BufferedDataSourceTest()
96 : view_(NULL) {
94 message_loop_ = MessageLoop::current(); 97 message_loop_ = MessageLoop::current();
95 98
96 // Prepare test data. 99 // Prepare test data.
97 for (size_t i = 0; i < sizeof(data_); ++i) { 100 for (size_t i = 0; i < sizeof(data_); ++i) {
98 data_[i] = i; 101 data_[i] = i;
99 } 102 }
100 } 103 }
101 104
102 virtual ~BufferedDataSourceTest() { 105 virtual ~BufferedDataSourceTest() {
106 if (view_) {
acolwell GONE FROM CHROMIUM 2011/05/13 17:36:37 nit: braces not necessary
scherkus (not reviewing) 2011/05/13 19:35:20 Done.
107 view_->close();
108 }
103 } 109 }
104 110
105 void ExpectCreateAndStartResourceLoader(int start_error) { 111 void ExpectCreateAndStartResourceLoader(int start_error) {
106 EXPECT_CALL(*data_source_, CreateResourceLoader(_, _)) 112 EXPECT_CALL(*data_source_, CreateResourceLoader(_, _))
107 .WillOnce(Return(loader_.get())); 113 .WillOnce(Return(loader_.get()));
108 114
109 EXPECT_CALL(*loader_, Start(NotNull(), NotNull(), NotNull())) 115 EXPECT_CALL(*loader_, Start(NotNull(), NotNull(), NotNull()))
110 .WillOnce( 116 .WillOnce(
111 DoAll(Assign(&error_, start_error), 117 DoAll(Assign(&error_, start_error),
112 Invoke(this, 118 Invoke(this,
113 &BufferedDataSourceTest::InvokeStartCallback))); 119 &BufferedDataSourceTest::InvokeStartCallback)));
114 } 120 }
115 121
116 void InitializeDataSource(const char* url, int error, 122 void InitializeDataSource(const char* url, int error,
117 bool partial_response, int64 instance_size, 123 bool partial_response, int64 instance_size,
118 NetworkState networkState) { 124 NetworkState networkState) {
119 // Saves the url first. 125 // Saves the url first.
120 gurl_ = GURL(url); 126 gurl_ = GURL(url);
121 127
122 frame_.reset(new NiceMock<MockWebFrame>()); 128 view_ = WebView::create(NULL);
129 view_->initializeMainFrame(&client_);
123 130
124 data_source_ = new MockBufferedDataSource(MessageLoop::current(), 131 data_source_ = new MockBufferedDataSource(MessageLoop::current(),
125 frame_.get()); 132 view_->mainFrame());
126 data_source_->set_host(&host_); 133 data_source_->set_host(&host_);
127 134
128 scoped_refptr<NiceMock<MockBufferedResourceLoader> > first_loader( 135 scoped_refptr<NiceMock<MockBufferedResourceLoader> > first_loader(
129 new NiceMock<MockBufferedResourceLoader>()); 136 new NiceMock<MockBufferedResourceLoader>());
130 137
131 // Creates the mock loader to be injected. 138 // Creates the mock loader to be injected.
132 loader_ = first_loader; 139 loader_ = first_loader;
133 140
134 bool initialized_ok = (error == net::OK); 141 bool initialized_ok = (error == net::OK);
135 bool loaded = networkState == LOADED; 142 bool loaded = networkState == LOADED;
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 position, size, buffer_, 360 position, size, buffer_,
354 NewCallback(this, &BufferedDataSourceTest::ReadCallback)); 361 NewCallback(this, &BufferedDataSourceTest::ReadCallback));
355 362
356 message_loop_->RunAllPending(); 363 message_loop_->RunAllPending();
357 } 364 }
358 365
359 MOCK_METHOD1(ReadCallback, void(size_t size)); 366 MOCK_METHOD1(ReadCallback, void(size_t size));
360 367
361 scoped_refptr<NiceMock<MockBufferedResourceLoader> > loader_; 368 scoped_refptr<NiceMock<MockBufferedResourceLoader> > loader_;
362 scoped_refptr<MockBufferedDataSource> data_source_; 369 scoped_refptr<MockBufferedDataSource> data_source_;
363 scoped_ptr<NiceMock<MockWebFrame> > frame_; 370
371 MockWebFrameClient client_;
372 WebView* view_;
364 373
365 StrictMock<media::MockFilterHost> host_; 374 StrictMock<media::MockFilterHost> host_;
366 GURL gurl_; 375 GURL gurl_;
367 MessageLoop* message_loop_; 376 MessageLoop* message_loop_;
368 377
369 int error_; 378 int error_;
370 uint8 buffer_[1024]; 379 uint8 buffer_[1024];
371 uint8 data_[1024]; 380 uint8 data_[1024];
372 381
373 private: 382 private:
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 data_source_->Stop(media::NewExpectedCallback()); 517 data_source_->Stop(media::NewExpectedCallback());
509 518
510 // Allow cleanup task to run. 519 // Allow cleanup task to run.
511 message_loop_->RunAllPending(); 520 message_loop_->RunAllPending();
512 521
513 // Verify that Read() was not called on the loader. 522 // Verify that Read() was not called on the loader.
514 EXPECT_FALSE(read_called); 523 EXPECT_FALSE(read_called);
515 } 524 }
516 525
517 } // namespace webkit_glue 526 } // namespace webkit_glue
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698