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/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
7 #include "content/renderer/media/android/media_info_loader.h" | 7 #include "content/renderer/media/android/media_info_loader.h" |
8 #include "content/test/mock_webframeclient.h" | 8 #include "content/test/mock_webframeclient.h" |
9 #include "content/test/mock_weburlloader.h" | 9 #include "content/test/mock_weburlloader.h" |
10 #include "third_party/WebKit/public/platform/WebURLError.h" | 10 #include "third_party/WebKit/public/platform/WebURLError.h" |
11 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 11 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
12 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 12 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
13 #include "third_party/WebKit/public/web/WebMediaPlayer.h" | 13 #include "third_party/WebKit/public/web/WebMediaPlayer.h" |
14 #include "third_party/WebKit/public/web/WebView.h" | 14 #include "third_party/WebKit/public/web/WebView.h" |
15 | 15 |
16 using ::testing::_; | 16 using ::testing::_; |
17 using ::testing::InSequence; | 17 using ::testing::InSequence; |
18 using ::testing::NiceMock; | 18 using ::testing::NiceMock; |
19 | 19 |
20 using WebKit::WebString; | 20 using blink::WebString; |
21 using WebKit::WebURLError; | 21 using blink::WebURLError; |
22 using WebKit::WebURLResponse; | 22 using blink::WebURLResponse; |
23 using WebKit::WebView; | 23 using blink::WebView; |
24 | 24 |
25 namespace content { | 25 namespace content { |
26 | 26 |
27 static const char* kHttpUrl = "http://test"; | 27 static const char* kHttpUrl = "http://test"; |
28 static const char kHttpRedirectToSameDomainUrl1[] = "http://test/ing"; | 28 static const char kHttpRedirectToSameDomainUrl1[] = "http://test/ing"; |
29 static const char kHttpRedirectToSameDomainUrl2[] = "http://test/ing2"; | 29 static const char kHttpRedirectToSameDomainUrl2[] = "http://test/ing2"; |
30 static const char kHttpRedirectToDifferentDomainUrl1[] = "http://test2"; | 30 static const char kHttpRedirectToDifferentDomainUrl1[] = "http://test2"; |
31 | 31 |
32 static const int kHttpOK = 200; | 32 static const int kHttpOK = 200; |
33 static const int kHttpNotFound = 404; | 33 static const int kHttpNotFound = 404; |
34 | 34 |
35 class MediaInfoLoaderTest : public testing::Test { | 35 class MediaInfoLoaderTest : public testing::Test { |
36 public: | 36 public: |
37 MediaInfoLoaderTest() | 37 MediaInfoLoaderTest() |
38 : view_(WebView::create(NULL)) { | 38 : view_(WebView::create(NULL)) { |
39 view_->initializeMainFrame(&client_); | 39 view_->initializeMainFrame(&client_); |
40 } | 40 } |
41 | 41 |
42 virtual ~MediaInfoLoaderTest() { | 42 virtual ~MediaInfoLoaderTest() { |
43 view_->close(); | 43 view_->close(); |
44 } | 44 } |
45 | 45 |
46 void Initialize( | 46 void Initialize( |
47 const char* url, | 47 const char* url, |
48 WebKit::WebMediaPlayer::CORSMode cors_mode) { | 48 blink::WebMediaPlayer::CORSMode cors_mode) { |
49 gurl_ = GURL(url); | 49 gurl_ = GURL(url); |
50 | 50 |
51 loader_.reset(new MediaInfoLoader( | 51 loader_.reset(new MediaInfoLoader( |
52 gurl_, cors_mode, | 52 gurl_, cors_mode, |
53 base::Bind(&MediaInfoLoaderTest::ReadyCallback, | 53 base::Bind(&MediaInfoLoaderTest::ReadyCallback, |
54 base::Unretained(this)))); | 54 base::Unretained(this)))); |
55 | 55 |
56 // |test_loader_| will be used when Start() is called. | 56 // |test_loader_| will be used when Start() is called. |
57 url_loader_ = new NiceMock<MockWebURLLoader>(); | 57 url_loader_ = new NiceMock<MockWebURLLoader>(); |
58 loader_->test_loader_ = scoped_ptr<WebKit::WebURLLoader>(url_loader_); | 58 loader_->test_loader_ = scoped_ptr<blink::WebURLLoader>(url_loader_); |
59 } | 59 } |
60 | 60 |
61 void Start() { | 61 void Start() { |
62 InSequence s; | 62 InSequence s; |
63 EXPECT_CALL(*url_loader_, loadAsynchronously(_, _)); | 63 EXPECT_CALL(*url_loader_, loadAsynchronously(_, _)); |
64 loader_->Start(view_->mainFrame()); | 64 loader_->Start(view_->mainFrame()); |
65 } | 65 } |
66 | 66 |
67 void Stop() { | 67 void Stop() { |
68 InSequence s; | 68 InSequence s; |
69 EXPECT_CALL(*url_loader_, cancel()); | 69 EXPECT_CALL(*url_loader_, cancel()); |
70 loader_.reset(); | 70 loader_.reset(); |
71 } | 71 } |
72 | 72 |
73 void Redirect(const char* url) { | 73 void Redirect(const char* url) { |
74 GURL redirect_url(url); | 74 GURL redirect_url(url); |
75 WebKit::WebURLRequest new_request(redirect_url); | 75 blink::WebURLRequest new_request(redirect_url); |
76 WebKit::WebURLResponse redirect_response(gurl_); | 76 blink::WebURLResponse redirect_response(gurl_); |
77 | 77 |
78 loader_->willSendRequest(url_loader_, new_request, redirect_response); | 78 loader_->willSendRequest(url_loader_, new_request, redirect_response); |
79 | 79 |
80 base::MessageLoop::current()->RunUntilIdle(); | 80 base::MessageLoop::current()->RunUntilIdle(); |
81 } | 81 } |
82 | 82 |
83 void SendResponse( | 83 void SendResponse( |
84 int http_status, MediaInfoLoader::Status expected_status) { | 84 int http_status, MediaInfoLoader::Status expected_status) { |
85 EXPECT_CALL(*this, ReadyCallback(expected_status)); | 85 EXPECT_CALL(*this, ReadyCallback(expected_status)); |
86 EXPECT_CALL(*url_loader_, cancel()); | 86 EXPECT_CALL(*url_loader_, cancel()); |
(...skipping 22 matching lines...) Expand all Loading... |
109 MockWebFrameClient client_; | 109 MockWebFrameClient client_; |
110 WebView* view_; | 110 WebView* view_; |
111 | 111 |
112 base::MessageLoop message_loop_; | 112 base::MessageLoop message_loop_; |
113 | 113 |
114 private: | 114 private: |
115 DISALLOW_COPY_AND_ASSIGN(MediaInfoLoaderTest); | 115 DISALLOW_COPY_AND_ASSIGN(MediaInfoLoaderTest); |
116 }; | 116 }; |
117 | 117 |
118 TEST_F(MediaInfoLoaderTest, StartStop) { | 118 TEST_F(MediaInfoLoaderTest, StartStop) { |
119 Initialize(kHttpUrl, WebKit::WebMediaPlayer::CORSModeUnspecified); | 119 Initialize(kHttpUrl, blink::WebMediaPlayer::CORSModeUnspecified); |
120 Start(); | 120 Start(); |
121 Stop(); | 121 Stop(); |
122 } | 122 } |
123 | 123 |
124 TEST_F(MediaInfoLoaderTest, LoadFailure) { | 124 TEST_F(MediaInfoLoaderTest, LoadFailure) { |
125 Initialize(kHttpUrl, WebKit::WebMediaPlayer::CORSModeUnspecified); | 125 Initialize(kHttpUrl, blink::WebMediaPlayer::CORSModeUnspecified); |
126 Start(); | 126 Start(); |
127 FailLoad(); | 127 FailLoad(); |
128 } | 128 } |
129 | 129 |
130 TEST_F(MediaInfoLoaderTest, HasSingleOriginNoRedirect) { | 130 TEST_F(MediaInfoLoaderTest, HasSingleOriginNoRedirect) { |
131 // Make sure no redirect case works as expected. | 131 // Make sure no redirect case works as expected. |
132 Initialize(kHttpUrl, WebKit::WebMediaPlayer::CORSModeUnspecified); | 132 Initialize(kHttpUrl, blink::WebMediaPlayer::CORSModeUnspecified); |
133 Start(); | 133 Start(); |
134 SendResponse(kHttpOK, MediaInfoLoader::kOk); | 134 SendResponse(kHttpOK, MediaInfoLoader::kOk); |
135 EXPECT_TRUE(loader_->HasSingleOrigin()); | 135 EXPECT_TRUE(loader_->HasSingleOrigin()); |
136 } | 136 } |
137 | 137 |
138 TEST_F(MediaInfoLoaderTest, HasSingleOriginSingleRedirect) { | 138 TEST_F(MediaInfoLoaderTest, HasSingleOriginSingleRedirect) { |
139 // Test redirect to the same domain. | 139 // Test redirect to the same domain. |
140 Initialize(kHttpUrl, WebKit::WebMediaPlayer::CORSModeUnspecified); | 140 Initialize(kHttpUrl, blink::WebMediaPlayer::CORSModeUnspecified); |
141 Start(); | 141 Start(); |
142 Redirect(kHttpRedirectToSameDomainUrl1); | 142 Redirect(kHttpRedirectToSameDomainUrl1); |
143 SendResponse(kHttpOK, MediaInfoLoader::kOk); | 143 SendResponse(kHttpOK, MediaInfoLoader::kOk); |
144 EXPECT_TRUE(loader_->HasSingleOrigin()); | 144 EXPECT_TRUE(loader_->HasSingleOrigin()); |
145 } | 145 } |
146 | 146 |
147 TEST_F(MediaInfoLoaderTest, HasSingleOriginDoubleRedirect) { | 147 TEST_F(MediaInfoLoaderTest, HasSingleOriginDoubleRedirect) { |
148 // Test redirect twice to the same domain. | 148 // Test redirect twice to the same domain. |
149 Initialize(kHttpUrl, WebKit::WebMediaPlayer::CORSModeUnspecified); | 149 Initialize(kHttpUrl, blink::WebMediaPlayer::CORSModeUnspecified); |
150 Start(); | 150 Start(); |
151 Redirect(kHttpRedirectToSameDomainUrl1); | 151 Redirect(kHttpRedirectToSameDomainUrl1); |
152 Redirect(kHttpRedirectToSameDomainUrl2); | 152 Redirect(kHttpRedirectToSameDomainUrl2); |
153 SendResponse(kHttpOK, MediaInfoLoader::kOk); | 153 SendResponse(kHttpOK, MediaInfoLoader::kOk); |
154 EXPECT_TRUE(loader_->HasSingleOrigin()); | 154 EXPECT_TRUE(loader_->HasSingleOrigin()); |
155 } | 155 } |
156 | 156 |
157 TEST_F(MediaInfoLoaderTest, HasSingleOriginDifferentDomain) { | 157 TEST_F(MediaInfoLoaderTest, HasSingleOriginDifferentDomain) { |
158 // Test redirect to a different domain. | 158 // Test redirect to a different domain. |
159 Initialize(kHttpUrl, WebKit::WebMediaPlayer::CORSModeUnspecified); | 159 Initialize(kHttpUrl, blink::WebMediaPlayer::CORSModeUnspecified); |
160 Start(); | 160 Start(); |
161 Redirect(kHttpRedirectToDifferentDomainUrl1); | 161 Redirect(kHttpRedirectToDifferentDomainUrl1); |
162 SendResponse(kHttpOK, MediaInfoLoader::kOk); | 162 SendResponse(kHttpOK, MediaInfoLoader::kOk); |
163 EXPECT_FALSE(loader_->HasSingleOrigin()); | 163 EXPECT_FALSE(loader_->HasSingleOrigin()); |
164 } | 164 } |
165 | 165 |
166 TEST_F(MediaInfoLoaderTest, HasSingleOriginMultipleDomains) { | 166 TEST_F(MediaInfoLoaderTest, HasSingleOriginMultipleDomains) { |
167 // Test redirect to the same domain and then to a different domain. | 167 // Test redirect to the same domain and then to a different domain. |
168 Initialize(kHttpUrl, WebKit::WebMediaPlayer::CORSModeUnspecified); | 168 Initialize(kHttpUrl, blink::WebMediaPlayer::CORSModeUnspecified); |
169 Start(); | 169 Start(); |
170 Redirect(kHttpRedirectToSameDomainUrl1); | 170 Redirect(kHttpRedirectToSameDomainUrl1); |
171 Redirect(kHttpRedirectToDifferentDomainUrl1); | 171 Redirect(kHttpRedirectToDifferentDomainUrl1); |
172 SendResponse(kHttpOK, MediaInfoLoader::kOk); | 172 SendResponse(kHttpOK, MediaInfoLoader::kOk); |
173 EXPECT_FALSE(loader_->HasSingleOrigin()); | 173 EXPECT_FALSE(loader_->HasSingleOrigin()); |
174 } | 174 } |
175 | 175 |
176 TEST_F(MediaInfoLoaderTest, CORSAccessCheckPassed) { | 176 TEST_F(MediaInfoLoaderTest, CORSAccessCheckPassed) { |
177 Initialize(kHttpUrl, WebKit::WebMediaPlayer::CORSModeUseCredentials); | 177 Initialize(kHttpUrl, blink::WebMediaPlayer::CORSModeUseCredentials); |
178 Start(); | 178 Start(); |
179 SendResponse(kHttpOK, MediaInfoLoader::kOk); | 179 SendResponse(kHttpOK, MediaInfoLoader::kOk); |
180 EXPECT_TRUE(loader_->DidPassCORSAccessCheck()); | 180 EXPECT_TRUE(loader_->DidPassCORSAccessCheck()); |
181 } | 181 } |
182 | 182 |
183 TEST_F(MediaInfoLoaderTest, CORSAccessCheckFailed) { | 183 TEST_F(MediaInfoLoaderTest, CORSAccessCheckFailed) { |
184 Initialize(kHttpUrl, WebKit::WebMediaPlayer::CORSModeUseCredentials); | 184 Initialize(kHttpUrl, blink::WebMediaPlayer::CORSModeUseCredentials); |
185 Start(); | 185 Start(); |
186 SendResponse(kHttpNotFound, MediaInfoLoader::kFailed); | 186 SendResponse(kHttpNotFound, MediaInfoLoader::kFailed); |
187 EXPECT_FALSE(loader_->DidPassCORSAccessCheck()); | 187 EXPECT_FALSE(loader_->DidPassCORSAccessCheck()); |
188 } | 188 } |
189 | 189 |
190 } // namespace content | 190 } // namespace content |
OLD | NEW |