Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "media/base/filters.h" | 5 #include "media/base/filters.h" |
| 6 #include "media/base/mock_callback.h" | 6 #include "media/base/mock_callback.h" |
| 7 #include "media/base/mock_filter_host.h" | 7 #include "media/base/mock_filter_host.h" |
| 8 #include "media/base/mock_filters.h" | 8 #include "media/base/mock_filters.h" |
| 9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
| 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h" | 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h" |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoader.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoader.h" |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" |
| 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" |
| 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | |
| 15 #include "webkit/glue/media/simple_data_source.h" | 15 #include "webkit/glue/media/simple_data_source.h" |
| 16 #include "webkit/mocks/mock_webframe.h" | 16 #include "webkit/mocks/mock_webframeclient.h" |
| 17 #include "webkit/mocks/mock_weburlloader.h" | 17 #include "webkit/mocks/mock_weburlloader.h" |
| 18 | 18 |
| 19 using ::testing::_; | 19 using ::testing::_; |
| 20 using ::testing::DoAll; | 20 using ::testing::DoAll; |
| 21 using ::testing::InSequence; | 21 using ::testing::InSequence; |
| 22 using ::testing::Invoke; | 22 using ::testing::Invoke; |
| 23 using ::testing::NiceMock; | 23 using ::testing::NiceMock; |
| 24 using ::testing::NotNull; | 24 using ::testing::NotNull; |
| 25 using ::testing::Return; | 25 using ::testing::Return; |
| 26 using ::testing::SetArgumentPointee; | 26 using ::testing::SetArgumentPointee; |
| 27 using ::testing::StrictMock; | 27 using ::testing::StrictMock; |
| 28 using ::testing::WithArgs; | 28 using ::testing::WithArgs; |
| 29 | 29 |
| 30 using WebKit::WebURLError; | 30 using WebKit::WebURLError; |
| 31 using WebKit::WebURLLoader; | 31 using WebKit::WebURLLoader; |
| 32 using WebKit::WebURLRequest; | 32 using WebKit::WebURLRequest; |
| 33 using WebKit::WebURLResponse; | 33 using WebKit::WebURLResponse; |
| 34 using WebKit::WebView; | |
| 34 | 35 |
| 35 namespace webkit_glue { | 36 namespace webkit_glue { |
| 36 | 37 |
| 37 static const int kDataSize = 1024; | 38 static const int kDataSize = 1024; |
| 38 static const char kHttpUrl[] = "http://test"; | 39 static const char kHttpUrl[] = "http://test"; |
| 39 static const char kHttpsUrl[] = "https://test"; | 40 static const char kHttpsUrl[] = "https://test"; |
| 40 static const char kFileUrl[] = "file://test"; | 41 static const char kFileUrl[] = "file://test"; |
| 41 static const char kDataUrl[] = | 42 static const char kDataUrl[] = |
| 42 "data:text/plain;base64,YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXoK"; | 43 "data:text/plain;base64,YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXoK"; |
| 43 static const char kDataUrlDecoded[] = "abcdefghijklmnopqrstuvwxyz"; | 44 static const char kDataUrlDecoded[] = "abcdefghijklmnopqrstuvwxyz"; |
| 44 static const char kInvalidUrl[] = "whatever://test"; | 45 static const char kInvalidUrl[] = "whatever://test"; |
| 45 static const char kHttpRedirectToSameDomainUrl1[] = "http://test/ing"; | 46 static const char kHttpRedirectToSameDomainUrl1[] = "http://test/ing"; |
| 46 static const char kHttpRedirectToSameDomainUrl2[] = "http://test/ing2"; | 47 static const char kHttpRedirectToSameDomainUrl2[] = "http://test/ing2"; |
| 47 static const char kHttpRedirectToDifferentDomainUrl1[] = "http://test2"; | 48 static const char kHttpRedirectToDifferentDomainUrl1[] = "http://test2"; |
| 48 static const char kHttpRedirectToDifferentDomainUrl2[] = "http://test2/ing"; | 49 static const char kHttpRedirectToDifferentDomainUrl2[] = "http://test2/ing"; |
| 49 | 50 |
| 50 class SimpleDataSourceTest : public testing::Test { | 51 class SimpleDataSourceTest : public testing::Test { |
| 51 public: | 52 public: |
| 52 SimpleDataSourceTest() { | 53 SimpleDataSourceTest() |
| 54 : view_(NULL) { | |
| 53 for (int i = 0; i < kDataSize; ++i) { | 55 for (int i = 0; i < kDataSize; ++i) { |
| 54 data_[i] = i; | 56 data_[i] = i; |
| 55 } | 57 } |
| 56 } | 58 } |
| 57 | 59 |
| 58 virtual ~SimpleDataSourceTest() { | 60 virtual ~SimpleDataSourceTest() { |
| 61 if (view_) { | |
|
acolwell GONE FROM CHROMIUM
2011/05/13 17:36:37
nit:braces
scherkus (not reviewing)
2011/05/13 19:35:20
Done.
| |
| 62 view_->close(); | |
| 63 } | |
| 59 } | 64 } |
| 60 | 65 |
| 61 void InitializeDataSource(const char* url, | 66 void InitializeDataSource(const char* url, |
| 62 media::MockStatusCallback* callback) { | 67 media::MockStatusCallback* callback) { |
| 63 gurl_ = GURL(url); | 68 gurl_ = GURL(url); |
| 64 | 69 |
| 65 frame_.reset(new NiceMock<MockWebFrame>()); | 70 view_ = WebView::create(NULL); |
| 71 view_->initializeMainFrame(&client_); | |
| 72 | |
| 66 url_loader_ = new NiceMock<MockWebURLLoader>(); | 73 url_loader_ = new NiceMock<MockWebURLLoader>(); |
| 67 | 74 |
| 68 data_source_ = new SimpleDataSource(MessageLoop::current(), | 75 data_source_ = new SimpleDataSource(MessageLoop::current(), |
| 69 frame_.get()); | 76 view_->mainFrame()); |
| 70 | 77 |
| 71 // There is no need to provide a message loop to data source. | 78 // There is no need to provide a message loop to data source. |
| 72 data_source_->set_host(&host_); | 79 data_source_->set_host(&host_); |
| 73 data_source_->SetURLLoaderForTest(url_loader_); | 80 data_source_->SetURLLoaderForTest(url_loader_); |
| 74 | 81 |
| 75 data_source_->Initialize(url, callback); | 82 data_source_->Initialize(url, callback); |
| 76 MessageLoop::current()->RunAllPending(); | 83 MessageLoop::current()->RunAllPending(); |
| 77 } | 84 } |
| 78 | 85 |
| 79 void RequestSucceeded(bool is_loaded) { | 86 void RequestSucceeded(bool is_loaded) { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 107 WebURLError error; | 114 WebURLError error; |
| 108 error.reason = net::ERR_FAILED; | 115 error.reason = net::ERR_FAILED; |
| 109 data_source_->didFail(NULL, error); | 116 data_source_->didFail(NULL, error); |
| 110 | 117 |
| 111 // Let the tasks to be executed. | 118 // Let the tasks to be executed. |
| 112 MessageLoop::current()->RunAllPending(); | 119 MessageLoop::current()->RunAllPending(); |
| 113 } | 120 } |
| 114 | 121 |
| 115 void Redirect(const char* url) { | 122 void Redirect(const char* url) { |
| 116 GURL redirectUrl(url); | 123 GURL redirectUrl(url); |
| 117 WebKit::WebURLRequest newRequest(redirectUrl); | 124 WebURLRequest newRequest(redirectUrl); |
| 118 WebKit::WebURLResponse redirectResponse(gurl_); | 125 WebURLResponse redirectResponse(gurl_); |
| 119 | 126 |
| 120 data_source_->willSendRequest(url_loader_, newRequest, redirectResponse); | 127 data_source_->willSendRequest(url_loader_, newRequest, redirectResponse); |
| 121 | 128 |
| 122 MessageLoop::current()->RunAllPending(); | 129 MessageLoop::current()->RunAllPending(); |
| 123 } | 130 } |
| 124 | 131 |
| 125 void DestroyDataSource() { | 132 void DestroyDataSource() { |
| 126 data_source_->Stop(media::NewExpectedCallback()); | 133 data_source_->Stop(media::NewExpectedCallback()); |
| 127 MessageLoop::current()->RunAllPending(); | 134 MessageLoop::current()->RunAllPending(); |
| 128 | 135 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 142 } | 149 } |
| 143 | 150 |
| 144 MOCK_METHOD1(ReadCallback, void(size_t size)); | 151 MOCK_METHOD1(ReadCallback, void(size_t size)); |
| 145 | 152 |
| 146 protected: | 153 protected: |
| 147 GURL gurl_; | 154 GURL gurl_; |
| 148 scoped_ptr<MessageLoop> message_loop_; | 155 scoped_ptr<MessageLoop> message_loop_; |
| 149 NiceMock<MockWebURLLoader>* url_loader_; | 156 NiceMock<MockWebURLLoader>* url_loader_; |
| 150 scoped_refptr<SimpleDataSource> data_source_; | 157 scoped_refptr<SimpleDataSource> data_source_; |
| 151 StrictMock<media::MockFilterHost> host_; | 158 StrictMock<media::MockFilterHost> host_; |
| 152 scoped_ptr<NiceMock<MockWebFrame> > frame_; | 159 |
| 160 MockWebFrameClient client_; | |
| 161 WebView* view_; | |
| 153 | 162 |
| 154 char data_[kDataSize]; | 163 char data_[kDataSize]; |
| 155 | 164 |
| 156 DISALLOW_COPY_AND_ASSIGN(SimpleDataSourceTest); | 165 DISALLOW_COPY_AND_ASSIGN(SimpleDataSourceTest); |
| 157 }; | 166 }; |
| 158 | 167 |
| 159 TEST_F(SimpleDataSourceTest, InitializeHTTP) { | 168 TEST_F(SimpleDataSourceTest, InitializeHTTP) { |
| 160 InitializeDataSource(kHttpUrl, | 169 InitializeDataSource(kHttpUrl, |
| 161 media::NewExpectedStatusCallback(media::PIPELINE_OK)); | 170 media::NewExpectedStatusCallback(media::PIPELINE_OK)); |
| 162 RequestSucceeded(false); | 171 RequestSucceeded(false); |
| 163 DestroyDataSource(); | 172 DestroyDataSource(); |
| 164 } | 173 } |
| 165 | 174 |
| 166 TEST_F(SimpleDataSourceTest, InitializeHTTPS) { | 175 TEST_F(SimpleDataSourceTest, InitializeHTTPS) { |
| 167 InitializeDataSource(kHttpsUrl, | 176 InitializeDataSource(kHttpsUrl, |
| 168 media::NewExpectedStatusCallback(media::PIPELINE_OK)); | 177 media::NewExpectedStatusCallback(media::PIPELINE_OK)); |
| 169 RequestSucceeded(false); | 178 RequestSucceeded(false); |
| 170 DestroyDataSource(); | 179 DestroyDataSource(); |
| 171 } | 180 } |
| 172 | 181 |
| 173 TEST_F(SimpleDataSourceTest, InitializeFile) { | 182 TEST_F(SimpleDataSourceTest, InitializeFile) { |
| 174 InitializeDataSource(kFileUrl, | 183 InitializeDataSource(kFileUrl, |
| 175 media::NewExpectedStatusCallback(media::PIPELINE_OK)); | 184 media::NewExpectedStatusCallback(media::PIPELINE_OK)); |
| 176 RequestSucceeded(true); | 185 RequestSucceeded(true); |
| 177 DestroyDataSource(); | 186 DestroyDataSource(); |
| 178 } | 187 } |
| 179 | 188 |
| 180 TEST_F(SimpleDataSourceTest, InitializeData) { | 189 TEST_F(SimpleDataSourceTest, InitializeData) { |
| 181 frame_.reset(new NiceMock<MockWebFrame>()); | 190 view_ = WebView::create(NULL); |
| 191 view_->initializeMainFrame(&client_); | |
| 192 | |
| 182 url_loader_ = new NiceMock<MockWebURLLoader>(); | 193 url_loader_ = new NiceMock<MockWebURLLoader>(); |
| 183 | 194 |
| 184 data_source_ = new SimpleDataSource(MessageLoop::current(), | 195 data_source_ = new SimpleDataSource(MessageLoop::current(), |
| 185 frame_.get()); | 196 view_->mainFrame()); |
| 186 // There is no need to provide a message loop to data source. | 197 // There is no need to provide a message loop to data source. |
| 187 data_source_->set_host(&host_); | 198 data_source_->set_host(&host_); |
| 188 data_source_->SetURLLoaderForTest(url_loader_); | 199 data_source_->SetURLLoaderForTest(url_loader_); |
| 189 | 200 |
| 190 EXPECT_CALL(host_, SetLoaded(true)); | 201 EXPECT_CALL(host_, SetLoaded(true)); |
| 191 EXPECT_CALL(host_, SetTotalBytes(sizeof(kDataUrlDecoded))); | 202 EXPECT_CALL(host_, SetTotalBytes(sizeof(kDataUrlDecoded))); |
| 192 EXPECT_CALL(host_, SetBufferedBytes(sizeof(kDataUrlDecoded))); | 203 EXPECT_CALL(host_, SetBufferedBytes(sizeof(kDataUrlDecoded))); |
| 193 | 204 |
| 194 data_source_->Initialize(kDataUrl, | 205 data_source_->Initialize(kDataUrl, |
| 195 media::NewExpectedStatusCallback(media::PIPELINE_OK)); | 206 media::NewExpectedStatusCallback(media::PIPELINE_OK)); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 InitializeDataSource(kHttpUrl, | 277 InitializeDataSource(kHttpUrl, |
| 267 media::NewExpectedStatusCallback(media::PIPELINE_OK)); | 278 media::NewExpectedStatusCallback(media::PIPELINE_OK)); |
| 268 Redirect(kHttpRedirectToSameDomainUrl1); | 279 Redirect(kHttpRedirectToSameDomainUrl1); |
| 269 Redirect(kHttpRedirectToDifferentDomainUrl1); | 280 Redirect(kHttpRedirectToDifferentDomainUrl1); |
| 270 RequestSucceeded(false); | 281 RequestSucceeded(false); |
| 271 EXPECT_FALSE(data_source_->HasSingleOrigin()); | 282 EXPECT_FALSE(data_source_->HasSingleOrigin()); |
| 272 DestroyDataSource(); | 283 DestroyDataSource(); |
| 273 } | 284 } |
| 274 | 285 |
| 275 } // namespace webkit_glue | 286 } // namespace webkit_glue |
| OLD | NEW |