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

Unified Diff: media/blink/buffered_data_source_unittest.cc

Issue 1220963004: Check the response URL origin in BufferedDataSource to avoid mixing cross-origin responses. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: incorporated hubbe's comment Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/blink/buffered_data_source.cc ('k') | media/blink/buffered_resource_loader.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/blink/buffered_data_source_unittest.cc
diff --git a/media/blink/buffered_data_source_unittest.cc b/media/blink/buffered_data_source_unittest.cc
index b2716ac5940a569b83678a439f5f96b192182812..878d5f7ea007d663509dca2b131239f303645ad0 100644
--- a/media/blink/buffered_data_source_unittest.cc
+++ b/media/blink/buffered_data_source_unittest.cc
@@ -108,6 +108,8 @@ static const int kDataSize = 1024;
static const char kHttpUrl[] = "http://localhost/foo.webm";
static const char kFileUrl[] = "file:///tmp/bar.webm";
+static const char kHttpDifferentPathUrl[] = "http://localhost/bar.webm";
+static const char kHttpDifferentOriginUrl[] = "http://127.0.0.1/foo.webm";
class BufferedDataSourceTest : public testing::Test {
public:
@@ -220,6 +222,46 @@ class BufferedDataSourceTest : public testing::Test {
message_loop_.RunUntilIdle();
}
+ void ExecuteMixedResponseSuccessTest(const WebURLResponse& response1,
+ const WebURLResponse& response2) {
+ EXPECT_CALL(host_, SetTotalBytes(kFileSize));
+ EXPECT_CALL(host_, AddBufferedByteRange(kDataSize, kDataSize * 2 - 1));
+ EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize - 1));
+ EXPECT_CALL(*this, ReadCallback(kDataSize)).Times(2);
+
+ Respond(response1);
+ ReadAt(0);
+ ReceiveData(kDataSize);
+ EXPECT_TRUE(data_source_->loading());
+
+ ExpectCreateResourceLoader();
+ FinishLoading();
+ ReadAt(kDataSize);
+ Respond(response2);
+ ReceiveData(kDataSize);
+ FinishLoading();
+ Stop();
+ }
+
+ void ExecuteMixedResponseFailureTest(const WebURLResponse& response1,
+ const WebURLResponse& response2) {
+ EXPECT_CALL(host_, SetTotalBytes(kFileSize));
+ EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize - 1));
+ EXPECT_CALL(*this, ReadCallback(kDataSize));
+ EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError));
+
+ Respond(response1);
+ ReadAt(0);
+ ReceiveData(kDataSize);
+ EXPECT_TRUE(data_source_->loading());
+
+ ExpectCreateResourceLoader();
+ FinishLoading();
+ ReadAt(kDataSize);
+ Respond(response2);
+ Stop();
+ }
+
// Accessors for private variables on |data_source_|.
BufferedResourceLoader* loader() {
return data_source_->loader_.get();
@@ -443,6 +485,98 @@ TEST_F(BufferedDataSourceTest, Http_RetryOnError) {
Stop();
}
+TEST_F(BufferedDataSourceTest, Http_PartialResponse) {
+ Initialize(kHttpUrl, true);
+ WebURLResponse response1 =
+ response_generator_->GeneratePartial206(0, kDataSize - 1);
+ WebURLResponse response2 =
+ response_generator_->GeneratePartial206(kDataSize, kDataSize * 2 - 1);
+ // The origin URL of response1 and response2 are same. So no error should
+ // occur.
+ ExecuteMixedResponseSuccessTest(response1, response2);
+}
+
+TEST_F(BufferedDataSourceTest,
+ Http_MixedResponse_RedirectedToDifferentPathResponse) {
+ Initialize(kHttpUrl, true);
+ WebURLResponse response1 =
+ response_generator_->GeneratePartial206(0, kDataSize - 1);
+ WebURLResponse response2 =
+ response_generator_->GeneratePartial206(kDataSize, kDataSize * 2 - 1);
+ response2.setURL(GURL(kHttpDifferentPathUrl));
+ // The origin URL of response1 and response2 are same. So no error should
+ // occur.
+ ExecuteMixedResponseSuccessTest(response1, response2);
+}
+
+TEST_F(BufferedDataSourceTest,
+ Http_MixedResponse_RedirectedToDifferentOriginResponse) {
+ Initialize(kHttpUrl, true);
+ WebURLResponse response1 =
+ response_generator_->GeneratePartial206(0, kDataSize - 1);
+ WebURLResponse response2 =
+ response_generator_->GeneratePartial206(kDataSize, kDataSize * 2 - 1);
+ response2.setURL(GURL(kHttpDifferentOriginUrl));
+ // The origin URL of response1 and response2 are different. So an error should
+ // occur.
+ ExecuteMixedResponseFailureTest(response1, response2);
+}
+
+TEST_F(BufferedDataSourceTest,
+ Http_MixedResponse_ServiceWorkerGeneratedResponseAndNormalResponse) {
+ Initialize(kHttpUrl, true);
+ WebURLResponse response1 =
+ response_generator_->GeneratePartial206(0, kDataSize - 1);
+ response1.setWasFetchedViaServiceWorker(true);
+ WebURLResponse response2 =
+ response_generator_->GeneratePartial206(kDataSize, kDataSize * 2 - 1);
+ // response1 is generated in a Service Worker but response2 is from a native
+ // server. So an error should occur.
+ ExecuteMixedResponseFailureTest(response1, response2);
+}
+
+TEST_F(BufferedDataSourceTest,
+ Http_MixedResponse_ServiceWorkerProxiedAndSameURLResponse) {
+ Initialize(kHttpUrl, true);
+ WebURLResponse response1 =
+ response_generator_->GeneratePartial206(0, kDataSize - 1);
+ response1.setWasFetchedViaServiceWorker(true);
+ response1.setOriginalURLViaServiceWorker(GURL(kHttpUrl));
+ WebURLResponse response2 =
+ response_generator_->GeneratePartial206(kDataSize, kDataSize * 2 - 1);
+ // The origin URL of response1 and response2 are same. So no error should
+ // occur.
+ ExecuteMixedResponseSuccessTest(response1, response2);
+}
+
+TEST_F(BufferedDataSourceTest,
+ Http_MixedResponse_ServiceWorkerProxiedAndDifferentPathResponse) {
+ Initialize(kHttpUrl, true);
+ WebURLResponse response1 =
+ response_generator_->GeneratePartial206(0, kDataSize - 1);
+ response1.setWasFetchedViaServiceWorker(true);
+ response1.setOriginalURLViaServiceWorker(GURL(kHttpDifferentPathUrl));
+ WebURLResponse response2 =
+ response_generator_->GeneratePartial206(kDataSize, kDataSize * 2 - 1);
+ // The origin URL of response1 and response2 are same. So no error should
+ // occur.
+ ExecuteMixedResponseSuccessTest(response1, response2);
+}
+
+TEST_F(BufferedDataSourceTest,
+ Http_MixedResponse_ServiceWorkerProxiedAndDifferentOriginResponse) {
+ Initialize(kHttpUrl, true);
+ WebURLResponse response1 =
+ response_generator_->GeneratePartial206(0, kDataSize - 1);
+ response1.setWasFetchedViaServiceWorker(true);
+ response1.setOriginalURLViaServiceWorker(GURL(kHttpDifferentOriginUrl));
+ WebURLResponse response2 =
+ response_generator_->GeneratePartial206(kDataSize, kDataSize * 2 - 1);
+ // The origin URL of response1 and response2 are different. So an error should
+ // occur.
+ ExecuteMixedResponseFailureTest(response1, response2);
+}
+
TEST_F(BufferedDataSourceTest, File_Retry) {
InitializeWithFileResponse();
« no previous file with comments | « media/blink/buffered_data_source.cc ('k') | media/blink/buffered_resource_loader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698