| OLD | NEW |
| 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/macros.h" | 6 #include "base/macros.h" |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "content/renderer/media/android/media_info_loader.h" | 9 #include "content/renderer/media/android/media_info_loader.h" |
| 10 #include "content/test/mock_webframeclient.h" |
| 10 #include "content/test/mock_weburlloader.h" | 11 #include "content/test/mock_weburlloader.h" |
| 11 #include "third_party/WebKit/public/platform/WebMediaPlayer.h" | 12 #include "third_party/WebKit/public/platform/WebMediaPlayer.h" |
| 12 #include "third_party/WebKit/public/platform/WebURLError.h" | 13 #include "third_party/WebKit/public/platform/WebURLError.h" |
| 13 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 14 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 14 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 15 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
| 15 #include "third_party/WebKit/public/web/WebFrameClient.h" | |
| 16 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 16 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 17 #include "third_party/WebKit/public/web/WebView.h" | 17 #include "third_party/WebKit/public/web/WebView.h" |
| 18 | 18 |
| 19 using ::testing::_; | 19 using ::testing::_; |
| 20 using ::testing::InSequence; | 20 using ::testing::InSequence; |
| 21 using ::testing::NiceMock; | 21 using ::testing::NiceMock; |
| 22 | 22 |
| 23 using blink::WebLocalFrame; | 23 using blink::WebLocalFrame; |
| 24 using blink::WebString; | 24 using blink::WebString; |
| 25 using blink::WebURLError; | 25 using blink::WebURLError; |
| 26 using blink::WebURLResponse; | 26 using blink::WebURLResponse; |
| 27 using blink::WebView; | 27 using blink::WebView; |
| 28 | 28 |
| 29 namespace content { | 29 namespace content { |
| 30 | 30 |
| 31 static const char* kHttpUrl = "http://test"; | 31 static const char* kHttpUrl = "http://test"; |
| 32 static const char kHttpRedirectToSameDomainUrl1[] = "http://test/ing"; | 32 static const char kHttpRedirectToSameDomainUrl1[] = "http://test/ing"; |
| 33 static const char kHttpRedirectToSameDomainUrl2[] = "http://test/ing2"; | 33 static const char kHttpRedirectToSameDomainUrl2[] = "http://test/ing2"; |
| 34 static const char kHttpRedirectToDifferentDomainUrl1[] = "http://test2"; | 34 static const char kHttpRedirectToDifferentDomainUrl1[] = "http://test2"; |
| 35 static const char kHttpDataUrl[] = "data:audio/wav;base64,UklGRhwMAABXQVZFZm10"; | 35 static const char kHttpDataUrl[] = "data:audio/wav;base64,UklGRhwMAABXQVZFZm10"; |
| 36 | 36 |
| 37 static const int kHttpOK = 200; | 37 static const int kHttpOK = 200; |
| 38 static const int kHttpNotFound = 404; | 38 static const int kHttpNotFound = 404; |
| 39 | 39 |
| 40 class MediaInfoLoaderTest : public testing::Test { | 40 class MediaInfoLoaderTest : public testing::Test { |
| 41 public: | 41 public: |
| 42 MediaInfoLoaderTest() | 42 MediaInfoLoaderTest() |
| 43 : view_(WebView::create(nullptr, blink::WebPageVisibilityStateVisible)) { | 43 : view_(WebView::create(nullptr, blink::WebPageVisibilityStateVisible)), |
| 44 view_->setMainFrame( | 44 frame_(WebLocalFrame::create(blink::WebTreeScopeType::Document, |
| 45 WebLocalFrame::create(blink::WebTreeScopeType::Document, &client_)); | 45 &client_)) { |
| 46 view_->setMainFrame(frame_); |
| 46 } | 47 } |
| 47 | 48 |
| 48 virtual ~MediaInfoLoaderTest() { | 49 virtual ~MediaInfoLoaderTest() { |
| 49 view_->close(); | 50 view_->close(); |
| 51 frame_->close(); |
| 50 } | 52 } |
| 51 | 53 |
| 52 void Initialize( | 54 void Initialize( |
| 53 const char* url, | 55 const char* url, |
| 54 blink::WebMediaPlayer::CORSMode cors_mode) { | 56 blink::WebMediaPlayer::CORSMode cors_mode) { |
| 55 gurl_ = GURL(url); | 57 gurl_ = GURL(url); |
| 56 | 58 |
| 57 loader_.reset(new MediaInfoLoader( | 59 loader_.reset(new MediaInfoLoader( |
| 58 gurl_, cors_mode, | 60 gurl_, cors_mode, |
| 59 base::Bind(&MediaInfoLoaderTest::ReadyCallback, | 61 base::Bind(&MediaInfoLoaderTest::ReadyCallback, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 | 109 |
| 108 MOCK_METHOD4(ReadyCallback, | 110 MOCK_METHOD4(ReadyCallback, |
| 109 void(MediaInfoLoader::Status, const GURL&, const GURL&, bool)); | 111 void(MediaInfoLoader::Status, const GURL&, const GURL&, bool)); |
| 110 | 112 |
| 111 protected: | 113 protected: |
| 112 GURL gurl_; | 114 GURL gurl_; |
| 113 | 115 |
| 114 std::unique_ptr<MediaInfoLoader> loader_; | 116 std::unique_ptr<MediaInfoLoader> loader_; |
| 115 NiceMock<MockWebURLLoader>* url_loader_; | 117 NiceMock<MockWebURLLoader>* url_loader_; |
| 116 | 118 |
| 117 blink::WebFrameClient client_; | 119 MockWebFrameClient client_; |
| 118 WebView* view_; | 120 WebView* view_; |
| 121 WebLocalFrame* frame_; |
| 119 | 122 |
| 120 base::MessageLoop message_loop_; | 123 base::MessageLoop message_loop_; |
| 121 | 124 |
| 122 private: | 125 private: |
| 123 DISALLOW_COPY_AND_ASSIGN(MediaInfoLoaderTest); | 126 DISALLOW_COPY_AND_ASSIGN(MediaInfoLoaderTest); |
| 124 }; | 127 }; |
| 125 | 128 |
| 126 TEST_F(MediaInfoLoaderTest, StartStop) { | 129 TEST_F(MediaInfoLoaderTest, StartStop) { |
| 127 Initialize(kHttpUrl, blink::WebMediaPlayer::CORSModeUnspecified); | 130 Initialize(kHttpUrl, blink::WebMediaPlayer::CORSModeUnspecified); |
| 128 Start(); | 131 Start(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 } | 198 } |
| 196 | 199 |
| 197 TEST_F(MediaInfoLoaderTest, CORSAccessCheckFailed) { | 200 TEST_F(MediaInfoLoaderTest, CORSAccessCheckFailed) { |
| 198 Initialize(kHttpUrl, blink::WebMediaPlayer::CORSModeUseCredentials); | 201 Initialize(kHttpUrl, blink::WebMediaPlayer::CORSModeUseCredentials); |
| 199 Start(); | 202 Start(); |
| 200 SendResponse(kHttpNotFound, MediaInfoLoader::kFailed); | 203 SendResponse(kHttpNotFound, MediaInfoLoader::kFailed); |
| 201 EXPECT_FALSE(loader_->DidPassCORSAccessCheck()); | 204 EXPECT_FALSE(loader_->DidPassCORSAccessCheck()); |
| 202 } | 205 } |
| 203 | 206 |
| 204 } // namespace content | 207 } // namespace content |
| OLD | NEW |