| 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" | |
| 11 #include "content/test/mock_weburlloader.h" | 10 #include "content/test/mock_weburlloader.h" |
| 12 #include "third_party/WebKit/public/platform/WebMediaPlayer.h" | 11 #include "third_party/WebKit/public/platform/WebMediaPlayer.h" |
| 13 #include "third_party/WebKit/public/platform/WebURLError.h" | 12 #include "third_party/WebKit/public/platform/WebURLError.h" |
| 14 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 13 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 15 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 14 #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 frame_(WebLocalFrame::create(blink::WebTreeScopeType::Document, | 44 view_->setMainFrame( |
| 45 &client_)) { | 45 WebLocalFrame::create(blink::WebTreeScopeType::Document, &client_)); |
| 46 view_->setMainFrame(frame_); | |
| 47 } | 46 } |
| 48 | 47 |
| 49 virtual ~MediaInfoLoaderTest() { | 48 virtual ~MediaInfoLoaderTest() { |
| 50 view_->close(); | 49 view_->close(); |
| 51 frame_->close(); | |
| 52 } | 50 } |
| 53 | 51 |
| 54 void Initialize( | 52 void Initialize( |
| 55 const char* url, | 53 const char* url, |
| 56 blink::WebMediaPlayer::CORSMode cors_mode) { | 54 blink::WebMediaPlayer::CORSMode cors_mode) { |
| 57 gurl_ = GURL(url); | 55 gurl_ = GURL(url); |
| 58 | 56 |
| 59 loader_.reset(new MediaInfoLoader( | 57 loader_.reset(new MediaInfoLoader( |
| 60 gurl_, cors_mode, | 58 gurl_, cors_mode, |
| 61 base::Bind(&MediaInfoLoaderTest::ReadyCallback, | 59 base::Bind(&MediaInfoLoaderTest::ReadyCallback, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 | 107 |
| 110 MOCK_METHOD4(ReadyCallback, | 108 MOCK_METHOD4(ReadyCallback, |
| 111 void(MediaInfoLoader::Status, const GURL&, const GURL&, bool)); | 109 void(MediaInfoLoader::Status, const GURL&, const GURL&, bool)); |
| 112 | 110 |
| 113 protected: | 111 protected: |
| 114 GURL gurl_; | 112 GURL gurl_; |
| 115 | 113 |
| 116 std::unique_ptr<MediaInfoLoader> loader_; | 114 std::unique_ptr<MediaInfoLoader> loader_; |
| 117 NiceMock<MockWebURLLoader>* url_loader_; | 115 NiceMock<MockWebURLLoader>* url_loader_; |
| 118 | 116 |
| 119 MockWebFrameClient client_; | 117 blink::WebFrameClient client_; |
| 120 WebView* view_; | 118 WebView* view_; |
| 121 WebLocalFrame* frame_; | |
| 122 | 119 |
| 123 base::MessageLoop message_loop_; | 120 base::MessageLoop message_loop_; |
| 124 | 121 |
| 125 private: | 122 private: |
| 126 DISALLOW_COPY_AND_ASSIGN(MediaInfoLoaderTest); | 123 DISALLOW_COPY_AND_ASSIGN(MediaInfoLoaderTest); |
| 127 }; | 124 }; |
| 128 | 125 |
| 129 TEST_F(MediaInfoLoaderTest, StartStop) { | 126 TEST_F(MediaInfoLoaderTest, StartStop) { |
| 130 Initialize(kHttpUrl, blink::WebMediaPlayer::CORSModeUnspecified); | 127 Initialize(kHttpUrl, blink::WebMediaPlayer::CORSModeUnspecified); |
| 131 Start(); | 128 Start(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 } | 195 } |
| 199 | 196 |
| 200 TEST_F(MediaInfoLoaderTest, CORSAccessCheckFailed) { | 197 TEST_F(MediaInfoLoaderTest, CORSAccessCheckFailed) { |
| 201 Initialize(kHttpUrl, blink::WebMediaPlayer::CORSModeUseCredentials); | 198 Initialize(kHttpUrl, blink::WebMediaPlayer::CORSModeUseCredentials); |
| 202 Start(); | 199 Start(); |
| 203 SendResponse(kHttpNotFound, MediaInfoLoader::kFailed); | 200 SendResponse(kHttpNotFound, MediaInfoLoader::kFailed); |
| 204 EXPECT_FALSE(loader_->DidPassCORSAccessCheck()); | 201 EXPECT_FALSE(loader_->DidPassCORSAccessCheck()); |
| 205 } | 202 } |
| 206 | 203 |
| 207 } // namespace content | 204 } // namespace content |
| OLD | NEW |