diff options
Diffstat (limited to 'webkit/glue/media/buffered_resource_loader_unittest.cc')
-rw-r--r-- | webkit/glue/media/buffered_resource_loader_unittest.cc | 89 |
1 files changed, 80 insertions, 9 deletions
diff --git a/webkit/glue/media/buffered_resource_loader_unittest.cc b/webkit/glue/media/buffered_resource_loader_unittest.cc index 8e64c26..dc67edf 100644 --- a/webkit/glue/media/buffered_resource_loader_unittest.cc +++ b/webkit/glue/media/buffered_resource_loader_unittest.cc @@ -8,11 +8,11 @@ #include "base/stringprintf.h" #include "net/base/net_errors.h" #include "net/http/http_util.h" -#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" -#include "third_party/WebKit/WebKit/chromium/public/WebFrameClient.h" -#include "third_party/WebKit/WebKit/chromium/public/WebURLError.h" -#include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h" -#include "third_party/WebKit/WebKit/chromium/public/WebView.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" #include "webkit/glue/media/buffered_resource_loader.h" #include "webkit/mocks/mock_webframe.h" #include "webkit/mocks/mock_weburlloader.h" @@ -41,6 +41,11 @@ using WebKit::WebView; namespace { const char* kHttpUrl = "http://test"; +const char kHttpRedirectToSameDomainUrl1[] = "http://test/ing"; +const char kHttpRedirectToSameDomainUrl2[] = "http://test/ing2"; +const char kHttpRedirectToDifferentDomainUrl1[] = "http://test2"; +const char kHttpRedirectToDifferentDomainUrl2[] = "http://test2/ing"; + const int kDataSize = 1024; const int kHttpOK = 200; const int kHttpPartialContent = 206; @@ -67,14 +72,11 @@ ACTION_P(RequestCanceled, loader) { class BufferedResourceLoaderTest : public testing::Test { public: BufferedResourceLoaderTest() { - url_loader_ = new NiceMock<MockWebURLLoader>(); - for (int i = 0; i < kDataSize; ++i) data_[i] = i; } virtual ~BufferedResourceLoaderTest() { - ignore_result(frame_.release()); } void Initialize(const char* url, int first_position, int last_position) { @@ -84,6 +86,7 @@ class BufferedResourceLoaderTest : public testing::Test { frame_.reset(new NiceMock<MockWebFrame>()); + url_loader_ = new NiceMock<MockWebURLLoader>(); loader_ = new BufferedResourceLoader(gurl_, first_position_, last_position_); loader_->SetURLLoaderForTest(url_loader_); @@ -138,11 +141,22 @@ class BufferedResourceLoaderTest : public testing::Test { EXPECT_TRUE(loader_->partial_response()); } + void Redirect(const char* url) { + GURL redirectUrl(url); + WebKit::WebURLRequest newRequest(redirectUrl); + WebKit::WebURLResponse redirectResponse(gurl_); + + loader_->willSendRequest(url_loader_, newRequest, redirectResponse); + + MessageLoop::current()->RunAllPending(); + } + void StopWhenLoad() { InSequence s; EXPECT_CALL(*url_loader_, cancel()) .WillOnce(RequestCanceled(loader_)); loader_->Stop(); + loader_ = NULL; } // Helper method to write to |loader_| from |data_|. @@ -480,7 +494,64 @@ TEST_F(BufferedResourceLoaderTest, AllowDefer_DeferredReadPastWindow) { ReadLoader(20, 5, buffer); StopWhenLoad(); } + +// 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(BufferedResourceLoaderTest, HasSingleOrigin) { + // Make sure no redirect case works as expected. + Initialize(kHttpUrl, -1, -1); + Start(); + FullResponse(1024); + EXPECT_TRUE(loader_->HasSingleOrigin()); + StopWhenLoad(); + + // Test redirect to the same domain. + Initialize(kHttpUrl, -1, -1); + Start(); + Redirect(kHttpRedirectToSameDomainUrl1); + FullResponse(1024); + EXPECT_TRUE(loader_->HasSingleOrigin()); + StopWhenLoad(); + + // Test redirect twice to the same domain. + Initialize(kHttpUrl, -1, -1); + Start(); + Redirect(kHttpRedirectToSameDomainUrl1); + Redirect(kHttpRedirectToSameDomainUrl2); + FullResponse(1024); + EXPECT_TRUE(loader_->HasSingleOrigin()); + StopWhenLoad(); + + // Test redirect to a different domain. + Initialize(kHttpUrl, -1, -1); + Start(); + Redirect(kHttpRedirectToDifferentDomainUrl1); + FullResponse(1024); + EXPECT_FALSE(loader_->HasSingleOrigin()); + StopWhenLoad(); + + // Test redirect twice to a different domain. + Initialize(kHttpUrl, -1, -1); + Start(); + Redirect(kHttpRedirectToDifferentDomainUrl1); + Redirect(kHttpRedirectToDifferentDomainUrl2); + FullResponse(1024); + EXPECT_FALSE(loader_->HasSingleOrigin()); + StopWhenLoad(); + + // 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. + Initialize(kHttpUrl, -1, -1); + Start(); + Redirect(kHttpRedirectToDifferentDomainUrl1); + Redirect(kHttpRedirectToSameDomainUrl1); + FullResponse(1024); + EXPECT_FALSE(loader_->HasSingleOrigin()); + StopWhenLoad(); +} + // TODO(hclam): add unit test for defer loading. } // namespace webkit_glue - |