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

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

Issue 1356353003: Relax cross-origin partial response requirements for CORS presence. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert accidental php change. Created 5 years, 2 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
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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "media/base/media_log.h" 8 #include "media/base/media_log.h"
9 #include "media/base/mock_filters.h" 9 #include "media/base/mock_filters.h"
10 #include "media/base/test_helpers.h" 10 #include "media/base/test_helpers.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 private: 44 private:
45 DISALLOW_COPY_AND_ASSIGN(MockBufferedDataSourceHost); 45 DISALLOW_COPY_AND_ASSIGN(MockBufferedDataSourceHost);
46 }; 46 };
47 47
48 // Overrides CreateResourceLoader() to permit injecting a MockWebURLLoader. 48 // Overrides CreateResourceLoader() to permit injecting a MockWebURLLoader.
49 // Also keeps track of whether said MockWebURLLoader is actively loading. 49 // Also keeps track of whether said MockWebURLLoader is actively loading.
50 class MockBufferedDataSource : public BufferedDataSource { 50 class MockBufferedDataSource : public BufferedDataSource {
51 public: 51 public:
52 MockBufferedDataSource( 52 MockBufferedDataSource(
53 const GURL& url, 53 const GURL& url,
54 BufferedResourceLoader::CORSMode cors_mode,
54 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, 55 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
55 WebLocalFrame* frame, 56 WebLocalFrame* frame,
56 BufferedDataSourceHost* host) 57 BufferedDataSourceHost* host)
57 : BufferedDataSource(url, 58 : BufferedDataSource(url,
58 BufferedResourceLoader::kUnspecified, 59 cors_mode,
59 task_runner, 60 task_runner,
60 frame, 61 frame,
61 new media::MediaLog(), 62 new media::MediaLog(),
62 host, 63 host,
63 base::Bind(&MockBufferedDataSource::set_downloading, 64 base::Bind(&MockBufferedDataSource::set_downloading,
64 base::Unretained(this))), 65 base::Unretained(this))),
65 downloading_(false), 66 downloading_(false),
66 loading_(false) {} 67 loading_(false) {}
67 virtual ~MockBufferedDataSource() {} 68 virtual ~MockBufferedDataSource() {}
68 69
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 view_->setMainFrame(frame_); 122 view_->setMainFrame(frame_);
122 } 123 }
123 124
124 virtual ~BufferedDataSourceTest() { 125 virtual ~BufferedDataSourceTest() {
125 view_->close(); 126 view_->close();
126 frame_->close(); 127 frame_->close();
127 } 128 }
128 129
129 MOCK_METHOD1(OnInitialize, void(bool)); 130 MOCK_METHOD1(OnInitialize, void(bool));
130 131
131 void Initialize(const char* url, bool expected) { 132 void InitializeWithCORS(const char* url,
133 bool expected,
134 BufferedResourceLoader::CORSMode cors_mode) {
132 GURL gurl(url); 135 GURL gurl(url);
133 data_source_.reset( 136 data_source_.reset(new MockBufferedDataSource(
134 new MockBufferedDataSource(gurl, 137 gurl, cors_mode, message_loop_.task_runner(),
135 message_loop_.task_runner(), 138 view_->mainFrame()->toWebLocalFrame(), &host_));
136 view_->mainFrame()->toWebLocalFrame(),
137 &host_));
138 data_source_->SetPreload(preload_); 139 data_source_->SetPreload(preload_);
139 140
140 response_generator_.reset(new TestResponseGenerator(gurl, kFileSize)); 141 response_generator_.reset(new TestResponseGenerator(gurl, kFileSize));
141 ExpectCreateResourceLoader(); 142 ExpectCreateResourceLoader();
142 EXPECT_CALL(*this, OnInitialize(expected)); 143 EXPECT_CALL(*this, OnInitialize(expected));
143 data_source_->Initialize(base::Bind(&BufferedDataSourceTest::OnInitialize, 144 data_source_->Initialize(base::Bind(&BufferedDataSourceTest::OnInitialize,
144 base::Unretained(this))); 145 base::Unretained(this)));
145 message_loop_.RunUntilIdle(); 146 message_loop_.RunUntilIdle();
146 147
147 bool is_http = gurl.SchemeIsHTTPOrHTTPS(); 148 bool is_http = gurl.SchemeIsHTTPOrHTTPS();
148 EXPECT_EQ(data_source_->downloading(), is_http); 149 EXPECT_EQ(data_source_->downloading(), is_http);
149 } 150 }
150 151
152 void Initialize(const char* url, bool expected) {
153 InitializeWithCORS(url, expected, BufferedResourceLoader::kUnspecified);
154 }
155
151 // Helper to initialize tests with a valid 200 response. 156 // Helper to initialize tests with a valid 200 response.
152 void InitializeWith200Response() { 157 void InitializeWith200Response() {
153 Initialize(kHttpUrl, true); 158 Initialize(kHttpUrl, true);
154 159
155 EXPECT_CALL(host_, SetTotalBytes(response_generator_->content_length())); 160 EXPECT_CALL(host_, SetTotalBytes(response_generator_->content_length()));
156 Respond(response_generator_->Generate200()); 161 Respond(response_generator_->Generate200());
157 } 162 }
158 163
159 // Helper to initialize tests with a valid 206 response. 164 // Helper to initialize tests with a valid 206 response.
160 void InitializeWith206Response() { 165 void InitializeWith206Response() {
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 response_generator_->GeneratePartial206(0, kDataSize - 1); 575 response_generator_->GeneratePartial206(0, kDataSize - 1);
571 response1.setWasFetchedViaServiceWorker(true); 576 response1.setWasFetchedViaServiceWorker(true);
572 response1.setOriginalURLViaServiceWorker(GURL(kHttpDifferentOriginUrl)); 577 response1.setOriginalURLViaServiceWorker(GURL(kHttpDifferentOriginUrl));
573 WebURLResponse response2 = 578 WebURLResponse response2 =
574 response_generator_->GeneratePartial206(kDataSize, kDataSize * 2 - 1); 579 response_generator_->GeneratePartial206(kDataSize, kDataSize * 2 - 1);
575 // The origin URL of response1 and response2 are different. So an error should 580 // The origin URL of response1 and response2 are different. So an error should
576 // occur. 581 // occur.
577 ExecuteMixedResponseFailureTest(response1, response2); 582 ExecuteMixedResponseFailureTest(response1, response2);
578 } 583 }
579 584
585 TEST_F(BufferedDataSourceTest,
586 Http_MixedResponse_ServiceWorkerProxiedAndDifferentOriginResponseCORS) {
587 InitializeWithCORS(kHttpUrl, true, BufferedResourceLoader::kAnonymous);
588 WebURLResponse response1 =
589 response_generator_->GeneratePartial206(0, kDataSize - 1);
590 response1.setWasFetchedViaServiceWorker(true);
591 response1.setOriginalURLViaServiceWorker(GURL(kHttpDifferentOriginUrl));
592 WebURLResponse response2 =
593 response_generator_->GeneratePartial206(kDataSize, kDataSize * 2 - 1);
594 // The origin URL of response1 and response2 are different, but a CORS check
595 // has been passed for each request, so expect success.
596 ExecuteMixedResponseSuccessTest(response1, response2);
597 }
598
580 TEST_F(BufferedDataSourceTest, File_Retry) { 599 TEST_F(BufferedDataSourceTest, File_Retry) {
581 InitializeWithFileResponse(); 600 InitializeWithFileResponse();
582 601
583 // Read to advance our position. 602 // Read to advance our position.
584 EXPECT_CALL(*this, ReadCallback(kDataSize)); 603 EXPECT_CALL(*this, ReadCallback(kDataSize));
585 ReadAt(0); 604 ReadAt(0);
586 ReceiveData(kDataSize); 605 ReceiveData(kDataSize);
587 606
588 // Issue a pending read but terminate the connection to force a retry. 607 // Issue a pending read but terminate the connection to force a retry.
589 ReadAt(kDataSize); 608 ReadAt(kDataSize);
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 // Read a bit from the beginning. 997 // Read a bit from the beginning.
979 ReadAt(0); 998 ReadAt(0);
980 EXPECT_CALL(*this, ReadCallback(kDataSize)); 999 EXPECT_CALL(*this, ReadCallback(kDataSize));
981 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize - 1)); 1000 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize - 1));
982 ReceiveData(kDataSize); 1001 ReceiveData(kDataSize);
983 1002
984 EXPECT_FALSE(active_loader()); 1003 EXPECT_FALSE(active_loader());
985 } 1004 }
986 1005
987 } // namespace media 1006 } // namespace media
OLDNEW
« no previous file with comments | « media/blink/buffered_data_source.cc ('k') | third_party/WebKit/LayoutTests/http/tests/media/mixed-range-response.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698