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

Side by Side Diff: webkit/glue/media/buffered_resource_loader_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/format_macros.h" 7 #include "base/format_macros.h"
8 #include "base/stringprintf.h" 8 #include "base/stringprintf.h"
9 #include "net/base/net_errors.h" 9 #include "net/base/net_errors.h"
10 #include "net/http/http_util.h" 10 #include "net/http/http_util.h"
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h" 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h" 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
16 #include "webkit/glue/media/buffered_resource_loader.h" 16 #include "webkit/glue/media/buffered_resource_loader.h"
17 #include "webkit/mocks/mock_webframe.h" 17 #include "webkit/mocks/mock_webframeclient.h"
18 #include "webkit/mocks/mock_weburlloader.h" 18 #include "webkit/mocks/mock_weburlloader.h"
19 19
20 using ::testing::_; 20 using ::testing::_;
21 using ::testing::Assign; 21 using ::testing::Assign;
22 using ::testing::AtLeast; 22 using ::testing::AtLeast;
23 using ::testing::DeleteArg; 23 using ::testing::DeleteArg;
24 using ::testing::DoAll; 24 using ::testing::DoAll;
25 using ::testing::InSequence; 25 using ::testing::InSequence;
26 using ::testing::Invoke; 26 using ::testing::Invoke;
27 using ::testing::InvokeWithoutArgs; 27 using ::testing::InvokeWithoutArgs;
28 using ::testing::NotNull; 28 using ::testing::NotNull;
29 using ::testing::Return; 29 using ::testing::Return;
30 using ::testing::ReturnRef; 30 using ::testing::ReturnRef;
31 using ::testing::SetArgumentPointee; 31 using ::testing::SetArgumentPointee;
32 using ::testing::StrictMock; 32 using ::testing::StrictMock;
33 using ::testing::NiceMock; 33 using ::testing::NiceMock;
34 using ::testing::WithArgs; 34 using ::testing::WithArgs;
35 35
36 using WebKit::WebString;
36 using WebKit::WebURLError; 37 using WebKit::WebURLError;
37 using WebKit::WebFrameClient;
38 using WebKit::WebURLResponse; 38 using WebKit::WebURLResponse;
39 using WebKit::WebView; 39 using WebKit::WebView;
40 40
41 namespace webkit_glue { 41 namespace webkit_glue {
42 42
43 static const char* kHttpUrl = "http://test"; 43 static const char* kHttpUrl = "http://test";
44 static const char kHttpRedirectToSameDomainUrl1[] = "http://test/ing"; 44 static const char kHttpRedirectToSameDomainUrl1[] = "http://test/ing";
45 static const char kHttpRedirectToSameDomainUrl2[] = "http://test/ing2"; 45 static const char kHttpRedirectToSameDomainUrl2[] = "http://test/ing2";
46 static const char kHttpRedirectToDifferentDomainUrl1[] = "http://test2"; 46 static const char kHttpRedirectToDifferentDomainUrl1[] = "http://test2";
47 static const char kHttpRedirectToDifferentDomainUrl2[] = "http://test2/ing"; 47 static const char kHttpRedirectToDifferentDomainUrl2[] = "http://test2/ing";
(...skipping 12 matching lines...) Expand all
60 // being canceled. Pretending the event is from external. 60 // being canceled. Pretending the event is from external.
61 ACTION_P(RequestCanceled, loader) { 61 ACTION_P(RequestCanceled, loader) {
62 WebURLError error; 62 WebURLError error;
63 error.reason = net::ERR_ABORTED; 63 error.reason = net::ERR_ABORTED;
64 error.domain = WebString::fromUTF8(net::kErrorDomain); 64 error.domain = WebString::fromUTF8(net::kErrorDomain);
65 loader->didFail(NULL, error); 65 loader->didFail(NULL, error);
66 } 66 }
67 67
68 class BufferedResourceLoaderTest : public testing::Test { 68 class BufferedResourceLoaderTest : public testing::Test {
69 public: 69 public:
70 BufferedResourceLoaderTest() { 70 BufferedResourceLoaderTest()
71 : view_(NULL) {
71 for (int i = 0; i < kDataSize; ++i) 72 for (int i = 0; i < kDataSize; ++i)
72 data_[i] = i; 73 data_[i] = i;
73 } 74 }
74 75
75 virtual ~BufferedResourceLoaderTest() { 76 virtual ~BufferedResourceLoaderTest() {
77 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.
78 view_->close();
79 }
76 } 80 }
77 81
78 void Initialize(const char* url, int first_position, int last_position) { 82 void Initialize(const char* url, int first_position, int last_position) {
79 gurl_ = GURL(url); 83 gurl_ = GURL(url);
80 first_position_ = first_position; 84 first_position_ = first_position;
81 last_position_ = last_position; 85 last_position_ = last_position;
82 86
83 frame_.reset(new NiceMock<MockWebFrame>()); 87 view_ = WebView::create(NULL);
88 view_->initializeMainFrame(&client_);
84 89
85 url_loader_ = new NiceMock<MockWebURLLoader>(); 90 url_loader_ = new NiceMock<MockWebURLLoader>();
86 loader_ = new BufferedResourceLoader(gurl_, 91 loader_ = new BufferedResourceLoader(gurl_,
87 first_position_, last_position_); 92 first_position_, last_position_);
88 loader_->SetURLLoaderForTest(url_loader_); 93 loader_->SetURLLoaderForTest(url_loader_);
89 } 94 }
90 95
91 void SetLoaderBuffer(size_t forward_capacity, size_t backward_capacity) { 96 void SetLoaderBuffer(size_t forward_capacity, size_t backward_capacity) {
92 loader_->buffer_.reset( 97 loader_->buffer_.reset(
93 new media::SeekableBuffer(backward_capacity, forward_capacity)); 98 new media::SeekableBuffer(backward_capacity, forward_capacity));
94 } 99 }
95 100
96 void Start() { 101 void Start() {
97 InSequence s; 102 InSequence s;
98 EXPECT_CALL(*url_loader_, loadAsynchronously(_, loader_.get())); 103 EXPECT_CALL(*url_loader_, loadAsynchronously(_, loader_.get()));
99 loader_->Start( 104 loader_->Start(
100 NewCallback(this, &BufferedResourceLoaderTest::StartCallback), 105 NewCallback(this, &BufferedResourceLoaderTest::StartCallback),
101 NewCallback(this, &BufferedResourceLoaderTest::NetworkCallback), 106 NewCallback(this, &BufferedResourceLoaderTest::NetworkCallback),
102 frame_.get()); 107 view_->mainFrame());
103 } 108 }
104 109
105 void FullResponse(int64 instance_size) { 110 void FullResponse(int64 instance_size) {
106 FullResponse(instance_size, net::OK); 111 FullResponse(instance_size, net::OK);
107 } 112 }
108 113
109 void FullResponse(int64 instance_size, int status) { 114 void FullResponse(int64 instance_size, int status) {
110 EXPECT_CALL(*this, StartCallback(status)); 115 EXPECT_CALL(*this, StartCallback(status));
111 if (status != net::OK) { 116 if (status != net::OK) {
112 EXPECT_CALL(*url_loader_, cancel()) 117 EXPECT_CALL(*url_loader_, cancel())
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 MOCK_METHOD1(ReadCallback, void(int error)); 229 MOCK_METHOD1(ReadCallback, void(int error));
225 MOCK_METHOD0(NetworkCallback, void()); 230 MOCK_METHOD0(NetworkCallback, void());
226 231
227 protected: 232 protected:
228 GURL gurl_; 233 GURL gurl_;
229 int64 first_position_; 234 int64 first_position_;
230 int64 last_position_; 235 int64 last_position_;
231 236
232 scoped_refptr<BufferedResourceLoader> loader_; 237 scoped_refptr<BufferedResourceLoader> loader_;
233 NiceMock<MockWebURLLoader>* url_loader_; 238 NiceMock<MockWebURLLoader>* url_loader_;
234 scoped_ptr<NiceMock<MockWebFrame> > frame_; 239
240 MockWebFrameClient client_;
241 WebView* view_;
235 242
236 uint8 data_[kDataSize]; 243 uint8 data_[kDataSize];
237 244
238 private: 245 private:
239 DISALLOW_COPY_AND_ASSIGN(BufferedResourceLoaderTest); 246 DISALLOW_COPY_AND_ASSIGN(BufferedResourceLoaderTest);
240 }; 247 };
241 248
242 TEST_F(BufferedResourceLoaderTest, StartStop) { 249 TEST_F(BufferedResourceLoaderTest, StartStop) {
243 Initialize(kHttpUrl, -1, -1); 250 Initialize(kHttpUrl, -1, -1);
244 Start(); 251 Start();
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 Start(); 550 Start();
544 Redirect(kHttpRedirectToSameDomainUrl1); 551 Redirect(kHttpRedirectToSameDomainUrl1);
545 Redirect(kHttpRedirectToDifferentDomainUrl1); 552 Redirect(kHttpRedirectToDifferentDomainUrl1);
546 EXPECT_FALSE(loader_->HasSingleOrigin()); 553 EXPECT_FALSE(loader_->HasSingleOrigin());
547 StopWhenLoad(); 554 StopWhenLoad();
548 } 555 }
549 556
550 // TODO(hclam): add unit test for defer loading. 557 // TODO(hclam): add unit test for defer loading.
551 558
552 } // namespace webkit_glue 559 } // namespace webkit_glue
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698