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_weburlloader.h" | 10 #include "content/test/mock_webassociatedurlloader.h" |
11 #include "third_party/WebKit/public/platform/WebMediaPlayer.h" | 11 #include "third_party/WebKit/public/platform/WebMediaPlayer.h" |
12 #include "third_party/WebKit/public/platform/WebURLError.h" | 12 #include "third_party/WebKit/public/platform/WebURLError.h" |
13 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 13 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
14 #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" | 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; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 const char* url, | 53 const char* url, |
54 blink::WebMediaPlayer::CORSMode cors_mode) { | 54 blink::WebMediaPlayer::CORSMode cors_mode) { |
55 gurl_ = GURL(url); | 55 gurl_ = GURL(url); |
56 | 56 |
57 loader_.reset(new MediaInfoLoader( | 57 loader_.reset(new MediaInfoLoader( |
58 gurl_, cors_mode, | 58 gurl_, cors_mode, |
59 base::Bind(&MediaInfoLoaderTest::ReadyCallback, | 59 base::Bind(&MediaInfoLoaderTest::ReadyCallback, |
60 base::Unretained(this)))); | 60 base::Unretained(this)))); |
61 | 61 |
62 // |test_loader_| will be used when Start() is called. | 62 // |test_loader_| will be used when Start() is called. |
63 url_loader_ = new NiceMock<MockWebURLLoader>(); | 63 url_loader_ = new NiceMock<MockWebAssociatedURLLoader>(); |
64 loader_->test_loader_ = std::unique_ptr<blink::WebURLLoader>(url_loader_); | 64 loader_->test_loader_ = |
| 65 std::unique_ptr<blink::WebAssociatedURLLoader>(url_loader_); |
65 } | 66 } |
66 | 67 |
67 void Start() { | 68 void Start() { |
68 InSequence s; | 69 InSequence s; |
69 EXPECT_CALL(*url_loader_, loadAsynchronously(_, _)); | 70 EXPECT_CALL(*url_loader_, loadAsynchronously(_, _)); |
70 loader_->Start(view_->mainFrame()); | 71 loader_->Start(view_->mainFrame()); |
71 } | 72 } |
72 | 73 |
73 void Stop() { | 74 void Stop() { |
74 InSequence s; | 75 InSequence s; |
75 EXPECT_CALL(*url_loader_, cancel()); | 76 EXPECT_CALL(*url_loader_, cancel()); |
76 loader_.reset(); | 77 loader_.reset(); |
77 } | 78 } |
78 | 79 |
79 void Redirect(const char* url) { | 80 void Redirect(const char* url) { |
80 GURL redirect_url(url); | 81 GURL redirect_url(url); |
81 blink::WebURLRequest new_request(redirect_url); | 82 blink::WebURLRequest new_request(redirect_url); |
82 blink::WebURLResponse redirect_response(gurl_); | 83 blink::WebURLResponse redirect_response(gurl_); |
83 | 84 |
84 loader_->willFollowRedirect(url_loader_, new_request, redirect_response); | 85 loader_->willFollowRedirect(new_request, redirect_response); |
85 | 86 |
86 base::RunLoop().RunUntilIdle(); | 87 base::RunLoop().RunUntilIdle(); |
87 } | 88 } |
88 | 89 |
89 void SendResponse( | 90 void SendResponse( |
90 int http_status, MediaInfoLoader::Status expected_status) { | 91 int http_status, MediaInfoLoader::Status expected_status) { |
91 EXPECT_CALL(*this, ReadyCallback(expected_status, _, _, _)); | 92 EXPECT_CALL(*this, ReadyCallback(expected_status, _, _, _)); |
92 EXPECT_CALL(*url_loader_, cancel()); | 93 EXPECT_CALL(*url_loader_, cancel()); |
93 | 94 |
94 WebURLResponse response(gurl_); | 95 WebURLResponse response(gurl_); |
95 response.setHTTPHeaderField(WebString::fromUTF8("Content-Length"), | 96 response.setHTTPHeaderField(WebString::fromUTF8("Content-Length"), |
96 WebString::fromUTF8("0")); | 97 WebString::fromUTF8("0")); |
97 response.setExpectedContentLength(0); | 98 response.setExpectedContentLength(0); |
98 response.setHTTPStatusCode(http_status); | 99 response.setHTTPStatusCode(http_status); |
99 loader_->didReceiveResponse(url_loader_, response); | 100 loader_->didReceiveResponse(response); |
100 } | 101 } |
101 | 102 |
102 void FailLoad() { | 103 void FailLoad() { |
103 EXPECT_CALL(*this, ReadyCallback( | 104 EXPECT_CALL(*this, ReadyCallback( |
104 MediaInfoLoader::kFailed, _, _, _)); | 105 MediaInfoLoader::kFailed, _, _, _)); |
105 loader_->didFail(url_loader_, WebURLError()); | 106 loader_->didFail(WebURLError()); |
106 } | 107 } |
107 | 108 |
108 MOCK_METHOD4(ReadyCallback, | 109 MOCK_METHOD4(ReadyCallback, |
109 void(MediaInfoLoader::Status, const GURL&, const GURL&, bool)); | 110 void(MediaInfoLoader::Status, const GURL&, const GURL&, bool)); |
110 | 111 |
111 protected: | 112 protected: |
112 GURL gurl_; | 113 GURL gurl_; |
113 | 114 |
114 std::unique_ptr<MediaInfoLoader> loader_; | 115 std::unique_ptr<MediaInfoLoader> loader_; |
115 NiceMock<MockWebURLLoader>* url_loader_; | 116 NiceMock<MockWebAssociatedURLLoader>* url_loader_; |
116 | 117 |
117 blink::WebFrameClient client_; | 118 blink::WebFrameClient client_; |
118 WebView* view_; | 119 WebView* view_; |
119 | 120 |
120 base::MessageLoop message_loop_; | 121 base::MessageLoop message_loop_; |
121 | 122 |
122 private: | 123 private: |
123 DISALLOW_COPY_AND_ASSIGN(MediaInfoLoaderTest); | 124 DISALLOW_COPY_AND_ASSIGN(MediaInfoLoaderTest); |
124 }; | 125 }; |
125 | 126 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 } | 196 } |
196 | 197 |
197 TEST_F(MediaInfoLoaderTest, CORSAccessCheckFailed) { | 198 TEST_F(MediaInfoLoaderTest, CORSAccessCheckFailed) { |
198 Initialize(kHttpUrl, blink::WebMediaPlayer::CORSModeUseCredentials); | 199 Initialize(kHttpUrl, blink::WebMediaPlayer::CORSModeUseCredentials); |
199 Start(); | 200 Start(); |
200 SendResponse(kHttpNotFound, MediaInfoLoader::kFailed); | 201 SendResponse(kHttpNotFound, MediaInfoLoader::kFailed); |
201 EXPECT_FALSE(loader_->DidPassCORSAccessCheck()); | 202 EXPECT_FALSE(loader_->DidPassCORSAccessCheck()); |
202 } | 203 } |
203 | 204 |
204 } // namespace content | 205 } // namespace content |
OLD | NEW |