summaryrefslogtreecommitdiffstats
path: root/webkit/glue/media/simple_data_source_unittest.cc
diff options
context:
space:
mode:
authoracolwell@chromium.org <acolwell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-14 18:25:18 +0000
committeracolwell@chromium.org <acolwell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-14 18:25:18 +0000
commit969956486a47bf72bec6d5df38ad9d1ec069500f (patch)
tree19fc475bb033f0b002da813147618d6131c4cb93 /webkit/glue/media/simple_data_source_unittest.cc
parentf7f7d27ad1f998a4ed4295fa796870fe3628a285 (diff)
downloadchromium_src-969956486a47bf72bec6d5df38ad9d1ec069500f.zip
chromium_src-969956486a47bf72bec6d5df38ad9d1ec069500f.tar.gz
chromium_src-969956486a47bf72bec6d5df38ad9d1ec069500f.tar.bz2
Fix HasSingleOrigin() so it properly handles double redirect & added unit test.
BUG=72625 TEST=BufferedResourceLoaderTest.HasSingleOrigin, SimpleDataSourceTest.HasSingleOrigin Review URL: http://codereview.chromium.org/6488008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@74829 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/media/simple_data_source_unittest.cc')
-rw-r--r--webkit/glue/media/simple_data_source_unittest.cc65
1 files changed, 65 insertions, 0 deletions
diff --git a/webkit/glue/media/simple_data_source_unittest.cc b/webkit/glue/media/simple_data_source_unittest.cc
index 48131b1..a9a70a4 100644
--- a/webkit/glue/media/simple_data_source_unittest.cc
+++ b/webkit/glue/media/simple_data_source_unittest.cc
@@ -42,6 +42,10 @@ const char kDataUrl[] =
"data:text/plain;base64,YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXoK";
const char kDataUrlDecoded[] = "abcdefghijklmnopqrstuvwxyz";
const char kInvalidUrl[] = "whatever://test";
+const char kHttpRedirectToSameDomainUrl1[] = "http://test/ing";
+const char kHttpRedirectToSameDomainUrl2[] = "http://test/ing2";
+const char kHttpRedirectToDifferentDomainUrl1[] = "http://test2";
+const char kHttpRedirectToDifferentDomainUrl2[] = "http://test2/ing";
} // namespace
@@ -113,6 +117,16 @@ class SimpleDataSourceTest : public testing::Test {
MessageLoop::current()->RunAllPending();
}
+ void Redirect(const char* url) {
+ GURL redirectUrl(url);
+ WebKit::WebURLRequest newRequest(redirectUrl);
+ WebKit::WebURLResponse redirectResponse(gurl_);
+
+ data_source_->willSendRequest(url_loader_, newRequest, redirectResponse);
+
+ MessageLoop::current()->RunAllPending();
+ }
+
void DestroyDataSource() {
data_source_->Stop(media::NewExpectedCallback());
MessageLoop::current()->RunAllPending();
@@ -213,4 +227,55 @@ TEST_F(SimpleDataSourceTest, AsyncRead) {
DestroyDataSource();
}
+// NOTE: This test will need to be reworked a little once
+// http://code.google.com/p/chromium/issues/detail?id=72578
+// is fixed.
+TEST_F(SimpleDataSourceTest, HasSingleOrigin) {
+ // Make sure no redirect case works as expected.
+ InitializeDataSource(kHttpUrl, media::NewExpectedCallback());
+ RequestSucceeded(false);
+ EXPECT_TRUE(data_source_->HasSingleOrigin());
+ DestroyDataSource();
+
+ // Test redirect to the same domain.
+ InitializeDataSource(kHttpUrl, media::NewExpectedCallback());
+ Redirect(kHttpRedirectToSameDomainUrl1);
+ RequestSucceeded(false);
+ EXPECT_TRUE(data_source_->HasSingleOrigin());
+ DestroyDataSource();
+
+ // Test redirect twice to the same domain.
+ InitializeDataSource(kHttpUrl, media::NewExpectedCallback());
+ Redirect(kHttpRedirectToSameDomainUrl1);
+ Redirect(kHttpRedirectToSameDomainUrl2);
+ RequestSucceeded(false);
+ EXPECT_TRUE(data_source_->HasSingleOrigin());
+ DestroyDataSource();
+
+ // Test redirect to a different domain.
+ InitializeDataSource(kHttpUrl, media::NewExpectedCallback());
+ Redirect(kHttpRedirectToDifferentDomainUrl1);
+ RequestSucceeded(false);
+ EXPECT_FALSE(data_source_->HasSingleOrigin());
+ DestroyDataSource();
+
+ // Test redirect twice to a different domain.
+ InitializeDataSource(kHttpUrl, media::NewExpectedCallback());
+ Redirect(kHttpRedirectToDifferentDomainUrl1);
+ Redirect(kHttpRedirectToDifferentDomainUrl2);
+ RequestSucceeded(false);
+ EXPECT_FALSE(data_source_->HasSingleOrigin());
+ DestroyDataSource();
+
+ // Test to a different domain and then back to the same domain.
+ // NOTE: A different origin was encountered at least once so that
+ // makes HasSingleOrigin() become false.
+ InitializeDataSource(kHttpUrl, media::NewExpectedCallback());
+ Redirect(kHttpRedirectToDifferentDomainUrl1);
+ Redirect(kHttpRedirectToSameDomainUrl1);
+ RequestSucceeded(false);
+ EXPECT_FALSE(data_source_->HasSingleOrigin());
+ DestroyDataSource();
+}
+
} // namespace webkit_glue